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

Rafael Espindola rafael.espindola at gmail.com
Sat Nov 20 16:48:25 PST 2010


Author: rafael
Date: Sat Nov 20 18:48:25 2010
New Revision: 119917

URL: http://llvm.org/viewvc/llvm-project?rev=119917&view=rev
Log:
Handle PCRel relocations with absolute values. Fixes PR8656.

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=119917&r1=119916&r2=119917&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Sat Nov 20 18:48:25 2010
@@ -948,10 +948,12 @@
   for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
     ELFRelocationEntry entry = Relocs[e - i - 1];
 
-    if (entry.Index < 0)
+    if (!entry.Index)
+      ;
+    else if (entry.Index < 0)
       entry.Index = getSymbolIndexInSymbolTable(Asm, entry.Symbol);
     else
-      entry.Index += LocalSymbolData.size() + 1;
+      entry.Index += LocalSymbolData.size();
     if (Is64Bit) {
       String64(*F, entry.r_offset);
 
@@ -1085,13 +1087,22 @@
   }
 
   const MCSection *SectionB = 0;
+  const MCSymbol *SymbolB = 0;
   if (const MCSymbolRefExpr *B = Target.getSymB()) {
-    SectionB = &B->getSymbol().AliasedSymbol().getSection();
+    SymbolB = &B->getSymbol();
+    SectionB = &SymbolB->AliasedSymbol().getSection();
   }
 
   if (!BaseSection)
     return SectionA == SectionB;
 
+  if (SymbolB)
+    return false;
+
+  // Absolute address but PCrel instruction, so we need a relocation.
+  if (!SymbolA)
+    return false;
+
   // FIXME: This is in here just to match gnu as output. If the two ends
   // are in the same section, there is nothing that the linker can do to
   // break it.
@@ -1099,7 +1110,7 @@
   if (DataA.isExternal())
     return false;
 
-  return !SectionB && BaseSection == SectionA;
+  return BaseSection == SectionA;
 }
 
 void ELFObjectWriter::CreateGroupSections(MCAssembler &Asm,
@@ -1391,12 +1402,14 @@
   int64_t Addend = 0;
   int Index = 0;
   int64_t Value = Target.getConstant();
-  const MCSymbol &Symbol = Target.getSymA()->getSymbol();
-  const MCSymbol &ASymbol = Symbol.AliasedSymbol();
-  const MCSymbol *RelocSymbol = SymbolToReloc(Asm, Target, *Fragment);
+  const MCSymbol *RelocSymbol = NULL;
 
   bool IsPCRel = isFixupKindX86PCRel(Fixup.getKind());
   if (!Target.isAbsolute()) {
+    const MCSymbol &Symbol = Target.getSymA()->getSymbol();
+    const MCSymbol &ASymbol = Symbol.AliasedSymbol();
+    RelocSymbol = SymbolToReloc(Asm, Target, *Fragment);
+
     if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
       const MCSymbol &SymbolB = RefB->getSymbol();
       MCSymbolData &SDB = Asm.getSymbolData(SymbolB);
@@ -1415,7 +1428,7 @@
       MCSymbolData &SD = Asm.getSymbolData(ASymbol);
       MCFragment *F = SD.getFragment();
 
-      Index = F->getParent()->getOrdinal();
+      Index = F->getParent()->getOrdinal() + 1;
 
       MCSectionData *FSD = F->getParent();
       // Offset of the symbol in the section
@@ -1437,7 +1450,8 @@
 
   // determine the type of the relocation
 
-  MCSymbolRefExpr::VariantKind Modifier = Target.getSymA()->getKind();
+  MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute() ?
+    MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
   unsigned Type;
   if (Is64Bit) {
     if (IsPCRel) {

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=119917&r1=119916&r2=119917&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/relocation-386.s (original)
+++ llvm/trunk/test/MC/ELF/relocation-386.s Sat Nov 20 18:48:25 2010
@@ -98,6 +98,12 @@
 // CHECK-NEXT:  ('r_sym', 0x0000000b)
 // CHECK-NEXT:  ('r_type', 0x00000020)
 // CHECK-NEXT: ),
+// Relocation 12 (calll 4096) is of type R_386_PC32
+// CHECK-NEXT: # Relocation 0x0000000c
+// CHECK-NEXT: (('r_offset', 0x00000048)
+// CHECK-NEXT:  ('r_sym', 0x00000000)
+// CHECK-NEXT:  ('r_type', 0x00000002)
+// CHECK-NEXT: ),
 
         .text
 bar:
@@ -122,6 +128,7 @@
         addl foo at GOTNTPOFF(%ebx), %ecx
         leal foo at TLSLDM(%ebx), %eax
         leal foo at DTPOFF(%eax), %edx
+        calll 4096
 
         .section	.rodata.str1.16,"aMS", at progbits,1
 .Lfoo:





More information about the llvm-commits mailing list