You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For non-preemptible symbols in executables (static, dynamic, or PIE),
the 16-byte GD sequence:
66 48 8d 3d [rel32] leaq sym@tlsgd(%rip), %rdi
66 66 48 e8 [rel32] callq __tls_get_addr@PLT
is rewritten in-place to the LE form:
64 48 8b 04 25 00 00 00 00 movq %fs:0x0, %rax
48 8d 80 [imm32] leaq tpoff(%rax), %rax
This eliminates the 2-slot GD GOT pair, the R_X86_64_DTPMOD64 and
R_X86_64_DTPOFF64 dynamic relocations, and the __tls_get_addr PLT call.
Relaxation fires when:
- The symbol is non-preemptible and the output is an executable (static,
dynamic, or PIE) — LE requires the variable's TP-relative offset to be
a link-time constant, which holds only for the executable's own block
- The link is not partial (-r)
GD→LE is mandatory and fires regardless of --relax, matching lld and
bfd. The --relax flag governs optional relaxations (e.g. GOTPCRELX);
without GD→LE, executables fail with "undefined reference to
__tls_get_addr".
Approach
--------
- Scan: qualifying TLSGD relocations skip GOT-pair creation and are
recorded as candidates. The companion call reloc at TLSGD_offset+8
(R_X86_64_PLT32 for standard sequences, R_X86_64_GOTPCRELX for
-fno-plt) is tracked to suppress undefined-ref errors and skip GOT/PLT
allocation for __tls_get_addr.
- postProcessing: the TLSGD candidate loop always runs (mandatory).
The 16-byte rewrite uses finalizeTLSSymbol() to get the TP-relative
offset.
- Apply: early-return OK for candidates and companions to skip the
apply path, which has no GOT pair to reference.
- --trace=relax emits trace_relax_tlsgd_le for each relaxed reference.
Link modes
----------
Relaxation applies to static and dynamic executables and PIE, where the
variable's TP-relative offset is a link-time constant.
Tests:
- TLSGDRelax_StaticHidden
- TLSGDRelax_DynExeHidden
- TLSGDRelax_PIE_Hidden
- TLSGDRelax_SharedPreemptible_NoRelax
- TLSGDRelax_SharedHidden_NoRelax
- TLSGDRelax_PartialRelink
- TLSGDRelax_Trace
- TLSGDRelax_NoPLT
Fixes#1490
Signed-off-by: bsaharsh <[email protected]>
0 commit comments