-
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 3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -725,6 +725,49 @@ bool GOTBuilder::visitEdge(LinkGraph &G, Block *B, Edge &E) { | |
return true; | ||
} | ||
|
||
/// Create a new node in the link-graph for the given stub template. | ||
template <size_t Size> | ||
static Block &allocStub(LinkGraph &G, Section &S, const uint8_t (&Code)[Size]) { | ||
constexpr uint64_t Alignment = 4; | ||
ArrayRef<char> Template(reinterpret_cast<const char *>(Code), Size); | ||
return G.createContentBlock(S, Template, orc::ExecutorAddr(), Alignment, 0); | ||
} | ||
|
||
const uint8_t Armv5LongLdrPc[] = { | ||
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 |
||
|
||
Symbol &StubsManager_prev7::createEntry(LinkGraph &G, Symbol &Target) { | ||
Block &B = allocStub(G, getStubsSection(G), Armv5LongLdrPc); | ||
B.addEdge(Data_Pointer32, 4, Target, 0); | ||
return G.addAnonymousSymbol(B, 0, B.getSize(), true, false); | ||
} | ||
|
||
bool StubsManager_prev7::visitEdge(LinkGraph &G, Block *B, Edge &E) { | ||
if (E.getTarget().isDefined()) | ||
return false; | ||
|
||
switch (E.getKind()) { | ||
case Arm_Call: | ||
case Arm_Jump24: { | ||
DEBUG_WITH_TYPE("jitlink", { | ||
dbgs() << " Fixing " << G.getEdgeKindName(E.getKind()) << " edge at " | ||
<< B->getFixupAddress(E) << " (" << B->getAddress() << " + " | ||
<< formatv("{0:x}", E.getOffset()) << ")\n"; | ||
}); | ||
E.setTarget(this->getEntryForTarget(G, E.getTarget())); | ||
return true; | ||
} | ||
case Thumb_Call: | ||
case Thumb_Jump24: | ||
// BL is never out-of-range and can always be rewritten to BLX inline. | ||
weliveindetail marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// B can not target an external. | ||
break; | ||
} | ||
return false; | ||
} | ||
|
||
const uint8_t Armv7ABS[] = { | ||
0x00, 0xc0, 0x00, 0xe3, // movw r12, #0x0000 ; lower 16-bit | ||
0x00, 0xc0, 0x40, 0xe3, // movt r12, #0x0000 ; upper 16-bit | ||
|
@@ -737,14 +780,6 @@ const uint8_t Thumbv7ABS[] = { | |
0x60, 0x47 // bx r12 | ||
}; | ||
|
||
/// Create a new node in the link-graph for the given stub template. | ||
template <size_t Size> | ||
static Block &allocStub(LinkGraph &G, Section &S, const uint8_t (&Code)[Size]) { | ||
constexpr uint64_t Alignment = 4; | ||
ArrayRef<char> Template(reinterpret_cast<const char *>(Code), Size); | ||
return G.createContentBlock(S, Template, orc::ExecutorAddr(), Alignment, 0); | ||
} | ||
|
||
static Block &createStubThumbv7(LinkGraph &G, Section &S, Symbol &Target) { | ||
Block &B = allocStub(G, S, Thumbv7ABS); | ||
B.addEdge(Thumb_MovwAbsNC, 0, Target, 0); | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.