[lld] r374292 - [LLD] [MinGW] Look for other library patterns with -l

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 10 01:52:39 PDT 2019


Author: mstorsjo
Date: Thu Oct 10 01:52:39 2019
New Revision: 374292

URL: http://llvm.org/viewvc/llvm-project?rev=374292&view=rev
Log:
[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

Modified:
    lld/trunk/MinGW/Driver.cpp
    lld/trunk/test/MinGW/lib.test

Modified: lld/trunk/MinGW/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/MinGW/Driver.cpp?rev=374292&r1=374291&r2=374292&view=diff
==============================================================================
--- lld/trunk/MinGW/Driver.cpp (original)
+++ lld/trunk/MinGW/Driver.cpp Thu Oct 10 01:52:39 2019
@@ -125,17 +125,36 @@ searchLibrary(StringRef name, ArrayRef<S
     for (StringRef dir : searchPaths)
       if (Optional<std::string> s = findFile(dir, name.substr(1)))
         return *s;
-    fatal("unable to find library -l" + name);
+    error("unable to find library -l" + name);
+    return "";
   }
 
   for (StringRef dir : searchPaths) {
-    if (!bStatic)
+    if (!bStatic) {
       if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll.a"))
         return *s;
+      if (Optional<std::string> s = findFile(dir, name + ".dll.a"))
+        return *s;
+    }
     if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
       return *s;
+    if (!bStatic) {
+      if (Optional<std::string> s = findFile(dir, name + ".lib"))
+        return *s;
+      if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll")) {
+        error("lld doesn't support linking directly against " + *s +
+              ", use an import library");
+        return "";
+      }
+      if (Optional<std::string> s = findFile(dir, name + ".dll")) {
+        error("lld doesn't support linking directly against " + *s +
+              ", use an import library");
+        return "";
+      }
+    }
   }
-  fatal("unable to find library -l" + name);
+  error("unable to find library -l" + name);
+  return "";
 }
 
 // Convert Unix-ish command line arguments to Windows-ish ones and
@@ -342,6 +361,9 @@ bool mingw::link(ArrayRef<const char *>
     }
   }
 
+  if (errorCount())
+    return false;
+
   if (args.hasArg(OPT_verbose) || args.hasArg(OPT__HASH_HASH_HASH))
     outs() << llvm::join(linkArgs, " ") << "\n";
 

Modified: lld/trunk/test/MinGW/lib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/MinGW/lib.test?rev=374292&r1=374291&r2=374292&view=diff
==============================================================================
--- lld/trunk/test/MinGW/lib.test (original)
+++ lld/trunk/test/MinGW/lib.test Thu Oct 10 01:52:39 2019
@@ -26,3 +26,16 @@ RUN: echo > %t/lib/libbar.a
 RUN: ld.lld -### -m i386pep -Bstatic -lfoo -Bdynamic -lbar -L%t/lib | FileCheck -check-prefix=LIB5 %s
 LIB5:      libfoo.a
 LIB5-SAME: libbar.dll.a
+
+RUN: echo > %t/lib/noprefix.dll.a
+RUN: echo > %t/lib/msvcstyle.lib
+RUN: ld.lld -### -m i386pep -L%t/lib -lnoprefix -lmsvcstyle | FileCheck -check-prefix=OTHERSTYLES %s
+OTHERSTYLES: noprefix.dll.a
+OTHERSTYLES-SAME: msvcstyle.lib
+
+RUN: echo > %t/lib/libnoimplib.dll
+RUN: echo > %t/lib/noprefix_noimplib.dll
+RUN: not ld.lld -### -m i386pep -L%t/lib -lnoimplib 2>&1 | FileCheck -check-prefix=UNSUPPORTED-DLL1 %s
+RUN: not ld.lld -### -m i386pep -L%t/lib -lnoprefix_noimplib 2>&1 | FileCheck -check-prefix=UNSUPPORTED-DLL2 %s
+UNSUPPORTED-DLL1: lld doesn't support linking directly against {{.*}}libnoimplib.dll, use an import library
+UNSUPPORTED-DLL2: lld doesn't support linking directly against {{.*}}noprefix_noimplib.dll, use an import library




More information about the llvm-commits mailing list