Index: lld/wasm/SymbolTable.cpp =================================================================== --- lld/wasm/SymbolTable.cpp +++ lld/wasm/SymbolTable.cpp @@ -125,31 +125,23 @@ const WasmSignature *Type, uint32_t Flags) { DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n"); - Symbol *S; - bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - assert(WasInserted); - return replaceSymbol(S, Name, Flags, Type); + assert(!find(Name)); + return replaceSymbol(insert(Name).first, Name, Flags, Type); } DefinedData *SymbolTable::addSyntheticDataSymbol(StringRef Name, uint32_t Flags) { DEBUG(dbgs() << "addSyntheticDataSymbol: " << Name << "\n"); - Symbol *S; - bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - assert(WasInserted); - return replaceSymbol(S, Name, Flags); + assert(!find(Name)); + return replaceSymbol(insert(Name).first, Name, Flags); } DefinedGlobal *SymbolTable::addSyntheticGlobal(StringRef Name, uint32_t Flags, InputGlobal *Global) { DEBUG(dbgs() << "addSyntheticGlobal: " << Name << " -> " << Global << "\n"); - Symbol *S; - bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - assert(WasInserted); - return replaceSymbol(S, Name, Flags, nullptr, Global); + assert(!find(Name)); + return replaceSymbol(insert(Name).first, Name, Flags, nullptr, + Global); } static bool shouldReplace(const Symbol *Existing, InputFile *NewFile, @@ -251,7 +243,7 @@ if (WasInserted) replaceSymbol(S, Name, Flags, File, Sig); else if (auto *Lazy = dyn_cast(S)) - cast(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol()); + Lazy->fetch(); else if (S->isDefined()) checkFunctionType(S, File, Sig); return S; @@ -268,7 +260,7 @@ if (WasInserted) replaceSymbol(S, Name, Flags, File); else if (auto *Lazy = dyn_cast(S)) - cast(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol()); + Lazy->fetch(); else if (S->isDefined()) checkDataType(S, File); return S; @@ -286,7 +278,7 @@ if (WasInserted) replaceSymbol(S, Name, Flags, File, Type); else if (auto *Lazy = dyn_cast(S)) - cast(Lazy->getFile())->addMember(&Lazy->getArchiveSymbol()); + Lazy->fetch(); else if (S->isDefined()) checkGlobalType(S, File, Type); return S; Index: lld/wasm/Symbols.h =================================================================== --- lld/wasm/Symbols.h +++ lld/wasm/Symbols.h @@ -257,10 +257,9 @@ : Symbol(Name, LazyKind, 0, File), ArchiveSymbol(Sym) {} static bool classof(const Symbol *S) { return S->kind() == LazyKind; } + void fetch(); - const Archive::Symbol &getArchiveSymbol() { return ArchiveSymbol; } - -protected: +private: Archive::Symbol ArchiveSymbol; }; Index: lld/wasm/Symbols.cpp =================================================================== --- lld/wasm/Symbols.cpp +++ lld/wasm/Symbols.cpp @@ -178,6 +178,8 @@ Global ? &Global->getType() : nullptr), Global(Global) {} +void LazySymbol::fetch() { cast(File)->addMember(&ArchiveSymbol); } + std::string lld::toString(const wasm::Symbol &Sym) { if (Config->Demangle) if (Optional S = demangleItanium(Sym.getName()))