Add r228886 back now that r229530 fixed the issue lldb was hitting.

Original message:

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@229536 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2015-02-17 20:31:13 +00:00
parent 166769cfb4
commit 07102899ac

View File

@ -247,11 +247,12 @@ class ELFObjectWriter : public MCObjectWriter {
const RevGroupMapTy &RevGroupMap,
unsigned NumRegularSections);
void ComputeIndexMap(MCAssembler &Asm,
void computeIndexMap(MCAssembler &Asm,
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);
@ -263,11 +264,11 @@ class ELFObjectWriter : public MCObjectWriter {
// Create the sections that show up in the symbol table. Currently
// 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,
RevGroupMapTy &RevGroupMap,
SectionIndexMapTy &SectionIndexMap,
const RelMapTy &RelMap);
RelMapTy &RelMap);
void ExecutePostLayoutBinding(MCAssembler &Asm,
const MCAsmLayout &Layout) override;
@ -941,9 +942,9 @@ bool ELFObjectWriter::isLocal(const MCSymbolData &Data, bool isUsedInReloc) {
return true;
}
void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,
void ELFObjectWriter::computeIndexMap(MCAssembler &Asm,
SectionIndexMapTy &SectionIndexMap,
const RelMapTy &RelMap) {
RelMapTy &RelMap) {
unsigned Index = 1;
for (MCAssembler::iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) {
@ -956,16 +957,20 @@ void ELFObjectWriter::ComputeIndexMap(MCAssembler &Asm,
for (MCAssembler::iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) {
const MCSectionData &SD = *it;
const MCSectionELF &Section =
static_cast<const MCSectionELF &>(it->getSection());
static_cast<const MCSectionELF &>(SD.getSection());
if (Section.getType() == ELF::SHT_GROUP ||
Section.getType() == ELF::SHT_REL ||
Section.getType() == ELF::SHT_RELA)
continue;
SectionIndexMap[&Section] = Index++;
const MCSectionELF *RelSection = RelMap.lookup(&Section);
if (RelSection)
if (MCSectionData *RelSD = createRelocationSection(Asm, SD)) {
const MCSectionELF *RelSection =
static_cast<const MCSectionELF *>(&RelSD->getSection());
RelMap[&Section] = RelSection;
SectionIndexMap[RelSection] = Index++;
}
}
}
@ -1115,42 +1120,37 @@ ELFObjectWriter::computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
UndefinedSymbolData[i].SymbolData->setIndex(Index++);
}
void ELFObjectWriter::CreateRelocationSections(MCAssembler &Asm,
RelMapTy &RelMap) {
for (MCAssembler::const_iterator it = Asm.begin(),
ie = Asm.end(); it != ie; ++it) {
const MCSectionData &SD = *it;
if (Relocations[&SD].empty())
continue;
MCSectionData *
ELFObjectWriter::createRelocationSection(MCAssembler &Asm,
const MCSectionData &SD) {
if (Relocations[&SD].empty())
return nullptr;
MCContext &Ctx = Asm.getContext();
const MCSectionELF &Section =
static_cast<const MCSectionELF&>(SD.getSection());
MCContext &Ctx = Asm.getContext();
const MCSectionELF &Section =
static_cast<const MCSectionELF &>(SD.getSection());
const StringRef SectionName = Section.getSectionName();
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
RelaSectionName += SectionName;
const StringRef SectionName = Section.getSectionName();
std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
RelaSectionName += SectionName;
unsigned EntrySize;
if (hasRelocationAddend())
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
else
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
unsigned EntrySize;
if (hasRelocationAddend())
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
else
EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
unsigned Flags = 0;
StringRef Group = "";
if (Section.getFlags() & ELF::SHF_GROUP) {
Flags = ELF::SHF_GROUP;
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);
unsigned Flags = 0;
StringRef Group = "";
if (Section.getFlags() & ELF::SHF_GROUP) {
Flags = ELF::SHF_GROUP;
Group = Section.getGroup()->getName();
}
const MCSectionELF *RelaSection = Ctx.getELFSection(
RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
Flags, EntrySize, Group);
return &Asm.getOrCreateSectionData(*RelaSection);
}
static SmallVector<char, 128>
@ -1445,12 +1445,12 @@ void ELFObjectWriter::CreateMetadataSections(
ShStrTabBuilder.data().end());
}
void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm,
void ELFObjectWriter::createIndexedSections(MCAssembler &Asm,
MCAsmLayout &Layout,
GroupMapTy &GroupMap,
RevGroupMapTy &RevGroupMap,
SectionIndexMapTy &SectionIndexMap,
const RelMapTy &RelMap) {
RelMapTy &RelMap) {
MCContext &Ctx = Asm.getContext();
// Build the groups
@ -1474,7 +1474,7 @@ void ELFObjectWriter::CreateIndexedSections(MCAssembler &Asm,
GroupMap[Group] = SignatureSymbol;
}
ComputeIndexMap(Asm, SectionIndexMap, RelMap);
computeIndexMap(Asm, SectionIndexMap, RelMap);
// Add sections to the groups
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));
DenseMap<const MCSectionELF*, const MCSectionELF*> RelMap;
CreateRelocationSections(Asm, RelMap);
const unsigned NumUserAndRelocSections = Asm.size();
CreateIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap,
createIndexedSections(Asm, const_cast<MCAsmLayout&>(Layout), GroupMap,
RevGroupMap, SectionIndexMap, RelMap);
const unsigned AllSections = Asm.size();
const unsigned NumIndexedSections = AllSections - NumUserAndRelocSections;