Include the section address in the computation of the relocation.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 4 Oct 2010 15:59:01 +0000 (15:59 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 4 Oct 2010 15:59:01 +0000 (15:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115509 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/ELFObjectWriter.cpp
test/MC/ELF/pic-diff.s

index cc6d51efb0bafbe0edb004a03b453fd6d655dd49..7e0ce7d711ef14c2e8cea5434f05c6f156df13df 100644 (file)
@@ -539,7 +539,14 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
       const MCSymbol &SymbolB = RefB->getSymbol();
       MCSymbolData &SDB = Asm.getSymbolData(SymbolB);
       IsPCRel = true;
-      Value += Layout.getFragmentOffset(Fragment) + Fixup.getOffset() - Layout.getSymbolAddress(&SDB);
+      MCSectionData *Sec = Fragment->getParent();
+
+      // Offset of the symbol in the section
+      int64_t a = Layout.getSymbolAddress(&SDB) - Layout.getSectionAddress(Sec);
+
+      // Ofeset of the relocation in the section
+      int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
+      Value += b - a;
     }
 
     // Check that this case has already been fully resolved before we get
index 099ae1f0ad63cd0940297a765e8818472a8b35e6..50117d420bf1feef8b8c2194251f17d2d56695b5 100644 (file)
@@ -19,6 +19,9 @@
 // CHECK-NEXT:    ),
 // CHECK-NEXT:   ])
 
+.zero 4
+.data
+
 .zero 1
 .align 4
 foo: