[llvm] 5af9e64 - [JITLink][AArch46] Update aarch64 pointer jump stub sequence, add utilities.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 31 08:41:27 PDT 2022
Author: Lang Hames
Date: 2022-10-31T08:41:20-07:00
New Revision: 5af9e648ae10c50d94ab169f65907e12f210ec99
URL: https://github.com/llvm/llvm-project/commit/5af9e648ae10c50d94ab169f65907e12f210ec99
DIFF: https://github.com/llvm/llvm-project/commit/5af9e648ae10c50d94ab169f65907e12f210ec99.diff
LOG: [JITLink][AArch46] Update aarch64 pointer jump stub sequence, add utilities.
Updates the aarch64 pointer jump stub sequence to:
ADRP x16, <ptr>@page21
LDR x16, [x16, <ptr>@pageoff12]
BR x16
from:
LDR x16, <ptr>@ldrimm19
BR x16
The old sequence can only reference pointers within +/-1Mb, which may not be
enough for large object files. The new sequence can reach pointers within
+/-4Gb. (A future pre-fixup-pass could apply range-based optimizations to
turn this into an ldr-br-nop sequence.)
Also adds createPointerJumpStubBlock and createAnonymousPointerJumpStub
utilities along the same lines as their x86-64 counterparts.
The PLTTableManager is updated to use the new utility functions.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
index efd1eed080e33..33c09e1a2a315 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
@@ -481,8 +481,14 @@ constexpr uint64_t PointerSize = 8;
/// AArch64 null pointer content.
extern const char NullPointerContent[PointerSize];
-/// AArch64 PLT stub content.
-extern const uint8_t StubContent[8];
+/// AArch64 pointer jump stub content.
+///
+/// Contains the instruction sequence for an indirect jump via an in-memory
+/// pointer:
+/// ADRP x16, ptr at page21
+/// LDR x16, [x16, ptr at pageoff12]
+/// BR x16
+extern const char PointerJumpStubContent[12];
/// Creates a new pointer block in the given section and returns an
/// Anonymous symobl pointing to it.
@@ -504,6 +510,33 @@ inline Symbol &createAnonymousPointer(LinkGraph &G, Section &PointerSection,
return G.addAnonymousSymbol(B, 0, 8, false, false);
}
+/// Create a jump stub block that jumps via the pointer at the given symbol.
+///
+/// The stub block will have the following default values:
+/// alignment: 32-bit
+/// alignment-offset: 0
+/// address: highest allowable: (~11U)
+inline Block &createPointerJumpStubBlock(LinkGraph &G, Section &StubSection,
+ Symbol &PointerSymbol) {
+ auto &B = G.createContentBlock(StubSection, PointerJumpStubContent,
+ orc::ExecutorAddr(~uint64_t(11)), 1, 0);
+ B.addEdge(Page21, 0, PointerSymbol, 0);
+ B.addEdge(PageOffset12, 4, PointerSymbol, 0);
+ return B;
+}
+
+/// Create a jump stub that jumps via the pointer at the given symbol and
+/// an anonymous symbol pointing to it. Return the anonymous symbol.
+///
+/// The stub block will be created by createPointerJumpStubBlock.
+inline Symbol &createAnonymousPointerJumpStub(LinkGraph &G,
+ Section &StubSection,
+ Symbol &PointerSymbol) {
+ return G.addAnonymousSymbol(
+ createPointerJumpStubBlock(G, StubSection, PointerSymbol), 0,
+ sizeof(PointerJumpStubContent), true, false);
+}
+
/// Global Offset Table Builder.
class GOTTableManager : public TableManager<GOTTableManager> {
public:
@@ -586,12 +619,8 @@ class PLTTableManager : public TableManager<PLTTableManager> {
}
Symbol &createEntry(LinkGraph &G, Symbol &Target) {
- auto &StubContentBlock = G.createContentBlock(
- getStubsSection(G), getStubBlockContent(), orc::ExecutorAddr(), 1, 0);
- // Re-use GOT entries for stub targets.
- auto &GOTEntrySymbol = GOT.getEntryForTarget(G, Target);
- StubContentBlock.addEdge(aarch64::LDRLiteral19, 0, GOTEntrySymbol, 0);
- return G.addAnonymousSymbol(StubContentBlock, 0, 8, true, false);
+ return createAnonymousPointerJumpStub(G, getStubsSection(G),
+ GOT.getEntryForTarget(G, Target));
}
public:
@@ -602,10 +631,6 @@ class PLTTableManager : public TableManager<PLTTableManager> {
return *StubsSection;
}
- ArrayRef<char> getStubBlockContent() {
- return {reinterpret_cast<const char *>(StubContent), sizeof(StubContent)};
- }
-
GOTTableManager &GOT;
Section *StubsSection = nullptr;
};
diff --git a/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
index d51416d0ddf0e..1011fa81f750f 100644
--- a/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
@@ -21,9 +21,10 @@ namespace aarch64 {
const char NullPointerContent[8] = {0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
-const uint8_t StubContent[8] = {
- 0x10, 0x00, 0x00, 0x58, // LDR x16, <literal>
- 0x00, 0x02, 0x1f, 0xd6 // BR x16
+const char PointerJumpStubContent[12] = {
+ 0x10, 0x00, 0x00, (char)0x90u, // ADRP x16, <imm>@page21
+ 0x10, 0x02, 0x40, (char)0xf9u, // LDR x16, [x16, <imm>@pageoff12]
+ 0x00, 0x02, 0x1f, (char)0xd6u // BR x16
};
const char *getEdgeKindName(Edge::Kind R) {
More information about the llvm-commits
mailing list