[lld] r305337 - Make OutputSections and OutputSectionCommands globals.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 16:26:31 PDT 2017


Author: rafael
Date: Tue Jun 13 18:26:31 2017
New Revision: 305337

URL: http://llvm.org/viewvc/llvm-project?rev=305337&view=rev
Log:
Make OutputSections and OutputSectionCommands globals.

This is similar to what we do for InputSections and makes them easier
to access.

Modified:
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=305337&r1=305336&r2=305337&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Jun 13 18:26:31 2017
@@ -458,7 +458,7 @@ void LinkerScript::fabricateDefaultComma
 
   // For each OutputSection that needs a VA fabricate an OutputSectionCommand
   // with an InputSectionDescription describing the InputSections
-  for (OutputSection *Sec : *OutputSections) {
+  for (OutputSection *Sec : OutputSections) {
     auto *OSCmd = createOutputSectionCommand(Sec->Name, "<internal>");
     OSCmd->Sec = Sec;
     SecToCommand[Sec] = OSCmd;
@@ -680,8 +680,8 @@ void LinkerScript::removeEmptyCommands()
   auto Pos = std::remove_if(
       Opt.Commands.begin(), Opt.Commands.end(), [&](BaseCommand *Base) {
         if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
-          return std::find(OutputSections->begin(), OutputSections->end(),
-                           Cmd->Sec) == OutputSections->end();
+          return std::find(OutputSections.begin(), OutputSections.end(),
+                           Cmd->Sec) == OutputSections.end();
         return false;
       });
   Opt.Commands.erase(Pos, Opt.Commands.end());
@@ -715,7 +715,7 @@ void LinkerScript::adjustSectionsBeforeS
 
     auto *OutSec = make<OutputSection>(Cmd->Name, SHT_PROGBITS, Flags);
     OutSec->SectionIndex = I;
-    OutputSections->push_back(OutSec);
+    OutputSections.push_back(OutSec);
     Cmd->Sec = OutSec;
     SecToCommand[OutSec] = Cmd;
   }
@@ -826,7 +826,7 @@ void LinkerScript::placeOrphanSections()
       ++CmdIndex;
   }
 
-  for (OutputSection *Sec : *OutputSections) {
+  for (OutputSection *Sec : OutputSections) {
     StringRef Name = Sec->Name;
 
     // Find the last spot where we can insert a command and still get the
@@ -921,9 +921,7 @@ allocateHeaders(std::vector<PhdrEntry> &
   return false;
 }
 
-void LinkerScript::assignAddresses(
-    std::vector<PhdrEntry> &Phdrs,
-    ArrayRef<OutputSectionCommand *> OutputSectionCommands) {
+void LinkerScript::assignAddresses(std::vector<PhdrEntry> &Phdrs) {
   // Assign addresses as instructed by linker script SECTIONS sub-commands.
   Dot = 0;
   ErrorOnMissingSection = true;
@@ -955,8 +953,7 @@ void LinkerScript::assignAddresses(
 }
 
 // Creates program headers as instructed by PHDRS linker script command.
-std::vector<PhdrEntry> LinkerScript::createPhdrs(
-    ArrayRef<OutputSectionCommand *> OutputSectionCommands) {
+std::vector<PhdrEntry> LinkerScript::createPhdrs() {
   std::vector<PhdrEntry> Ret;
 
   // Process PHDRS and FILEHDR keywords because they are not

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=305337&r1=305336&r2=305337&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Tue Jun 13 18:26:31 2017
@@ -267,15 +267,13 @@ public:
   ExprValue getSymbolValue(const Twine &Loc, StringRef S);
   bool isDefined(StringRef S);
 
-  std::vector<OutputSection *> *OutputSections;
   void fabricateDefaultCommands();
   void addOrphanSections(OutputSectionFactory &Factory);
   void removeEmptyCommands();
   void adjustSectionsBeforeSorting();
   void adjustSectionsAfterSorting();
 
-  std::vector<PhdrEntry>
-  createPhdrs(ArrayRef<OutputSectionCommand *> OutputSectionCommands);
+  std::vector<PhdrEntry> createPhdrs();
   bool ignoreInterpSection();
 
   bool hasLMA(OutputSection *Sec);
@@ -283,8 +281,7 @@ public:
   void assignOffsets(OutputSectionCommand *Cmd);
   void placeOrphanSections();
   void processNonSectionCommands();
-  void assignAddresses(std::vector<PhdrEntry> &Phdrs,
-                       ArrayRef<OutputSectionCommand *> OutputSectionCommands);
+  void assignAddresses(std::vector<PhdrEntry> &Phdrs);
 
   void addSymbol(SymbolAssignment *Cmd);
   void processCommands(OutputSectionFactory &Factory);

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=305337&r1=305336&r2=305337&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Jun 13 18:26:31 2017
@@ -41,6 +41,9 @@ OutputSection *Out::PreinitArray;
 OutputSection *Out::InitArray;
 OutputSection *Out::FiniArray;
 
+std::vector<OutputSection *> elf::OutputSections;
+std::vector<OutputSectionCommand *> elf::OutputSectionCommands;
+
 uint32_t OutputSection::getPhdrFlags() const {
   uint32_t Ret = PF_R;
   if (Flags & SHF_WRITE)

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=305337&r1=305336&r2=305337&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Jun 13 18:26:31 2017
@@ -150,6 +150,8 @@ private:
 uint64_t getHeaderSize();
 void reportDiscarded(InputSectionBase *IS);
 
+extern std::vector<OutputSection *> OutputSections;
+extern std::vector<OutputSectionCommand *> OutputSectionCommands;
 } // namespace elf
 } // namespace lld
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=305337&r1=305336&r2=305337&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Jun 13 18:26:31 2017
@@ -73,8 +73,6 @@ private:
 
   std::unique_ptr<FileOutputBuffer> Buffer;
 
-  std::vector<OutputSection *> OutputSections;
-  std::vector<OutputSectionCommand *> OutputSectionCommands;
   OutputSectionFactory Factory{OutputSections};
 
   void addRelIpltSymbols();
@@ -174,7 +172,6 @@ template <class ELFT> void Writer<ELFT>:
     addReservedSymbols();
 
   // Create output sections.
-  Script->OutputSections = &OutputSections;
   if (Script->Opt.HasSections) {
     // If linker script contains SECTIONS commands, let it create sections.
     Script->processCommands(Factory);
@@ -215,7 +212,7 @@ template <class ELFT> void Writer<ELFT>:
       OutputSectionCommands.begin(), OutputSectionCommands.end(),
       [](OutputSectionCommand *Cmd) { Cmd->maybeCompress<ELFT>(); });
 
-  Script->assignAddresses(Phdrs, OutputSectionCommands);
+  Script->assignAddresses(Phdrs);
 
   // Remove empty PT_LOAD to avoid causing the dynamic linker to try to mmap a
   // 0 sized region. This has to be done late since only after assignAddresses
@@ -1174,9 +1171,7 @@ template <class ELFT> void Writer<ELFT>:
   // The headers have to be created before finalize as that can influence the
   // image base and the dynamic section on mips includes the image base.
   if (!Config->Relocatable && !Config->OFormatBinary) {
-    Phdrs = Script->hasPhdrsCommands()
-                ? Script->createPhdrs(OutputSectionCommands)
-                : createPhdrs();
+    Phdrs = Script->hasPhdrsCommands() ? Script->createPhdrs() : createPhdrs();
     addPtArmExid(Phdrs);
     Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
   }




More information about the llvm-commits mailing list