Index: COFF/SymbolTable.h =================================================================== --- COFF/SymbolTable.h +++ COFF/SymbolTable.h @@ -108,6 +108,7 @@ } private: + std::pair insert(StringRef Name, InputFile *F); std::pair insert(StringRef Name); StringRef findByPrefix(StringRef Prefix); Index: COFF/SymbolTable.cpp =================================================================== --- COFF/SymbolTable.cpp +++ COFF/SymbolTable.cpp @@ -216,13 +216,22 @@ return {Sym, true}; } -Symbol *SymbolTable::addUndefined(StringRef Name, InputFile *F, - bool IsWeakAlias) { +std::pair SymbolTable::insert(StringRef Name, InputFile *File) { Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); - if (!F || !isa(F)) + + if (!File || !isa(File)) S->IsUsedInRegularObj = true; + + return {S, WasInserted}; +} + +Symbol *SymbolTable::addUndefined(StringRef Name, InputFile *F, + bool IsWeakAlias) { + Symbol *S; + bool WasInserted; + std::tie(S, WasInserted) = insert(Name, F); if (WasInserted || (isa(S) && IsWeakAlias)) { replaceSymbol(S, Name); return S; @@ -298,9 +307,7 @@ SectionChunk *C) { Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(N); - if (!isa(F)) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(N, F); if (WasInserted || !isa(S)) replaceSymbol(S, F, N, /*IsCOMDAT*/ false, /*IsExternal*/ true, Sym, C); @@ -314,9 +321,7 @@ const coff_symbol_generic *Sym) { Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(N); - if (!isa(F)) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(N, F); if (WasInserted || !isa(S)) { replaceSymbol(S, F, N, /*IsCOMDAT*/ true, /*IsExternal*/ true, Sym, nullptr); @@ -331,9 +336,7 @@ const coff_symbol_generic *Sym, CommonChunk *C) { Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(N); - if (!isa(F)) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(N, F); if (WasInserted || !isa(S)) replaceSymbol(S, F, N, Size, Sym, C); else if (auto *DC = dyn_cast(S)) @@ -362,7 +365,6 @@ Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); - S->IsUsedInRegularObj = true; if (WasInserted || isa(S) || isa(S)) { replaceSymbol(S, Name, ID, Machine); return cast(S); Index: wasm/SymbolTable.h =================================================================== --- wasm/SymbolTable.h +++ wasm/SymbolTable.h @@ -78,6 +78,7 @@ private: std::pair insert(StringRef Name); + std::pair insert(StringRef Name, InputFile *File); llvm::DenseMap SymMap; std::vector SymVector; Index: wasm/SymbolTable.cpp =================================================================== --- wasm/SymbolTable.cpp +++ wasm/SymbolTable.cpp @@ -98,6 +98,17 @@ return {Sym, true}; } +std::pair SymbolTable::insert(StringRef Name, InputFile *File) { + Symbol *S; + bool WasInserted; + std::tie(S, WasInserted) = insert(Name); + + if (!File || File->kind() == InputFile::ObjectKind) + S->IsUsedInRegularObj = true; + + return {S, WasInserted}; +} + static void reportTypeError(const Symbol *Existing, const InputFile *File, llvm::wasm::WasmSymbolType Type) { error("symbol type mismatch: " + toString(*Existing) + "\n>>> defined as " + @@ -213,10 +224,7 @@ LLVM_DEBUG(dbgs() << "addDefinedFunction: " << Name << "\n"); Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - - if (!File || File->kind() == InputFile::ObjectKind) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted || S->isLazy()) { replaceSymbol(S, Name, Flags, File, Function); @@ -238,10 +246,7 @@ << "\n"); Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - - if (!File || File->kind() == InputFile::ObjectKind) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted || S->isLazy()) { replaceSymbol(S, Name, Flags, File, Segment, Address, Size); @@ -258,12 +263,10 @@ Symbol *SymbolTable::addDefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File, InputGlobal *Global) { LLVM_DEBUG(dbgs() << "addDefinedGlobal:" << Name << "\n"); + Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - - if (!File || File->kind() == InputFile::ObjectKind) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted || S->isLazy()) { replaceSymbol(S, Name, Flags, File, Global); @@ -284,10 +287,7 @@ Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - - if (!File || File->kind() == InputFile::ObjectKind) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted) replaceSymbol(S, Name, Flags, File, Sig); @@ -305,10 +305,7 @@ Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - - if (!File || File->kind() == InputFile::ObjectKind) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted) replaceSymbol(S, Name, Flags, File); @@ -326,10 +323,7 @@ Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - - if (!File || File->kind() == InputFile::ObjectKind) - S->IsUsedInRegularObj = true; + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted) replaceSymbol(S, Name, Flags, File, Type); @@ -346,7 +340,7 @@ Symbol *S; bool WasInserted; - std::tie(S, WasInserted) = insert(Name); + std::tie(S, WasInserted) = insert(Name, File); if (WasInserted) { replaceSymbol(S, Name, File, *Sym);