-
Notifications
You must be signed in to change notification settings - Fork 63
ARM: support R_ARM_THM_JUMP19 relocation in THM stubs #1127
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
sai18022001
wants to merge
2
commits into
qualcomm:main
Choose a base branch
from
sai18022001:fix/r-arm-thm-jump19-stub-support
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -92,7 +92,9 @@ bool THMToTHMStub::isNeeded(const Relocation *pReloc, int64_t pTargetValue, | |
| Module &Module) const { | ||
| int64_t Offset = 0; | ||
| // This stub cannot be used for ARM target. | ||
| if ((pTargetValue & 0x1) == 0) | ||
| if ((pTargetValue & 0x1) == 0 && | ||
| pReloc->type() != llvm::ELF::R_ARM_THM_JUMP19 && | ||
| pReloc->type() != llvm::ELF::R_ARM_THM_JUMP24) | ||
| return false; | ||
| // The stub is needed only if the target is unreachable | ||
| return !isRelocInRange(pReloc, pTargetValue, Offset, Module); | ||
|
|
@@ -107,11 +109,13 @@ bool THMToTHMStub::isRelocInRange(const Relocation *pReloc, | |
| Offset = pTargetValue + addend - pReloc->place(Module); | ||
| switch (pReloc->type()) { | ||
| case llvm::ELF::R_ARM_THM_JUMP24: | ||
| case llvm::ELF::R_ARM_THM_CALL: { | ||
| case llvm::ELF::R_ARM_THM_CALL:{ | ||
| if (m_Target->isJ1J2BranchEncoding()) | ||
| return llvm::isInt<THM2_MAX_BRANCH_BITS>(Offset); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix |
||
| return llvm::isInt<THM_MAX_BRANCH_BITS>(Offset); | ||
| } | ||
| case llvm::ELF::R_ARM_THM_JUMP19: | ||
| return llvm::isInt<21>(Offset); | ||
| default: | ||
| break; | ||
| } | ||
|
|
||
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,30 @@ | ||
| // Tests that R_ARM_THM_JUMP19 (conditional branch) links successfully | ||
| // for an in-range target without requiring a stub. | ||
| // Regression test for https://github.com/qualcomm/eld/issues/1005 | ||
|
|
||
| // RUN: %clang %clangopts %s -o %t.o -c --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=soft | ||
| // RUN: %link %linkopts %t.o -o %t.out --entry=my_func -static | ||
| // RUN: %objdump -d %t.out | %filecheck %s | ||
|
|
||
| // CHECK: <my_func>: | ||
| // CHECK: {{.*}} beq.w {{.*}} <plain_entry> | ||
|
|
||
| // CHECK: <plain_entry>: | ||
| // CHECK-NEXT: {{.*}} bx lr | ||
|
|
||
| .syntax unified | ||
| .thumb | ||
|
|
||
| .section .text.caller, "ax", %progbits | ||
| .thumb_func | ||
| .global my_func | ||
| .type my_func, %function | ||
| my_func: | ||
| cmp r0, #0 | ||
| beq plain_entry | ||
| bx lr | ||
|
|
||
| .section .text.target, "ax", %progbits | ||
| .global plain_entry | ||
| plain_entry: | ||
| bx lr |
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,22 @@ | ||
| // Tests that R_ARM_THM_JUMP19 correctly emits a detailed error | ||
| // when attempting to branch to a PLT entry. | ||
| // Regression test for https://github.com/qualcomm/eld/issues/1005 | ||
|
|
||
| // RUN: %clang %clangopts %s -o %t.o -c --target=arm-none-eabi -march=armv7-a | ||
| // RUN: not %link %linkopts -shared %t.o -o %t.so 2>&1 | %filecheck %s | ||
|
|
||
| // CHECK: Error: | ||
| // CHECK-SAME: conditional branch to PLT in THUMB-2 not supported yet for symbol `extern_func' | ||
| // CHECK-SAME: [.text.caller][.text.caller] | ||
|
|
||
| .syntax unified | ||
| .thumb | ||
|
|
||
| .section .text.caller, "ax", %progbits | ||
| .thumb_func | ||
| .global my_func | ||
| .type my_func, %function | ||
| my_func: | ||
| cmp r0, #0 | ||
| beq extern_func // Conditional branch to an undefined external symbol | ||
| bx lr |
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,41 @@ | ||
| // Tests that R_ARM_THM_JUMP19 (conditional branch) produces both T2T and T2A veneers | ||
| // when the targets are out of range (beyond 21-bit range). | ||
| // Regression test for https://github.com/qualcomm/eld/issues/1005 | ||
|
|
||
| // RUN: %clang %clangopts %s -o %t.o -c --target=arm-none-eabi -march=armv7-a -mfloat-abi=soft | ||
| // RUN: echo "SECTIONS { .text.caller 0x0 : { *(.text.caller) } .text.thumb_target 0x200000 : { *(.text.thumb_target) } .text.arm_target 0x400000 : { *(.text.arm_target) } }" > %t.script | ||
| // RUN: %link %linkopts -T %t.script %t.o -o %t.out --entry=my_func -static --trace=trampolines 2>&1 | %filecheck %s | ||
|
|
||
| // CHECK: Creating Stub __thumb_target_{{.*}}veneer@island-{{.*}} | ||
| // CHECK: Creating Stub __arm_target_{{.*}}veneer@island-{{.*}} | ||
|
|
||
| .syntax unified | ||
|
|
||
| // --- CALLER (Thumb) --- | ||
| .section .text.caller, "ax", %progbits | ||
| .thumb | ||
| .thumb_func | ||
| .global my_func | ||
| .type my_func, %function | ||
| my_func: | ||
| cmp r0, #0 | ||
| beq thumb_target // Triggers T2T Veneer | ||
| beq arm_target // Triggers T2A Veneer | ||
| bx lr | ||
|
|
||
| // --- TARGET 1 (Thumb) --- | ||
| .section .text.thumb_target, "ax", %progbits | ||
| .thumb | ||
| .thumb_func | ||
| .global thumb_target | ||
| .type thumb_target, %function | ||
| thumb_target: | ||
| bx lr | ||
|
|
||
| // --- TARGET 2 (ARM) --- | ||
| .section .text.arm_target, "ax", %progbits | ||
| .arm | ||
| .global arm_target | ||
| .type arm_target, %function | ||
| arm_target: | ||
| bx lr |
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.
same here
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.
Same fix for this too.