Stop using MCSectionData in MCExpr.h.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238163 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2015-05-26 00:52:18 +00:00
parent f363960679
commit 504473e6ae
7 changed files with 33 additions and 46 deletions

View File

@@ -21,13 +21,12 @@ class MCAssembler;
class MCContext; class MCContext;
class MCFixup; class MCFixup;
class MCSection; class MCSection;
class MCSectionData;
class MCStreamer; class MCStreamer;
class MCSymbol; class MCSymbol;
class MCValue; class MCValue;
class raw_ostream; class raw_ostream;
class StringRef; class StringRef;
typedef DenseMap<const MCSectionData*, uint64_t> SectionAddrMap; typedef DenseMap<const MCSection *, uint64_t> SectionAddrMap;
/// \brief Base class for the full range of assembler expressions which are /// \brief Base class for the full range of assembler expressions which are
/// needed for parsing. /// needed for parsing.

View File

@@ -141,8 +141,8 @@ public:
SectionAddrMap &getSectionAddressMap() { return SectionAddress; } SectionAddrMap &getSectionAddressMap() { return SectionAddress; }
uint64_t getSectionAddress(const MCSectionData* SD) const { uint64_t getSectionAddress(const MCSection *Sec) const {
return SectionAddress.lookup(SD); return SectionAddress.lookup(Sec);
} }
uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const; uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const;

View File

