Avoid almost duplication in .dynamic finalize and write.
There are a few cases where we have almost duplicated code.
This patches fixes the simplest: the finalize and write of dynamic
section. Right now they have to have exactly the same structure to
decide if a DT_* entry is needed and then to actually write it.
We cannot just write it to a std::vector in the first pass since
addresses have not been computed yet.
llvm-svn: 258723
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 622ca04..04d9214 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -874,16 +874,15 @@
Out<ELFT>::ShStrTab->reserve(Sec->getName());
// Finalizers fix each section's size.
- // .dynamic section's finalizer may add strings to .dynstr,
- // so finalize that early.
- // Likewise, .dynsym is finalized early since that may fill up .gnu.hash.
- Out<ELFT>::Dynamic->finalize();
+ // .dynsym is finalized early since that may fill up .gnu.hash.
if (isOutputDynamic())
Out<ELFT>::DynSymTab->finalize();
- // Fill other section headers.
+ // Fill other section headers. The dynamic string table in finalized
+ // once the .dynamic finalizer has added a few last strings.
for (OutputSectionBase<ELFT> *Sec : OutputSections)
- Sec->finalize();
+ if (Sec != Out<ELFT>::DynStrTab)
+ Sec->finalize();
}
// This function add Out<ELFT>::* sections to OutputSections.