Introduce adjustFixupOffset that adjusts the fixup offset of a relocation.
authorRoman Divacky <rdivacky@freebsd.org>
Thu, 4 Aug 2011 19:08:19 +0000 (19:08 +0000)
committerRoman Divacky <rdivacky@freebsd.org>
Thu, 4 Aug 2011 19:08:19 +0000 (19:08 +0000)
This is meant to be overriden by backends. Implement an override on PowerPC
which adjusts the offset by 2 for ha16/lo16 relocation kinds. This removes
a commented out hack and enables hello world to be compiled on PowerPC.

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

lib/MC/ELFObjectWriter.cpp
lib/MC/ELFObjectWriter.h

index 18fed21afc66266bdb15e4055a873a397f8202f4..99a675d392f9ebbda97560f6065ce2a0c3b47b62 100644 (file)
@@ -447,18 +447,8 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
 
   uint64_t RelocOffset = Layout.getFragmentOffset(Fragment) +
     Fixup.getOffset();
-#if 0
-  // TODO: This is necessary on PPC32 but it must be implemented
-  // in a different way.
-  switch ((unsigned)Fixup.getKind()) {
-    case PPC::fixup_ppc_ha16:
-    case PPC::fixup_ppc_lo16:
-      RelocOffset += 2;
-      break;
-    default:
-      break;
-  }
-#endif
+
+  adjustFixupOffset(Fixup, RelocOffset);
 
   if (!hasRelocationAddend())
     Addend = 0;
@@ -1583,6 +1573,18 @@ unsigned PPCELFObjectWriter::GetRelocType(const MCValue &Target,
   return Type;
 }
 
+void
+PPCELFObjectWriter::adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset) {
+  switch ((unsigned)Fixup.getKind()) {
+    case PPC::fixup_ppc_ha16:
+    case PPC::fixup_ppc_lo16:
+      RelocOffset += 2;
+      break;
+    default:
+      break;
+  }
+}
+
 //===- MBlazeELFObjectWriter -------------------------------------------===//
 
 MBlazeELFObjectWriter::MBlazeELFObjectWriter(MCELFObjectTargetWriter *MOTW,
index 45a88985c4bc84e03daadd65cc618d0304fa12a6..d657d131bd335e3fc5e27cf3e978aa5cb5d3ca9f 100644 (file)
@@ -347,6 +347,7 @@ class ELFObjectWriter : public MCObjectWriter {
     virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
                                   bool IsPCRel, bool IsRelocWithSymbol,
                                   int64_t Addend) = 0;
+    virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset) { }
   };
 
   //===- X86ELFObjectWriter -------------------------------------------===//
@@ -408,6 +409,7 @@ class ELFObjectWriter : public MCObjectWriter {
     virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
                                   bool IsPCRel, bool IsRelocWithSymbol,
                                   int64_t Addend);
+    virtual void adjustFixupOffset(const MCFixup &Fixup, uint64_t &RelocOffset);
   };
 
   //===- MBlazeELFObjectWriter -------------------------------------------===//