[PATCH] [RuntimeDyld] Adapt PPC64 relocations to PPC32

Pierre-Andre Saulais pierre-andre at codeplay.com
Mon May 25 10:47:16 PDT 2015


Hi hfinkel, lhames,

RuntimeDyldELF implements many PPC64 relocations but none for PPC32. This patch adapts (copies, really) from PPC64 the code for two relocations that can be used to access global variables like in the attached test case.

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9998

Files:
  lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
  lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h

Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
+++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp
@@ -635,6 +635,33 @@
   return ((value + 0x8000) >> 48) & 0xffff;
 }
 
+void RuntimeDyldELF::resolvePPC32Relocation(const SectionEntry &Section,
+                                            uint64_t Offset, uint64_t Value,
+                                            uint32_t Type, int64_t Addend) {
+  uint8_t *LocalAddress = Section.Address + Offset;
+  uint64_t FinalAddress = (Section.LoadAddress + Offset);
+  int32_t delta = static_cast<int32_t>(Value - FinalAddress + Addend);
+  switch (Type) {
+  default:
+    llvm_unreachable("Relocation type not implemented yet!");
+    break;
+  case ELF::R_PPC_ADDR16_LO:
+    writeInt16BE(LocalAddress, applyPPClo(Value + Addend));
+    break;
+  case ELF::R_PPC_ADDR16_HI:
+    writeInt16BE(LocalAddress, applyPPChi(Value + Addend));
+    break;
+  case ELF::R_PPC_ADDR16_HA:
+    writeInt16BE(LocalAddress, applyPPCha(Value + Addend));
+    break;
+  case ELF::R_PPC_REL32:
+    if (SignExtend32<32>(delta) != delta)
+      llvm_unreachable("Relocation R_PPC_REL32 overflow");
+    writeInt32BE(LocalAddress, delta);
+    break;
+  }
+}
+
 void RuntimeDyldELF::resolvePPC64Relocation(const SectionEntry &Section,
                                             uint64_t Offset, uint64_t Value,
                                             uint32_t Type, int64_t Addend) {
@@ -815,6 +842,10 @@
     resolveMIPSRelocation(Section, Offset, (uint32_t)(Value & 0xffffffffL),
                           Type, (uint32_t)(Addend & 0xffffffffL));
     break;
+  case Triple::ppc:
+    resolvePPC32Relocation(Section, Offset, (uint32_t)(Value & 0xffffffffL),
+                           Type, (uint32_t)(Addend & 0xffffffffL));
+    break;
   case Triple::ppc64: // Fall through.
   case Triple::ppc64le:
     resolvePPC64Relocation(Section, Offset, Value, Type, Addend);
Index: lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
===================================================================
--- lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
+++ lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.h
@@ -43,6 +43,9 @@
   void resolveMIPSRelocation(const SectionEntry &Section, uint64_t Offset,
                              uint32_t Value, uint32_t Type, int32_t Addend);
 
+  void resolvePPC32Relocation(const SectionEntry &Section, uint64_t Offset,
+                              uint64_t Value, uint32_t Type, int64_t Addend);
+  
   void resolvePPC64Relocation(const SectionEntry &Section, uint64_t Offset,
                               uint64_t Value, uint32_t Type, int64_t Addend);

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9998.26461.patch
Type: text/x-patch
Size: 2769 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150525/20531fb7/attachment.bin>


More information about the llvm-commits mailing list