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,31 @@ +# REQUIRES: x86 + +## This checks that if --whole-archive is left unterminated in the command line, +## that does not affect how dependent libraries are included in the link. +## They still should not pull unused members and the link should not terminate +## with the "duplicate symbol" error even if a dependent library is referenced +## more than once, which is very common with them. +## --whole-archive applying to dependent libraries is confusing and +## build-systems are not always allow developers to add --no-whole-archive to +## the very end of the command line. + +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: echo ".global foo; foo:" | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64 - -o %tfoo.o +# RUN: echo ".global bar; bar:" | \ +# RUN: llvm-mc -filetype=obj -triple=x86_64 - -o %tbar.o +# RUN: rm -rf %t.dir +# RUN: mkdir -p %t.dir +# RUN: llvm-ar rc %t.dir/lib.a %tfoo.o %tbar.o +# RUN: ld.lld %t.o -o %t -L %t.dir --whole-archive +# RUN: llvm-nm %t | FileCheck %s + +# CHECK-NOT: bar + + .global _start +_start: + call foo + + .section ".deplibs","MS",@llvm_dependent_libraries,1 + .asciz "lib.a" + .asciz "lib.a"