[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 23:26:35 PDT 2020


ikudrin updated this revision to Diff 296606.
ikudrin marked an inline comment as done.
ikudrin added a comment.

- Simplified the comment.

Even if that was not decided in the discussion, I am pretty sure that `--whole-archive` cannot be used with dependent libraries, at least as the feature is implemented currently. The whole idea of the feature is that you can place `#pragma comment(lib,...)` in each and every source file which depends on the library. This results in multiple references to the library from many input object files, and if `--whole-archive` is active, this leads the linker to fail with the "duplicate symbol" error.


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,9 @@
 
   if (files.empty() && errorCount() == 0)
     error("no input files");
+
+  // Dependent libraries should be linked in --no-whole-archive mode.
+  inWholeArchive = false;
 }
 
 // If -m <machine_type> was not given, infer it from object files.


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


More information about the llvm-commits mailing list