[X86] Fix R_X86_64_TPOFF32 against weak undefined TLS symbols - #1646
Open
Rachit Mehta (rachitmeht) wants to merge 1 commit into
Open
[X86] Fix R_X86_64_TPOFF32 against weak undefined TLS symbols#1646Rachit Mehta (rachitmeht) wants to merge 1 commit into
Rachit Mehta (rachitmeht) wants to merge 1 commit into
Conversation
Rachit Mehta (rachitmeht)
requested review from
Parth (parth-07) and
Shankar Easwaran (quic-seaswara)
as code owners
August 6, 2026 09:14
Shankar Easwaran (quic-seaswara)
requested changes
Aug 7, 2026
| // be 0 instead of 1 (true). | ||
| if (!pSymbol->hasFragRef()) | ||
| return true; | ||
| return false; |
Contributor
There was a problem hiding this comment.
This should be a seperate change.
| (pParent.config().codeGenType() == LinkerConfig::Exec)) { | ||
| Relocator::DWord A = pReloc.addend(); | ||
| return ApplyReloc(pReloc, A, pRelocDesc, DiagEngine, options, pParent); | ||
| } |
Contributor
There was a problem hiding this comment.
What about shared/pie ?
what is the difference for other targets ?
There was a problem hiding this comment.
TPOFF handling for Weak undef is not done for other architectures also.
There was a problem hiding this comment.
I copied the check from relocAbs(), it mentions that weak-undef symbol resolving to 0 is only the correct link-time behavior in a static executable. So, for a shared/PIE, an unresolved symbol should be handled via dynamic relocations.
| # Case 6: TPOFF32 + weak-undef + addend=2 -> 0x00000002 | ||
| RUN: %clang %clangopts -c %p/Inputs/weak_tls_le_addend.s -o %t.addend.o | ||
| RUN: %link %linkopts -static %t.addend.o -o %t.addend.exe | ||
| RUN: llvm-objdump -s -j .data %t.addend.exe | FileCheck %s --check-prefix=ADDEND |
Contributor
There was a problem hiding this comment.
%objdump
A weak undefined TLS symbol has no slot in the PT_TLS segment, so the thread-pointer-offset formula (S - templateSize) is meaningless for it. Previously relocTPOFF applied that formula with a bogus symbol value, producing an incorrect tpoff (e.g. -3) instead of the correct 0. Fix: add a weak-undef guard in relocTPOFF mirroring lld's R_TPREL handling (if (sym.isUndefined()) return a) and the existing guard in relocAbs (line 638). Add x86_64/linux/WeakUndefTLS covering TPOFF32/64 and DTPOFF32/64 against weak-undef symbols, a defined-symbol regression guard, and a non-zero addend case. Resolves qualcomm#1540 Signed-off-by: Rachit Mehta <rachmeht@qti.qualcomm.com>
Rachit Mehta (rachitmeht)
force-pushed
the
fix/weak-undef-tls-tpoff
branch
from
August 10, 2026 04:29
dc53d25 to
67a06c5
Compare
Rachit Mehta (rachitmeht)
requested a review
from Shankar Easwaran (quic-seaswara)
August 10, 2026 04:32
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.
A weak undefined TLS symbol has no slot in the PT_TLS segment, so the thread-pointer-offset formula (S - templateSize) is meaningless for it. Previously relocTPOFF applied that formula with a bogus symbol value, producing an incorrect tpoff (e.g. -3) instead of the correct 0.
Two fixes, comparing lld's R_TPREL handling:
Add x86_64/linux/WeakUndefTLS covering TPOFF32/64 and DTPOFF32/64 against weak-undef symbols, a defined-symbol regression guard, and a non-zero addend case.
Resolves #1540