[x86] Implement R_X86_64_TLSGD GD→LE TLS relaxation#1528
Open
Saharsh Burra (bsaharsh) wants to merge 1 commit into
Open
[x86] Implement R_X86_64_TLSGD GD→LE TLS relaxation#1528Saharsh Burra (bsaharsh) wants to merge 1 commit into
Saharsh Burra (bsaharsh) wants to merge 1 commit into
Conversation
Saharsh Burra (bsaharsh)
requested review from
Parth (parth-07) and
Shankar Easwaran (quic-seaswara)
as code owners
July 20, 2026 15:17
Parth (parth-07)
requested changes
Jul 20, 2026
Saharsh Burra (bsaharsh)
force-pushed
the
relaxation/TLS-GD-LE
branch
from
July 21, 2026 14:26
b1ae8f2 to
2bab0e2
Compare
Parth (parth-07)
self-requested a review
July 21, 2026 14:43
Parth (parth-07)
approved these changes
Jul 21, 2026
Saharsh Burra (bsaharsh)
force-pushed
the
relaxation/TLS-GD-LE
branch
from
July 22, 2026 04:48
2bab0e2 to
4eaad43
Compare
Contributor
Author
|
Have fixed the clang format and added the fixes comment. |
Saharsh Burra (bsaharsh)
force-pushed
the
relaxation/TLS-GD-LE
branch
from
July 22, 2026 05:32
4eaad43 to
29c590f
Compare
Steven Ramirez Rosa (Steven6798)
approved these changes
Jul 22, 2026
Contributor
|
the changes here also have GOTPCRELX, now since GOTPCRELX is merged, please rebase |
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 qualcomm#1490 Signed-off-by: bsaharsh <[email protected]>
Saharsh Burra (bsaharsh)
force-pushed
the
relaxation/TLS-GD-LE
branch
from
July 23, 2026 14:07
29c590f to
1b55ec6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements GD→LE TLS relaxation for R_X86_64_TLSGD relocations.
For non-preemptible symbols in executables, the 16-byte GD sequence is
rewritten in-place to the LE form when:
dynamic, or PIE)
GD→LE is mandatory and fires regardless of --relax, matching lld and
bfd. Without this relaxation, executables fail with "undefined reference
to __tls_get_addr".
The companion call relocation at TLSGD_offset+8 may be either
R_X86_64_PLT32 (standard) or R_X86_64_GOTPCRELX (-fno-plt). Both are
handled.
Note: This PR contains two commits. The first ([x86] Support
R_X86_64_GOTPCRELX relaxation) is a dependency
Tests:
Fixes #1490