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
Reproduce :
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