@@ -501,8 +501,7 @@ static void AttemptToFoldSymbolOffsetDifference(
Addend += Layout->getSymbolOffset(A->getSymbol()) - Addend += Layout->getSymbolOffset(A->getSymbol()) -
Layout->getSymbolOffset(B->getSymbol()); Layout->getSymbolOffset(B->getSymbol());
if (Addrs && (&SecA != &SecB)) if (Addrs && (&SecA != &SecB))
Addend += (Addrs->lookup(&SecA.getSectionData()) - Addend += (Addrs->lookup(&SecA) - Addrs->lookup(&SecB));
Addrs->lookup(&SecB.getSectionData()));
// Pointers to Thumb symbols need to have their low-bit set to allow // Pointers to Thumb symbols need to have their low-bit set to allow
// for interworking. // for interworking.

View File

@@ -67,7 +67,7 @@ bool MachObjectWriter::isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind) {
uint64_t MachObjectWriter::getFragmentAddress(const MCFragment *Fragment, uint64_t MachObjectWriter::getFragmentAddress(const MCFragment *Fragment,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
return getSectionAddress(&Fragment->getParent()->getSectionData()) + return getSectionAddress(Fragment->getParent()) +
Layout.getFragmentOffset(Fragment); Layout.getFragmentOffset(Fragment);
} }
@@ -101,14 +101,14 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
return Address; return Address;
} }
return getSectionAddress( return getSectionAddress(S.getData().getFragment()->getParent()) +
&S.getData().getFragment()->getParent()->getSectionData()) +
Layout.getSymbolOffset(S); Layout.getSymbolOffset(S);
} }
uint64_t MachObjectWriter::getPaddingSize(const MCSectionData *SD, uint64_t MachObjectWriter::getPaddingSize(const MCSectionData *SD,
const MCAsmLayout &Layout) const { const MCAsmLayout &Layout) const {
uint64_t EndAddr = getSectionAddress(SD) + Layout.getSectionAddressSize(SD); uint64_t EndAddr =
getSectionAddress(&SD->getSection()) + Layout.getSectionAddressSize(SD);
unsigned Next = SD->getSection().getLayoutOrder() + 1; unsigned Next = SD->getSection().getLayoutOrder() + 1;
if (Next >= Layout.getSectionOrder().size()) if (Next >= Layout.getSectionOrder().size())
return 0; return 0;
@@ -217,10 +217,10 @@ void MachObjectWriter::WriteSection(const MCAssembler &Asm,
WriteBytes(Section.getSectionName(), 16); WriteBytes(Section.getSectionName(), 16);
WriteBytes(Section.getSegmentName(), 16); WriteBytes(Section.getSegmentName(), 16);
if (is64Bit()) { if (is64Bit()) {
Write64(getSectionAddress(&SD)); // address Write64(getSectionAddress(&SD.getSection())); // address
Write64(SectionSize); // size Write64(SectionSize); // size
} else { } else {
Write32(getSectionAddress(&SD)); // address Write32(getSectionAddress(&SD.getSection())); // address
Write32(SectionSize); // size Write32(SectionSize); // size
} }
Write32(FileOffset); Write32(FileOffset);
@@ -649,7 +649,7 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
const MCSectionData *SD = Order[i]; const MCSectionData *SD = Order[i];
StartAddress = StartAddress =
RoundUpToAlignment(StartAddress, SD->getSection().getAlignment()); RoundUpToAlignment(StartAddress, SD->getSection().getAlignment());
SectionAddress[SD] = StartAddress; SectionAddress[&SD->getSection()] = StartAddress;
StartAddress += Layout.getSectionAddressSize(SD); StartAddress += Layout.getSectionAddressSize(SD);
// Explicitly pad the section to match the alignment requirements of the // Explicitly pad the section to match the alignment requirements of the
@@ -804,7 +804,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
for (MCAssembler::const_iterator it = Asm.begin(), for (MCAssembler::const_iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) { ie = Asm.end(); it != ie; ++it) {
const MCSectionData &SD = it->getSectionData(); const MCSectionData &SD = it->getSectionData();
uint64_t Address = getSectionAddress(&SD); uint64_t Address = getSectionAddress(&*it);
uint64_t Size = Layout.getSectionAddressSize(&SD); uint64_t Size = Layout.getSectionAddressSize(&SD);
uint64_t FileSize = Layout.getSectionFileSize(&SD); uint64_t FileSize = Layout.getSectionFileSize(&SD);
FileSize += getPaddingSize(&SD, Layout); FileSize += getPaddingSize(&SD, Layout);
@@ -837,7 +837,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
const MCSectionData &SD = it->getSectionData(); const MCSectionData &SD = it->getSectionData();
std::vector<RelAndSymbol> &Relocs = Relocations[&SD]; std::vector<RelAndSymbol> &Relocs = Relocations[&SD];
unsigned NumRelocs = Relocs.size(); unsigned NumRelocs = Relocs.size();
uint64_t SectionStart = SectionDataStart + getSectionAddress(&SD); uint64_t SectionStart = SectionDataStart + getSectionAddress(&*it);
WriteSection(Asm, Layout, SD, SectionStart, RelocTableEnd, NumRelocs); WriteSection(Asm, Layout, SD, SectionStart, RelocTableEnd, NumRelocs);
RelocTableEnd += NumRelocs * sizeof(MachO::any_relocation_info); RelocTableEnd += NumRelocs * sizeof(MachO::any_relocation_info);
} }

View File

@@ -161,8 +161,8 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
uint32_t Value = Writer->getSymbolAddress(*A, Layout); uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint32_t Value2 = 0; uint32_t Value2 = 0;
uint64_t SecAddr = Writer->getSectionAddress( uint64_t SecAddr =
&A_SD->getFragment()->getParent()->getSectionData()); Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr; FixedValue += SecAddr;
if (const MCSymbolRefExpr *B = Target.getSymB()) { if (const MCSymbolRefExpr *B = Target.getSymB()) {
@@ -176,8 +176,7 @@ RecordARMScatteredHalfRelocation(MachObjectWriter *Writer,
// Select the appropriate difference relocation type. // Select the appropriate difference relocation type.
Type = MachO::ARM_RELOC_HALF_SECTDIFF; Type = MachO::ARM_RELOC_HALF_SECTDIFF;
Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress( FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
&B_SD->getFragment()->getParent()->getSectionData());
} }
// Relocations are written out in reverse order, so the PAIR comes first. // Relocations are written out in reverse order, so the PAIR comes first.
@@ -265,8 +264,8 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
"' can not be undefined in a subtraction expression"); "' can not be undefined in a subtraction expression");
uint32_t Value = Writer->getSymbolAddress(*A, Layout); uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint64_t SecAddr = Writer->getSectionAddress( uint64_t SecAddr =
&A_SD->getFragment()->getParent()->getSectionData()); Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr; FixedValue += SecAddr;
uint32_t Value2 = 0; uint32_t Value2 = 0;
@@ -282,8 +281,7 @@ void ARMMachObjectWriter::RecordARMScatteredRelocation(MachObjectWriter *Writer,
// Select the appropriate difference relocation type. // Select the appropriate difference relocation type.
Type = MachO::ARM_RELOC_SECTDIFF; Type = MachO::ARM_RELOC_SECTDIFF;
Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress( FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
&B_SD->getFragment()->getParent()->getSectionData());
} }
// Relocations are written out in reverse order, so the PAIR comes first. // Relocations are written out in reverse order, so the PAIR comes first.
@@ -339,9 +337,8 @@ bool ARMMachObjectWriter::requiresExternRelocation(MachObjectWriter *Writer,
// BL/BLX also use external relocations when an internal relocation // BL/BLX also use external relocations when an internal relocation
// would result in the target being out of range. This gives the linker // would result in the target being out of range. This gives the linker
// enough information to generate a branch island. // enough information to generate a branch island.
const MCSectionData &SymSD = Asm.getSectionData(S.getSection()); Value += Writer->getSectionAddress(&S.getSection());
Value += Writer->getSectionAddress(&SymSD); Value -= Writer->getSectionAddress(Fragment.getParent());
Value -= Writer->getSectionAddress(&Fragment.getParent()->getSectionData());
// If the resultant value would be out of range for an internal relocation, // If the resultant value would be out of range for an internal relocation,
// use an external instead. // use an external instead.
if (Value > Range || Value < -(Range + 1)) if (Value > Range || Value < -(Range + 1))
@@ -430,13 +427,11 @@ void ARMMachObjectWriter::RecordRelocation(MachObjectWriter *Writer,
} else { } else {
// The index is the section ordinal (1-based). // The index is the section ordinal (1-based).
const MCSection &Sec = A->getSection(); const MCSection &Sec = A->getSection();
const MCSectionData &SymSD = Asm.getSectionData(Sec);
Index = Sec.getOrdinal() + 1; Index = Sec.getOrdinal() + 1;
FixedValue += Writer->getSectionAddress(&SymSD); FixedValue += Writer->getSectionAddress(&Sec);
} }
if (IsPCRel) if (IsPCRel)
FixedValue -= FixedValue -= Writer->getSectionAddress(Fragment->getParent());
Writer->getSectionAddress(&Fragment->getParent()->getSectionData());
// The type is determined by the fixup kind. // The type is determined by the fixup kind.
Type = RelocType; Type = RelocType;

View File

@@ -213,8 +213,8 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
"' can not be undefined in a subtraction expression"); "' can not be undefined in a subtraction expression");
uint32_t Value = Writer->getSymbolAddress(*A, Layout); uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint64_t SecAddr = Writer->getSectionAddress( uint64_t SecAddr =
&A_SD->getFragment()->getParent()->getSectionData()); Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr; FixedValue += SecAddr;
uint32_t Value2 = 0; uint32_t Value2 = 0;
@@ -227,8 +227,7 @@ bool PPCMachObjectWriter::RecordScatteredRelocation(
// FIXME: is Type correct? see include/llvm/Support/MachO.h // FIXME: is Type correct? see include/llvm/Support/MachO.h
Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress( FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
&B_SD->getFragment()->getParent()->getSectionData());
} }
// FIXME: does FixedValue get used?? // FIXME: does FixedValue get used??
@@ -366,13 +365,11 @@ void PPCMachObjectWriter::RecordPPCRelocation(
} else { } else {
// The index is the section ordinal (1-based). // The index is the section ordinal (1-based).
const MCSection &Sec = A->getSection(); const MCSection &Sec = A->getSection();
const MCSectionData &SymSD = Asm.getSectionData(Sec);
Index = Sec.getOrdinal() + 1; Index = Sec.getOrdinal() + 1;
FixedValue += Writer->getSectionAddress(&SymSD); FixedValue += Writer->getSectionAddress(&Sec);
} }
if (IsPCRel) if (IsPCRel)
FixedValue -= FixedValue -= Writer->getSectionAddress(Fragment->getParent());
Writer->getSectionAddress(&Fragment->getParent()->getSectionData());
} }
// struct relocation_info (8 bytes) // struct relocation_info (8 bytes)

