From 5acccb16a83ffeaf8e3dad89145302135ef05513 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 28 Apr 2015 22:59:58 +0000 Subject: [PATCH] Map directly from signature symbol to group index. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236058 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/MC/ELFObjectWriter.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp index 201b1a40f39..573443756a3 100644 --- a/lib/MC/ELFObjectWriter.cpp +++ b/lib/MC/ELFObjectWriter.cpp @@ -217,8 +217,8 @@ class ELFObjectWriter : public MCObjectWriter { uint64_t getSymbolIndexInSymbolTable(const MCAssembler &Asm, const MCSymbol *S); - // Map from a signature symbol to the group section - typedef DenseMap RevGroupMapTy; + // Map from a signature symbol to the group section index + typedef DenseMap RevGroupMapTy; // Start and end offset of each section typedef std::vector> SectionOffsetsTy; @@ -231,7 +231,9 @@ class ELFObjectWriter : public MCObjectWriter { const SectionIndexMapTy &SectionIndexMap, const RevGroupMapTy &RevGroupMap); - void maybeAddToGroup(MCAssembler &Asm, const RevGroupMapTy &RevGroupMap, + void maybeAddToGroup(MCAssembler &Asm, + ArrayRef Sections, + const RevGroupMapTy &RevGroupMap, const MCSectionELF &Section, unsigned Index); void computeIndexMap(MCAssembler &Asm, @@ -940,13 +942,14 @@ bool ELFObjectWriter::isLocal(const MCSymbolData &Data, bool isUsedInReloc) { } void ELFObjectWriter::maybeAddToGroup(MCAssembler &Asm, + ArrayRef Sections, const RevGroupMapTy &RevGroupMap, const MCSectionELF &Section, unsigned Index) { const MCSymbol *Sym = Section.getGroup(); if (!Sym) return; - const MCSectionELF *Group = RevGroupMap.lookup(Sym); + const MCSectionELF *Group = Sections[RevGroupMap.lookup(Sym) - 1]; MCSectionData &Data = Asm.getOrCreateSectionData(*Group); // FIXME: we could use the previous fragment MCDataFragment *F = new MCDataFragment(&Data); @@ -964,7 +967,7 @@ void ELFObjectWriter::computeIndexMap( Sections.push_back(&Section); unsigned Index = Sections.size(); SectionIndexMap[&Section] = Index; - maybeAddToGroup(Asm, RevGroupMap, Section, Index); + maybeAddToGroup(Asm, Sections, RevGroupMap, Section, Index); createRelocationSection(Asm, SD); } } @@ -1017,7 +1020,7 @@ void ELFObjectWriter::computeSymbolTable( MSD.SectionIndex = ELF::SHN_COMMON; } else if (BaseSymbol->isUndefined()) { if (isSignature && !Used) - MSD.SectionIndex = SectionIndexMap.lookup(RevGroupMap.lookup(&Symbol)); + MSD.SectionIndex = RevGroupMap.lookup(&Symbol); else MSD.SectionIndex = ELF::SHN_UNDEF; if (!Used && WeakrefUsed) @@ -1435,11 +1438,11 @@ void ELFObjectWriter::createIndexedSections( const MCSymbol *SignatureSymbol = Section.getGroup(); Asm.getOrCreateSymbolData(*SignatureSymbol); - const MCSectionELF *&Group = RevGroupMap[SignatureSymbol]; - if (!Group) { - Group = Ctx.createELFGroupSection(SignatureSymbol); + unsigned &GroupIdx = RevGroupMap[SignatureSymbol]; + if (!GroupIdx) { + const MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol); Sections.push_back(Group); - SectionIndexMap[Group] = Sections.size(); + GroupIdx = Sections.size(); MCSectionData &Data = Asm.getOrCreateSectionData(*Group); Data.setAlignment(4); -- 2.34.1