From d15a4154a8b7391941e0592427588b0a1b229e65 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 8 Mar 2019 21:10:48 +0000 Subject: [PATCH] [WebAssembly] Don't mark lazy symbols as `IsUsedInRegularObj` This matches the ELF does. Update the comment in ELF/Symbols.h and duplicate it in wasm/Symbols.h This a followup on rL355580 and rL355577. Differential Revision: https://reviews.llvm.org/D59075 llvm-svn: 355737 --- lld/ELF/Symbols.h | 4 ++-- lld/wasm/SymbolTable.cpp | 8 ++++---- lld/wasm/Symbols.h | 8 +++++++- lld/wasm/Writer.cpp | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index fc48b09..4b722b01 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -109,8 +109,8 @@ public: // True if the symbol was used for linking and thus need to be added to the // output file's symbol table. This is true for all symbols except for - // unreferenced DSO symbols and bitcode symbols that are unreferenced except - // by other bitcode objects. + // unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that + // are unreferenced except by other bitcode objects. unsigned IsUsedInRegularObj : 1; // If this flag is true and the symbol has protected or default visibility, it diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index 9315e72..1e7357d 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -191,7 +191,7 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef Name, LLVM_DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n"); assert(!find(Name)); SyntheticFunctions.emplace_back(Function); - return replaceSymbol(insert(Name, nullptr).first, Name, + return replaceSymbol(insertName(Name).first, Name, Flags, nullptr, Function); } @@ -199,7 +199,7 @@ DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name, uint32_t Flags) { LLVM_DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n"); assert(!find(Name)); - return replaceSymbol(insert(Name, nullptr).first, Name, Flags); + return replaceSymbol(insertName(Name).first, Name, Flags); } DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags, @@ -208,7 +208,7 @@ DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags, << "\n"); assert(!find(Name)); SyntheticGlobals.emplace_back(Global); - return replaceSymbol(insert(Name, nullptr).first, Name, Flags, + return replaceSymbol(insertName(Name).first, Name, Flags, nullptr, Global); } @@ -442,7 +442,7 @@ void SymbolTable::addLazy(ArchiveFile *File, const Archive::Symbol *Sym) { Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name, nullptr); + std::tie(S, WasInserted) = insertName(Name); if (WasInserted) { replaceSymbol(S, Name, 0, File, *Sym); diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index 3ed9e7a..fa321d1 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -98,8 +98,14 @@ public: WasmSymbolType getWasmType() const; bool isExported() const; - // True if this symbol was referenced by a regular (non-bitcode) object. + // True if the symbol was used for linking and thus need to be added to the + // output file's symbol table. This is true for all symbols except for + // unreferenced DSO symbols, lazy (archive) symbols, and bitcode symbols that + // are unreferenced except by other bitcode objects. unsigned IsUsedInRegularObj : 1; + + // True if ths symbol is explicity marked for export (i.e. via the -e/--export + // command line flag) unsigned ForceExport : 1; // True if this symbol is specified by --trace-symbol option. diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index f5ff302..0082ae3 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -950,7 +950,7 @@ void Writer::assignSymtab() { }; for (Symbol *Sym : Symtab->getSymbols()) - if (!Sym->isLazy() && Sym->IsUsedInRegularObj) + if (Sym->IsUsedInRegularObj) AddSymbol(Sym); for (ObjFile *File : Symtab->ObjectFiles) { -- 2.7.4