From 91e1080bcb5246f68e1890b492a7b94802d92ee6 Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Mon, 26 Mar 2012 20:52:07 +0000 Subject: [PATCH] Patched LLVM to handle generic i386 relocations. This avoids some sudden termination problems on i386 where the JIT would exit() out reporting "Invalid CPU type!" llvm-svn: 153467 --- lldb/scripts/llvm.i386-relocations.diff | 73 +++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lldb/scripts/llvm.i386-relocations.diff diff --git a/lldb/scripts/llvm.i386-relocations.diff b/lldb/scripts/llvm.i386-relocations.diff new file mode 100644 index 000000000000..a349aec8cbb4 --- /dev/null +++ b/lldb/scripts/llvm.i386-relocations.diff @@ -0,0 +1,73 @@ +Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp +=================================================================== +--- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (revision 153361) ++++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.cpp (working copy) +@@ -32,6 +32,14 @@ + // This just dispatches to the proper target specific routine. + switch (CPUType) { + default: llvm_unreachable("Unsupported CPU type!"); ++ case mach::CTM_i386: ++ return resolveI386Relocation(LocalAddress, ++ FinalAddress, ++ (uintptr_t)Value, ++ isPCRel, ++ Type, ++ Size, ++ Addend); + case mach::CTM_x86_64: + return resolveX86_64Relocation(LocalAddress, + FinalAddress, +@@ -52,6 +60,35 @@ + } + + bool RuntimeDyldMachO:: ++resolveI386Relocation(uint8_t *LocalAddress, ++ uint64_t FinalAddress, ++ uint64_t Value, ++ bool isPCRel, ++ unsigned Type, ++ unsigned Size, ++ int64_t Addend) { ++ if (isPCRel) ++ Value -= FinalAddress + 4; // see resolveX86_64Relocation ++ ++ switch (Type) { ++ default: ++ llvm_unreachable("Invalid relocation type!"); ++ case macho::RIT_Vanilla: { ++ uint8_t *p = LocalAddress; ++ uint64_t ValueToWrite = Value + Addend; ++ for (unsigned i = 0; i < Size; ++i) { ++ *p++ = (uint8_t)(ValueToWrite & 0xff); ++ ValueToWrite >>= 8; ++ } ++ } ++ case macho::RIT_Difference: ++ case macho::RIT_Generic_LocalDifference: ++ case macho::RIT_Generic_PreboundLazyPointer: ++ return Error("Relocation type not implemented yet!"); ++ } ++} ++ ++bool RuntimeDyldMachO:: + resolveX86_64Relocation(uint8_t *LocalAddress, + uint64_t FinalAddress, + uint64_t Value, +Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h +=================================================================== +--- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (revision 153361) ++++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldMachO.h (working copy) +@@ -74,6 +74,13 @@ + unsigned Type, + unsigned Size, + int64_t Addend); ++ bool resolveI386Relocation(uint8_t *LocalAddress, ++ uint64_t FinalAddress, ++ uint64_t Value, ++ bool isPCRel, ++ unsigned Type, ++ unsigned Size, ++ int64_t Addend); + bool resolveX86_64Relocation(uint8_t *LocalAddress, + uint64_t FinalAddress, + uint64_t Value,