Refactor LinkerScript::assignAddresses. NFC.

llvm-svn: 266666
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index fec2e19..ecc6838 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -90,30 +90,33 @@
   return R && R->Keep;
 }
 
-// This method finalizes the Locations list. Adds neccesary locations for
-// orphan sections, what prepares it for futher use without
-// changes in LinkerScript::assignAddresses().
 template <class ELFT>
-void LinkerScript::fixupLocations(std::vector<OutputSectionBase<ELFT> *> &S) {
+static OutputSectionBase<ELFT> *
+findSection(std::vector<OutputSectionBase<ELFT> *> &V, StringRef Name) {
+  for (OutputSectionBase<ELFT> *Sec : V)
+    if (Sec->getName() == Name)
+      return Sec;
+  return nullptr;
+}
+
+template <class ELFT>
+void LinkerScript::assignAddresses(
+    std::vector<OutputSectionBase<ELFT> *> &Sections) {
+  typedef typename ELFT::uint uintX_t;
+
   // Orphan sections are sections present in the input files which
-  // are not explicitly placed into the output file by the linker
-  // script. We place orphan sections at end of file. Other linkers places
-  // them using some heuristics as described in
+  // are not explicitly placed into the output file by the linker script.
+  // We place orphan sections at end of file.
+  // Other linkers places them using some heuristics as described in
   // https://sourceware.org/binutils/docs/ld/Orphan-Sections.html#Orphan-Sections.
-  for (OutputSectionBase<ELFT> *Sec : S) {
+  for (OutputSectionBase<ELFT> *Sec : Sections) {
     StringRef Name = Sec->getName();
     auto I = std::find(SectionOrder.begin(), SectionOrder.end(), Name);
     if (I == SectionOrder.end())
       Locations.push_back({Command::Section, {}, {Name}});
   }
-}
 
-template <class ELFT>
-void LinkerScript::assignAddresses(std::vector<OutputSectionBase<ELFT> *> &S) {
-  typedef typename ELFT::uint uintX_t;
-
-  Script->fixupLocations(S);
-
+  // Assign addresses as instructed by linker script SECTIONS sub-commands.
   uintX_t ThreadBssOffset = 0;
   uintX_t VA =
       Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
@@ -124,25 +127,20 @@
       continue;
     }
 
-    auto I =
-        std::find_if(S.begin(), S.end(), [&](OutputSectionBase<ELFT> *Sec) {
-          return Sec->getName() == Node.SectionName;
-        });
-    if (I == S.end())
+    OutputSectionBase<ELFT> *Sec = findSection(Sections, Node.SectionName);
+    if (!Sec)
       continue;
 
-    OutputSectionBase<ELFT> *Sec = *I;
-    uintX_t Align = Sec->getAlign();
     if ((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS) {
       uintX_t TVA = VA + ThreadBssOffset;
-      TVA = alignTo(TVA, Align);
+      TVA = alignTo(TVA, Sec->getAlign());
       Sec->setVA(TVA);
       ThreadBssOffset = TVA - VA + Sec->getSize();
       continue;
     }
 
     if (Sec->getFlags() & SHF_ALLOC) {
-      VA = alignTo(VA, Align);
+      VA = alignTo(VA, Sec->getAlign());
       Sec->setVA(VA);
       VA += Sec->getSize();
       continue;
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index c67ab1f..309599b 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -72,8 +72,6 @@
   bool DoLayout = false;
 
 private:
-  template <class ELFT>
-  void fixupLocations(std::vector<OutputSectionBase<ELFT> *> &);
   uint64_t evaluate(std::vector<StringRef> &Tokens, uint64_t LocCounter);
   template <class ELFT> SectionRule *find(InputSectionBase<ELFT> *S);