MC: Use MCSymbol in MCAsmLayout::getSymbolOffset(), NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 19 May 2015 23:53:20 +0000 (23:53 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Tue, 19 May 2015 23:53:20 +0000 (23:53 +0000)
Continue to canonicalize on MCSymbol instead of MCSymbolData when both
are needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237749 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmLayout.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCAssembler.cpp
lib/MC/MCExpr.cpp
lib/MC/MachObjectWriter.cpp
lib/MC/WinCOFFObjectWriter.cpp
lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp

index ae7fd7c2e29fd33b790d12d14ec2945baa23bc99..ae008300f0e247ca2fac844f81a7fb9434437bf9 100644 (file)
@@ -99,10 +99,10 @@ public:
   /// \brief Get the offset of the given symbol, as computed in the current
   /// layout.
   /// \return True on success.
-  bool getSymbolOffset(const MCSymbolData *SD, uint64_t &Val) const;
+  bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const;
 
   /// \brief Variant that reports a fatal error if the offset is not computable.
-  uint64_t getSymbolOffset(const MCSymbolData *SD) const;
+  uint64_t getSymbolOffset(const MCSymbol &S) const;
 
   /// \brief If this symbol is equivalent to A + Constant, return A.
   const MCSymbol *getBaseSymbol(const MCSymbol &Symbol) const;
index 9f87cd1f183aed13748daa73426e6bc20399ecad..97d6d39f2ecf326cbd2773c8205a67b23dbd14c8 100644 (file)
@@ -407,7 +407,7 @@ uint64_t ELFObjectWriter::SymbolValue(MCSymbolData &Data,
     return Data.getCommonAlignment();
 
   uint64_t Res;
-  if (!Layout.getSymbolOffset(&Data, Res))
+  if (!Layout.getSymbolOffset(Data.getSymbol(), Res))
     return 0;
 
   if (Layout.getAssembler().isThumbFunc(&Data.getSymbol()))
@@ -800,12 +800,11 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
       Asm.getContext().reportFatalError(
           Fixup.getLoc(), "Cannot represent a difference across sections");
 
-    const MCSymbolData &SymBD = Asm.getSymbolData(SymB);
-    if (::isWeak(SymBD))
+    if (::isWeak(SymB.getData()))
       Asm.getContext().reportFatalError(
           Fixup.getLoc(), "Cannot represent a subtraction with a weak symbol");
 
-    uint64_t SymBOffset = Layout.getSymbolOffset(&SymBD);
+    uint64_t SymBOffset = Layout.getSymbolOffset(SymB);
     uint64_t K = SymBOffset - FixupOffset;
     IsPCRel = true;
     C -= K;
@@ -819,7 +818,7 @@ void ELFObjectWriter::RecordRelocation(MCAssembler &Asm,
   unsigned Type = GetRelocType(Target, Fixup, IsPCRel);
   bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymAD, C, Type);
   if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
-    C += Layout.getSymbolOffset(SymAD);
+    C += Layout.getSymbolOffset(*SymA);
 
   uint64_t Addend = 0;
   if (hasRelocationAddend()) {
index 18687cdd6a2b17768463f95c560acbcafb8e52bf..1f1e9a16d50f4306bc681d7141f4422c671aa7af 100644 (file)
@@ -132,13 +132,10 @@ static bool getLabelOffset(const MCAsmLayout &Layout, const MCSymbolData &SD,
   return true;
 }
 
-static bool getSymbolOffsetImpl(const MCAsmLayout &Layout,
-                                const MCSymbolData *SD, bool ReportError,
-                                uint64_t &Val) {
-  const MCSymbol &S = SD->getSymbol();
-
+static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S,
+                                bool ReportError, uint64_t &Val) {
   if (!S.isVariable())
-    return getLabelOffset(Layout, *SD, ReportError, Val);
+    return getLabelOffset(Layout, S.getData(), ReportError, Val);
 
   // If SD is a variable, evaluate it.
   MCValue Target;
@@ -172,13 +169,13 @@ static bool getSymbolOffsetImpl(const MCAsmLayout &Layout,
   return true;
 }
 
-bool MCAsmLayout::getSymbolOffset(const MCSymbolData *SD, uint64_t &Val) const {
-  return getSymbolOffsetImpl(*this, SD, false, Val);
+bool MCAsmLayout::getSymbolOffset(const MCSymbol &S, uint64_t &Val) const {
+  return getSymbolOffsetImpl(*this, S, false, Val);
 }
 
-uint64_t MCAsmLayout::getSymbolOffset(const MCSymbolData *SD) const {
+uint64_t MCAsmLayout::getSymbolOffset(const MCSymbol &S) const {
   uint64_t Val;
-  getSymbolOffsetImpl(*this, SD, true, Val);
+  getSymbolOffsetImpl(*this, S, true, Val);
   return Val;
 }
 
@@ -519,12 +516,12 @@ bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
   if (const MCSymbolRefExpr *A = Target.getSymA()) {
     const MCSymbol &Sym = A->getSymbol();
     if (Sym.isDefined())
-      Value += Layout.getSymbolOffset(&getSymbolData(Sym));
+      Value += Layout.getSymbolOffset(Sym);
   }
   if (const MCSymbolRefExpr *B = Target.getSymB()) {
     const MCSymbol &Sym = B->getSymbol();
     if (Sym.isDefined())
-      Value -= Layout.getSymbolOffset(&getSymbolData(Sym));
+      Value -= Layout.getSymbolOffset(Sym);
   }
 
 
index 01a63665484c8fe7807c92633e10829afe8d32db..cd11caec6bc28a7454cbe8f57ca072ece2eb9439 100644 (file)
@@ -498,8 +498,8 @@ static void AttemptToFoldSymbolOffsetDifference(
     return;
 
   // Eagerly evaluate.
-  Addend += (Layout->getSymbolOffset(&Asm->getSymbolData(A->getSymbol())) -
-             Layout->getSymbolOffset(&Asm->getSymbolData(B->getSymbol())));
+  Addend += Layout->getSymbolOffset(A->getSymbol()) -
+            Layout->getSymbolOffset(B->getSymbol());
   if (Addrs && (&SecA != &SecB))
     Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
 
index 002aa3c705e01434ae3d11d223ca06204b3512c0..12e5a17ea2234738149e539480a377575f3100ec 100644 (file)
@@ -108,7 +108,7 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbolData* SD,
   }
 
   return getSectionAddress(SD->getFragment()->getParent()) +
-    Layout.getSymbolOffset(SD);
+         Layout.getSymbolOffset(S);
 }
 
 uint64_t MachObjectWriter::getPaddingSize(const MCSectionData *SD,
index 278329aed5f22134ed19642e420c10a776a40ddc..6bf4a4d213620a04b5eabd12bbdb824bd8c299c9 100644 (file)
@@ -355,7 +355,7 @@ static uint64_t getSymbolValue(const MCSymbolData &Data,
     return Data.getCommonSize();
 
   uint64_t Res;
-  if (!Layout.getSymbolOffset(&Data, Res))
+  if (!Layout.getSymbolOffset(Data.getSymbol(), Res))
     return 0;
 
   return Res;
@@ -724,13 +724,13 @@ void WinCOFFObjectWriter::RecordRelocation(
     CrossSection = &Symbol.getSection() != &B->getSection();
 
     // Offset of the symbol in the section
-    int64_t OffsetOfB = Layout.getSymbolOffset(&B_SD);
+    int64_t OffsetOfB = Layout.getSymbolOffset(*B);
 
     // In the case where we have SymbA and SymB, we just need to store the delta
     // between the two symbols.  Update FixedValue to account for the delta, and
     // skip recording the relocation.
     if (!CrossSection) {
-      int64_t OffsetOfA = Layout.getSymbolOffset(&A_SD);
+      int64_t OffsetOfA = Layout.getSymbolOffset(A);
       FixedValue = (OffsetOfA - OffsetOfB) + Target.getConstant();
       return;
     }
index 99f30bcac7e2da5542a98cff5cfa9d4d836b5470..8abe78c8ced72ec4d8b701ad9233128272cc9630 100644 (file)
@@ -221,7 +221,7 @@ void AArch64MachObjectWriter::RecordRelocation(
     //    ... _foo@got - Ltmp0
     if (Target.getSymA()->getKind() == MCSymbolRefExpr::VK_GOT &&
         Target.getSymB()->getKind() == MCSymbolRefExpr::VK_None &&
-        Layout.getSymbolOffset(&B_SD) ==
+        Layout.getSymbolOffset(*B) ==
             Layout.getFragmentOffset(Fragment) + Fixup.getOffset()) {
       // SymB is the PC, so use a PC-rel pointer-to-GOT relocation.
       Type = MachO::ARM64_RELOC_POINTER_TO_GOT;
@@ -341,9 +341,9 @@ void AArch64MachObjectWriter::RecordRelocation(
       RelSymbol = Base;
 
       // Add the local offset, if needed.
-      if (&Base->getData() != &SD)
-        Value += Layout.getSymbolOffset(&SD) -
-                 Layout.getSymbolOffset(&Base->getData());
+      if (Base != Symbol)
+        Value +=
+            Layout.getSymbolOffset(*Symbol) - Layout.getSymbolOffset(*Base);
     } else if (Symbol->isInSection()) {
       if (!CanUseLocalRelocation)
         Asm.getContext().reportFatalError(
index 5b85a2a41fa804e5e186040fc4364334d7afa015..4572119779af217b5004e5f77dda9872b8cd6c8f 100644 (file)
@@ -422,7 +422,7 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer,
       // compensate for the addend of the symbol address, if it was
       // undefined. This occurs with weak definitions, for example.
       if (!SD->getSymbol().isUndefined())
-        FixedValue -= Layout.getSymbolOffset(SD);
+        FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
     } else {
       // The index is the section ordinal (1-based).
       const MCSectionData &SymSD = Asm.getSectionData(
index 6e10169e923ea5d1d515ffc568aeb8029972b3dd..d7dd4581508dd5ad8448e14dd9eac29e165f7a28 100644 (file)
@@ -360,7 +360,7 @@ void PPCMachObjectWriter::RecordPPCRelocation(
       // compensate for the addend of the symbol address, if it was
       // undefined. This occurs with weak definitions, for example.
       if (!SD->getSymbol().isUndefined())
-        FixedValue -= Layout.getSymbolOffset(SD);
+        FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
     } else {
       // The index is the section ordinal (1-based).
       const MCSectionData &SymSD =
index 3ede3ce1df139152cd3b04cd60956fd9402f67db..01f4bbe03e1974cef6316b9172b42e146adeacae 100644 (file)
@@ -232,9 +232,9 @@ void X86MachObjectWriter::RecordX86_64Relocation(
     // non-local symbol).
     if (RelSymbol) {
       // Add the local offset, if needed.
-      if (&RelSymbol->getData() != &SD)
-        Value += Layout.getSymbolOffset(&SD) -
-                 Layout.getSymbolOffset(&RelSymbol->getData());
+      if (RelSymbol != Symbol)
+        Value += Layout.getSymbolOffset(*Symbol) -
+                 Layout.getSymbolOffset(*RelSymbol);
     } else if (Symbol->isInSection() && !Symbol->isVariable()) {
       // The index is the section ordinal (1-based).
       Index = SD.getFragment()->getParent()->getOrdinal() + 1;
@@ -553,7 +553,7 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
       // compensate for the addend of the symbol address, if it was
       // undefined. This occurs with weak definitions, for example.
       if (!SD->getSymbol().isUndefined())
-        FixedValue -= Layout.getSymbolOffset(SD);
+        FixedValue -= Layout.getSymbolOffset(SD->getSymbol());
     } else {
       // The index is the section ordinal (1-based).
       const MCSectionData &SymSD = Asm.getSectionData(