From c09e5e50b13aa1f5a2eafc81097ffe8a5799e5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 17 Jun 2021 15:57:20 +0300 Subject: [PATCH] [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 --- lld/MinGW/Driver.cpp | 14 ++++---------- lld/test/MinGW/lib.test | 8 ++++---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index 734f4092a666..27cb508403f6 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -142,16 +142,10 @@ searchLibrary(StringRef name, ArrayRef searchPaths, bool bStatic) { if (!bStatic) { if (Optional s = findFile(dir, name + ".lib")) return *s; - if (Optional s = findFile(dir, "lib" + name + ".dll")) { - error("lld doesn't support linking directly against " + *s + - ", use an import library"); - return ""; - } - if (Optional s = findFile(dir, name + ".dll")) { - error("lld doesn't support linking directly against " + *s + - ", use an import library"); - return ""; - } + if (Optional s = findFile(dir, "lib" + name + ".dll")) + return *s; + if (Optional 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 ddff5debab3c..45dd79712213 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