Add strings to .dynstr early.

Previously, we added strings from DynamicSection::finalize().
It was a bit tricky because finalize() is supposed to fix the final
size of the section, but adding new strings would change the size of
.dynstr section. So there was a dependency between finalize functions
of .dynamic and .dynstr.

However, I noticed that we can elimiante the dependency by simply
add strings early; we don't have to do that in finalize() but can do
from DynamicSection's ctor.

This patch defines a new function, DynamicSection::addEntries, to
add .dynamic entries that doesn't depend on other sections.

llvm-svn: 285784
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 1e5e3a2..af4fe83 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -218,6 +218,7 @@
   // Create singleton output sections.
   Out<ELFT>::Bss =
       make<OutputSection<ELFT>>(".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE);
+  Out<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
   Out<ELFT>::Dynamic = make<DynamicSection<ELFT>>();
   Out<ELFT>::EhFrame = make<EhOutputSection<ELFT>>();
   Out<ELFT>::Got = make<GotSection<ELFT>>();
@@ -237,7 +238,6 @@
     Out<ELFT>::Interp = make<InterpSection<ELFT>>();
 
   if (!Symtab<ELFT>::X->getSharedFiles().empty() || Config->Pic) {
-    Out<ELFT>::DynStrTab = make<StringTableSection<ELFT>>(".dynstr", true);
     Out<ELFT>::DynSymTab =
         make<SymbolTableSection<ELFT>>(*Out<ELFT>::DynStrTab);
   }
@@ -837,11 +837,9 @@
 
   // Fill other section headers. The dynamic table is finalized
   // at the end because some tags like RELSZ depend on result
-  // of finalizing other sections. The dynamic string table is
-  // finalized once the .dynamic finalizer has added a few last
-  // strings. See DynamicSection::finalize()
+  // of finalizing other sections.
   for (OutputSectionBase<ELFT> *Sec : OutputSections)
-    if (Sec != Out<ELFT>::DynStrTab && Sec != Out<ELFT>::Dynamic)
+    if (Sec != Out<ELFT>::Dynamic)
       Sec->finalize();
 
   if (Out<ELFT>::DynSymTab)