[llvm-commits] [llvm] r146238 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/relocation-386.s

Rafael Espindola rafael.espindola at gmail.com
Thu Dec 8 19:03:58 PST 2011


Author: rafael
Date: Thu Dec  8 21:03:58 2011
New Revision: 146238

URL: http://llvm.org/viewvc/llvm-project?rev=146238&view=rev
Log:
Handle the case of the magical _GLOBAL_OFFSET_TABLE_ showing up in a
symbol difference. This matches gas behavior and fixes PR11513.

We still don't handle _GLOBAL_OFFSET_TABLE_ in data sections.

Modified:
    llvm/trunk/lib/MC/ELFObjectWriter.cpp
    llvm/trunk/test/MC/ELF/relocation-386.s

Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=146238&r1=146237&r2=146238&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Dec  8 21:03:58 2011
@@ -1742,14 +1742,25 @@
     }
   } else {
     if (IsPCRel) {
-      switch (Modifier) {
-      default:
-        llvm_unreachable("Unimplemented");
-      case MCSymbolRefExpr::VK_None:
-        Type = ELF::R_386_PC32;
+      switch ((unsigned)Fixup.getKind()) {
+      default: llvm_unreachable("invalid fixup kind!");
+
+      case X86::reloc_global_offset_table:
+        Type = ELF::R_386_GOTPC;
         break;
-      case MCSymbolRefExpr::VK_PLT:
-        Type = ELF::R_386_PLT32;
+
+      case FK_PCRel_4:
+      case FK_Data_4:
+        switch (Modifier) {
+        default:
+          llvm_unreachable("Unimplemented");
+        case MCSymbolRefExpr::VK_None:
+          Type = ELF::R_386_PC32;
+          break;
+        case MCSymbolRefExpr::VK_PLT:
+          Type = ELF::R_386_PLT32;
+          break;
+        }
         break;
       }
     } else {

Modified: llvm/trunk/test/MC/ELF/relocation-386.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/relocation-386.s?rev=146238&r1=146237&r2=146238&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relocation-386.s (original)
+++ llvm/trunk/test/MC/ELF/relocation-386.s Thu Dec  8 21:03:58 2011
@@ -160,6 +160,11 @@
 // CHECK-NEXT:  ('r_sym', 0x00000d)
 // CHECK-NEXT:  ('r_type', 0x21)
 // CHECK-NEXT: ),
+// Relocation 25 (_GLOBAL_OFFSET_TABLE_-bar2) is of type R_386_GOTPC.
+// CHECK-NEXT: Relocation 25
+// CHECK-NEXT: (('r_offset', 0x00000094)
+// CHECK-NEXT:  ('r_sym', 0x00000b)
+// CHECK-NEXT:  ('r_type', 0x0a)
 
 // Section 4 is bss
 // CHECK:      # Section 4
@@ -225,6 +230,7 @@
         movl zed at DTPOFF(%eax), %eax
         pushl $bar
         addl foo at GOTTPOFF(%edx), %eax
+        subl    _GLOBAL_OFFSET_TABLE_-bar2, %ebx
 
         .section        zedsec,"awT", at progbits
 zed:





More information about the llvm-commits mailing list