diff --git a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp --- a/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp +++ b/llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -292,8 +292,9 @@ return 0; } - // If no input files, silently do nothing to match lib.exe. - if (!Args.hasArgNoClaim(OPT_INPUT)) + // If no input files and not told otherwise, silently do nothing to match + // lib.exe + if (!Args.hasArgNoClaim(OPT_INPUT) && !Args.hasArg(OPT_llvmlibempty)) return 0; if (Args.hasArg(OPT_lst)) { diff --git a/llvm/lib/ToolDrivers/llvm-lib/Options.td b/llvm/lib/ToolDrivers/llvm-lib/Options.td --- a/llvm/lib/ToolDrivers/llvm-lib/Options.td +++ b/llvm/lib/ToolDrivers/llvm-lib/Options.td @@ -18,6 +18,9 @@ def llvmlibthin : F<"llvmlibthin">, HelpText<"Make .lib point to .obj files instead of copying their contents">; +def llvmlibempty : F<"llvmlibempty">, + HelpText<"When given no contents, produce an empty .lib file">; + def machine: P<"machine", "Specify target platform">; def help : F<"help">; diff --git a/llvm/test/tools/llvm-lib/no-inputs.test b/llvm/test/tools/llvm-lib/no-inputs.test --- a/llvm/test/tools/llvm-lib/no-inputs.test +++ b/llvm/test/tools/llvm-lib/no-inputs.test @@ -1,2 +1,6 @@ RUN: llvm-lib -out:%t.a RUN: test ! -e %t.a + +RUN: llvm-lib /llvmlibempty -out:%t.a +RUN: FileCheck %s < %t.a +CHECK: !