[PATCH] D123591: [LLD][COFF] Add support for /noimplib

Tobias Hieta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 12 05:03:54 PDT 2022


thieta created this revision.
thieta added reviewers: mstorsjo, aganea, saudi.
Herald added a project: All.
thieta requested review of this revision.
Herald added a project: LLVM.

Mostly for compatibility reasons with link.exe this flag
makes sure we don't write a implib - not even when /implib
is also passed, that's how link.exe works.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123591

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/Options.td
  lld/test/COFF/noimplib.test


Index: lld/test/COFF/noimplib.test
===================================================================
--- /dev/null
+++ lld/test/COFF/noimplib.test
@@ -0,0 +1,20 @@
+REQUIRES: x86
+RUN: mkdir -p %t-out
+RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t-out/object.obj %S/Inputs/object.s
+
+Test that /noimplib writes no .lib file
+
+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 /noimplib
+RUN: not test -f %t-out/library.lib
+
+Just make sure the normal stuff works and then we just add /noimplib
+
+RUN: lld-link -dll -machine:x64 -def:%S/Inputs/named.def -out:%t-out/library.dll %t-out/object.obj -entry:f -subsystem:console /implib:%t-out/nolibrary.lib
+RUN: test -f %t-out/nolibrary.lib
+
+Test that it overrides /implib as well. This is how link.exe works
+
+RUN: rm -f %t-out/nolibrary.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 /implib:%t-out/nolibrary.lib /noimplib
+RUN: not test -f %t-out/nolibrary.lib
Index: lld/COFF/Options.td
===================================================================
--- lld/COFF/Options.td
+++ lld/COFF/Options.td
@@ -56,6 +56,8 @@
 def heap    : P<"heap", "Size of the heap">;
 def ignore : P<"ignore", "Specify warning codes to ignore">;
 def implib  : P<"implib", "Import library name">;
+def noimplib : F<"noimplib">,
+    HelpText<"Don't output a implementation lib">;
 def lib : F<"lib">,
     HelpText<"Act like lib.exe; must be first argument if present">;
 def libpath : P<"libpath", "Additional library search path">;
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1673,6 +1673,9 @@
   if (auto *arg = args.getLastArg(OPT_implib))
     config->implib = arg->getValue();
 
+  if (auto *arg = args.getLastArg(OPT_noimplib))
+    config->noimplib = true;
+
   // Handle /opt.
   bool doGC = debug == DebugKind::None || args.hasArg(OPT_profile);
   Optional<ICFLevel> icfLevel = None;
@@ -2022,7 +2025,8 @@
   // Handle generation of import library from a def file.
   if (!args.hasArg(OPT_INPUT, OPT_wholearchive_file)) {
     fixupExports();
-    createImportLibrary(/*asLib=*/true);
+    if (!config->noimplib)
+      createImportLibrary(/*asLib=*/true);
     return;
   }
 
@@ -2281,7 +2285,7 @@
   // -implib option is given explicitly, for compatibility with GNU ld.
   if (!config->exports.empty() || config->dll) {
     fixupExports();
-    if (!config->mingw || !config->implib.empty())
+    if (!config->noimplib && (!config->mingw || !config->implib.empty()))
       createImportLibrary(/*asLib=*/false);
     assignExportOrdinals();
   }
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -140,6 +140,7 @@
   // True if we are creating a DLL.
   bool dll = false;
   StringRef implib;
+  bool noimplib = false;
   std::vector<Export> exports;
   bool hadExplicitExports;
   std::set<std::string> delayLoads;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123591.422184.patch
Type: text/x-patch
Size: 3171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220412/ee12f9d9/attachment.bin>


More information about the llvm-commits mailing list