Skip to content

Commit 0226c35

Browse files
committed
[LLD] [MinGW] Look for other library patterns with -l
GNU ld looks for a number of other patterns than just lib<name>.dll.a and lib<name>.a. GNU ld does support linking directly against a DLL without using an import library. If that's the only match for a -l argument, point out that the user needs to use an import library, instead of leaving the user with a puzzling message about the -l argument not being found at all. Also convert an existing case of fatal() into error(). Differential Revision: https://reviews.llvm.org/D68689 llvm-svn: 374292
1 parent e742794 commit 0226c35

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

lld/MinGW/Driver.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,36 @@ searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
125125
for (StringRef dir : searchPaths)
126126
if (Optional<std::string> s = findFile(dir, name.substr(1)))
127127
return *s;
128-
fatal("unable to find library -l" + name);
128+
error("unable to find library -l" + name);
129+
return "";
129130
}
130131

131132
for (StringRef dir : searchPaths) {
132-
if (!bStatic)
133+
if (!bStatic) {
133134
if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll.a"))
134135
return *s;
136+
if (Optional<std::string> s = findFile(dir, name + ".dll.a"))
137+
return *s;
138+
}
135139
if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
136140
return *s;
141+
if (!bStatic) {
142+
if (Optional<std::string> s = findFile(dir, name + ".lib"))
143+
return *s;
144+
if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll")) {
145+
error("lld doesn't support linking directly against " + *s +
146+
", use an import library");
147+
return "";
148+
}
149+
if (Optional<std::string> s = findFile(dir, name + ".dll")) {
150+
error("lld doesn't support linking directly against " + *s +
151+
", use an import library");
152+
return "";
153+
}
154+
}
137155
}
138-
fatal("unable to find library -l" + name);
156+
error("unable to find library -l" + name);
157+
return "";
139158
}
140159

141160
// Convert Unix-ish command line arguments to Windows-ish ones and
@@ -342,6 +361,9 @@ bool mingw::link(ArrayRef<const char *> argsArr, raw_ostream &diag) {
342361
}
343362
}
344363

364+
if (errorCount())
365+
return false;
366+
345367
if (args.hasArg(OPT_verbose) || args.hasArg(OPT__HASH_HASH_HASH))
346368
outs() << llvm::join(linkArgs, " ") << "\n";
347369

lld/test/MinGW/lib.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,16 @@ RUN: echo > %t/lib/libbar.a
2626
RUN: ld.lld -### -m i386pep -Bstatic -lfoo -Bdynamic -lbar -L%t/lib | FileCheck -check-prefix=LIB5 %s
2727
LIB5: libfoo.a
2828
LIB5-SAME: libbar.dll.a
29+
30+
RUN: echo > %t/lib/noprefix.dll.a
31+
RUN: echo > %t/lib/msvcstyle.lib
32+
RUN: ld.lld -### -m i386pep -L%t/lib -lnoprefix -lmsvcstyle | FileCheck -check-prefix=OTHERSTYLES %s
33+
OTHERSTYLES: noprefix.dll.a
34+
OTHERSTYLES-SAME: msvcstyle.lib
35+
36+
RUN: echo > %t/lib/libnoimplib.dll
37+
RUN: echo > %t/lib/noprefix_noimplib.dll
38+
RUN: not ld.lld -### -m i386pep -L%t/lib -lnoimplib 2>&1 | FileCheck -check-prefix=UNSUPPORTED-DLL1 %s
39+
RUN: not ld.lld -### -m i386pep -L%t/lib -lnoprefix_noimplib 2>&1 | FileCheck -check-prefix=UNSUPPORTED-DLL2 %s
40+
UNSUPPORTED-DLL1: lld doesn't support linking directly against {{.*}}libnoimplib.dll, use an import library
41+
UNSUPPORTED-DLL2: lld doesn't support linking directly against {{.*}}noprefix_noimplib.dll, use an import library

0 commit comments

Comments
 (0)