diff options
author | Peter Smith <peter.smith@linaro.org> | 2017-12-12 13:38:51 +0000 |
---|---|---|
committer | Peter Smith <peter.smith@linaro.org> | 2017-12-12 13:38:51 +0000 |
commit | 2128df7e7ba35697ad749540b962c8170778e499 (patch) | |
tree | f6140fa5423dd65e6124dcba4e8dd83e648817e2 /lld/ELF/OutputSections.cpp | |
parent | 03cbf468cdecc11ef2432a64722f761ea68239fb (diff) | |
download | bcm5719-llvm-2128df7e7ba35697ad749540b962c8170778e499.tar.gz bcm5719-llvm-2128df7e7ba35697ad749540b962c8170778e499.zip |
[ELF] Refactor to remove loop copying all Sections in OS->finalize() [NFC]
Moving the SHF_LINK_ORDER processing out of OutputSection::finalize()
means that we no longer need to copy all InputSections as we now only need
the first one.
Differential Revision: https://reviews.llvm.org/D40966
llvm-svn: 320478
Diffstat (limited to 'lld/ELF/OutputSections.cpp')
-rw-r--r-- | lld/ELF/OutputSections.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 438dfa17205..f0677f7e1ca 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -275,8 +275,8 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) { template <class ELFT> static void finalizeShtGroup(OutputSection *OS, - ArrayRef<InputSection *> Sections) { - assert(Config->Relocatable && Sections.size() == 1); + InputSection *Section) { + assert(Config->Relocatable); // sh_link field for SHT_GROUP sections should contain the section index of // the symbol table. @@ -284,17 +284,19 @@ static void finalizeShtGroup(OutputSection *OS, // sh_info then contain index of an entry in symbol table section which // provides signature of the section group. - ObjFile<ELFT> *Obj = Sections[0]->getFile<ELFT>(); + ObjFile<ELFT> *Obj = Section->getFile<ELFT>(); ArrayRef<Symbol *> Symbols = Obj->getSymbols(); - OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]); + OS->Info = InX::SymTab->getSymbolIndex(Symbols[Section->Info]); } template <class ELFT> void OutputSection::finalize() { - std::vector<InputSection *> Sections; + InputSection *First = nullptr; for (BaseCommand *Base : SectionCommands) { if (auto *ISD = dyn_cast<InputSectionDescription>(Base)) { - for (InputSection *&IS : ISD->Sections) - Sections.push_back(IS); + if (ISD->Sections.empty()) + continue; + if (First == nullptr) + First = ISD->Sections.front(); } if (isa<ByteCommand>(Base) && Type == SHT_NOBITS) Type = SHT_PROGBITS; @@ -305,19 +307,18 @@ template <class ELFT> void OutputSection::finalize() { // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We // need to translate the InputSection sh_link to the OutputSection sh_link, // all InputSections in the OutputSection have the same dependency. - if (auto *D = Sections.front()->getLinkOrderDep()) + if (auto *D = First->getLinkOrderDep()) Link = D->getParent()->SectionIndex; } if (Type == SHT_GROUP) { - finalizeShtGroup<ELFT>(this, Sections); + finalizeShtGroup<ELFT>(this, First); return; } if (!Config->CopyRelocs || (Type != SHT_RELA && Type != SHT_REL)) return; - InputSection *First = Sections[0]; if (isa<SyntheticSection>(First)) return; |