diff options
author | Fangrui Song <maskray@google.com> | 2023-03-10 11:53:32 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2023-03-10 11:53:32 -0800 |
commit | d58854b6dd88e05dbf2a5d1c32c5acb7bd6ea274 (patch) | |
tree | 35344b9a4158bf6262adbdad02be3875057e9de5 /bfd/elf64-x86-64.c | |
parent | 7f3294a9b784ad011624cace3a1e81e32f273030 (diff) | |
download | gdb-d58854b6dd88e05dbf2a5d1c32c5acb7bd6ea274.zip gdb-d58854b6dd88e05dbf2a5d1c32c5acb7bd6ea274.tar.gz gdb-d58854b6dd88e05dbf2a5d1c32c5acb7bd6ea274.tar.bz2 |
ld: Allow R_X86_64_GOTPCREL for call *__tls_get_addr@GOTPCREL(%rip)
_Thread_local int a;
int main() { return a; }
% gcc -fno-plt -fpic a.c -fuse-ld=bfd -Wa,-mrelax-relocations=no
/usr/bin/ld.bfd: /tmp/ccSSBgrg.o: TLS transition from R_X86_64_TLSGD to R_X86_64_GOTTPOFF against `a' at 0xd in section `.text' failed
/usr/bin/ld.bfd: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
This commit fixes the issue.
There is an argument that the -fno-plt TLS sequence was added after
R_X86_64_GOTPCRELX was required for call, so R_X86_64_GOTPCREL was
intended to be unsupported.
Unfortunately this standpoint has caused interop difficulty: some
projects specify -mrelax-relocations=no to build relocatable object
files compatible with older linkers (e.g.
https://github.com/IHaskell/IHaskell/issues/636) or do so by accident
(e.g. https://github.com/rust-lang/rust/pull/106511 not addressed as of
today). Many uses have not been cleaned up in practice, and compiling
with -fno-plt will lead to the `TLS transition from R_X86_64_TLSGD ...`
error which is hard to reason about.
There is another argument which may be weaker but relevant to the
necessity of -mrelax-relocations=no: HWAddressSanitizer x86-64 will
likely need some assembler support to disable relaxation. Without the
support and if the compiler needs to support many gas version, the
simplest solution would be to use -Wa,-mrelax-relocations=no.
PR ld/24784
* bfd/elf64-x86-64.c (elf_x86_64_check_tls_transition): Allow
R_X86_64_GOTPCREL.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r-- | bfd/elf64-x86-64.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 0aa9af5..dd987ee 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -1253,7 +1253,7 @@ elf_x86_64_check_tls_transition (bfd *abfd, if (largepic) return r_type == R_X86_64_PLTOFF64; else if (indirect_call) - return r_type == R_X86_64_GOTPCRELX; + return (r_type == R_X86_64_GOTPCRELX || r_type == R_X86_64_GOTPCREL); else return (r_type == R_X86_64_PC32 || r_type == R_X86_64_PLT32); } |