-
Notifications
You must be signed in to change notification settings - Fork 75
[X86] Fix R_X86_64_TPOFF32 against weak undefined TLS symbols #1646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rachit Mehta (rachitmeht)
wants to merge
1
commit into
qualcomm:main
Choose a base branch
from
rachitmeht:fix/weak-undef-tls-tpoff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .section .tdata, "awT", @progbits | ||
| .align 4 | ||
| .global real_tls | ||
| real_tls: | ||
| .long 0 | ||
|
|
||
| .section .data | ||
| .align 4 | ||
| result: | ||
| .long 0xdeadbeef | ||
| .reloc result, R_X86_64_TPOFF32, real_tls |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .weak weak_tls | ||
| .section .data | ||
| .align 4 | ||
| result: | ||
| .long 0xdeadbeef | ||
| .reloc result, R_X86_64_DTPOFF32, weak_tls |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .weak weak_tls | ||
| .section .data | ||
| .align 8 | ||
| result: | ||
| .quad 0xdeadbeefdeadbeef | ||
| .reloc result, R_X86_64_DTPOFF64, weak_tls |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .weak weak_tls | ||
| .section .data | ||
| .align 4 | ||
| result: | ||
| .long 0xdeadbeef | ||
| .reloc result, R_X86_64_TPOFF32, weak_tls |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .weak weak_tls | ||
| .section .data | ||
| .align 8 | ||
| result: | ||
| .quad 0xdeadbeefdeadbeef | ||
| .reloc result, R_X86_64_TPOFF64, weak_tls |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .weak weak_tls | ||
| .section .data | ||
| .align 4 | ||
| result: | ||
| .long 0xdeadbeef | ||
| .reloc result, R_X86_64_TPOFF32, weak_tls+2 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #--WeakUndefTLS.test----------Executable--------# | ||
| BEGIN_COMMENT | ||
| # Test R_X86_64_TPOFF32/64 and R_X86_64_DTPOFF32/64 relocations against | ||
| # weak undefined TLS symbols. A weak undefined TLS symbol has no TLS slot, | ||
| # so the tpoff formula must not run; the result is the addend only (= 0 | ||
| # for the common case). Mirrors lld's R_TPREL guard: | ||
| # if (sym.isUndefined()) return a; | ||
| # Also verifies that defined TLS symbols are unaffected (regression guard). | ||
| #END_COMMENT | ||
|
|
||
| #START_TEST | ||
|
|
||
| # Case 1: TPOFF32 + weak-undef -> 0x00000000 | ||
| RUN: %clang %clangopts -c %p/Inputs/weak_tls_le.s -o %t.le.o | ||
| RUN: %link %linkopts -static %t.le.o -o %t.le.exe | ||
| RUN: %objdump -s -j .data %t.le.exe | %filecheck %s --check-prefix=LE32 | ||
|
|
||
| # Case 2: TPOFF64 + weak-undef -> 0x0000000000000000 | ||
| RUN: %clang %clangopts -c %p/Inputs/weak_tls_le64.s -o %t.le64.o | ||
| RUN: %link %linkopts -static %t.le64.o -o %t.le64.exe | ||
| RUN: %objdump -s -j .data %t.le64.exe | %filecheck %s --check-prefix=LE64 | ||
|
|
||
| # Case 3: DTPOFF32 + weak-undef -> 0x00000000 | ||
| RUN: %clang %clangopts -c %p/Inputs/weak_tls_ld.s -o %t.ld.o | ||
| RUN: %link %linkopts -static %t.ld.o -o %t.ld.exe | ||
| RUN: %objdump -s -j .data %t.ld.exe | %filecheck %s --check-prefix=LD32 | ||
|
|
||
| # Case 4: DTPOFF64 + weak-undef -> 0x0000000000000000 | ||
| RUN: %clang %clangopts -c %p/Inputs/weak_tls_ld64.s -o %t.ld64.o | ||
| RUN: %link %linkopts -static %t.ld64.o -o %t.ld64.exe | ||
| RUN: %objdump -s -j .data %t.ld64.exe | %filecheck %s --check-prefix=LD64 | ||
|
|
||
| # Case 5: TPOFF32 + defined symbol -> -4 = 0xfffffffc (regression guard) | ||
| RUN: %clang %clangopts -c %p/Inputs/weak_tls_defined.s -o %t.def.o | ||
| RUN: %link %linkopts -static %t.def.o -o %t.def.exe | ||
| RUN: %objdump -s -j .data %t.def.exe | %filecheck %s --check-prefix=DEFINED | ||
|
|
||
| # 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: %objdump -s -j .data %t.addend.exe | %filecheck %s --check-prefix=ADDEND | ||
|
|
||
| LE32: Contents of section .data: | ||
| LE32-NEXT: {{[0-9a-f]+}} 00000000 | ||
|
|
||
| LE64: Contents of section .data: | ||
| LE64-NEXT: {{[0-9a-f]+}} 00000000 00000000 | ||
|
|
||
| LD32: Contents of section .data: | ||
| LD32-NEXT: {{[0-9a-f]+}} 00000000 | ||
|
|
||
| LD64: Contents of section .data: | ||
| LD64-NEXT: {{[0-9a-f]+}} 00000000 00000000 | ||
|
|
||
| DEFINED: Contents of section .data: | ||
| DEFINED-NEXT: {{[0-9a-f]+}} fcffffff | ||
|
|
||
| ADDEND: Contents of section .data: | ||
| ADDEND-NEXT: {{[0-9a-f]+}} 02000000 | ||
|
|
||
| #END_TEST |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about shared/pie ?
what is the difference for other targets ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TPOFF handling for Weak undef is not done for other architectures also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.