Add X86::reloc_global_offset_table and use it to have a single place where
authorRafael Espindola <rafael.espindola@gmail.com>
Sun, 24 Oct 2010 17:35:42 +0000 (17:35 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sun, 24 Oct 2010 17:35:42 +0000 (17:35 +0000)
we check for _GLOBAL_OFFSET_TABLE_.

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

lib/MC/ELFObjectWriter.cpp
lib/Target/X86/X86AsmBackend.cpp
lib/Target/X86/X86FixupKinds.h
lib/Target/X86/X86MCCodeEmitter.cpp

index dad69eb14ab8bb418d2ccafcce13a469b0f978c7..db33af67d6f8223ce58e146f89ba90c1be223f40 100644 (file)
@@ -701,6 +701,10 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
       switch ((unsigned)Fixup.getKind()) {
       default: llvm_unreachable("invalid fixup kind!");
 
+      case X86::reloc_global_offset_table:
+        Type = ELF::R_386_GOTPC;
+        break;
+
       // FIXME: Should we avoid selecting reloc_signed_4byte in 32 bit mode
       // instead?
       case X86::reloc_signed_4byte:
@@ -710,10 +714,7 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
         default:
           llvm_unreachable("Unimplemented");
         case MCSymbolRefExpr::VK_None:
-          if (Symbol->getName() == "_GLOBAL_OFFSET_TABLE_")
-            Type = ELF::R_386_GOTPC;
-          else
-            Type = ELF::R_386_32;
+          Type = ELF::R_386_32;
           break;
         case MCSymbolRefExpr::VK_GOT:
           Type = ELF::R_386_GOT32;
index 17db41a76bb7cf113eb49aab068537d9018f4599..be5671919dc3099ce33dd2f6c8df563cd69b799f 100644 (file)
@@ -39,6 +39,7 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
   case X86::reloc_riprel_4byte:
   case X86::reloc_riprel_4byte_movq_load:
   case X86::reloc_signed_4byte:
+  case X86::reloc_global_offset_table:
   case FK_Data_4: return 2;
   case FK_Data_8: return 3;
   }
index f408a413f0461588e5a43919344a7f0ec5d63352..64ee3eb33047337c494433a4466bd84525204495 100644 (file)
@@ -20,9 +20,12 @@ enum Fixups {
   reloc_pcrel_2byte,                         // 16-bit pcrel, e.g. callw
   reloc_riprel_4byte,                        // 32-bit rip-relative
   reloc_riprel_4byte_movq_load,              // 32-bit rip-relative in movq
-  reloc_signed_4byte                         // 32-bit signed. Unlike FK_Data_4
+  reloc_signed_4byte,                        // 32-bit signed. Unlike FK_Data_4
                                              // this will be sign extended at
                                              // runtime.
+  reloc_global_offset_table                  // 32-bit, relative to the start
+                                             // of the instruction. Used only
+                                             // for _GLOBAL_OFFSET_TABLE_.
 };
 }
 }
index 47e91a8159c61e106a235118d9ec51f091931e4f..950fdf107a2c11be894fe6c8a5ad74e88cb465a0 100644 (file)
@@ -39,7 +39,7 @@ public:
   ~X86MCCodeEmitter() {}
 
   unsigned getNumFixupKinds() const {
-    return 6;
+    return 7;
   }
 
   const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
@@ -49,7 +49,8 @@ public:
       { "reloc_pcrel_2byte", 0, 2 * 8, MCFixupKindInfo::FKF_IsPCRel },
       { "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
       { "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
-      { "reloc_signed_4byte", 0, 4 * 8, 0}
+      { "reloc_signed_4byte", 0, 4 * 8, 0},
+      { "reloc_global_offset_table", 0, 4 * 8, 0}
     };
 
     if (Kind < FirstTargetFixupKind)
@@ -229,10 +230,10 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
   // If we have an immoffset, add it to the expression.
   const MCExpr *Expr = DispOp.getExpr();
 
-  if (StartsWithGlobalOffsetTable(Expr)) {
-    // FIXME: We should probably change the FixupKind to a special one so that
-    // other parts of MC don't have to check the symbol name.
+  if (FixupKind == FK_Data_4 && StartsWithGlobalOffsetTable(Expr)) {
     assert(ImmOffset == 0);
+
+    FixupKind = MCFixupKind(X86::reloc_global_offset_table);
     ImmOffset = CurByte;
   }