[ELF] - Store PhdrEntry values by pointers instead of storing by value.

That is slightly more convinent as allows to store pointer on
program header entry in a more safe way.
 
Change was used in 2 patches currently on review.

Differential revision: https://reviews.llvm.org/D35832

llvm-svn: 309253
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index dc69b70..8bf968f 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -761,7 +761,7 @@
   removeEmptyCommands();
 }
 
-void LinkerScript::allocateHeaders(std::vector<PhdrEntry> &Phdrs) {
+void LinkerScript::allocateHeaders(std::vector<PhdrEntry *> &Phdrs) {
   uint64_t Min = std::numeric_limits<uint64_t>::max();
   for (OutputSectionCommand *Cmd : OutputSectionCommands) {
     OutputSection *Sec = Cmd->Sec;
@@ -769,10 +769,11 @@
       Min = std::min<uint64_t>(Min, Sec->Addr);
   }
 
-  auto FirstPTLoad = llvm::find_if(
-      Phdrs, [](const PhdrEntry &E) { return E.p_type == PT_LOAD; });
-  if (FirstPTLoad == Phdrs.end())
+  auto It = llvm::find_if(
+      Phdrs, [](const PhdrEntry *E) { return E->p_type == PT_LOAD; });
+  if (It == Phdrs.end())
     return;
+  PhdrEntry *FirstPTLoad = *It;
 
   uint64_t HeaderSize = getHeaderSize();
   if (HeaderSize <= Min || Script->hasPhdrsCommands()) {
@@ -799,11 +800,11 @@
     }
     FirstPTLoad->First = ActualFirst;
   } else {
-    Phdrs.erase(FirstPTLoad);
+    Phdrs.erase(It);
   }
 
   auto PhdrI = llvm::find_if(
-      Phdrs, [](const PhdrEntry &E) { return E.p_type == PT_PHDR; });
+      Phdrs, [](const PhdrEntry *E) { return E->p_type == PT_PHDR; });
   if (PhdrI != Phdrs.end())
     Phdrs.erase(PhdrI);
 }
@@ -845,24 +846,25 @@
 }
 
 // Creates program headers as instructed by PHDRS linker script command.
-std::vector<PhdrEntry> LinkerScript::createPhdrs() {
-  std::vector<PhdrEntry> Ret;
+std::vector<PhdrEntry *> LinkerScript::createPhdrs() {
+  std::vector<PhdrEntry *> Ret;
 
   // 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) {
-    Ret.emplace_back(Cmd.Type, Cmd.Flags == UINT_MAX ? PF_R : Cmd.Flags);
-    PhdrEntry &Phdr = Ret.back();
+    PhdrEntry *Phdr =
+        make<PhdrEntry>(Cmd.Type, Cmd.Flags == UINT_MAX ? PF_R : Cmd.Flags);
 
     if (Cmd.HasFilehdr)
-      Phdr.add(Out::ElfHeader);
+      Phdr->add(Out::ElfHeader);
     if (Cmd.HasPhdrs)
-      Phdr.add(Out::ProgramHeaders);
+      Phdr->add(Out::ProgramHeaders);
 
     if (Cmd.LMAExpr) {
-      Phdr.p_paddr = Cmd.LMAExpr().getValue();
-      Phdr.HasLMA = true;
+      Phdr->p_paddr = Cmd.LMAExpr().getValue();
+      Phdr->HasLMA = true;
     }
+    Ret.push_back(Phdr);
   }
 
   // Add output sections to program headers.
@@ -870,9 +872,9 @@
     // Assign headers specified by linker script
     for (size_t Id : getPhdrIndices(Cmd)) {
       OutputSection *Sec = Cmd->Sec;
-      Ret[Id].add(Sec);
+      Ret[Id]->add(Sec);
       if (Opt.PhdrsCommands[Id].Flags == UINT_MAX)
-        Ret[Id].p_flags |= Sec->getPhdrFlags();
+        Ret[Id]->p_flags |= Sec->getPhdrFlags();
     }
   }
   return Ret;