[ELF2] Add DT_INIT and DT_FINI dynamic table entries

The entries are added if there are "_init" or "_fini" entries in
the symbol table respectively. According to the behavior of ld,
entries are inserted even for undefined symbols.

Symbol names can be overridden by using -init and -fini command
line switches. If used, these switches neither add new symbol table
entries nor require those symbols to be resolved.

Differential Revision: http://reviews.llvm.org/D13385

llvm-svn: 249297
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index e36ac9e..5e21196 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -320,7 +320,8 @@
 
 public:
   DynamicSection(SymbolTable &SymTab, HashTableSection<ELFT> &HashSec,
-                 RelocationSection<ELFT> &RelaDynSec);
+                 RelocationSection<ELFT> &RelaDynSec,
+                 const OutputSection<ELFT> &BssSec);
   void finalize() override;
   void writeTo(uint8_t *Buf) override;
 
@@ -333,7 +334,10 @@
   SymbolTableSection<ELFT> &DynSymSec;
   StringTableSection<ELFT::Is64Bits> &DynStrSec;
   RelocationSection<ELFT> &RelaDynSec;
+  const OutputSection<ELFT> &BssSec;
   SymbolTable &SymTab;
+  const ELFSymbolBody<ELFT> *InitSym = nullptr;
+  const ELFSymbolBody<ELFT> *FiniSym = nullptr;
 };
 }
 }