[llvm] 249cd9d - [JITLink][MachO][arm64] Build GOT entries for defined symbols too.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue May 25 12:19:23 PDT 2021


Author: Lang Hames
Date: 2021-05-25T12:19:09-07:00
New Revision: 249cd9dd6002836b6d4b89a940149d518e8aa48b

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

LOG: [JITLink][MachO][arm64] Build GOT entries for defined symbols too.

During the generic x86-64 support refactor in ecf6466f01c52 the implementation
of MachO_arm64_GOTAndStubsBuilder::isGOTEdgeToFix was altered to only return
true for external symbols. This behavior is incorrect: GOT entries may be
required for defined symbols (e.g. in the large code model).

This patch fixes the bug and adds a test case for it (renaming an old test
case to avoid any ambiguity).

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
    llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
index 701ddb4a8ae74..169e20a1d1d32 100644
--- a/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/MachO_arm64.cpp
@@ -413,9 +413,8 @@ class PerGraphGOTAndPLTStubsBuilder_MachO_arm64
       PerGraphGOTAndPLTStubsBuilder_MachO_arm64>::PerGraphGOTAndPLTStubsBuilder;
 
   bool isGOTEdgeToFix(Edge &E) const {
-    return (E.getKind() == GOTPage21 || E.getKind() == GOTPageOffset12 ||
-            E.getKind() == PointerToGOT) &&
-           E.getTarget().isExternal();
+    return E.getKind() == GOTPage21 || E.getKind() == GOTPageOffset12 ||
+           E.getKind() == PointerToGOT;
   }
 
   Symbol &createGOTEntry(Symbol &Target) {

diff  --git a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s
index e09857ffc74cd..67f07857f820c 100644
--- a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s
+++ b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_relocations.s
@@ -52,6 +52,23 @@ test_gotpage21_external:
 test_gotpageoff12_external:
         ldr   x0, [x0, external_data at GOTPAGEOFF]
 
+# Check ARM64_RELOC_GOTPAGE21 / ARM64_RELOC_GOTPAGEOFF12 handling with a
+# reference to a defined symbol. Validate both the reference to the GOT entry,
+# and also the content of the GOT entry.
+# jitlink-check: *{8}(got_addr(macho_reloc.o, named_data)) = named_data
+# jitlink-check: decode_operand(test_gotpage21_defined, 1) = \
+# jitlink-check:     (got_addr(macho_reloc.o, named_data)[32:12] - \
+# jitlink-check:        test_gotpage21_defined[32:12])
+# jitlink-check: decode_operand(test_gotpageoff12_defined, 2) = \
+# jitlink-check:     got_addr(macho_reloc.o, named_data)[11:3]
+        .globl  test_gotpage21_defined
+        .p2align  2
+test_gotpage21_defined:
+        adrp  x0, named_data at GOTPAGE
+        .globl  test_gotpageoff12_defined
+test_gotpageoff12_defined:
+        ldr   x0, [x0, named_data at GOTPAGEOFF]
+
 # Check ARM64_RELOC_PAGE21 / ARM64_RELOC_PAGEOFF12 handling with a reference to
 # a local symbol.
 #


        


More information about the llvm-commits mailing list