Merge isAbsolute into IsSymbolRefDifferenceFullyResolved.
authorRafael Espindola <rafael.espindola@gmail.com>
Sat, 18 Dec 2010 06:27:54 +0000 (06:27 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sat, 18 Dec 2010 06:27:54 +0000 (06:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122148 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCObjectWriter.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCExpr.cpp
lib/MC/MCObjectWriter.cpp
lib/MC/MachObjectWriter.cpp
lib/MC/WinCOFFObjectWriter.cpp

index ef1a969b8c476dd2424dd17ff819eafade5ff62b..977b504a6ef99a68f0a202ae9daea970108e7c5a 100644 (file)
@@ -87,7 +87,8 @@ public:
   virtual bool
   IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
                                      const MCSymbolRefExpr *A,
-                                     const MCSymbolRefExpr *B) const = 0;
+                                     const MCSymbolRefExpr *B,
+                                     bool InSet) const;
 
   /// Check if a fixup is fully resolved.
   ///
@@ -99,9 +100,6 @@ public:
                                     bool IsPCRel,
                                     const MCFragment *DF) const = 0;
 
-  virtual bool isAbsolute(bool IsSet, const MCSymbol &A,
-                          const MCSymbol &B) const = 0;
-
   /// Write the object file.
   ///
   /// This routine is called by the assembler after layout and relaxation is
index a6503b7cacb7bee85e416cb79c44ed9bdab5d483..1bb47751ed4d7425bb31979529bf3a2b56835f11 100644 (file)
@@ -344,20 +344,6 @@ namespace {
                                           MCDataFragment *F,
                                           const MCSectionData *SD);
 
-    virtual bool
-    IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
-                                       const MCSymbolRefExpr *A,
-                                       const MCSymbolRefExpr *B) const {
-      // FIXME: Implement this!
-      return false;
-    }
-
-    virtual bool isAbsolute(bool IsSet, const MCSymbol &A,
-                            const MCSymbol &B) const {
-      // On ELF A - B is absolute if A and B are in the same section.
-      return &A.getSection() == &B.getSection();
-    }
-
     virtual bool IsFixupFullyResolved(const MCAssembler &Asm,
                               const MCValue Target,
                               bool IsPCRel,
index 22d8740a197d65bc41e8de88505b481bbeb7fcc4..94b9f0079a4adf86476ac9478c0381f7462f8681 100644 (file)
@@ -300,7 +300,7 @@ static void AttemptToFoldSymbolOffsetDifference(const MCAsmLayout *Layout,
   const MCAssembler &Asm = Layout->getAssembler();
 
   if (A && B &&
-      Asm.getWriter().IsSymbolRefDifferenceFullyResolved(Asm, A, B)) {
+      Asm.getWriter().IsSymbolRefDifferenceFullyResolved(Asm, A, B, false)) {
     // Eagerly evaluate.
     Addend += (Layout->getSymbolOffset(&Asm.getSymbolData(A->getSymbol())) -
                Layout->getSymbolOffset(&Asm.getSymbolData(B->getSymbol())));
@@ -385,10 +385,9 @@ static bool EvaluateSymbolicAdd(const MCAssembler *Asm,
          "Must have an assembler object if layout is given!");
 
   if (Asm && A && B) {
-    const MCSymbol &SA = A->getSymbol();
-    const MCSymbol &SB = B->getSymbol();
-    if (SA.isDefined() && SB.isDefined() &&
-        Asm->getWriter().isAbsolute(InSet, SA, SB)) {
+    if (A->getSymbol().isDefined() && B->getSymbol().isDefined() &&
+        Asm->getWriter().IsSymbolRefDifferenceFullyResolved(*Asm, A, B,
+                                                            InSet)) {
       MCSymbolData &AD = Asm->getSymbolData(A->getSymbol());
       MCSymbolData &BD = Asm->getSymbolData(B->getSymbol());
 
index 6cee76d0400ac7d35f1bc75b68d3d8efe5b0d9c4..e5f5f703289afee318b7ddd291d20a0247d3d138 100644 (file)
@@ -7,7 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectWriter.h"
+#include "llvm/MC/MCSymbol.h"
 
 using namespace llvm;
 
@@ -39,3 +41,22 @@ void MCObjectWriter::EncodeULEB128(uint64_t Value, raw_ostream &OS) {
     OS << char(Byte);
   } while (Value != 0);
 }
+
+bool
+MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
+                                                   const MCSymbolRefExpr *A,
+                                                   const MCSymbolRefExpr *B,
+                                                   bool InSet) const {
+  // Modified symbol references cannot be resolved.
+  if (A->getKind() != MCSymbolRefExpr::VK_None ||
+      B->getKind() != MCSymbolRefExpr::VK_None)
+    return false;
+
+  const MCSymbol &SA = A->getSymbol();
+  const MCSymbol &SB = B->getSymbol();
+  if (SA.isUndefined() || SB.isUndefined())
+    return false;
+
+  // On ELF and COFF A - B is absolute if A and B are in the same section.
+  return &SA.getSection() == &SB.getSection();
+}
index 42cf43fea34ea0ee82a06afdabb52a636d7d220e..11681ca90b162775d263e7d8529a4e3451c3d086 100644 (file)
@@ -1123,15 +1123,13 @@ public:
                        UndefinedSymbolData);
   }
 
-  bool isAbsolute(bool IsSet, const MCSymbol &A,
-                                     const MCSymbol &B) const  {
-    // On MachO A - B is absolute only if in a set.
-    return IsSet;
-  }
-
   bool IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
                                           const MCSymbolRefExpr *A,
-                                          const MCSymbolRefExpr *B) const {
+                                          const MCSymbolRefExpr *B,
+                                          bool InSet) const {
+    if (InSet)
+      return true;
+
     if (!TargetObjectWriter->useAggressiveSymbolFolding())
       return false;
 
index 7f75662219743d988a68d7775e0fbf3e99e15314..3a88a03f8bdaad6b28f0fd80abf6dfe5101a8d30 100644 (file)
@@ -179,20 +179,6 @@ public:
                         MCValue Target,
                         uint64_t &FixedValue);
 
-  virtual bool
-  IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
-                                     const MCSymbolRefExpr *A,
-                                     const MCSymbolRefExpr *B) const {
-    // FIXME: Implement this!
-    return false;
-  }
-
-  virtual bool isAbsolute(bool IsSet, const MCSymbol &A,
-                          const MCSymbol &B) const  {
-    // On COFF A - B is absolute if A and B are in the same section.
-    return &A.getSection() == &B.getSection();
-  }
-
   virtual bool IsFixupFullyResolved(const MCAssembler &Asm,
                                     const MCValue Target,
                                     bool IsPCRel,