Index: ELF/SymbolTable.h =================================================================== --- ELF/SymbolTable.h +++ ELF/SymbolTable.h @@ -97,6 +97,9 @@ StringRef VersionName); void assignWildcardVersion(SymbolVersion Ver, uint16_t VersionId); + using ReplaceFn = llvm::function_ref; + bool replaceOrIgnoreLazy(StringRef Name, ReplaceFn Replace); + // The order the global symbols are in is not defined. We can use an arbitrary // order, but it has to be reproducible. That is true even when cross linking. // The default hashing of StringRef produces different results on 32 and 64 Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -598,47 +598,47 @@ template void SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F, const object::Archive::Symbol Sym) { - Symbol *S; - bool WasInserted; - std::tie(S, WasInserted) = insert(Name); - if (WasInserted) { - replaceSymbol(S, F, Sym, Symbol::UnknownType); - return; - } - if (!S->isUndefined()) - return; + auto ReplaceFn = [&](Symbol *S, uint8_t Type) { + replaceSymbol(S, F, Sym, Type); + }; - // An undefined weak will not fetch archive members. See comment on Lazy in - // Symbols.h for the details. - if (S->isWeak()) { - replaceSymbol(S, F, Sym, S->Type); - S->Binding = STB_WEAK; - return; - } - if (InputFile *File = F.fetch(Sym)) - addFile(File); + if (!replaceOrIgnoreLazy(Name, ReplaceFn)) + if (InputFile *File = F.fetch(Sym)) + addFile(File); } template void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) { + auto ReplaceFn = [&](Symbol *S, uint8_t Type) { + replaceSymbol(S, Obj, Name, Type); + }; + + if (!replaceOrIgnoreLazy(Name, ReplaceFn)) + if (InputFile *F = Obj.fetch()) + addFile(F); +} + +// This is used to handle lazy symbols. Returns true if symbol was replaced +// with Replace or should be ignored. +bool SymbolTable::replaceOrIgnoreLazy(StringRef Name, ReplaceFn Replace) { Symbol *S; bool WasInserted; std::tie(S, WasInserted) = insert(Name); if (WasInserted) { - replaceSymbol(S, Obj, Name, Symbol::UnknownType); - return; + Replace(S, Symbol::UnknownType); + return true; } if (!S->isUndefined()) - return; + return true; - // See comment for addLazyArchive above. + // An undefined weak will not fetch archive members. See comment on Lazy in + // Symbols.h for the details. if (S->isWeak()) { - replaceSymbol(S, Obj, Name, S->Type); + Replace(S, S->Type); S->Binding = STB_WEAK; - return; + return true; } - if (InputFile *F = Obj.fetch()) - addFile(F); + return false; } template void SymbolTable::fetchLazy(Symbol *Sym) {