Skip to content

Commit ce0f3ee

Browse files
committed
[COFF] Don't error if the only inputs are from /wholearchive:
Fixes PR43744 Differential Revision: https://reviews.llvm.org/D69968
1 parent 4516dc1 commit ce0f3ee

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lld/COFF/Driver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
11711171
}
11721172
}
11731173

1174-
if (!args.hasArg(OPT_INPUT)) {
1174+
if (!args.hasArg(OPT_INPUT, OPT_wholearchive_file)) {
11751175
if (args.hasArg(OPT_deffile))
11761176
config->noEntry = true;
11771177
else
@@ -1700,7 +1700,7 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
17001700
}
17011701

17021702
// Handle generation of import library from a def file.
1703-
if (!args.hasArg(OPT_INPUT)) {
1703+
if (!args.hasArg(OPT_INPUT, OPT_wholearchive_file)) {
17041704
fixupExports();
17051705
createImportLibrary(/*asLib=*/true);
17061706
return;
@@ -1749,8 +1749,8 @@ void LinkerDriver::link(ArrayRef<const char *> argsArr) {
17491749

17501750
// Set default image name if neither /out or /def set it.
17511751
if (config->outputFile.empty()) {
1752-
config->outputFile =
1753-
getOutputPath((*args.filtered(OPT_INPUT).begin())->getValue());
1752+
config->outputFile = getOutputPath(
1753+
(*args.filtered(OPT_INPUT, OPT_wholearchive_file).begin())->getValue());
17541754
}
17551755

17561756
// Fail early if an output file is not writable.

lld/test/COFF/entry-inference.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# RUN: not lld-link /nodefaultlib /out:%t.exe %t.obj > %t.log 2>&1
55
# RUN: FileCheck -check-prefix=MAIN %s < %t.log
66

7+
# Entry inference should work through /wholearchive:, they are also inputs.
8+
# RUN: lld-link /lib %t.obj /out:%t.lib
9+
# RUN: not lld-link /nodefaultlib /out:%t.exe /wholearchive:%t.lib > %t.log 2>&1
10+
# RUN: FileCheck -check-prefix=MAIN %s < %t.log
11+
712
# RUN: sed s/ENTRYNAME/wmain/ %s | yaml2obj > %t.obj
813
# RUN: not lld-link /out:%t.exe %t.obj > %t.log 2>&1
914
# RUN: FileCheck -check-prefix=WMAIN %s < %t.log

lld/test/COFF/out.test

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
# RUN: cp %t.obj %T/out/out1.obj
55
# RUN: cp %t.obj %T/out/tmp/out2
66
# RUN: cp %t.obj %T/out/tmp/out3.xyz
7+
# RUN: lld-link /lib %t.obj /out:%T/out/out4.lib
78

8-
# RUN: rm -f out1.exe out2.exe out3.exe out3.dll
9+
# RUN: rm -f out1.exe out2.exe out3.exe out3.dll out4.exe
910
# RUN: lld-link /entry:main %T/out/out1.obj
1011
# RUN: lld-link /entry:main %T/out/tmp/out2
1112
# RUN: lld-link /dll /entry:main %T/out/tmp/out3.xyz
13+
# RUN: lld-link /entry:main -wholearchive:%T/out/out4.lib
1214

1315
# RUN: llvm-readobj out1.exe | FileCheck %s
1416
# RUN: llvm-readobj out2.exe | FileCheck %s
1517
# RUN: llvm-readobj out3.dll | FileCheck %s
18+
# RUN: llvm-readobj out4.exe | FileCheck %s
1619

1720
CHECK: File:

lld/test/COFF/wholearchive.s

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# RUN: lld-link -dll -out:%t.dll -entry:main %t.main.obj %t.archive.lib -wholearchive:%t.archive.lib -implib:%t.lib
1515
# RUN: llvm-readobj %t.lib | FileCheck %s -check-prefix CHECK-IMPLIB
1616

17+
# PR43744: Test no inputs except a whole archive.
18+
# RUN: lld-link -dll -out:%t.dll -noentry -wholearchive:%t.archive.lib -implib:%t.lib
19+
# RUN: llvm-readobj %t.lib | FileCheck %s -check-prefix CHECK-IMPLIB
20+
1721
# RUN: mkdir -p %t.dir
1822
# RUN: cp %t.archive.lib %t.dir/foo.lib
1923
# RUN: lld-link -dll -out:%t.dll -entry:main -libpath:%t.dir %t.main.obj %t.dir/./foo.lib -wholearchive:foo.lib -implib:%t.lib

0 commit comments

Comments
 (0)