[PATCH] D88877: [ELF] Drop -whole-archive before processing dependent libraries.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 21:45:52 PDT 2020


ikudrin updated this revision to Diff 296594.
ikudrin added a comment.

- Fixed the comment.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88877/new/

https://reviews.llvm.org/D88877

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/deplibs-ignore-whole-archive.s


Index: lld/test/ELF/deplibs-ignore-whole-archive.s
===================================================================
--- /dev/null
+++ lld/test/ELF/deplibs-ignore-whole-archive.s
@@ -0,0 +1,28 @@
+# 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.
+
+# 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", at llvm_dependent_libraries,1
+  .asciz  "lib.a"
+  .asciz  "lib.a"
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -1419,6 +1419,17 @@
 
   if (files.empty() && errorCount() == 0)
     error("no input files");
+
+  // A sequence started with -whole-archive flag might not be closed with
+  // -no-whole-archive at the end of the command line because in normal usage
+  // that is not required and makes no difference.
+  // Nonetheless, if there are dependent libraries, they should always be
+  // included in the normal way so that unnecessary members are not pulled.
+  // Moreover, it is very common for a dependent library to be mentioned several
+  // times in input files, and, as the flag forces the archive members to be
+  // processed immediately, that results in duplicating symbol definitions.
+  // Thus, force the flag off before processing dependent libraries.
+  inWholeArchive = false;
 }
 
 // If -m <machine_type> was not given, infer it from object files.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88877.296594.patch
Type: text/x-patch
Size: 2178 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201007/3bc59e62/attachment.bin>


More information about the llvm-commits mailing list