[llvm] r237750 - MC: Take MCSymbol in MachObjectWriter::getSymbolAddress(), NFC
Duncan P. N. Exon Smith
dexonsmith at apple.com
Tue May 19 17:02:39 PDT 2015
Author: dexonsmith
Date: Tue May 19 19:02:39 2015
New Revision: 237750
URL: http://llvm.org/viewvc/llvm-project?rev=237750&view=rev
Log:
MC: Take MCSymbol in MachObjectWriter::getSymbolAddress(), NFC
Pass through an `MCSymbol` instead of an `MCSymbolData` so we can get
rid of the back pointer.
Modified:
llvm/trunk/include/llvm/MC/MCMachObjectWriter.h
llvm/trunk/lib/MC/MCLinkerOptimizationHint.cpp
llvm/trunk/lib/MC/MachObjectWriter.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/MCMachObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCMachObjectWriter.h?rev=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCMachObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCMachObjectWriter.h Tue May 19 19:02:39 2015
@@ -144,8 +144,7 @@ public:
uint64_t getSectionAddress(const MCSectionData* SD) const {
return SectionAddress.lookup(SD);
}
- uint64_t getSymbolAddress(const MCSymbolData* SD,
- const MCAsmLayout &Layout) const;
+ uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const;
uint64_t getFragmentAddress(const MCFragment *Fragment,
const MCAsmLayout &Layout) const;
Modified: llvm/trunk/lib/MC/MCLinkerOptimizationHint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCLinkerOptimizationHint.cpp?rev=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCLinkerOptimizationHint.cpp (original)
+++ llvm/trunk/lib/MC/MCLinkerOptimizationHint.cpp Tue May 19 19:02:39 2015
@@ -25,11 +25,9 @@ using namespace llvm;
void MCLOHDirective::Emit_impl(raw_ostream &OutStream,
const MachObjectWriter &ObjWriter,
const MCAsmLayout &Layout) const {
- const MCAssembler &Asm = Layout.getAssembler();
encodeULEB128(Kind, OutStream);
encodeULEB128(Args.size(), OutStream);
for (LOHArgs::const_iterator It = Args.begin(), EndIt = Args.end();
It != EndIt; ++It)
- encodeULEB128(ObjWriter.getSymbolAddress(&Asm.getSymbolData(**It), Layout),
- OutStream);
+ encodeULEB128(ObjWriter.getSymbolAddress(**It, Layout), OutStream);
}
Modified: llvm/trunk/lib/MC/MachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MachObjectWriter.cpp?rev=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/MachObjectWriter.cpp Tue May 19 19:02:39 2015
@@ -73,10 +73,8 @@ uint64_t MachObjectWriter::getFragmentAd
Layout.getFragmentOffset(Fragment);
}
-uint64_t MachObjectWriter::getSymbolAddress(const MCSymbolData* SD,
+uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
const MCAsmLayout &Layout) const {
- const MCSymbol &S = SD->getSymbol();
-
// If this is a variable, then recursively evaluate now.
if (S.isVariable()) {
if (const MCConstantExpr *C =
@@ -99,15 +97,13 @@ uint64_t MachObjectWriter::getSymbolAddr
uint64_t Address = Target.getConstant();
if (Target.getSymA())
- Address += getSymbolAddress(&Layout.getAssembler().getSymbolData(
- Target.getSymA()->getSymbol()), Layout);
+ Address += getSymbolAddress(Target.getSymA()->getSymbol(), Layout);
if (Target.getSymB())
- Address += getSymbolAddress(&Layout.getAssembler().getSymbolData(
- Target.getSymB()->getSymbol()), Layout);
+ Address += getSymbolAddress(Target.getSymB()->getSymbol(), Layout);
return Address;
}
- return getSectionAddress(SD->getFragment()->getParent()) +
+ return getSectionAddress(S.getData().getFragment()->getParent()) +
Layout.getSymbolOffset(S);
}
@@ -377,7 +373,9 @@ void MachObjectWriter::WriteNlist(MachSy
if (IsAlias && Symbol->isUndefined())
Address = AliaseeInfo->StringIndex;
else if (Symbol->isDefined())
- Address = getSymbolAddress(&Data, Layout);
+ // FIXME: Should Data.getSymbol() always be *Symbol? It doesn't look like
+ // that's true.
+ Address = getSymbolAddress(Data.getSymbol(), Layout);
else if (Data.isCommon()) {
// Common symbols are encoded with the size in the address
// field, and their alignment in the flags.
@@ -940,12 +938,8 @@ void MachObjectWriter::WriteObject(MCAss
it = Asm.data_region_begin(), ie = Asm.data_region_end();
it != ie; ++it) {
const DataRegionData *Data = &(*it);
- uint64_t Start =
- getSymbolAddress(&Layout.getAssembler().getSymbolData(*Data->Start),
- Layout);
- uint64_t End =
- getSymbolAddress(&Layout.getAssembler().getSymbolData(*Data->End),
- Layout);
+ uint64_t Start = getSymbolAddress(*Data->Start, Layout);
+ uint64_t End = getSymbolAddress(*Data->End, Layout);
DEBUG(dbgs() << "data in code region-- kind: " << Data->Kind
<< " start: " << Start << "(" << Data->Start->getName() << ")"
<< " end: " << End << "(" << Data->End->getName() << ")"
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=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp Tue May 19 19:02:39 2015
@@ -264,16 +264,14 @@ void AArch64MachObjectWriter::RecordRelo
Asm.getContext().reportFatalError(Fixup.getLoc(),
"unsupported relocation with identical base");
- Value +=
- (!A_SD.getFragment() ? 0 : Writer->getSymbolAddress(&A_SD, Layout)) -
- (!A_Base || !A_Base->getData().getFragment()
- ? 0
- : Writer->getSymbolAddress(&A_Base->getData(), Layout));
- Value -=
- (!B_SD.getFragment() ? 0 : Writer->getSymbolAddress(&B_SD, Layout)) -
- (!B_Base || !B_Base->getData().getFragment()
- ? 0
- : Writer->getSymbolAddress(&B_Base->getData(), Layout));
+ Value += (!A_SD.getFragment() ? 0 : Writer->getSymbolAddress(*A, Layout)) -
+ (!A_Base || !A_Base->getData().getFragment()
+ ? 0
+ : Writer->getSymbolAddress(*A_Base, Layout));
+ Value -= (!B_SD.getFragment() ? 0 : Writer->getSymbolAddress(*B, Layout)) -
+ (!B_Base || !B_Base->getData().getFragment()
+ ? 0
+ : Writer->getSymbolAddress(*B_Base, Layout));
Type = MachO::ARM64_RELOC_UNSIGNED;
@@ -355,7 +353,7 @@ void AArch64MachObjectWriter::RecordRelo
const MCSectionData &SymSD =
Asm.getSectionData(SD.getSymbol().getSection());
Index = SymSD.getOrdinal() + 1;
- Value += Writer->getSymbolAddress(&SD, Layout);
+ Value += Writer->getSymbolAddress(SD.getSymbol(), Layout);
if (IsPCRel)
Value -= Writer->getFragmentAddress(Fragment, Layout) +
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=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp Tue May 19 19:02:39 2015
@@ -159,7 +159,7 @@ RecordARMScatteredHalfRelocation(MachObj
"symbol '" + A->getName() +
"' can not be undefined in a subtraction expression");
- uint32_t Value = Writer->getSymbolAddress(A_SD, Layout);
+ uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint32_t Value2 = 0;
uint64_t SecAddr =
Writer->getSectionAddress(A_SD->getFragment()->getParent());
@@ -175,7 +175,7 @@ RecordARMScatteredHalfRelocation(MachObj
// Select the appropriate difference relocation type.
Type = MachO::ARM_RELOC_HALF_SECTDIFF;
- Value2 = Writer->getSymbolAddress(B_SD, Layout);
+ Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
}
@@ -262,7 +262,7 @@ void ARMMachObjectWriter::RecordARMScatt
"symbol '" + A->getName() +
"' can not be undefined in a subtraction expression");
- uint32_t Value = Writer->getSymbolAddress(A_SD, Layout);
+ uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint64_t SecAddr = Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr;
uint32_t Value2 = 0;
@@ -278,7 +278,7 @@ void ARMMachObjectWriter::RecordARMScatt
// Select the appropriate difference relocation type.
Type = MachO::ARM_RELOC_SECTDIFF;
- Value2 = Writer->getSymbolAddress(B_SD, Layout);
+ Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
}
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=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/MCTargetDesc/PPCMachObjectWriter.cpp Tue May 19 19:02:39 2015
@@ -212,7 +212,7 @@ bool PPCMachObjectWriter::RecordScattere
report_fatal_error("symbol '" + A->getName() +
"' can not be undefined in a subtraction expression");
- uint32_t Value = Writer->getSymbolAddress(A_SD, Layout);
+ uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint64_t SecAddr =
Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr;
@@ -226,7 +226,7 @@ bool PPCMachObjectWriter::RecordScattere
"' can not be undefined in a subtraction expression");
// FIXME: is Type correct? see include/llvm/Support/MachO.h
- Value2 = Writer->getSymbolAddress(B_SD, Layout);
+ Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
}
// FIXME: does FixedValue get used??
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=237750&r1=237749&r2=237750&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/X86/MCTargetDesc/X86MachObjectWriter.cpp Tue May 19 19:02:39 2015
@@ -184,12 +184,10 @@ void X86MachObjectWriter::RecordX86_64Re
Name + "' can not be undefined in a subtraction expression");
}
- Value +=
- Writer->getSymbolAddress(&A_SD, Layout) -
- (!A_Base ? 0 : Writer->getSymbolAddress(&A_Base->getData(), Layout));
- Value -=
- Writer->getSymbolAddress(&B_SD, Layout) -
- (!B_Base ? 0 : Writer->getSymbolAddress(&B_Base->getData(), Layout));
+ Value += Writer->getSymbolAddress(*A, Layout) -
+ (!A_Base ? 0 : Writer->getSymbolAddress(*A_Base, Layout));
+ Value -= Writer->getSymbolAddress(*B, Layout) -
+ (!B_Base ? 0 : Writer->getSymbolAddress(*B_Base, Layout));
if (!A_Base)
Index = A_SD.getFragment()->getParent()->getOrdinal() + 1;
@@ -238,7 +236,7 @@ void X86MachObjectWriter::RecordX86_64Re
} else if (Symbol->isInSection() && !Symbol->isVariable()) {
// The index is the section ordinal (1-based).
Index = SD.getFragment()->getParent()->getOrdinal() + 1;
- Value += Writer->getSymbolAddress(&SD, Layout);
+ Value += Writer->getSymbolAddress(*Symbol, Layout);
if (IsPCRel)
Value -= FixupAddress + (1 << Log2Size);
@@ -363,7 +361,7 @@ bool X86MachObjectWriter::RecordScattere
"' can not be undefined in a subtraction expression",
false);
- uint32_t Value = Writer->getSymbolAddress(A_SD, Layout);
+ uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint64_t SecAddr = Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr;
uint32_t Value2 = 0;
@@ -383,7 +381,7 @@ bool X86MachObjectWriter::RecordScattere
// pedantic compatibility with 'as'.
Type = A_SD->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF :
(unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF;
- Value2 = Writer->getSymbolAddress(B_SD, Layout);
+ Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
}
@@ -459,11 +457,11 @@ void X86MachObjectWriter::RecordTLVPRelo
// If this is a subtraction then we're pcrel.
uint32_t FixupAddress =
Writer->getFragmentAddress(Fragment, Layout) + Fixup.getOffset();
- const MCSymbolData *SD_B =
- &Asm.getSymbolData(Target.getSymB()->getSymbol());
IsPCRel = 1;
- FixedValue = (FixupAddress - Writer->getSymbolAddress(SD_B, Layout) +
- Target.getConstant());
+ FixedValue =
+ FixupAddress -
+ Writer->getSymbolAddress(Target.getSymB()->getSymbol(), Layout) +
+ Target.getConstant();
FixedValue += 1ULL << Log2Size;
} else {
FixedValue = 0;
More information about the llvm-commits
mailing list