[llvm] r228886 - Create the Seciton -> Rel Section map when it is first needed. NFC.

Chandler Carruth chandlerc at google.com
Thu Feb 12 23:46:08 PST 2015


FYI, some of the LLDB developers reported on lldb-dev@ that this revision
regressed tests. Rafael is away from a computer and on that thread said we
should go ahead and revert them, so I'm reverting this and a few other
revisions to get things back to green.

Rafael, ping here if you've any trouble reproducing when you're back. I've
CC-ed LLDB folks so they'll see and make sure we get to the root cause.

On Wed, Feb 11, 2015 at 3:17 PM, Rafael Espindola <
rafael.espindola at gmail.com> wrote:

> Author: rafael
> Date: Wed Feb 11 17:17:48 2015
> New Revision: 228886
>
> URL: http://llvm.org/viewvc/llvm-project?rev=228886&view=rev
> Log:
> Create the Seciton -> Rel Section map when it is first needed. NFC.
>
> Saves a walk over every section.
>
> Modified:
>     llvm/trunk/lib/MC/ELFObjectWriter.cpp
>
> Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=228886&r1=228885&r2=228886&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
> +++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Wed Feb 11 17:17:48 2015
> @@ -247,11 +247,12 @@ class ELFObjectWriter : public MCObjectW
>                              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 MCObjectW
>
>      // 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 MCSy
>    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(MC
>
>    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(MCAs
>      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;
> -
> -    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);
> +  MCContext &Ctx = Asm.getContext();
> +  const MCSectionELF &Section =
> +      static_cast<const MCSectionELF &>(SD.getSection());
>
> -    unsigned Flags = 0;
> -    StringRef Group = "";
> -    if (Section.getFlags() & ELF::SHF_GROUP) {
> -      Flags = ELF::SHF_GROUP;
> -      Group = Section.getGroup()->getName();
> -    }
> +  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);
>
> -    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::CreateMetadataSect
>                            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::CreateIndexedSecti
>      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(MCAsse
>    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;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150212/cd21b1c9/attachment.html>


More information about the llvm-commits mailing list