[llvm-commits] [llvm] r116013 - /llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp

Michael J. Spencer bigcheesegs at gmail.com
Thu Oct 7 16:55:40 PDT 2010


Author: mspencer
Date: Thu Oct  7 18:55:40 2010
New Revision: 116013

URL: http://llvm.org/viewvc/llvm-project?rev=116013&view=rev
Log:
MC-COFF: Handle relaxation in COFF better. Fixes PR8321.

Modified:
    llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp

Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=116013&r1=116012&r2=116013&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Thu Oct  7 18:55:40 2010
@@ -639,6 +639,11 @@
   COFFSymbol *coff_symbol = SymbolMap[&A_SD];
 
   if (Target.getSymB()) {
+    if (&Target.getSymA()->getSymbol().getSection()
+     != &Target.getSymB()->getSymbol().getSection()) {
+      llvm_unreachable("Symbol relative relocations are only allowed between "
+                       "symbols in the same section");
+    }
     const MCSymbol *B = &Target.getSymB()->getSymbol();
     MCSymbolData &B_SD = Asm.getSymbolData(*B);
 
@@ -701,7 +706,30 @@
                                                const MCValue Target,
                                                bool IsPCRel,
                                                const MCFragment *DF) const {
-  return false;
+  // If this is a PCrel relocation, find the section this fixup value is
+  // relative to.
+  const MCSection *BaseSection = 0;
+  if (IsPCRel) {
+    BaseSection = &DF->getParent()->getSection();
+    assert(BaseSection);
+  }
+
+  const MCSection *SectionA = 0;
+  const MCSymbol *SymbolA = 0;
+  if (const MCSymbolRefExpr *A = Target.getSymA()) {
+    SymbolA = &A->getSymbol();
+    SectionA = &SymbolA->getSection();
+  }
+
+  const MCSection *SectionB = 0;
+  if (const MCSymbolRefExpr *B = Target.getSymB()) {
+    SectionB = &B->getSymbol().getSection();
+  }
+
+  if (!BaseSection)
+    return SectionA == SectionB;
+
+  return !SectionB && BaseSection == SectionA;
 }
 
 void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,





More information about the llvm-commits mailing list