[llvm-commits] [llvm] r122334 - in /llvm/trunk: include/llvm/MC/MCMachObjectWriter.h include/llvm/Object/MachOFormat.h lib/MC/MachObjectWriter.cpp

Daniel Dunbar daniel at zuster.org
Tue Dec 21 07:26:45 PST 2010


Author: ddunbar
Date: Tue Dec 21 09:26:45 2010
New Revision: 122334

URL: http://llvm.org/viewvc/llvm-project?rev=122334&view=rev
Log:
MC/Mach-O: Shuffle enums a bit to make it harder to inadvertently use the wrong
type.

Modified:
    llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
    llvm/trunk/include/llvm/Object/MachOFormat.h
    llvm/trunk/lib/MC/MachObjectWriter.cpp

Modified: llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCMachObjectWriter.h?rev=122334&r1=122333&r2=122334&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h Tue Dec 21 09:26:45 2010
@@ -22,12 +22,17 @@
   // FIXME: Remove this, we should just always use it once we no longer care
   // about Darwin 'as' compatibility.
   const unsigned UseAggressiveSymbolFolding : 1;
+  unsigned LocalDifference_RIT;
 
 protected:
   MCMachObjectTargetWriter(bool Is64Bit_, uint32_t CPUType_,
                            uint32_t CPUSubtype_,
                            bool UseAggressiveSymbolFolding_ = false);
 
+  void setLocalDifferenceRelocationType(unsigned Type) {
+    LocalDifference_RIT = Type;
+  }
+
 public:
   virtual ~MCMachObjectTargetWriter();
 
@@ -38,6 +43,9 @@
   bool useAggressiveSymbolFolding() const { return UseAggressiveSymbolFolding; }
   uint32_t getCPUType() const { return CPUType; }
   uint32_t getCPUSubtype() const { return CPUSubtype; }
+  unsigned getLocalDifferenceRelocationType() const {
+    return LocalDifference_RIT;
+  }
 
   /// @}
 };

Modified: llvm/trunk/include/llvm/Object/MachOFormat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/MachOFormat.h?rev=122334&r1=122333&r2=122334&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/MachOFormat.h (original)
+++ llvm/trunk/include/llvm/Object/MachOFormat.h Tue Dec 21 09:26:45 2010
@@ -317,17 +317,24 @@
     RF_Scattered = 0x80000000
   };
 
+  /// Common relocation info types.
   enum RelocationInfoType {
     RIT_Vanilla             = 0,
     RIT_Pair                = 1,
-    RIT_Difference          = 2,
-    RIT_PreboundLazyPointer = 3,
-    RIT_LocalDifference     = 4,
-    RIT_TLV                 = 5
+    RIT_Difference          = 2
+  };
+
+  /// Generic relocation info types, which are shared by some (but not all)
+  /// platforms.
+  enum RelocationInfoType_Generic {
+    RIT_Generic_PreboundLazyPointer = 3,
+    RIT_Generic_LocalDifference     = 4,
+    RIT_Generic_TLV                 = 5
   };
 
   /// X86_64 uses its own relocation types.
   enum RelocationInfoTypeX86_64 {
+    // Note that x86_64 doesn't even share the common relocation types.
     RIT_X86_64_Unsigned   = 0,
     RIT_X86_64_Signed     = 1,
     RIT_X86_64_Branch     = 2,
@@ -342,11 +349,8 @@
 
   /// ARM also has its own relocation types.
   enum RelocationInfoTypeARM {
-    RIT_ARM_Vanilla = 0,
-    RIT_ARM_Pair = 1,
-    RIT_ARM_Difference = 2,
     RIT_ARM_LocalDifference = 3,
-    RIT_ARM_PreboundLazyPointer =4,
+    RIT_ARM_PreboundLazyPointer = 4,
     RIT_ARM_Branch24Bit = 5,
     RIT_ARM_ThumbBranch22Bit = 6,
     RIT_ARM_ThumbBranch32Bit = 7

Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=122334&r1=122333&r2=122334&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Tue Dec 21 09:26:45 2010
@@ -766,13 +766,14 @@
       // relocation types from the linkers point of view, this is done solely
       // for pedantic compatibility with 'as'.
       Type = A_SD->isExternal() ? macho::RIT_Difference :
-        macho::RIT_LocalDifference;
+        macho::RIT_Generic_LocalDifference;
       Value2 = getSymbolAddress(B_SD, Layout);
       FixedValue -= getSectionAddress(B_SD->getFragment()->getParent());
     }
 
     // Relocations are written out in reverse order, so the PAIR comes first.
-    if (Type == macho::RIT_Difference || Type == macho::RIT_LocalDifference) {
+    if (Type == macho::RIT_Difference ||
+        Type == macho::RIT_Generic_LocalDifference) {
       macho::RelocationEntry MRE;
       MRE.Word0 = ((0         <<  0) |
                    (macho::RIT_Pair  << 24) |
@@ -830,11 +831,11 @@
     // struct relocation_info (8 bytes)
     macho::RelocationEntry MRE;
     MRE.Word0 = Value;
-    MRE.Word1 = ((Index     <<  0) |
-                 (IsPCRel   << 24) |
-                 (Log2Size  << 25) |
-                 (1         << 27) | // Extern
-                 (macho::RIT_TLV   << 28)); // Type
+    MRE.Word1 = ((Index                  <<  0) |
+                 (IsPCRel                << 24) |
+                 (Log2Size               << 25) |
+                 (1                      << 27) | // Extern
+                 (macho::RIT_Generic_TLV << 28)); // Type
     Relocations[Fragment->getParent()].push_back(MRE);
   }
 





More information about the llvm-commits mailing list