[lld] r304827 - Avoid using OutputSection::Sections. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 13:13:19 PDT 2017


Author: rafael
Date: Tue Jun  6 15:13:19 2017
New Revision: 304827

URL: http://llvm.org/viewvc/llvm-project?rev=304827&view=rev
Log:
Avoid using OutputSection::Sections. NFC.

We now used the InputSectionDescriptions in
OutputSectionCommand::finalize. This will allow moving
clearOutputSections earlier.

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=304827&r1=304826&r2=304827&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Jun  6 15:13:19 2017
@@ -1085,31 +1085,34 @@ static bool compareByFilePosition(InputS
   return LA->OutSecOff < LB->OutSecOff;
 }
 
-template <class ELFT> static void finalizeShtGroup(OutputSection *Sec) {
+template <class ELFT>
+static void finalizeShtGroup(OutputSection *OS,
+                             ArrayRef<InputSection *> Sections) {
   // sh_link field for SHT_GROUP sections should contain the section index of
   // the symbol table.
-  Sec->Link = InX::SymTab->getParent()->SectionIndex;
+  OS->Link = InX::SymTab->getParent()->SectionIndex;
 
   // sh_info then contain index of an entry in symbol table section which
   // provides signature of the section group.
-  elf::ObjectFile<ELFT> *Obj = Sec->Sections[0]->getFile<ELFT>();
-  assert(Config->Relocatable && Sec->Sections.size() == 1);
+  elf::ObjectFile<ELFT> *Obj = Sections[0]->getFile<ELFT>();
+  assert(Config->Relocatable && Sections.size() == 1);
   ArrayRef<SymbolBody *> Symbols = Obj->getSymbols();
-  Sec->Info = InX::SymTab->getSymbolIndex(Symbols[Sec->Sections[0]->Info - 1]);
+  OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info - 1]);
 }
 
 template <class ELFT> void OutputSectionCommand::finalize() {
-  if ((Sec->Flags & SHF_LINK_ORDER) && !Sec->Sections.empty()) {
-    // Link order may be distributed across several InputSectionDescriptions
-    // but sort must consider them all at once.
-    std::vector<InputSection **> ScriptSections;
-    std::vector<InputSection *> Sections;
-    for (BaseCommand *Base : Commands)
-      if (auto *ISD = dyn_cast<InputSectionDescription>(Base))
-        for (InputSection *&IS : ISD->Sections) {
-          ScriptSections.push_back(&IS);
-          Sections.push_back(IS);
-        }
+  // Link order may be distributed across several InputSectionDescriptions
+  // but sort must consider them all at once.
+  std::vector<InputSection **> ScriptSections;
+  std::vector<InputSection *> Sections;
+  for (BaseCommand *Base : Commands)
+    if (auto *ISD = dyn_cast<InputSectionDescription>(Base))
+      for (InputSection *&IS : ISD->Sections) {
+        ScriptSections.push_back(&IS);
+        Sections.push_back(IS);
+      }
+
+  if ((Sec->Flags & SHF_LINK_ORDER)) {
     std::sort(Sections.begin(), Sections.end(), compareByFilePosition);
     for (int I = 0, N = Sections.size(); I < N; ++I)
       *ScriptSections[I] = Sections[I];
@@ -1118,20 +1121,20 @@ template <class ELFT> void OutputSection
     // 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 = Sec->Sections.front()->getLinkOrderDep())
+    if (auto *D = Sections.front()->getLinkOrderDep())
       Sec->Link = D->getParent()->SectionIndex;
   }
 
   uint32_t Type = Sec->Type;
   if (Type == SHT_GROUP) {
-    finalizeShtGroup<ELFT>(Sec);
+    finalizeShtGroup<ELFT>(Sec, Sections);
     return;
   }
 
   if (!Config->CopyRelocs || (Type != SHT_RELA && Type != SHT_REL))
     return;
 
-  InputSection *First = Sec->Sections[0];
+  InputSection *First = Sections[0];
   if (isa<SyntheticSection>(First))
     return;
 




More information about the llvm-commits mailing list