-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them for all pre-v7 targets #79082
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
Merged
weliveindetail
merged 4 commits into
llvm:main
from
weliveindetail:jitlink-aarch32-pre-v7
Jan 23, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c206fb2
[JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them for all …
weliveindetail 646898b
[JITLink][AArch32] Expand tests to non-v7 targets
weliveindetail b29100b
fixup! [JITLink][AArch32] Implement Armv5 ldr-pc stubs and use them f…
weliveindetail 559606e
Add multi-stub support for Armv5 ldr-pc
weliveindetail 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -725,6 +725,13 @@ bool GOTBuilder::visitEdge(LinkGraph &G, Block *B, Edge &E) { | |
return true; | ||
} | ||
|
||
const uint8_t ArmThumbv5LdrPc[] = { | ||
0x78, 0x47, // bx pc | ||
0xfd, 0xe7, // b #-6 ; Arm recommended sequence to follow bx pc | ||
0x04, 0xf0, 0x1f, 0xe5, // ldr pc, [pc,#-4] ; L1 | ||
0x00, 0x00, 0x00, 0x00, // L1: .word S | ||
}; | ||
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. Extended the |
||
|
||
const uint8_t Armv7ABS[] = { | ||
0x00, 0xc0, 0x00, 0xe3, // movw r12, #0x0000 ; lower 16-bit | ||
0x00, 0xc0, 0x40, 0xe3, // movt r12, #0x0000 ; upper 16-bit | ||
|
@@ -745,6 +752,12 @@ static Block &allocStub(LinkGraph &G, Section &S, const uint8_t (&Code)[Size]) { | |
return G.createContentBlock(S, Template, orc::ExecutorAddr(), Alignment, 0); | ||
} | ||
|
||
static Block &createStubPrev7(LinkGraph &G, Section &S, Symbol &Target) { | ||
Block &B = allocStub(G, S, ArmThumbv5LdrPc); | ||
B.addEdge(Data_Pointer32, 8, Target, 0); | ||
return B; | ||
} | ||
|
||
static Block &createStubThumbv7(LinkGraph &G, Section &S, Symbol &Target) { | ||
Block &B = allocStub(G, S, Thumbv7ABS); | ||
B.addEdge(Thumb_MovwAbsNC, 0, Target, 0); | ||
|
@@ -802,6 +815,60 @@ static bool needsStub(const Edge &E) { | |
return false; | ||
} | ||
|
||
// The ArmThumbv5LdrPc stub has 2 entrypoints: Thumb at offset 0 is taken only | ||
// for Thumb B instructions. Thumb BL is rewritten to BLX and takes the Arm | ||
// entrypoint at offset 4. Arm branches always use that one. | ||
Symbol *StubsManager_prev7::getOrCreateSlotEntrypoint(LinkGraph &G, | ||
StubMapEntry &Slot, | ||
bool Thumb) { | ||
constexpr orc::ExecutorAddrDiff ThumbEntrypointOffset = 0; | ||
constexpr orc::ExecutorAddrDiff ArmEntrypointOffset = 4; | ||
if (Thumb && !Slot.ThumbEntry) { | ||
Slot.ThumbEntry = | ||
&G.addAnonymousSymbol(*Slot.B, ThumbEntrypointOffset, 4, true, false); | ||
Slot.ThumbEntry->setTargetFlags(ThumbSymbol); | ||
} | ||
if (!Thumb && !Slot.ArmEntry) | ||
Slot.ArmEntry = | ||
&G.addAnonymousSymbol(*Slot.B, ArmEntrypointOffset, 8, true, false); | ||
return Thumb ? Slot.ThumbEntry : Slot.ArmEntry; | ||
} | ||
|
||
bool StubsManager_prev7::visitEdge(LinkGraph &G, Block *B, Edge &E) { | ||
if (!needsStub(E)) | ||
return false; | ||
|
||
Symbol &Target = E.getTarget(); | ||
assert(Target.hasName() && "Edge cannot point to anonymous target"); | ||
auto [Slot, NewStub] = getStubMapSlot(Target.getName()); | ||
|
||
if (NewStub) { | ||
if (!StubsSection) | ||
StubsSection = &G.createSection(getSectionName(), | ||
orc::MemProt::Read | orc::MemProt::Exec); | ||
LLVM_DEBUG({ | ||
dbgs() << " Created stub entry for " << Target.getName() << " in " | ||
<< StubsSection->getName() << "\n"; | ||
}); | ||
Slot->B = &createStubPrev7(G, *StubsSection, Target); | ||
} | ||
|
||
// The ArmThumbv5LdrPc stub has 2 entrypoints: Thumb at offset 0 is taken only | ||
// for Thumb B instructions. Thumb BL is rewritten to BLX and takes the Arm | ||
// entrypoint at offset 4. Arm branches always use that one. | ||
bool UseThumb = E.getKind() == Thumb_Jump24; | ||
Symbol *StubEntrypoint = getOrCreateSlotEntrypoint(G, *Slot, UseThumb); | ||
|
||
LLVM_DEBUG({ | ||
dbgs() << " Using " << (UseThumb ? "Thumb" : "Arm") << " entrypoint " | ||
<< *StubEntrypoint << " in " | ||
<< StubEntrypoint->getBlock().getSection().getName() << "\n"; | ||
}); | ||
|
||
E.setTarget(*StubEntrypoint); | ||
return true; | ||
} | ||
|
||
bool StubsManager_v7::visitEdge(LinkGraph &G, Block *B, Edge &E) { | ||
if (!needsStub(E)) | ||
return false; | ||
|
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
49 changes: 49 additions & 0 deletions
49
llvm/test/ExecutionEngine/JITLink/AArch32/ELF_relocations_armv7plus.s
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,49 @@ | ||
# Test v7 Arm features | ||
# | ||
# RUN: llvm-mc -triple=armv7-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t_armv7.o %s | ||
# RUN: llvm-objdump -r %t_armv7.o | FileCheck --check-prefix=CHECK-TYPE %s | ||
# RUN: llvm-objdump --disassemble %t_armv7.o | FileCheck --check-prefix=CHECK-INSTR %s | ||
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb \ | ||
# RUN: -slab-page-size 4096 -abs data_symbol=0x00001234 -check %s %t_armv7.o | ||
# | ||
# RUN: llvm-mc -triple=armv9-linux-gnueabi -arm-add-build-attributes -filetype=obj -o %t_armv9.o %s | ||
# RUN: llvm-objdump -r %t_armv9.o | FileCheck --check-prefix=CHECK-TYPE %s | ||
# RUN: llvm-objdump --disassemble %t_armv9.o | FileCheck --check-prefix=CHECK-INSTR %s | ||
# RUN: llvm-jitlink -noexec -slab-address 0x76ff0000 -slab-allocate 10Kb \ | ||
# RUN: -slab-page-size 4096 -abs data_symbol=0x00001234 -check %s %t_armv9.o | ||
|
||
|
||
.text | ||
.syntax unified | ||
|
||
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_MOVW_ABS_NC data_symbol | ||
# CHECK-INSTR: <movw>: | ||
# CHECK-INSTR: e3000000 movw r0, #0x0 | ||
# jitlink-check: decode_operand(movw, 1) = data_symbol[15:0] | ||
.globl movw | ||
.type movw,%function | ||
.p2align 2 | ||
movw: | ||
movw r0, :lower16:data_symbol | ||
.size movw, .-movw | ||
|
||
# CHECK-TYPE: {{[0-9a-f]+}} R_ARM_MOVT_ABS data_symbol | ||
# CHECK-INSTR: <movt>: | ||
# CHECK-INSTR: e3400000 movt r0, #0x0 | ||
# We decode the operand with index 2, because movt generates one leading implicit | ||
# predicate operand that we have to skip in order to decode the data_symbol operand | ||
# jitlink-check: decode_operand(movt, 2) = data_symbol[31:16] | ||
.globl movt | ||
.type movt,%function | ||
.p2align 2 | ||
movt: | ||
movt r0, :upper16:data_symbol | ||
.size movt, .-movt | ||
|
||
# Empty main function for jitlink to be happy | ||
.globl main | ||
.type main,%function | ||
.p2align 2 | ||
main: | ||
bx lr | ||
.size main, .-main |
7 changes: 6 additions & 1 deletion
7
llvm/test/ExecutionEngine/JITLink/AArch32/ELF_relocations_data.s
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
Oops, something went wrong.
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.
(Unrelated change that is on mainline already)