[RuntimeDyld] Fix handling of i386 PC-rel external relocations. This fixes
authorLang Hames <lhames@gmail.com>
Tue, 13 May 2014 22:09:07 +0000 (22:09 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 13 May 2014 22:09:07 +0000 (22:09 +0000)
several more i386 MCJIT regression test failures.

<rdar://problem/16889891>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208735 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp

index df7f04cdf8b6007f052e31e3b9057388aeb82681..66456a990b7634c7e8d87f3d5ba8bbecc499d57a 100644 (file)
@@ -546,6 +546,17 @@ relocation_iterator RuntimeDyldMachO::processRelocationRef(
         Value.Addend = Addend;
       }
     }
+
+    // Addends for external, PC-rel relocations on i386 point back to the zero
+    // offset. Calculate the final offset from the relocation target instead.
+    // This allows us to use the same logic for both external and internal
+    // relocations in resolveI386RelocationRef.
+    if (Arch == Triple::x86 && IsPCRel) {
+      uint64_t RelocAddr = 0;
+      RelI->getAddress(RelocAddr);
+      Value.Addend += RelocAddr + 4;
+    }
+
   } else {
     SectionRef Sec = MachO->getRelocationSection(RE);
     bool IsCode = false;