diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-02-11 23:17:48 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-02-11 23:17:48 +0000 |
commit | fbfbdc4377cf20dc9284cc13718f83ac75628298 (patch) | |
tree | e129d0783da92432d68152d0e29d5a19c289ae6a /llvm/lib/MC | |
parent | 02438033e864f368cfc6ff3c915b2d113b46dde9 (diff) | |
download | bcm5719-llvm-fbfbdc4377cf20dc9284cc13718f83ac75628298.tar.gz bcm5719-llvm-fbfbdc4377cf20dc9284cc13718f83ac75628298.zip |
Create the Seciton -> Rel Section map when it is first needed. NFC.
Saves a walk over every section.
llvm-svn: 228886
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 600d06472fc..bd86e610715 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -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; - - MCContext &Ctx = Asm.getContext(); - const MCSectionELF &Section = - static_cast<const MCSectionELF&>(SD.getSection()); +MCSectionData * +ELFObjectWriter::createRelocationSection(MCAssembler &Asm, + const MCSectionData &SD) { + if (Relocations[&SD].empty()) + return nullptr; - const StringRef SectionName = Section.getSectionName(); - std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel"; - RelaSectionName += SectionName; + MCContext &Ctx = Asm.getContext(); + const MCSectionELF &Section = + static_cast<const MCSectionELF &>(SD.getSection()); - 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); + const StringRef SectionName = Section.getSectionName(); + std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel"; + RelaSectionName += SectionName; - unsigned Flags = 0; - StringRef Group = ""; - if (Section.getFlags() & ELF::SHF_GROUP) { - Flags = ELF::SHF_GROUP; - Group = Section.getGroup()->getName(); - } + 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); - 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; |