Hi,
I decided to breakout part of
https://groups.google.com/g/x86-64-abi/c/iEwXPVq48i4/m/1qns04tICAAJ
into it's own topic, specificaly about TLS relocation overflows.
Here is an example of a relocation overflow I've run into:
ld.lld: error: ...libgen_patch_client_config-cpp2-types...o:
relocation R_X86_64_PLT32 out of range:
2636113542 is not in
[-2147483648,
2147483647];
references '__tls_get_addr'
>>> defined in fbcode/third-party-buck/platform010/build/glibc/lib/ld-linux-x86-64.so.2
RELOCATION: R_X86_64_TLSGD ... offset in output section .ltext ... 2.04 GiB
TARGET: folly::SharedMutexImpl<...>::tls_lastTokenlessSlot()::tl (.tbss)
output section .tbss address 0xd1a7c6a0 (~3.52 GB)
I will admit my knowledge about TLS is relatively minimal especially
when it comes to relocations.
I decided to do a somewhat deep-dive into it and wrote-up the
following to describe the failure mode:
https://fzakaria.com/2026/07/26/seriously-what-is-the-large-code-model-even-for
Knowledge about TLS online is varied and sparse. I tried to root it in
the ABI and what clang/gcc emits.)
tl;dr;
Looks like the ABI for TLS code-sequences always rely on 32-bit offsets.
- local-exec: Uses R_X86_64_TPOFF32 which is 32-bit
- initial-exec: Uses GOTTPOFF which is 32 bit
- general-dynamic: Uses R_X86_64_TLSGD which is 32 bit
The easiest to fix seems initial-exec since we can replace GOTTPOFF
with GOTPC64/GOT64 equivalent. We can/should probably also expand the
ABI to include a code sequence for R_X86_64_TPOFF64 with
mcmodel=large.