Remove ScriptConfiguration class and move the members to LinkerScript class.

ScriptConfiguration was a class to contain parsed results of
linker scripts. LinkerScript is a class to interpret it.

That ditinction was needed because we haven't instantiated
LinkerScript early (because, IIRC, LinkerScript class was a
ELFT template function). So, when we parse linker scripts,
we couldn't directly store the result to a LinkerScript instance.

Now, that limitation is gone. We instantiate LinkerScript
at the very beginning of our main function. We can directly
store parse results to a LinkerScript instance.

llvm-svn: 315403
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 14861d9..ae413b5 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -201,7 +201,7 @@
 }
 
 bool LinkerScript::shouldKeep(InputSectionBase *S) {
-  for (InputSectionDescription *ID : Opt.KeptSections) {
+  for (InputSectionDescription *ID : KeptSections) {
     std::string Filename = filename(S->File);
     if (ID->FilePat.match(Filename))
       for (SectionPattern &P : ID->SectionPatterns)
@@ -366,7 +366,7 @@
   // which will map to whatever the first actual section is.
   Aether = make<OutputSection>("", 0, SHF_ALLOC);
   Aether->SectionIndex = 1;
-  auto State = make_unique<AddressState>(Opt);
+  auto State = make_unique<AddressState>();
 
   // CurAddressState captures the local AddressState and makes it accessible
   // deliberately. This is needed as there are some cases where we cannot just
@@ -375,14 +375,14 @@
   CurAddressState = State.get();
   CurAddressState->OutSec = Aether;
 
-  for (size_t I = 0; I < Opt.Commands.size(); ++I) {
+  for (size_t I = 0; I < Commands.size(); ++I) {
     // Handle symbol assignments outside of any output section.
-    if (auto *Cmd = dyn_cast<SymbolAssignment>(Opt.Commands[I])) {
+    if (auto *Cmd = dyn_cast<SymbolAssignment>(Commands[I])) {
       addSymbol(Cmd);
       continue;
     }
 
-    if (auto *Sec = dyn_cast<OutputSection>(Opt.Commands[I])) {
+    if (auto *Sec = dyn_cast<OutputSection>(Commands[I])) {
       std::vector<InputSectionBase *> V = createInputSectionList(*Sec);
 
       // The output section name `/DISCARD/' is special.
@@ -402,7 +402,7 @@
       if (!matchConstraints(V, Sec->Constraint)) {
         for (InputSectionBase *S : V)
           S->Assigned = false;
-        Opt.Commands.erase(Opt.Commands.begin() + I);
+        Commands.erase(Commands.begin() + I);
         --I;
         continue;
       }
@@ -448,8 +448,7 @@
   auto Expr = [=] {
     return std::min(StartAddr, Target->getImageBase() + elf::getHeaderSize());
   };
-  Opt.Commands.insert(Opt.Commands.begin(),
-                      make<SymbolAssignment>(".", Expr, ""));
+  Commands.insert(Commands.begin(), make<SymbolAssignment>(".", Expr, ""));
 }
 
 static OutputSection *findByName(ArrayRef<BaseCommand *> Vec,
@@ -463,7 +462,7 @@
 
 // Add sections that didn't match any sections command.
 void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) {
-  unsigned End = Opt.Commands.size();
+  unsigned End = Commands.size();
 
   for (InputSectionBase *S : InputSections) {
     if (!S->Live || S->Parent)
@@ -472,14 +471,14 @@
     StringRef Name = getOutputSectionName(S->Name);
     log(toString(S) + " is being placed in '" + Name + "'");
 
-    if (OutputSection *Sec = findByName(
-            makeArrayRef(Opt.Commands).slice(0, End), Name)) {
+    if (OutputSection *Sec =
+            findByName(makeArrayRef(Commands).slice(0, End), Name)) {
       Sec->addSection(cast<InputSection>(S));
       continue;
     }
 
     if (OutputSection *OS = Factory.addInputSec(S, Name))
-      Script->Opt.Commands.push_back(OS);
+      Script->Commands.push_back(OS);
     assert(S->getOutputSection()->SectionIndex == INT_MAX);
   }
 }
@@ -588,8 +587,8 @@
   // If a memory region name was specified in the output section command,
   // then try to find that region first.
   if (!Sec->MemoryRegionName.empty()) {
-    auto It = Opt.MemoryRegions.find(Sec->MemoryRegionName);
-    if (It != Opt.MemoryRegions.end())
+    auto It = MemoryRegions.find(Sec->MemoryRegionName);
+    if (It != MemoryRegions.end())
       return It->second;
     error("memory region '" + Sec->MemoryRegionName + "' not declared");
     return nullptr;
@@ -598,11 +597,11 @@
   // If at least one memory region is defined, all sections must
   // belong to some memory region. Otherwise, we don't need to do
   // anything for memory regions.
-  if (Opt.MemoryRegions.empty())
+  if (MemoryRegions.empty())
     return nullptr;
 
   // See if a region can be found by matching section flags.
-  for (auto &Pair : Opt.MemoryRegions) {
+  for (auto &Pair : MemoryRegions) {
     MemoryRegion *M = Pair.second;
     if ((M->Flags & Sec->Flags) && (M->NegFlags & Sec->Flags) == 0)
       return M;
@@ -649,7 +648,7 @@
   // clutter the output.
   // We instead remove trivially empty sections. The bfd linker seems even
   // more aggressive at removing them.
-  llvm::erase_if(Opt.Commands, [&](BaseCommand *Base) {
+  llvm::erase_if(Commands, [&](BaseCommand *Base) {
     if (auto *Sec = dyn_cast<OutputSection>(Base))
       return !Sec->Live;
     return false;
@@ -670,7 +669,7 @@
   // consequeces and gives us a section to put the symbol in.
   uint64_t Flags = SHF_ALLOC;
 
-  for (BaseCommand * Cmd : Opt.Commands) {
+  for (BaseCommand *Cmd : Commands) {
     auto *Sec = dyn_cast<OutputSection>(Cmd);
     if (!Sec)
       continue;
@@ -689,7 +688,7 @@
 
 void LinkerScript::adjustSectionsAfterSorting() {
   // Try and find an appropriate memory region to assign offsets in.
-  for (BaseCommand *Base : Opt.Commands) {
+  for (BaseCommand *Base : Commands) {
     if (auto *Sec = dyn_cast<OutputSection>(Base)) {
       if (!Sec->Live)
         continue;
@@ -709,14 +708,14 @@
   // SECTIONS { .aaa : { *(.aaa) } }
   std::vector<StringRef> DefPhdrs;
   auto FirstPtLoad =
-      std::find_if(Opt.PhdrsCommands.begin(), Opt.PhdrsCommands.end(),
+      std::find_if(PhdrsCommands.begin(), PhdrsCommands.end(),
                    [](const PhdrsCommand &Cmd) { return Cmd.Type == PT_LOAD; });
-  if (FirstPtLoad != Opt.PhdrsCommands.end())
+  if (FirstPtLoad != PhdrsCommands.end())
     DefPhdrs.push_back(FirstPtLoad->Name);
 
   // Walk the commands and propagate the program headers to commands that don't
   // explicitly specify them.
-  for (BaseCommand *Base : Opt.Commands) {
+  for (BaseCommand *Base : Commands) {
     auto *Sec = dyn_cast<OutputSection>(Base);
     if (!Sec)
       continue;
@@ -765,7 +764,7 @@
   uint64_t HeaderSize = getHeaderSize();
   // When linker script with SECTIONS is being used, don't output headers
   // unless there's a space for them.
-  uint64_t Base = Opt.HasSections ? alignDown(Min, Config->MaxPageSize) : 0;
+  uint64_t Base = HasSections ? alignDown(Min, Config->MaxPageSize) : 0;
   if (HeaderSize <= Min - Base || Script->hasPhdrsCommands()) {
     Min = alignDown(Min - HeaderSize, Config->MaxPageSize);
     Out::ElfHeader->Addr = Min;
@@ -781,8 +780,8 @@
                  [](const PhdrEntry *E) { return E->p_type == PT_PHDR; });
 }
 
-LinkerScript::AddressState::AddressState(const ScriptConfiguration &Opt) {
-  for (auto &MRI : Opt.MemoryRegions) {
+LinkerScript::AddressState::AddressState() {
+  for (auto &MRI : Script->MemoryRegions) {
     const MemoryRegion *MR = MRI.second;
     MemRegionOffset[MR] = MR->Origin;
   }
@@ -793,7 +792,7 @@
   // By default linker scripts use an initial value of 0 for '.', but prefer
   // -image-base if set.
   Dot = Config->ImageBase ? *Config->ImageBase : 0;
-  auto State = make_unique<AddressState>(Opt);
+  auto State = make_unique<AddressState>();
 
   // CurAddressState captures the local AddressState and makes it accessible
   // deliberately. This is needed as there are some cases where we cannot just
@@ -803,7 +802,7 @@
   ErrorOnMissingSection = true;
   switchTo(Aether);
 
-  for (BaseCommand *Base : Opt.Commands) {
+  for (BaseCommand *Base : Commands) {
     if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {
       assignSymbol(Cmd, false);
       continue;
@@ -825,7 +824,7 @@
 
   // Process PHDRS and FILEHDR keywords because they are not
   // real output sections and cannot be added in the following loop.
-  for (const PhdrsCommand &Cmd : Opt.PhdrsCommands) {
+  for (const PhdrsCommand &Cmd : PhdrsCommands) {
     PhdrEntry *Phdr = make<PhdrEntry>(Cmd.Type, Cmd.Flags ? *Cmd.Flags : PF_R);
 
     if (Cmd.HasFilehdr)
@@ -845,7 +844,7 @@
     // Assign headers specified by linker script
     for (size_t Id : getPhdrIndices(Sec)) {
       Ret[Id]->add(Sec);
-      if (!Opt.PhdrsCommands[Id].Flags.hasValue())
+      if (!PhdrsCommands[Id].Flags.hasValue())
         Ret[Id]->p_flags |= Sec->getPhdrFlags();
     }
   }
@@ -858,9 +857,9 @@
 // no PT_INTERP is there, there's no place to emit an
 // .interp, so we don't do that in that case.
 bool LinkerScript::needsInterpSection() {
-  if (Opt.PhdrsCommands.empty())
+  if (PhdrsCommands.empty())
     return true;
-  for (PhdrsCommand &Cmd : Opt.PhdrsCommands)
+  for (PhdrsCommand &Cmd : PhdrsCommands)
     if (Cmd.Type == PT_INTERP)
       return true;
   return false;
@@ -899,7 +898,7 @@
   std::vector<size_t> Ret;
 
   for (StringRef S : Cmd->Phdrs) {
-    if (Optional<size_t> Idx = getPhdrIndex(Opt.PhdrsCommands, S))
+    if (Optional<size_t> Idx = getPhdrIndex(PhdrsCommands, S))
       Ret.push_back(*Idx);
     else if (S != "NONE")
       error(Cmd->Location + ": section header '" + S +