[PATCH] D66367: [LLD] [COFF] Require an explicit -implib option for creating implibs in mingw mode

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 13:56:08 PDT 2019


mstorsjo created this revision.
mstorsjo added reviewers: ruiu, rnk.
Herald added a project: LLVM.

GNU ld doesn't produce implibs unless explicitly requested.

Is the `test` command ok to use in lit tests, is that one of the commands that can be assumed to be available for all users, or is there a better way for testing whether a file exists? (I guess some other dummy command that inspects the file also would work...)


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D66367

Files:
  COFF/Driver.cpp
  test/COFF/implib-name-mingw.test


Index: test/COFF/implib-name-mingw.test
===================================================================
--- /dev/null
+++ test/COFF/implib-name-mingw.test
@@ -0,0 +1,20 @@
+REQUIRES: x86
+RUN: mkdir -p %t-out
+RUN: llvm-mc -triple x86_64-windows-gnu -filetype obj -o %t-out/object.obj %S/Inputs/object.s
+
+Check that linking without an explicit -implib doesn't produce any implib.
+
+First test that linking without -lldmingw does produce an implib, but when
+adding -lldmingw, it no longer is produced. And when it is explicitly named,
+it is created.
+
+RUN: rm -f %t-out/library.lib
+RUN: lld-link -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console
+RUN: test -f %t-out/library.lib
+
+RUN: rm -f %t-out/library.lib
+RUN: lld-link -lldmingw -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console
+RUN: not test -f %t-out/library.lib
+
+RUN: lld-link -lldmingw -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console -implib:%t-out/library.lib
+RUN: test -f %t-out/library.lib
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -1850,7 +1850,12 @@
 
   // Windows specific -- when we are creating a .dll file, we also
   // need to create a .lib file.
-  if (!config->exports.empty() || config->dll) {
+  bool createImpLib;
+  if (config->mingw)
+    createImpLib = !config->implib.empty();
+  else
+    createImpLib = !config->exports.empty() || config->dll;
+  if (createImpLib) {
     fixupExports();
     createImportLibrary(/*asLib=*/false);
     assignExportOrdinals();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66367.215670.patch
Type: text/x-patch
Size: 1742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190816/e7527ca0/attachment-0001.bin>


More information about the llvm-commits mailing list