[llvm] b5d5813 - [JITLink][AArch64] Add a generic 'createAnonymousPointer' utility.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 11:46:11 PDT 2022


Author: Lang Hames
Date: 2022-10-25T11:46:06-07:00
New Revision: b5d5813762b57a8b086ad485ec6e7e06f137fdcf

URL: https://github.com/llvm/llvm-project/commit/b5d5813762b57a8b086ad485ec6e7e06f137fdcf
DIFF: https://github.com/llvm/llvm-project/commit/b5d5813762b57a8b086ad485ec6e7e06f137fdcf.diff

LOG: [JITLink][AArch64] Add a generic 'createAnonymousPointer' utility.

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.

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 e3bf62aee118b..9b50fb1ee0301 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
@@ -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 @@ class GOTTableManager : public TableManager<GOTTableManager> {
   }
 
   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 @@ class GOTTableManager : public TableManager<GOTTableManager> {
     return *GOTSection;
   }
 
-  ArrayRef<char> getGOTEntryBlockContent() {
-    return {reinterpret_cast<const char *>(NullGOTEntryContent),
-            sizeof(NullGOTEntryContent)};
-  }
-
   Section *GOTSection = nullptr;
 };
 

diff  --git a/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
index 9ecc71dfbb540..1b75e540b0e25 100644
--- a/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/aarch64.cpp
@@ -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>


        


More information about the llvm-commits mailing list