[MCJIT] Defer application of AArch64 MachO GOT relocations until resolve time.
authorLang Hames <lhames@gmail.com>
Tue, 21 Oct 2014 23:41:15 +0000 (23:41 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 21 Oct 2014 23:41:15 +0000 (23:41 +0000)
On AArch64, GOT references are page relative (ADRP + LDR), so they can't be
applied until we know exactly where, within a page, the GOT entry will be in
the target address space.

Fixes <rdar://problem/18693976>.

llvm-svn: 220347

llvm/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h
llvm/test/ExecutionEngine/RuntimeDyld/AArch64/MachO_ARM64_relocations.s

index 980daaa..f5cf9ac 100644 (file)
@@ -368,9 +368,9 @@ private:
     assert(RE.Size == 2);
     SectionEntry &Section = Sections[RE.SectionID];
     StubMap::const_iterator i = Stubs.find(Value);
-    uintptr_t Addr;
+    int64_t Offset;
     if (i != Stubs.end())
-      Addr = reinterpret_cast<uintptr_t>(Section.Address) + i->second;
+      Offset = static_cast<int64_t>(i->second);
     else {
       // FIXME: There must be a better way to do this then to check and fix the
       // alignment every time!!!
@@ -391,11 +391,11 @@ private:
       else
         addRelocationForSection(GOTRE, Value.SectionID);
       Section.StubOffset = StubOffset + getMaxStubSize();
-      Addr = StubAddress;
+      Offset = static_cast<int64_t>(StubOffset);
     }
-    RelocationEntry TargetRE(RE.SectionID, RE.Offset, RE.RelType, /*Addend=*/0,
+    RelocationEntry TargetRE(RE.SectionID, RE.Offset, RE.RelType, Offset,
                              RE.IsPCRel, RE.Size);
-    resolveRelocation(TargetRE, static_cast<uint64_t>(Addr));
+    addRelocationForSection(TargetRE, RE.SectionID);
   }
 };
 }
index 29c95e6..04d269e 100644 (file)
@@ -1,5 +1,5 @@
 # RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -code-model=small -relocation-model=pic -filetype=obj -o %T/foo.o %s
-# RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -verify -check=%s %/T/foo.o
+# RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -map-section foo.o,__text=0x10bc0 -verify -check=%s %/T/foo.o
 
     .section  __TEXT,__text,regular,pure_instructions
     .ios_version_min 7, 0