[ELF] Insert linkerscript symbols directly into symbol table

This change exposes the symbol table insert method and uses it to
insert the linkerscript defined symbols directly into the symbol
table to avoid unnecessarily pulling the object out of an archive.

Differential Revision: https://reviews.llvm.org/D30224

llvm-svn: 295780
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index a5ecf48..7c9328d 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -57,12 +57,12 @@
 ScriptConfiguration *elf::ScriptConfig;
 
 template <class ELFT> static SymbolBody *addRegular(SymbolAssignment *Cmd) {
+  Symbol *Sym;
   uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
-  Symbol *Sym = Symtab<ELFT>::X->addUndefined(
-      Cmd->Name, /*IsLocal=*/false, STB_GLOBAL, Visibility,
-      /*Type*/ 0,
-      /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
-
+  std::tie(Sym, std::ignore) = Symtab<ELFT>::X->insert(
+      Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
+      /*File*/ nullptr);
+  Sym->Binding = STB_GLOBAL;
   replaceBody<DefinedRegular<ELFT>>(Sym, Cmd->Name, /*IsLocal=*/false,
                                     Visibility, STT_NOTYPE, 0, 0, nullptr,
                                     nullptr);
@@ -70,14 +70,14 @@
 }
 
 template <class ELFT> static SymbolBody *addSynthetic(SymbolAssignment *Cmd) {
+  Symbol *Sym;
   uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
   const OutputSectionBase *Sec =
       ScriptConfig->HasSections ? nullptr : Cmd->Expression.Section();
-  Symbol *Sym = Symtab<ELFT>::X->addUndefined(
-      Cmd->Name, /*IsLocal=*/false, STB_GLOBAL, Visibility,
-      /*Type*/ 0,
-      /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
-
+  std::tie(Sym, std::ignore) = Symtab<ELFT>::X->insert(
+      Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
+      /*File*/ nullptr);
+  Sym->Binding = STB_GLOBAL;
   replaceBody<DefinedSynthetic>(Sym, Cmd->Name, 0, Sec);
   return Sym->body();
 }