[lld] c09e5e5 - [LLD] [MinGW] Allow linking to DLLs directly

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 1 23:49:39 PDT 2021


Author: Martin Storsjö
Date: 2021-07-02T09:49:13+03:00
New Revision: c09e5e50b13aa1f5a2eafc81097ffe8a5799e5b3

URL: https://github.com/llvm/llvm-project/commit/c09e5e50b13aa1f5a2eafc81097ffe8a5799e5b3
DIFF: https://github.com/llvm/llvm-project/commit/c09e5e50b13aa1f5a2eafc81097ffe8a5799e5b3.diff

LOG: [LLD] [MinGW] Allow linking to DLLs directly

As the COFF linker is capable of linking directly against a DLL now
(after D104530, as long as it is running in mingw mode), don't error
out here but successfully load libraries specified with "-l" from DLLs
if that's what ld.bfd would have matched.

Differential Revision: https://reviews.llvm.org/D104531

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 734f4092a666f..27cb508403f63 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -142,16 +142,10 @@ searchLibrary(StringRef name, ArrayRef<StringRef> searchPaths, bool bStatic) {
     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 "";
-      }
+      if (Optional<std::string> s = findFile(dir, "lib" + name + ".dll"))
+        return *s;
+      if (Optional<std::string> s = findFile(dir, name + ".dll"))
+        return *s;
     }
   }
   error("unable to find library -l" + name);

diff  --git a/lld/test/MinGW/lib.test b/lld/test/MinGW/lib.test
index ddff5debab3ce..45dd79712213d 100644
--- a/lld/test/MinGW/lib.test
+++ b/lld/test/MinGW/lib.test
@@ -40,7 +40,7 @@ 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
+RUN: ld.lld -### -m i386pep -L%t/lib -lnoimplib 2>&1 | FileCheck -check-prefix=DLL1 %s
+RUN: ld.lld -### -m i386pep -L%t/lib -lnoprefix_noimplib 2>&1 | FileCheck -check-prefix=DLL2 %s
+DLL1: libnoimplib.dll
+DLL2: noprefix_noimplib.dll


        


More information about the llvm-commits mailing list