[PATCH] D62106: [X86] Support -fno-plt __tls_get_addr calls
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 7 05:47:12 PDT 2019
MaskRay added a comment.
In D62106#1572575 <https://reviews.llvm.org/D62106#1572575>, @nikic wrote:
> I'm seeing linker failures that I suspect are related to this change:
>
> /usr/bin/ld: /home/nikic/rust/foo/libtest2.rlib(test2.test2.3a1fbbbh-cgu.0.rcgu.o): TLS transition from R_X86_64_TLSLD to R_X86_64_TPOFF32 against `_ZN5test24TEST17h9cebda1c5e0bffdeE' at 0x4 in section `.text._ZN5test28get_test17h7831513ccc936b83E' failed
>
>
> Old:
>
> 0000000000000000 <_ZN5test28get_test17h7831513ccc936b83E>:
> 0: 50 push %rax
> 1: 48 8d 3d 00 00 00 00 lea 0x0(%rip),%rdi # 8 <_ZN5test28get_test17h7831513ccc936b83E+0x8>
> 4: R_X86_64_TLSLD _ZN5test24TEST17h9cebda1c5e0bffdeE-0x4
> 8: e8 00 00 00 00 callq d <_ZN5test28get_test17h7831513ccc936b83E+0xd>
> 9: R_X86_64_PLT32 __tls_get_addr-0x4
> d: 48 8b 80 00 00 00 00 mov 0x0(%rax),%rax
> 10: R_X86_64_DTPOFF32 _ZN5test24TEST17h9cebda1c5e0bffdeE
> 14: 59 pop %rcx
> 15: c3 retq
>
>
> New:
>
> 0000000000000000 <_ZN5test28get_test17h7831513ccc936b83E>:
> 0: 50 push %rax
> 1: 48 8d 3d 00 00 00 00 lea 0x0(%rip),%rdi # 8 <_ZN5test28get_test17h7831513ccc936b83E+0x8>
> 4: R_X86_64_TLSLD _ZN5test24TEST17h9cebda1c5e0bffdeE-0x4
> 8: ff 15 00 00 00 00 callq *0x0(%rip) # e <_ZN5test28get_test17h7831513ccc936b83E+0xe>
> a: R_X86_64_GOTPCREL __tls_get_addr-0x4
> e: 48 8b 80 00 00 00 00 mov 0x0(%rax),%rax
> 11: R_X86_64_DTPOFF32 _ZN5test24TEST17h9cebda1c5e0bffdeE
> 15: 59 pop %rcx
> 16: c3 retq
>
>
> I'm not really familiar with TLS relocations -- do you have any pointers on what could be going wrong here?
% clang -fno-plt -fpic a.cc -Wa,-mrelax-relocations=no -fuse-ld=gold
% clang -fno-plt -fpic a.cc -Wa,-mrelax-relocations=no -fuse-ld=lld
% clang -fno-plt -fpic a.cc -Wa,-mrelax-relocations=no -fuse-ld=bfd
/usr/bin/ld.bfd: /tmp/a-9fd9f7.o: TLS transition from R_X86_64_TLSLD to R_X86_64_TPOFF32 against `_ZL1a' at 0x17 in section `.text' failed
# bfd/elf-x86-64.c:elf_x86_64_check_tls_transition
...
if (largepic)
return r_type == R_X86_64_PLTOFF64;
else if (indirect_call)
return r_type == R_X86_64_GOTPCRELX; // it doesn't allow R_X86_64_GOTPCREL
else
return (r_type == R_X86_64_PC32 || r_type == R_X86_64_PLT32);
ld.bfd doesn't allow R_X86_64_GOTPCREL. You can work around the issue with:
% clang -fno-plt -fpic a.cc -Wa,-mrelax-relocations=yes -fuse-ld=bfd
I'll file a bug against binutils-gdb.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62106/new/
https://reviews.llvm.org/D62106
More information about the llvm-commits
mailing list