mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Turn MCSectionData into a field of MCSection.
This also changes MCAssembler to store a vector of MCSections instead of an iplist of MCSectionData. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238159 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5e435847b0
commit
e86bc46939
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/ilist.h"
|
||||
@ -551,11 +552,11 @@ class MCAssembler {
|
||||
friend class MCAsmLayout;
|
||||
|
||||
public:
|
||||
typedef iplist<MCSectionData> SectionDataListType;
|
||||
typedef SetVector<MCSection *> SectionListType;
|
||||
typedef std::vector<const MCSymbol *> SymbolDataListType;
|
||||
|
||||
typedef SectionDataListType::const_iterator const_iterator;
|
||||
typedef SectionDataListType::iterator iterator;
|
||||
typedef pointee_iterator<SectionListType::const_iterator> const_iterator;
|
||||
typedef pointee_iterator<SectionListType::iterator> iterator;
|
||||
|
||||
typedef pointee_iterator<SymbolDataListType::const_iterator>
|
||||
const_symbol_iterator;
|
||||
@ -599,17 +600,12 @@ private:
|
||||
|
||||
raw_ostream &OS;
|
||||
|
||||
iplist<MCSectionData> Sections;
|
||||
SectionListType Sections;
|
||||
|
||||
SymbolDataListType Symbols;
|
||||
|
||||
DenseSet<const MCSymbol *> LocalsUsedInReloc;
|
||||
|
||||
/// The map of sections to their associated assembler backend data.
|
||||
//
|
||||
// FIXME: Avoid this indirection?
|
||||
DenseMap<const MCSection *, MCSectionData *> SectionMap;
|
||||
|
||||
std::vector<IndirectSymbolData> IndirectSymbols;
|
||||
|
||||
std::vector<DataRegionData> DataRegions;
|
||||
@ -888,24 +884,22 @@ public:
|
||||
/// \name Backend Data Access
|
||||
/// @{
|
||||
|
||||
MCSectionData &getSectionData(const MCSection &Section) const {
|
||||
MCSectionData *Entry = SectionMap.lookup(&Section);
|
||||
assert(Entry && "Missing section data!");
|
||||
return *Entry;
|
||||
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) {
|
||||
MCSectionData *&Entry = SectionMap[&Section];
|
||||
|
||||
bool C = Sections.insert(&Section);
|
||||
if (Created)
|
||||
*Created = !Entry;
|
||||
if (!Entry) {
|
||||
Entry = new MCSectionData(Section);
|
||||
Sections.push_back(Entry);
|
||||
}
|
||||
|
||||
return *Entry;
|
||||
*Created = C;
|
||||
return Section.getSectionData();
|
||||
}
|
||||
|
||||
bool hasSymbolData(const MCSymbol &Symbol) const { return Symbol.hasData(); }
|
||||
|
@ -31,7 +31,7 @@ class MCSection;
|
||||
class MCSymbol;
|
||||
class raw_ostream;
|
||||
|
||||
class MCSectionData : public ilist_node<MCSectionData> {
|
||||
class MCSectionData {
|
||||
friend class MCAsmLayout;
|
||||
|
||||
MCSectionData(const MCSectionData &) = delete;
|
||||
@ -62,9 +62,7 @@ private:
|
||||
/// @}
|
||||
|
||||
public:
|
||||
// Only for use as sentinel.
|
||||
MCSectionData();
|
||||
MCSectionData(MCSection &Section);
|
||||
explicit MCSectionData(MCSection &Section);
|
||||
|
||||
MCSection &getSection() const { return *Section; }
|
||||
|
||||
@ -144,9 +142,10 @@ private:
|
||||
/// Whether this section has had instructions emitted into it.
|
||||
unsigned HasInstructions : 1;
|
||||
|
||||
MCSectionData Data;
|
||||
|
||||
protected:
|
||||
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
|
||||
: Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
|
||||
MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin);
|
||||
SectionVariant Variant;
|
||||
SectionKind Kind;
|
||||
|
||||
@ -191,6 +190,31 @@ public:
|
||||
bool hasInstructions() const { return HasInstructions; }
|
||||
void setHasInstructions(bool Value) { HasInstructions = Value; }
|
||||
|
||||
MCSectionData &getSectionData() { return Data; }
|
||||
const MCSectionData &getSectionData() const {
|
||||
return const_cast<MCSection *>(this)->getSectionData();
|
||||
}
|
||||
|
||||
MCSectionData::FragmentListType &getFragmentList();
|
||||
const MCSectionData::FragmentListType &getFragmentList() const {
|
||||
return const_cast<MCSection *>(this)->getFragmentList();
|
||||
}
|
||||
|
||||
MCSectionData::iterator begin();
|
||||
MCSectionData::const_iterator begin() const {
|
||||
return const_cast<MCSection *>(this)->begin();
|
||||
}
|
||||
|
||||
MCSectionData::iterator end();
|
||||
MCSectionData::const_iterator end() const {
|
||||
return const_cast<MCSection *>(this)->end();
|
||||
}
|
||||
|
||||
MCSectionData::reverse_iterator rend();
|
||||
MCSectionData::const_reverse_iterator rend() const {
|
||||
return const_cast<MCSection *>(this)->rend();
|
||||
}
|
||||
|
||||
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
|
||||
const MCExpr *Subsection) const = 0;
|
||||
|
||||
|
@ -1348,8 +1348,9 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
SectionOffsetsTy SectionOffsets;
|
||||
std::vector<MCSectionELF *> Groups;
|
||||
std::vector<MCSectionELF *> Relocations;
|
||||
for (const MCSectionData &SD : Asm) {
|
||||
const MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
|
||||
for (const MCSection &Sec : Asm) {
|
||||
const MCSectionELF &Section = static_cast<const MCSectionELF &>(Sec);
|
||||
const MCSectionData &SD = Section.getSectionData();
|
||||
|
||||
uint64_t Padding = OffsetToAlignment(OS.tell(), Section.getAlignment());
|
||||
WriteZeros(Padding);
|
||||
|
@ -69,11 +69,11 @@ MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
|
||||
{
|
||||
// Compute the section layout order. Virtual sections must go last.
|
||||
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
||||
if (!it->getSection().isVirtualSection())
|
||||
SectionOrder.push_back(&*it);
|
||||
if (!it->isVirtualSection())
|
||||
SectionOrder.push_back(&it->getSectionData());
|
||||
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
||||
if (it->getSection().isVirtualSection())
|
||||
SectionOrder.push_back(&*it);
|
||||
if (it->isVirtualSection())
|
||||
SectionOrder.push_back(&it->getSectionData());
|
||||
}
|
||||
|
||||
bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
|
||||
@ -290,8 +290,6 @@ MCEncodedFragmentWithFixups::~MCEncodedFragmentWithFixups() {
|
||||
|
||||
/* *** */
|
||||
|
||||
MCSectionData::MCSectionData() : Section(nullptr) {}
|
||||
|
||||
MCSectionData::MCSectionData(MCSection &Section) : Section(&Section) {}
|
||||
|
||||
MCSectionData::iterator
|
||||
@ -342,7 +340,6 @@ MCAssembler::~MCAssembler() {
|
||||
void MCAssembler::reset() {
|
||||
Sections.clear();
|
||||
Symbols.clear();
|
||||
SectionMap.clear();
|
||||
IndirectSymbols.clear();
|
||||
DataRegions.clear();
|
||||
LinkerOptions.clear();
|
||||
@ -862,9 +859,9 @@ void MCAssembler::Finish() {
|
||||
// Create dummy fragments to eliminate any empty sections, this simplifies
|
||||
// layout.
|
||||
if (it->getFragmentList().empty())
|
||||
new MCDataFragment(it);
|
||||
new MCDataFragment(&it->getSectionData());
|
||||
|
||||
it->getSection().setOrdinal(SectionIndex++);
|
||||
it->setOrdinal(SectionIndex++);
|
||||
}
|
||||
|
||||
// Assign layout order indices to sections and fragments.
|
||||
@ -1084,8 +1081,8 @@ bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
|
||||
|
||||
bool WasRelaxed = false;
|
||||
for (iterator it = begin(), ie = end(); it != ie; ++it) {
|
||||
MCSectionData &SD = *it;
|
||||
while (layoutSectionOnce(Layout, SD))
|
||||
MCSection &Sec = *it;
|
||||
while (layoutSectionOnce(Layout, Sec.getSectionData()))
|
||||
WasRelaxed = true;
|
||||
}
|
||||
|
||||
@ -1261,7 +1258,7 @@ void MCAssembler::dump() {
|
||||
OS << " Sections:[\n ";
|
||||
for (iterator it = begin(), ie = end(); it != ie; ++it) {
|
||||
if (it != begin()) OS << ",\n ";
|
||||
it->dump();
|
||||
it->getSectionData().dump();
|
||||
}
|
||||
OS << "],\n";
|
||||
OS << " Symbols:[";
|
||||
|
@ -19,6 +19,9 @@ using namespace llvm;
|
||||
// MCSection
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
|
||||
: Begin(Begin), HasInstructions(false), Data(*this), Variant(V), Kind(K) {}
|
||||
|
||||
MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
|
||||
if (!End)
|
||||
End = Ctx.createTempSymbol("sec_end", true);
|
||||
@ -49,6 +52,14 @@ void MCSection::setBundleLockState(BundleLockStateType NewState) {
|
||||
++BundleLockNestingDepth;
|
||||
}
|
||||
|
||||
MCSectionData::iterator MCSection::begin() { return Data.begin(); }
|
||||
|
||||
MCSectionData::iterator MCSection::end() { return Data.end(); }
|
||||
|
||||
MCSectionData::FragmentListType &MCSection::getFragmentList() {
|
||||
return Data.getFragmentList();
|
||||
}
|
||||
|
||||
MCSectionData::iterator MCSectionData::begin() { return Fragments.begin(); }
|
||||
|
||||
MCSectionData::iterator MCSectionData::end() { return Fragments.end(); }
|
||||
|
@ -540,7 +540,7 @@ void MachObjectWriter::ComputeSymbolTable(
|
||||
unsigned Index = 1;
|
||||
for (MCAssembler::iterator it = Asm.begin(),
|
||||
ie = Asm.end(); it != ie; ++it, ++Index)
|
||||
SectionIndexMap[&it->getSection()] = Index;
|
||||
SectionIndexMap[&*it] = Index;
|
||||
assert(Index <= 256 && "Too many sections!");
|
||||
|
||||
// Build the string table.
|
||||
@ -622,7 +622,8 @@ void MachObjectWriter::ComputeSymbolTable(
|
||||
for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
|
||||
UndefinedSymbolData[i].Symbol->setIndex(Index++);
|
||||
|
||||
for (const MCSectionData &SD : Asm) {
|
||||
for (const MCSection &Section : Asm) {
|
||||
const MCSectionData &SD = Section.getSectionData();
|
||||
std::vector<RelAndSymbol> &Relocs = Relocations[&SD];
|
||||
for (RelAndSymbol &Rel : Relocs) {
|
||||
if (!Rel.Sym)
|
||||
@ -801,7 +802,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
uint64_t VMSize = 0;
|
||||
for (MCAssembler::const_iterator it = Asm.begin(),
|
||||
ie = Asm.end(); it != ie; ++it) {
|
||||
const MCSectionData &SD = *it;
|
||||
const MCSectionData &SD = it->getSectionData();
|
||||
uint64_t Address = getSectionAddress(&SD);
|
||||
uint64_t Size = Layout.getSectionAddressSize(&SD);
|
||||
uint64_t FileSize = Layout.getSectionFileSize(&SD);
|
||||
@ -832,10 +833,11 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
uint64_t RelocTableEnd = SectionDataStart + SectionDataFileSize;
|
||||
for (MCAssembler::const_iterator it = Asm.begin(),
|
||||
ie = Asm.end(); it != ie; ++it) {
|
||||
std::vector<RelAndSymbol> &Relocs = Relocations[it];
|
||||
const MCSectionData &SD = it->getSectionData();
|
||||
std::vector<RelAndSymbol> &Relocs = Relocations[&SD];
|
||||
unsigned NumRelocs = Relocs.size();
|
||||
uint64_t SectionStart = SectionDataStart + getSectionAddress(it);
|
||||
WriteSection(Asm, Layout, *it, SectionStart, RelocTableEnd, NumRelocs);
|
||||
uint64_t SectionStart = SectionDataStart + getSectionAddress(&SD);
|
||||
WriteSection(Asm, Layout, SD, SectionStart, RelocTableEnd, NumRelocs);
|
||||
RelocTableEnd += NumRelocs * sizeof(MachO::any_relocation_info);
|
||||
}
|
||||
|
||||
@ -911,9 +913,10 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
// Write the actual section data.
|
||||
for (MCAssembler::const_iterator it = Asm.begin(),
|
||||
ie = Asm.end(); it != ie; ++it) {
|
||||
Asm.writeSectionData(it, Layout);
|
||||
const MCSectionData &SD = it->getSectionData();
|
||||
Asm.writeSectionData(&SD, Layout);
|
||||
|
||||
uint64_t Pad = getPaddingSize(it, Layout);
|
||||
uint64_t Pad = getPaddingSize(&SD, Layout);
|
||||
WriteZeros(Pad);
|
||||
}
|
||||
|
||||
@ -925,7 +928,7 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
ie = Asm.end(); it != ie; ++it) {
|
||||
// Write the section relocation entries, in reverse order to match 'as'
|
||||
// (approximately, the exact algorithm is more complicated than this).
|
||||
std::vector<RelAndSymbol> &Relocs = Relocations[it];
|
||||
std::vector<RelAndSymbol> &Relocs = Relocations[&it->getSectionData()];
|
||||
for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
|
||||
Write32(Relocs[e - i - 1].MRE.r_word0);
|
||||
Write32(Relocs[e - i - 1].MRE.r_word1);
|
||||
|
@ -636,7 +636,7 @@ void WinCOFFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm,
|
||||
// "Define" each section & symbol. This creates section & symbol
|
||||
// entries in the staging area.
|
||||
for (const auto &Section : Asm)
|
||||
DefineSection(Section);
|
||||
DefineSection(Section.getSectionData());
|
||||
|
||||
for (const MCSymbol &Symbol : Asm.symbols())
|
||||
if (ExportSymbol(Symbol, Asm))
|
||||
@ -946,12 +946,13 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
offset += COFF::SectionSize * Header.NumberOfSections;
|
||||
|
||||
for (const auto &Section : Asm) {
|
||||
COFFSection *Sec = SectionMap[&Section.getSection()];
|
||||
COFFSection *Sec = SectionMap[&Section];
|
||||
|
||||
if (Sec->Number == -1)
|
||||
continue;
|
||||
|
||||
Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(&Section);
|
||||
Sec->Header.SizeOfRawData =
|
||||
Layout.getSectionAddressSize(&Section.getSectionData());
|
||||
|
||||
if (IsPhysicalSection(Sec)) {
|
||||
// Align the section data to a four byte boundary.
|
||||
@ -1035,7 +1036,7 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
||||
|
||||
WriteZeros(SectionDataPadding);
|
||||
|
||||
Asm.writeSectionData(j, Layout);
|
||||
Asm.writeSectionData(&j->getSectionData(), Layout);
|
||||
}
|
||||
|
||||
if ((*i)->Relocations.size() > 0) {
|
||||
|
@ -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, Layout);
|
||||
Asm.writeSectionData(&I->getSectionData(), Layout);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user