Skip to content

Weak undefined symbols causing wrong tpoff in Local Exec model #1540

Description

Reproduce :

cat > weak_tls.c <<\EOF
  extern __thread int weak_tls __attribute__((weak));
  __attribute__((visibility("hidden"))) __thread int real_tls;
  int *get_weak(void) { return &weak_tls; }
EOF

clang -target x86_64-linux-gnu -ftls-model=local-exec -c weak_tls.c -o weak_tls.o
LDs=(ld.eld ld.lld ld.bfd ld.mold ld.gold)
SFs=(eld    lld    bfd    mold    gold)

for i in "${!SFs[@]}"; do
  ${LDs[$i]} -static -e get_weak -o ${SFs[$i]}.out weak_tls.o
done

Results (real_tls = 4 bytes, templateSize = 4):
eld: lea -0x3(%rax),%rax tpoff = -3
lld: lea 0x0(%rax),%rax tpoff = 0
gold: lea -0x4(%rax),%rax tpoff = -4
bfd: lea -0x404004(%rax),%rax tpoff = -tp_addr
mold: lea -0x2022ac(%rax),%rax tpoff = -tp_addr

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingx86-64

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions