Index: lld/ELF/SymbolTable.cpp =================================================================== --- lld/ELF/SymbolTable.cpp +++ lld/ELF/SymbolTable.cpp @@ -599,9 +599,14 @@ for (InputFile *F : SharedFiles) { for (StringRef U : cast>(F)->getUndefinedSymbols()) { Symbol *Sym = find(U); - if (!Sym || !Sym->isDefined()) + if (!Sym) continue; - Sym->ExportDynamic = true; + if (auto *L = dyn_cast(Sym)) + if (InputFile *File = L->fetch()) + addFile(File); + + if (Sym->isDefined()) + Sym->ExportDynamic = true; } } } Index: lld/test/ELF/shlib-undefined-archive.s =================================================================== --- /dev/null +++ lld/test/ELF/shlib-undefined-archive.s @@ -0,0 +1,18 @@ +# REQUIRES: x86 + +# Undefined symbols in a DSO should pull out object files from archives +# to resolve them. + +# RUN: echo '.globl foo' | llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o - +# RUN: ld.lld -shared -o %t.so %t1.o + +# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s +# RUN: llvm-ar cru %t.a %t2.o +# RUN: ld.lld -o %t.exe %t.so %t.a +# RUN: llvm-nm -D %t.exe | FileCheck %s + +# CHECK: T foo + +.globl foo +foo: + ret