mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
MC: Take MCSymbol in MachObjectWriter::getSymbolAddress(), NFC
Pass through an `MCSymbol` instead of an `MCSymbolData` so we can get rid of the back pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237750 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e1fce8692d
commit
891fd53a90
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -73,10 +73,8 @@ uint64_t MachObjectWriter::getFragmentAddress(const MCFragment *Fragment,
|
||||
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::getSymbolAddress(const MCSymbolData* SD,
|
||||
|
||||
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(MachSymbolData &MSD,
|
||||
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(MCAssembler &Asm,
|
||||
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() << ")"
|
||||
|
@ -264,16 +264,14 @@ void AArch64MachObjectWriter::RecordRelocation(
|
||||
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::RecordRelocation(
|
||||
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) +
|
||||
|
@ -159,7 +159,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
|
||||
"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(MachObjectWriter *Writer,
|
||||
|
||||
// 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::RecordARMScatteredRelocation(MachObjectWriter *Writer,
|
||||
"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::RecordARMScatteredRelocation(MachObjectWriter *Writer,
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
|
||||
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::RecordScatteredRelocation(
|
||||
"' 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??
|
||||
|
@ -184,12 +184,10 @@ void X86MachObjectWriter::RecordX86_64Relocation(
|
||||
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_64Relocation(
|
||||
} 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::RecordScatteredRelocation(MachObjectWriter *Writer,
|
||||
"' 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::RecordScatteredRelocation(MachObjectWriter *Writer,
|
||||
// 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::RecordTLVPRelocation(MachObjectWriter *Writer,
|
||||
// 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;
|
||||
|
Loading…
Reference in New Issue
Block a user