Revert 122160 while I debug it.
[oota-llvm.git] / lib / MC / MachObjectWriter.cpp
index b2258027b1ce68338075021e77722d8fd32ac338..11681ca90b162775d263e7d8529a4e3451c3d086 100644 (file)
@@ -1123,15 +1123,48 @@ public:
                        UndefinedSymbolData);
   }
 
+  bool IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
+                                          const MCSymbolRefExpr *A,
+                                          const MCSymbolRefExpr *B,
+                                          bool InSet) const {
+    if (InSet)
+      return true;
+
+    if (!TargetObjectWriter->useAggressiveSymbolFolding())
+      return false;
+
+    // The effective address is
+    //     addr(atom(A)) + offset(A)
+    //   - addr(atom(B)) - offset(B)
+    // and the offsets are not relocatable, so the fixup is fully resolved when
+    //  addr(atom(A)) - addr(atom(B)) == 0.
+    const MCSymbolData *A_Base = 0, *B_Base = 0;
+
+    // Modified symbol references cannot be resolved.
+    if (A->getKind() != MCSymbolRefExpr::VK_None ||
+        B->getKind() != MCSymbolRefExpr::VK_None)
+      return false;
+
+    A_Base = Asm.getAtom(&Asm.getSymbolData(A->getSymbol()));
+    if (!A_Base)
+      return false;
+
+    B_Base = Asm.getAtom(&Asm.getSymbolData(B->getSymbol()));
+    if (!B_Base)
+      return false;
+
+    // If the atoms are the same, they are guaranteed to have the same address.
+    if (A_Base == B_Base)
+      return true;
+
+    // Otherwise, we can't prove this is fully resolved.
+    return false;
+  }
 
   bool IsFixupFullyResolved(const MCAssembler &Asm,
                             const MCValue Target,
                             bool IsPCRel,
                             const MCFragment *DF) const {
-    // If we aren't using scattered symbols, the fixup is fully resolved.
-    if (!Asm.getBackend().hasScatteredSymbols())
-      return true;
-
     // Otherwise, determine whether this value is actually resolved; scattering
     // may cause atoms to move.
 
@@ -1262,7 +1295,7 @@ public:
     // Write the actual section data.
     for (MCAssembler::const_iterator it = Asm.begin(),
            ie = Asm.end(); it != ie; ++it) {
-      Asm.WriteSectionData(it, Layout, this);
+      Asm.WriteSectionData(it, Layout);
 
       uint64_t Pad = getPaddingSize(it, Layout);
       for (unsigned int i = 0; i < Pad; ++i)