[llvm] r237749 - MC: Use MCSymbol in MCAsmLayout::getSymbolOffset(), NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue May 19 16:53:21 PDT 2015
Author: dexonsmith
Date: Tue May 19 18:53:20 2015
New Revision: 237749
URL: http://llvm.org/viewvc/llvm-project?rev=237749&view=rev
Log:
MC: Use MCSymbol in MCAsmLayout::getSymbolOffset(), NFC
Continue to canonicalize on MCSymbol instead of MCSymbolData when both
are needed.
Modified:
llvm/trunk/include/llvm/MC/MCAsmLayout.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/lib/MC/MachObjectWriter.cpp
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
Modified: llvm/trunk/include/llvm/MC/MCAsmLayout.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmLayout.h?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmLayout.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmLayout.h Tue May 19 18:53:20 2015
@@ -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;
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -407,7 +407,7 @@ uint64_t ELFObjectWriter::SymbolValue(MC
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(M
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(M
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()) {
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Tue May 19 18:53:20 2015
@@ -132,13 +132,10 @@ static bool getLabelOffset(const MCAsmLa
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 MC
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 MC
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);
}
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Tue May 19 18:53:20 2015
@@ -498,8 +498,8 @@ static void AttemptToFoldSymbolOffsetDif
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));
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -108,7 +108,7 @@ uint64_t MachObjectWriter::getSymbolAddr
}
return getSectionAddress(SD->getFragment()->getParent()) +
- Layout.getSymbolOffset(SD);
+ Layout.getSymbolOffset(S);
}
uint64_t MachObjectWriter::getPaddingSize(const MCSectionData *SD,
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -355,7 +355,7 @@ static uint64_t getSymbolValue(const MCS
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::RecordRelocati
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;
}
Modified: llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -221,7 +221,7 @@ void AArch64MachObjectWriter::RecordRelo
// ... _foo at 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::RecordRelo
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(
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -422,7 +422,7 @@ void ARMMachObjectWriter::RecordRelocati
// 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(
Modified: llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -360,7 +360,7 @@ void PPCMachObjectWriter::RecordPPCReloc
// 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 =
Modified: llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp?rev=237749&r1=237748&r2=237749&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp Tue May 19 18:53:20 2015
@@ -232,9 +232,9 @@ void X86MachObjectWriter::RecordX86_64Re
// 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::RecordX86Reloc
// 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(
More information about the llvm-commits
mailing list