Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -492,18 +492,16 @@ if (Sym.getVisibility() == STV_DEFAULT) S->ExportDynamic = true; - // An undefined symbol with non default visibility must be satisfied - // in the same DSO. - auto Replace = [&](uint8_t Binding) { + if (WasInserted || + // An undefined/lazy symbol with non default visibility must be satisfied + // in the same DSO. + ((S->isUndefined() || S->isLazy()) && S->Visibility == STV_DEFAULT)) { + // Use the original binding if inserted before. + uint8_t Binding = WasInserted ? Sym.getBinding() : S->Binding; replaceSymbol(S, File, Name, Binding, Sym.st_other, Sym.getType(), Sym.st_value, Sym.st_size, Alignment, VerdefIndex); - }; - - if (WasInserted) - Replace(Sym.getBinding()); - else if (S->Visibility == STV_DEFAULT && (S->isUndefined() || S->isLazy())) - Replace(S->Binding); + } } Symbol *SymbolTable::addBitcode(StringRef Name, uint8_t Binding,