mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-16 11:30:51 +00:00
Create the Seciton -> Rel Section map when it is first needed. NFC.
Saves a walk over every section. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228886 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7f75841a73
commit
3ce0dd9867
@ -247,11 +247,12 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
const RevGroupMapTy &RevGroupMap,
|
const RevGroupMapTy &RevGroupMap,
|
||||||
unsigned NumRegularSections);
|
unsigned NumRegularSections);
|
||||||
|
|
||||||
void ComputeIndexMap(MCAssembler &Asm,
|
void computeIndexMap(MCAssembler &Asm,
|
||||||
SectionIndexMapTy &SectionIndexMap,
|
SectionIndexMapTy &SectionIndexMap,
|
||||||
const RelMapTy &RelMap);
|
RelMapTy &RelMap);
|
||||||
|
|
||||||
void CreateRelocationSections(MCAssembler &Asm, RelMapTy &RelMap);
|
MCSectionData *createRelocationSection(MCAssembler &Asm,
|
||||||
|
const MCSectionData &SD);
|
||||||
|
|
||||||
void CompressDebugSections(MCAssembler &Asm, MCAsmLayout &Layout);
|
void CompressDebugSections(MCAssembler &Asm, MCAsmLayout &Layout);
|
||||||
|
|
||||||
@ -263,11 +264,11 @@ class ELFObjectWriter : public MCObjectWriter {
|
|||||||
|
|
||||||
// Create the sections that show up in the symbol table. Currently
|
// Create the sections that show up in the symbol table. Currently
|
||||||
// those are the .note.GNU-stack section and the group sections.
|
// those are the .note.GNU-stack section and the group sections.
|
||||||
void CreateIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout,
|
void createIndexedSections(MCAssembler &Asm, MCAsmLayout &Layout,
|
||||||
GroupMapTy &GroupMap,
|
GroupMapTy &GroupMap,
|
||||||
RevGroupMapTy &RevGroupMap,
|
RevGroupMapTy &RevGroupMap,
|
||||||
SectionIndexMapTy &SectionIndexMap,
|
SectionIndexMapTy &SectionIndexMap,
|
||||||
const RelMapTy &RelMap);
|
RelMapTy &RelMap);
|
||||||
|
|
||||||
void ExecutePostLayoutBinding(MCAssembler &Asm,
|
void ExecutePostLayoutBinding(MCAssembler &Asm,
|
||||||
const MCAsmLayout &Layout) override;
|
const MCAsmLayout &Layout) override;
|
||||||
@ -941,9 +942,9 @@ bool ELFObjectWriter::isLocal(const MCSymbolData &Data, bool isUsedInReloc) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,
|
void ELFObjectWriter::computeIndexMap(MCAssembler &Asm,
|
||||||
SectionIndexMapTy &SectionIndexMap,
|
SectionIndexMapTy &SectionIndexMap,
|
||||||
const RelMapTy &RelMap) {
|
RelMapTy &RelMap) {
|
||||||
unsigned Index = 1;
|
unsigned Index = 1;
|
||||||
for (MCAssembler::iterator it = Asm.begin(),
|
for (MCAssembler::iterator it = Asm.begin(),
|
||||||
ie = Asm.end(); it != ie; ++it) {
|
ie = Asm.end(); it != ie; ++it) {
|
||||||
@ -956,16 +957,20 @@ void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,
|
|||||||
|
|
||||||
for (MCAssembler::iterator it = Asm.begin(),
|
for (MCAssembler::iterator it = Asm.begin(),
|
||||||
ie = Asm.end(); it != ie; ++it) {
|
ie = Asm.end(); it != ie; ++it) {
|
||||||
|
const MCSectionData &SD = *it;
|
||||||
const MCSectionELF &Section =
|
const MCSectionELF &Section =
|
||||||
static_cast<const MCSectionELF &>(it->getSection());
|
static_cast<const MCSectionELF &>(SD.getSection());
|
||||||
if (Section.getType() == ELF::SHT_GROUP ||
|
if (Section.getType() == ELF::SHT_GROUP ||
|
||||||
Section.getType() == ELF::SHT_REL ||
|
Section.getType() == ELF::SHT_REL ||
|
||||||
Section.getType() == ELF::SHT_RELA)
|
Section.getType() == ELF::SHT_RELA)
|
||||||
continue;
|
continue;
|
||||||
SectionIndexMap[&Section] = Index++;
|
SectionIndexMap[&Section] = Index++;
|
||||||
const MCSectionELF *RelSection = RelMap.lookup(&Section);
|
if (MCSectionData *RelSD = createRelocationSection(Asm, SD)) {
|
||||||
if (RelSection)
|
const MCSectionELF *RelSection =
|
||||||
|
static_cast<const MCSectionELF *>(&RelSD->getSection());
|
||||||
|
RelMap[&Section] = RelSection;
|
||||||
SectionIndexMap[RelSection] = Index++;
|
SectionIndexMap[RelSection] = Index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1115,42 +1120,37 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
|
|||||||
UndefinedSymbolData[i].SymbolData->setIndex(Index++);
|
UndefinedSymbolData[i].SymbolData->setIndex(Index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ELFObjectWriter::CreateRelocationSections(MCAssembler &Asm,
|
MCSectionData *
|
||||||
RelMapTy &RelMap) {
|
ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
|
||||||
for (MCAssembler::const_iterator it = Asm.begin(),
|
const MCSectionData &SD) {
|
||||||
ie = Asm.end(); it != ie; ++it) {
|
if (Relocations[&SD].empty())
|
||||||
const MCSectionData &SD = *it;
|
return nullptr;
|
||||||
if (Relocations[&SD].empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
MCContext &Ctx = Asm.getContext();
|
MCContext &Ctx = Asm.getContext();
|
||||||
const MCSectionELF &Section =
|
const MCSectionELF &Section =
|
||||||
static_cast<const MCSectionELF&>(SD.getSection());
|
static_cast<const MCSectionELF &>(SD.getSection());
|
||||||
|
|
||||||
const StringRef SectionName = Section.getSectionName();
|
const StringRef SectionName = Section.getSectionName();
|
||||||
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
|
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
|
||||||
RelaSectionName += SectionName;
|
RelaSectionName += SectionName;
|
||||||
|
|
||||||
unsigned EntrySize;
|
unsigned EntrySize;
|
||||||
if (hasRelocationAddend())
|
if (hasRelocationAddend())
|
||||||
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
|
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
|
||||||
else
|
else
|
||||||
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
|
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
|
||||||
|
|
||||||
unsigned Flags = 0;
|
unsigned Flags = 0;
|
||||||
StringRef Group = "";
|
StringRef Group = "";
|
||||||
if (Section.getFlags() & ELF::SHF_GROUP) {
|
if (Section.getFlags() & ELF::SHF_GROUP) {
|
||||||
Flags = ELF::SHF_GROUP;
|
Flags = ELF::SHF_GROUP;
|
||||||
Group = Section.getGroup()->getName();
|
Group = Section.getGroup()->getName();
|
||||||
}
|
|
||||||
|
|
||||||
const MCSectionELF *RelaSection =
|
|
||||||
Ctx.getELFSection(RelaSectionName, hasRelocationAddend() ?
|
|
||||||
ELF::SHT_RELA : ELF::SHT_REL, Flags,
|
|
||||||
EntrySize, Group);
|
|
||||||
RelMap[&Section] = RelaSection;
|
|
||||||
Asm.getOrCreateSectionData(*RelaSection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MCSectionELF *RelaSection = Ctx.getELFSection(
|
||||||
|
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
|
||||||
|
Flags, EntrySize, Group);
|
||||||
|
return &Asm.getOrCreateSectionData(*RelaSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SmallVector<char, 128>
|
static SmallVector<char, 128>
|
||||||
@ -1445,12 +1445,12 @@ void ELFObjectWriter::CreateMetadataSections(
|
|||||||
ShStrTabBuilder.data().end());
|
ShStrTabBuilder.data().end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm,
|
void ELFObjectWriter::createIndexedSections(MCAssembler &Asm,
|
||||||
MCAsmLayout &Layout,
|
MCAsmLayout &Layout,
|
||||||
GroupMapTy &GroupMap,
|
GroupMapTy &GroupMap,
|
||||||
RevGroupMapTy &RevGroupMap,
|
RevGroupMapTy &RevGroupMap,
|
||||||
SectionIndexMapTy &SectionIndexMap,
|
SectionIndexMapTy &SectionIndexMap,
|
||||||
const RelMapTy &RelMap) {
|
RelMapTy &RelMap) {
|
||||||
MCContext &Ctx = Asm.getContext();
|
MCContext &Ctx = Asm.getContext();
|
||||||
|
|
||||||
// Build the groups
|
// Build the groups
|
||||||
@ -1474,7 +1474,7 @@ void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm,
|
|||||||
GroupMap[Group] = SignatureSymbol;
|
GroupMap[Group] = SignatureSymbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputeIndexMap(Asm, SectionIndexMap, RelMap);
|
computeIndexMap(Asm, SectionIndexMap, RelMap);
|
||||||
|
|
||||||
// Add sections to the groups
|
// Add sections to the groups
|
||||||
for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end();
|
for (MCAssembler::const_iterator it = Asm.begin(), ie = Asm.end();
|
||||||
@ -1716,10 +1716,8 @@ void ELFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
CompressDebugSections(Asm, const_cast<MCAsmLayout &>(Layout));
|
CompressDebugSections(Asm, const_cast<MCAsmLayout &>(Layout));
|
||||||
|
|
||||||
DenseMap<const MCSectionELF*, const MCSectionELF*> RelMap;
|
DenseMap<const MCSectionELF*, const MCSectionELF*> RelMap;
|
||||||
CreateRelocationSections(Asm, RelMap);
|
|
||||||
|
|
||||||
const unsigned NumUserAndRelocSections = Asm.size();
|
const unsigned NumUserAndRelocSections = Asm.size();
|
||||||
CreateIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap,
|
createIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap,
|
||||||
RevGroupMap, SectionIndexMap, RelMap);
|
RevGroupMap, SectionIndexMap, RelMap);
|
||||||
const unsigned AllSections = Asm.size();
|
const unsigned AllSections = Asm.size();
|
||||||
const unsigned NumIndexedSections = AllSections - NumUserAndRelocSections;
|
const unsigned NumIndexedSections = AllSections - NumUserAndRelocSections;
|
||||||
|
Loading…
Reference in New Issue
Block a user