Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -1419,6 +1419,9 @@ if (files.empty() && errorCount() == 0) error("no input files"); + + // Dependent libraries should be linked in --no-whole-archive mode. + inWholeArchive = false; } // If -m was not given, infer it from object files. Index: lld/test/ELF/deplibs-ignore-whole-archive.s =================================================================== --- /dev/null +++ lld/test/ELF/deplibs-ignore-whole-archive.s @@ -0,0 +1,25 @@ +# REQUIRES: x86 + +## Check that the dependent libraries are processed in --no-whole-archive mode +## even if there is an unterminated --whole-archive on the command line. This +## behaviour is desirable because, applying --whole-archive to the "invisible" +## dependent libraries is confusing, and not all build-systems support allowing +## developers to add --no-whole-archive to the very end of the command line. + +# RUN: rm -rf %t.dir +# RUN: mkdir -p %t.dir +# RUN: cd %t.dir +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o main.o +# RUN: echo ".global foo; foo:" | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64 - -o foo.o +# RUN: echo ".global bar; bar:" | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64 - -o bar.o +# RUN: llvm-ar rc libfoobar.a foo.o bar.o + +# RUN: ld.lld -o %t --whole-archive -L. -u foo main.o +# RUN: llvm-nm %t | FileCheck %s + +# CHECK-NOT: bar + + .section ".deplibs","MS",@llvm_dependent_libraries,1 + .asciz "foobar"