LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 37592 - LLD "foo.lib -wholearchive:foo.lib" doesn't work
Summary: LLD "foo.lib -wholearchive:foo.lib" doesn't work
Status: RESOLVED FIXED
Alias: None
Product: lld
Classification: Unclassified
Component: COFF (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
: 35343 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-25 13:54 PDT by Reid Kleckner
Modified: 2018-08-30 11:04 PDT (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Kleckner 2018-05-25 13:54:42 PDT
Consider:

$ cat a.c
int foo() { return 1; }

$ cat b.c
int bar() { return 2; }

$ cat t.c
int foo();
int main() {
  return foo();
}

$ cl -c t.c a.c b.c && lld-link /LIB a.obj b.obj -out:foo.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.13.26131.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

t.c
a.c
b.c
Generating Code...

$ lld-link t.obj foo.lib -wholearchive:foo.lib -out:t.exe -verbose -nodefaultlib -entry:main
C:\src\llvm-project\build\bin\lld-link.exe: Reading t.obj
C:\src\llvm-project\build\bin\lld-link.exe: Directives: t.obj: /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES"
C:\src\llvm-project\build\bin\lld-link.exe: Reading foo.lib
C:\src\llvm-project\build\bin\lld-link.exe: Reading foo.lib(a.obj)
C:\src\llvm-project\build\bin\lld-link.exe: Directives: foo.lib(a.obj): /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES"
C:\src\llvm-project\build\bin\lld-link.exe: Loaded foo.lib(a.obj) for foo
C:\src\llvm-project\build\bin\lld-link.exe: ICF needed 2 iterations

As you can see from the verbose output, b.obj is not loaded, but it is if I swap in link.exe:

$ link t.obj foo.lib -wholearchive:foo.lib -out:t.exe -verbose -nodefaultlib -entry:main
Microsoft (R) Incremental Linker Version 14.13.26131.1
Copyright (C) Microsoft Corporation.  All rights reserved.

Processed /NODEFAULTLIB (suppressing all default libs)

Starting pass 1
        Loaded foo.lib(a.obj)
        Loaded foo.lib(b.obj)

Searching libraries
    Searching foo.lib:

Finished searching libraries

Finished pass 1

Starting pass 2
     t.obj
     foo.lib(b.obj)
     foo.lib(a.obj)
Finished pass 2

This is causing Chromium's base_unittests tests to fail with asan, which uses wholearchive.
Comment 1 Nico Weber 2018-06-01 06:36:56 PDT
ruiu's https://reviews.llvm.org/D41094 might have regressed this (?)
Comment 2 Rui Ueyama 2018-06-01 09:58:35 PDT
Not sure about that, but a fix is under review: https://reviews.llvm.org/D47565
Comment 3 Reid Kleckner 2018-06-12 11:36:23 PDT
*** Bug 35343 has been marked as a duplicate of this bug. ***
Comment 4 Nico Weber 2018-08-30 11:04:31 PDT
rL334552 / r334761.