[PATCH] D68689: [LLD] [MinGW] Look for other library patterns with -l

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 23:43:47 PDT 2019


mstorsjo updated this revision to Diff 224260.
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Changed to use error() instead of fatal() in the added lines of code, and in another place in the same function. Added an `if (errorCount()) return false;` at the end of the MinGW driver, to avoid actually trying to start the linking if errors were reported at this stage.

All other existing error reporting in the MinGW driver is still using fatal(), but changing that is a different matter.


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

https://reviews.llvm.org/D68689

Files:
  lld/MinGW/Driver.cpp
  lld/test/MinGW/lib.test


Index: lld/test/MinGW/lib.test
===================================================================
--- lld/test/MinGW/lib.test
+++ lld/test/MinGW/lib.test
@@ -26,3 +26,16 @@
 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
Index: lld/MinGW/Driver.cpp
===================================================================
--- lld/MinGW/Driver.cpp
+++ lld/MinGW/Driver.cpp
@@ -125,17 +125,36 @@
     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
@@ -352,5 +371,7 @@
   std::vector<const char *> vec;
   for (const std::string &s : linkArgs)
     vec.push_back(s.c_str());
+  if (errorCount())
+    return false;
   return coff::link(vec, true);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68689.224260.patch
Type: text/x-patch
Size: 2785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/122da443/attachment.bin>


More information about the llvm-commits mailing list