[JITLink][AArch64] Add a generic 'createAnonymousPointer' utility.
authorLang Hames <lhames@gmail.com>
Tue, 25 Oct 2022 18:31:48 +0000 (11:31 -0700)
committerLang Hames <lhames@gmail.com>
Tue, 25 Oct 2022 18:46:06 +0000 (11:46 -0700)
Adds a generic utility for creating anonymous aarch64 pointer blocks
(automatically adding an edge to initialize the pointer if given an
initial target).

Updates the aarch64 GOTTableManager to use the utility when building
GOT entries.

llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
llvm/lib/ExecutionEngine/JITLink/aarch64.cpp

index e3bf62a..9b50fb1 100644 (file)
@@ -248,11 +248,31 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E) {
 constexpr uint64_t PointerSize = 8;
 
 /// AArch64 null pointer content.
-extern const uint8_t NullGOTEntryContent[PointerSize];
+extern const char NullPointerContent[PointerSize];
 
 /// AArch64 PLT stub content.
 extern const uint8_t StubContent[8];
 
+/// Creates a new pointer block in the given section and returns an
+/// Anonymous symobl pointing to it.
+///
+/// If InitialTarget is given then an Pointer64 relocation will be added to the
+/// block pointing at InitialTarget.
+///
+/// The pointer block will have the following default values:
+///   alignment: 64-bit
+///   alignment-offset: 0
+///   address: highest allowable (~7U)
+inline Symbol &createAnonymousPointer(LinkGraph &G, Section &PointerSection,
+                                      Symbol *InitialTarget = nullptr,
+                                      uint64_t InitialAddend = 0) {
+  auto &B = G.createContentBlock(PointerSection, NullPointerContent,
+                                 orc::ExecutorAddr(~uint64_t(7)), 8, 0);
+  if (InitialTarget)
+    B.addEdge(Pointer64, 0, *InitialTarget, InitialAddend);
+  return G.addAnonymousSymbol(B, 0, 8, false, false);
+}
+
 /// Global Offset Table Builder.
 class GOTTableManager : public TableManager<GOTTableManager> {
 public:
@@ -300,10 +320,7 @@ public:
   }
 
   Symbol &createEntry(LinkGraph &G, Symbol &Target) {
-    auto &GOTEntryBlock = G.createContentBlock(
-        getGOTSection(G), getGOTEntryBlockContent(), orc::ExecutorAddr(), 8, 0);
-    GOTEntryBlock.addEdge(aarch64::Pointer64, 0, Target, 0);
-    return G.addAnonymousSymbol(GOTEntryBlock, 0, 8, false, false);
+    return createAnonymousPointer(G, getGOTSection(G), &Target);
   }
 
 private:
@@ -314,11 +331,6 @@ private:
     return *GOTSection;
   }
 
-  ArrayRef<char> getGOTEntryBlockContent() {
-    return {reinterpret_cast<const char *>(NullGOTEntryContent),
-            sizeof(NullGOTEntryContent)};
-  }
-
   Section *GOTSection = nullptr;
 };
 
index 9ecc71d..1b75e54 100644 (file)
@@ -18,8 +18,8 @@ namespace llvm {
 namespace jitlink {
 namespace aarch64 {
 
-const uint8_t NullGOTEntryContent[8] = {0x00, 0x00, 0x00, 0x00,
-                                        0x00, 0x00, 0x00, 0x00};
+const char NullPointerContent[8] = {0x00, 0x00, 0x00, 0x00,
+                                    0x00, 0x00, 0x00, 0x00};
 
 const uint8_t StubContent[8] = {
     0x10, 0x00, 0x00, 0x58, // LDR x16, <literal>