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

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 18:11:23 PDT 2020


bd1976llvm added a comment.

In D88877#2316039 <https://reviews.llvm.org/D88877#2316039>, @ikudrin wrote:

> - 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.

Sorry for the late reply.

Firstly, is this a real problem? In the RFC thread http://lists.llvm.org/pipermail/llvm-dev/2019-March/131105.html Rui said:

>>>>> I'm less convinced about --whole-archive as
>>>>> I think this tends to be a way of structuring the build and would be
>>>>> best made explicit in the build system. Moreover, what if someone
>>>>> wants to not use --whole-archive, for their autolink, but one already
>>>>> exists.
>>>>
>>>> Then they can specify --no-whole-archive on the end of the command
>>>> line, no?

I think we want to be sure that users can't simply adjust their linker command line before we complicate autolinking. Given that autolinking is a new feature on ELF it doesn't seem unfair that users should understand the feature and consider adjusting their linker command lines. Maybe we could add some diagnostics to help them.. e.g. lld could advise users that "--whole-archive was active" if a duplicate symbol error arises during auto-linking?

I also want to be certain that the GNU linkers can implement whatever we decide as that was as important design consideration.

As to --whole-archive not being compatible with autolinking.. maybe the set of autolinked inputs should be deduplicated. This was discussed in the original RFC thread and would also solve https://bugs.llvm.org/show_bug.cgi?id=42460.


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

https://reviews.llvm.org/D88877



More information about the llvm-commits mailing list