[lld] r304014 - Avoid a couple uses of OutputSections.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri May 26 10:48:27 PDT 2017


Author: rafael
Date: Fri May 26 12:48:27 2017
New Revision: 304014

URL: http://llvm.org/viewvc/llvm-project?rev=304014&view=rev
Log:
Avoid a couple uses of OutputSections.

After fabricateDefaultCommands we can look at the script commands.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=304014&r1=304013&r2=304014&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri May 26 12:48:27 2017
@@ -81,7 +81,8 @@ private:
   void addStartStopSymbols(OutputSection *Sec);
   uint64_t getEntryAddr();
   OutputSection *findSection(StringRef Name);
-  OutputSectionCommand *findSectionInScript(StringRef Name);
+  OutputSection *findSectionInScript(StringRef Name);
+  OutputSectionCommand *findSectionCommand(StringRef Name);
 
   std::vector<PhdrEntry> Phdrs;
 
@@ -1313,7 +1314,7 @@ void Writer<ELFT>::addStartStopSymbols(O
 }
 
 template <class ELFT>
-OutputSectionCommand *Writer<ELFT>::findSectionInScript(StringRef Name) {
+OutputSectionCommand *Writer<ELFT>::findSectionCommand(StringRef Name) {
   for (BaseCommand *Base : Script->Opt.Commands)
     if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
       if (Cmd->Name == Name)
@@ -1321,6 +1322,12 @@ OutputSectionCommand *Writer<ELFT>::find
   return nullptr;
 }
 
+template <class ELFT> OutputSection *Writer<ELFT>::findSectionInScript(StringRef Name) {
+  if (OutputSectionCommand *Cmd = findSectionCommand(Name))
+    return Cmd->Sec;
+  return nullptr;
+}
+
 template <class ELFT> OutputSection *Writer<ELFT>::findSection(StringRef Name) {
   for (OutputSection *Sec : OutputSections)
     if (Sec->Name == Name)
@@ -1607,7 +1614,7 @@ template <class ELFT> uint64_t Writer<EL
     return Addr;
 
   // Case 4
-  if (OutputSection *Sec = findSection(".text")) {
+  if (OutputSection *Sec = findSectionInScript(".text")) {
     if (Config->WarnMissingEntry)
       warn("cannot find entry symbol " + Config->Entry + "; defaulting to 0x" +
            utohexstr(Sec->Addr));
@@ -1670,7 +1677,7 @@ template <class ELFT> void Writer<ELFT>:
   }
 
   if (ElfSym::Bss)
-    ElfSym::Bss->Section = findSection(".bss");
+    ElfSym::Bss->Section = findSectionInScript(".bss");
 
   // Setup MIPS _gp_disp/__gnu_local_gp symbols which should
   // be equal to the _gp symbol's value.
@@ -1778,7 +1785,7 @@ template <class ELFT> void Writer<ELFT>:
 
   // PPC64 needs to process relocations in the .opd section
   // before processing relocations in code-containing sections.
-  if (auto *OpdCmd = findSectionInScript(".opd")) {
+  if (auto *OpdCmd = findSectionCommand(".opd")) {
     Out::Opd = OpdCmd->Sec;
     Out::OpdBuf = Buf + Out::Opd->Offset;
     OpdCmd->template writeTo<ELFT>(Buf + Out::Opd->Offset);




More information about the llvm-commits mailing list