diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1374,7 +1374,7 @@ if (!file->archiveName.empty()) if (all || libs.count(path::filename(file->archiveName))) for (Symbol *sym : file->getSymbols()) - if (!sym->isLocal() && sym->file == file) + if (!sym->isUndefined() && !sym->isLocal() && sym->file == file) sym->versionId = VER_NDX_LOCAL; }; diff --git a/lld/test/ELF/exclude-libs-undef.s b/lld/test/ELF/exclude-libs-undef.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/exclude-libs-undef.s @@ -0,0 +1,15 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: mkdir -p %t.dir +# RUN: rm -f %t.dir/t.a +# RUN: llvm-ar rc %t.dir/t.a %t.o +# RUN: ld.lld -shared --whole-archive --exclude-libs=t.a %t.dir/t.a -o %t.so +# RUN: llvm-readelf --dyn-syms %t.so | FileCheck %s + +# CHECK: 1: {{.*}} WEAK DEFAULT UND bar +# CHECK-NOT: 2: + +.globl foo +.weak bar +foo: + call bar