Remove most uses of MCSectionData from MCAssembler.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238172 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-05-26 02:17:21 +00:00
parent ea3533b4c6
commit 2224f64c6d
8 changed files with 30 additions and 46 deletions

View File

@ -535,7 +535,7 @@ public:
// FIXME: This really doesn't belong here. See comments below.
struct IndirectSymbolData {
MCSymbol *Symbol;
MCSectionData *SectionData;
MCSection *Section;
};
// FIXME: Ditto this. Purely so the Streamer and the ObjectWriter can talk
@ -679,7 +679,7 @@ private:
/// \brief Perform one layout iteration of the given section and return true
/// if any offsets were adjusted.
bool layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD);
bool layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec);
bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
@ -715,7 +715,7 @@ public:
bool isSymbolLinkerVisible(const MCSymbol &SD) const;
/// Emit the section contents using the given object writer.
void writeSectionData(const MCSectionData *Section,
void writeSectionData(const MCSection *Section,
const MCAsmLayout &Layout) const;
/// Check whether a given symbol has been flagged with .thumb_func.
@ -884,16 +884,6 @@ public:
/// \name Backend Data Access
/// @{
MCSectionData &getSectionData(MCSection &Section) {
assert(Sections.count(&Section) && "Unknown Seciton");
return Section.getSectionData();
}
const MCSectionData &getSectionData(const MCSection &Section) const {
return const_cast<MCAssembler *>(this)
->getSectionData(const_cast<MCSection &>(Section));
}
MCSectionData &getOrCreateSectionData(MCSection &Section,
bool *Created = nullptr) {
bool C = Sections.insert(&Section);

View File

@ -1150,7 +1150,7 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm,
// for writing to arbitrary buffers) for little benefit.
if (!Asm.getContext().getAsmInfo()->compressDebugSections() ||
!SectionName.startswith(".debug_") || SectionName == ".debug_frame") {
Asm.writeSectionData(&SD, Layout);
Asm.writeSectionData(&Section, Layout);
return;
}
@ -1164,12 +1164,12 @@ void ELFObjectWriter::writeSectionData(const MCAssembler &Asm,
StringRef(UncompressedData.data(), UncompressedData.size()),
CompressedContents);
if (Success != zlib::StatusOK) {
Asm.writeSectionData(&SD, Layout);
Asm.writeSectionData(&Section, Layout);
return;
}
if (!prependCompressionHeader(UncompressedData.size(), CompressedContents)) {
Asm.writeSectionData(&SD, Layout);
Asm.writeSectionData(&Section, Layout);
return;
}
Asm.getContext().renameELFSection(&Section,

View File

@ -768,16 +768,15 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
"The stream should advance by fragment size");
}
void MCAssembler::writeSectionData(const MCSectionData *SD,
void MCAssembler::writeSectionData(const MCSection *Sec,
const MCAsmLayout &Layout) const {
// Ignore virtual sections.
const MCSection &Sec = SD->getSection();
if (Sec.isVirtualSection()) {
assert(Layout.getSectionFileSize(&Sec) == 0 && "Invalid size for section!");
if (Sec->isVirtualSection()) {
assert(Layout.getSectionFileSize(Sec) == 0 && "Invalid size for section!");
// Check that contents are only things legal inside a virtual section.
for (MCSectionData::const_iterator it = SD->begin(),
ie = SD->end(); it != ie; ++it) {
for (MCSectionData::const_iterator it = Sec->begin(), ie = Sec->end();
it != ie; ++it) {
switch (it->getKind()) {
default: llvm_unreachable("Invalid fragment in virtual section!");
case MCFragment::FT_Data: {
@ -789,7 +788,7 @@ void MCAssembler::writeSectionData(const MCSectionData *SD,
"Cannot have fixups in virtual section!");
for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
if (DF.getContents()[i]) {
if (auto *ELFSec = dyn_cast<const MCSectionELF>(&SD->getSection()))
if (auto *ELFSec = dyn_cast<const MCSectionELF>(Sec))
report_fatal_error("non-zero initializer found in section '" +
ELFSec->getSectionName() + "'");
else
@ -818,12 +817,12 @@ void MCAssembler::writeSectionData(const MCSectionData *SD,
uint64_t Start = getWriter().getStream().tell();
(void)Start;
for (MCSectionData::const_iterator it = SD->begin(), ie = SD->end();
for (MCSectionData::const_iterator it = Sec->begin(), ie = Sec->end();
it != ie; ++it)
writeFragment(*this, Layout, *it);
assert(getWriter().getStream().tell() - Start ==
Layout.getSectionAddressSize(&SD->getSection()));
Layout.getSectionAddressSize(Sec));
}
std::pair<uint64_t, bool> MCAssembler::handleFixup(const MCAsmLayout &Layout,
@ -1033,7 +1032,7 @@ bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
return OldSize != Data.size();
}
bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) {
// Holds the first fragment which needed relaxing during this layout. It will
// remain NULL if none were relaxed.
// When a fragment is relaxed, all the fragments following it should get
@ -1041,7 +1040,7 @@ bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSectionData &SD) {
MCFragment *FirstRelaxedFragment = nullptr;
// Attempt to relax all the fragments in the section.
for (MCSectionData::iterator I = SD.begin(), IE = SD.end(); I != IE; ++I) {
for (MCSectionData::iterator I = Sec.begin(), IE = Sec.end(); I != IE; ++I) {
// Check if this is a fragment that needs relaxation.
bool RelaxedFrag = false;
switch(I->getKind()) {
@ -1081,7 +1080,7 @@ bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
bool WasRelaxed = false;
for (iterator it = begin(), ie = end(); it != ie; ++it) {
MCSection &Sec = *it;
while (layoutSectionOnce(Layout, Sec.getSectionData()))
while (layoutSectionOnce(Layout, Sec))
WasRelaxed = true;
}

View File

@ -204,7 +204,7 @@ bool MCELFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
// important for matching the string table that 'as' generates.
IndirectSymbolData ISD;
ISD.Symbol = Symbol;
ISD.SectionData = getCurrentSectionData();
ISD.Section = &getCurrentSectionData()->getSection();
getAssembler().getIndirectSymbols().push_back(ISD);
return true;
}

View File

@ -287,7 +287,7 @@ bool MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
// important for matching the string table that 'as' generates.
IndirectSymbolData ISD;
ISD.Symbol = Symbol;
ISD.SectionData = getCurrentSectionData();
ISD.Section = &getCurrentSectionData()->getSection();
getAssembler().getIndirectSymbols().push_back(ISD);
return true;
}

View File

@ -478,8 +478,7 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) {
// or stub section.
for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
ie = Asm.indirect_symbol_end(); it != ie; ++it) {
const MCSectionMachO &Section =
cast<MCSectionMachO>(it->SectionData->getSection());
const MCSectionMachO &Section = cast<MCSectionMachO>(*it->Section);
if (Section.getType() != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
Section.getType() != MachO::S_LAZY_SYMBOL_POINTERS &&
@ -494,15 +493,13 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) {
unsigned IndirectIndex = 0;
for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
ie = Asm.indirect_symbol_end(); it != ie; ++it, ++IndirectIndex) {
const MCSectionMachO &Section =
cast<MCSectionMachO>(it->SectionData->getSection());
const MCSectionMachO &Section = cast<MCSectionMachO>(*it->Section);
if (Section.getType() != MachO::S_NON_LAZY_SYMBOL_POINTERS)
continue;
// Initialize the section indirect symbol base, if necessary.
IndirectSymBase.insert(
std::make_pair(&it->SectionData->getSection(), IndirectIndex));
IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex));
Asm.getOrCreateSymbolData(*it->Symbol);
}
@ -511,16 +508,14 @@ void MachObjectWriter::BindIndirectSymbols(MCAssembler &Asm) {
IndirectIndex = 0;
for (MCAssembler::indirect_symbol_iterator it = Asm.indirect_symbol_begin(),
ie = Asm.indirect_symbol_end(); it != ie; ++it, ++IndirectIndex) {
const MCSectionMachO &Section =
cast<MCSectionMachO>(it->SectionData->getSection());
const MCSectionMachO &Section = cast<MCSectionMachO>(*it->Section);
if (Section.getType() != MachO::S_LAZY_SYMBOL_POINTERS &&
Section.getType() != MachO::S_SYMBOL_STUBS)
continue;
// Initialize the section indirect symbol base, if necessary.
IndirectSymBase.insert(
std::make_pair(&it->SectionData->getSection(), IndirectIndex));
IndirectSymBase.insert(std::make_pair(it->Section, IndirectIndex));
// Set the symbol type to undefined lazy, but only on construction.
//
@ -913,10 +908,10 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
// Write the actual section data.
for (MCAssembler::const_iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) {
const MCSectionData &SD = it->getSectionData();
Asm.writeSectionData(&SD, Layout);
MCSection &Sec = *it;
Asm.writeSectionData(&Sec, Layout);
uint64_t Pad = getPaddingSize(&*it, Layout);
uint64_t Pad = getPaddingSize(&Sec, Layout);
WriteZeros(Pad);
}
@ -972,7 +967,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
// Indirect symbols in the non-lazy symbol pointer section have some
// special handling.
const MCSectionMachO &Section =
static_cast<const MCSectionMachO&>(it->SectionData->getSection());
static_cast<const MCSectionMachO &>(*it->Section);
if (Section.getType() == MachO::S_NON_LAZY_SYMBOL_POINTERS) {
// If this symbol is defined and internal, mark it as such.
if (it->Symbol->isDefined() &&

View File

@ -1034,7 +1034,7 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
WriteZeros(SectionDataPadding);
Asm.writeSectionData(&j->getSectionData(), Layout);
Asm.writeSectionData(&*j, Layout);
}
if ((*i)->Relocations.size() > 0) {

View File

@ -67,7 +67,7 @@ public:
void AMDGPUMCObjectWriter::WriteObject(MCAssembler &Asm,
const MCAsmLayout &Layout) {
for (MCAssembler::iterator I = Asm.begin(), E = Asm.end(); I != E; ++I) {
Asm.writeSectionData(&I->getSectionData(), Layout);
Asm.writeSectionData(&*I, Layout);
}
}