View File

@@ -364,8 +364,8 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
false); false);
uint32_t Value = Writer->getSymbolAddress(*A, Layout); uint32_t Value = Writer->getSymbolAddress(*A, Layout);
uint64_t SecAddr = Writer->getSectionAddress( uint64_t SecAddr =
&A_SD->getFragment()->getParent()->getSectionData()); Writer->getSectionAddress(A_SD->getFragment()->getParent());
FixedValue += SecAddr; FixedValue += SecAddr;
uint32_t Value2 = 0; uint32_t Value2 = 0;
@@ -385,8 +385,7 @@ bool X86MachObjectWriter::RecordScatteredRelocation(MachObjectWriter *Writer,
Type = A_SD->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF : Type = A_SD->isExternal() ? (unsigned)MachO::GENERIC_RELOC_SECTDIFF :
(unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF; (unsigned)MachO::GENERIC_RELOC_LOCAL_SECTDIFF;
Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout); Value2 = Writer->getSymbolAddress(B->getSymbol(), Layout);
FixedValue -= Writer->getSectionAddress( FixedValue -= Writer->getSectionAddress(B_SD->getFragment()->getParent());
&B_SD->getFragment()->getParent()->getSectionData());
} }
// Relocations are written out in reverse order, so the PAIR comes first. // Relocations are written out in reverse order, so the PAIR comes first.
@@ -560,13 +559,11 @@ void X86MachObjectWriter::RecordX86Relocation(MachObjectWriter *Writer,
} else { } else {
// The index is the section ordinal (1-based). // The index is the section ordinal (1-based).
const MCSection &Sec = A->getSection(); const MCSection &Sec = A->getSection();
const MCSectionData &SymSD = Asm.getSectionData(Sec);
Index = Sec.getOrdinal() + 1; Index = Sec.getOrdinal() + 1;
FixedValue += Writer->getSectionAddress(&SymSD); FixedValue += Writer->getSectionAddress(&Sec);
} }
if (IsPCRel) if (IsPCRel)
FixedValue -= FixedValue -= Writer->getSectionAddress(Fragment->getParent());
Writer->getSectionAddress(&Fragment->getParent()->getSectionData());
Type = MachO::GENERIC_RELOC_VANILLA; Type = MachO::GENERIC_RELOC_VANILLA;
} }