mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-17 18:24:34 +00:00
Stop creating MCSectionData is the ELF writer.
Now is is just its use of MCSymbolData that requires it to take a non const MCAssembler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237951 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -221,7 +221,7 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
const SectionIndexMapTy &SectionIndexMap,
|
const SectionIndexMapTy &SectionIndexMap,
|
||||||
const RevGroupMapTy &RevGroupMap);
|
const RevGroupMapTy &RevGroupMap);
|
||||||
|
|
||||||
MCSectionELF *createRelocationSection(MCAssembler &Asm,
|
MCSectionELF *createRelocationSection(MCContext &Ctx,
|
||||||
const MCSectionELF &Sec);
|
const MCSectionELF &Sec);
|
||||||
|
|
||||||
const MCSectionELF *createSectionHeaderStringTable();
|
const MCSectionELF *createSectionHeaderStringTable();
|
||||||
@@ -1058,12 +1058,11 @@ void ELFObjectWriter::computeSymbolTable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
MCSectionELF *
|
MCSectionELF *
|
||||||
ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
|
ELFObjectWriter::createRelocationSection(MCContext &Ctx,
|
||||||
const MCSectionELF &Sec) {
|
const MCSectionELF &Sec) {
|
||||||
if (Relocations[&Sec].empty())
|
if (Relocations[&Sec].empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
MCContext &Ctx = Asm.getContext();
|
|
||||||
const StringRef SectionName = Sec.getSectionName();
|
const StringRef SectionName = Sec.getSectionName();
|
||||||
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
|
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
|
||||||
RelaSectionName += SectionName;
|
RelaSectionName += SectionName;
|
||||||
@@ -1081,8 +1080,7 @@ ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
|
|||||||
MCSectionELF *RelaSection = Ctx.createELFRelSection(
|
MCSectionELF *RelaSection = Ctx.createELFRelSection(
|
||||||
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
|
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
|
||||||
Flags, EntrySize, Sec.getGroup(), &Sec);
|
Flags, EntrySize, Sec.getGroup(), &Sec);
|
||||||
MCSectionData &RelSD = Asm.getOrCreateSectionData(*RelaSection);
|
RelaSection->setAlignment(is64Bit() ? 8 : 4);
|
||||||
RelSD.setAlignment(is64Bit() ? 8 : 4);
|
|
||||||
return RelaSection;
|
return RelaSection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1344,7 +1342,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
|
|
||||||
// ... then the sections ...
|
// ... then the sections ...
|
||||||
SectionOffsetsTy SectionOffsets;
|
SectionOffsetsTy SectionOffsets;
|
||||||
bool ComputedSymtab = false;
|
std::vector<MCSectionELF *> Groups;
|
||||||
|
std::vector<MCSectionELF *> Relocations;
|
||||||
for (const MCSectionData &SD : Asm) {
|
for (const MCSectionData &SD : Asm) {
|
||||||
MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
|
MCSectionELF &Section = static_cast<MCSectionELF &>(SD.getSection());
|
||||||
|
|
||||||
@@ -1355,32 +1354,12 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
uint64_t SecStart = OS.tell();
|
uint64_t SecStart = OS.tell();
|
||||||
|
|
||||||
const MCSymbol *SignatureSymbol = Section.getGroup();
|
const MCSymbol *SignatureSymbol = Section.getGroup();
|
||||||
unsigned Type = Section.getType();
|
writeSectionData(Asm, SD, Layout);
|
||||||
if (Type == ELF::SHT_GROUP) {
|
|
||||||
assert(SignatureSymbol);
|
|
||||||
write(uint32_t(ELF::GRP_COMDAT));
|
|
||||||
for (const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
|
|
||||||
uint32_t SecIndex = SectionIndexMap.lookup(Member);
|
|
||||||
write(SecIndex);
|
|
||||||
}
|
|
||||||
} else if (Type == ELF::SHT_REL || Type == ELF::SHT_RELA) {
|
|
||||||
if (!ComputedSymtab) {
|
|
||||||
// Compute symbol table information.
|
|
||||||
computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap);
|
|
||||||
ComputedSymtab = true;
|
|
||||||
}
|
|
||||||
writeRelocations(Asm, *Section.getAssociatedSection());
|
|
||||||
} else {
|
|
||||||
writeSectionData(Asm, SD, Layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t SecEnd = OS.tell();
|
uint64_t SecEnd = OS.tell();
|
||||||
SectionOffsets[&Section] = std::make_pair(SecStart, SecEnd);
|
SectionOffsets[&Section] = std::make_pair(SecStart, SecEnd);
|
||||||
|
|
||||||
if (Type == ELF::SHT_GROUP || Type == ELF::SHT_REL || Type == ELF::SHT_RELA)
|
MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
|
||||||
continue;
|
|
||||||
|
|
||||||
MCSectionELF *RelSection = createRelocationSection(Asm, Section);
|
|
||||||
|
|
||||||
if (SignatureSymbol) {
|
if (SignatureSymbol) {
|
||||||
Asm.getOrCreateSymbolData(*SignatureSymbol);
|
Asm.getOrCreateSymbolData(*SignatureSymbol);
|
||||||
@@ -1388,8 +1367,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
if (!GroupIdx) {
|
if (!GroupIdx) {
|
||||||
MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
|
MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
|
||||||
GroupIdx = addToSectionTable(Group);
|
GroupIdx = addToSectionTable(Group);
|
||||||
MCSectionData *GroupD = &Asm.getOrCreateSectionData(*Group);
|
Group->setAlignment(4);
|
||||||
GroupD->setAlignment(4);
|
Groups.push_back(Group);
|
||||||
}
|
}
|
||||||
GroupMembers[SignatureSymbol].push_back(&Section);
|
GroupMembers[SignatureSymbol].push_back(&Section);
|
||||||
if (RelSection)
|
if (RelSection)
|
||||||
@@ -1397,14 +1376,45 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SectionIndexMap[&Section] = addToSectionTable(&Section);
|
SectionIndexMap[&Section] = addToSectionTable(&Section);
|
||||||
if (RelSection)
|
if (RelSection) {
|
||||||
SectionIndexMap[RelSection] = addToSectionTable(RelSection);
|
SectionIndexMap[RelSection] = addToSectionTable(RelSection);
|
||||||
|
Relocations.push_back(RelSection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ComputedSymtab) {
|
for (MCSectionELF *Group : Groups) {
|
||||||
// Compute symbol table information.
|
uint64_t Padding = OffsetToAlignment(OS.tell(), Group->getAlignment());
|
||||||
computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap);
|
WriteZeros(Padding);
|
||||||
ComputedSymtab = true;
|
|
||||||
|
// Remember the offset into the file for this section.
|
||||||
|
uint64_t SecStart = OS.tell();
|
||||||
|
|
||||||
|
const MCSymbol *SignatureSymbol = Group->getGroup();
|
||||||
|
assert(SignatureSymbol);
|
||||||
|
write(uint32_t(ELF::GRP_COMDAT));
|
||||||
|
for (const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
|
||||||
|
uint32_t SecIndex = SectionIndexMap.lookup(Member);
|
||||||
|
write(SecIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t SecEnd = OS.tell();
|
||||||
|
SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute symbol table information.
|
||||||
|
computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap);
|
||||||
|
|
||||||
|
for (MCSectionELF *RelSection : Relocations) {
|
||||||
|
uint64_t Padding = OffsetToAlignment(OS.tell(), RelSection->getAlignment());
|
||||||
|
WriteZeros(Padding);
|
||||||
|
|
||||||
|
// Remember the offset into the file for this section.
|
||||||
|
uint64_t SecStart = OS.tell();
|
||||||
|
|
||||||
|
writeRelocations(Asm, *RelSection->getAssociatedSection());
|
||||||
|
|
||||||
|
uint64_t SecEnd = OS.tell();
|
||||||
|
SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeSymbolTable(Ctx, Layout, SectionOffsets);
|
writeSymbolTable(Ctx, Layout, SectionOffsets);
|
||||||
|
Reference in New Issue
Block a user