diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 28af3d01cf4d..71a9c679d19f 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -703,8 +703,12 @@ void LinkerDriver::link(ArrayRef ArgsArr) { } } - if (!Args.hasArgNoClaim(OPT_INPUT)) - fatal("no input files"); + if (!Args.hasArgNoClaim(OPT_INPUT)) { + if (Args.hasArgNoClaim(OPT_deffile)) + Config->NoEntry = true; + else + fatal("no input files"); + } // Construct search path list. SearchPaths.push_back(""); @@ -986,6 +990,13 @@ void LinkerDriver::link(ArrayRef ArgsArr) { parseModuleDefs(Arg->getValue()); } + // Handle generation of import library from a def file. + if (!Args.hasArgNoClaim(OPT_INPUT)) { + fixupExports(); + createImportLibrary(); + exit(0); + } + // Handle /delayload for (auto *Arg : Args.filtered(OPT_delayload)) { Config->DelayLoads.insert(StringRef(Arg->getValue()).lower()); diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index ee4bd0f6b22c..42619b8fa438 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -522,7 +522,7 @@ void fixupExports() { for (Export &E : Config->Exports) { SymbolBody *Sym = E.Sym; - if (!E.ForwardTo.empty()) { + if (!E.ForwardTo.empty() || !Sym) { E.SymbolName = E.Name; } else { if (auto *U = dyn_cast(Sym)) diff --git a/lld/test/COFF/Inputs/library.def b/lld/test/COFF/Inputs/library.def new file mode 100644 index 000000000000..6c6880ffa18e --- /dev/null +++ b/lld/test/COFF/Inputs/library.def @@ -0,0 +1,5 @@ +LIBRARY library +EXPORTS + function + data DATA + constant CONSTANT diff --git a/lld/test/COFF/lib.test b/lld/test/COFF/lib.test new file mode 100644 index 000000000000..2d63ed6c2324 --- /dev/null +++ b/lld/test/COFF/lib.test @@ -0,0 +1,11 @@ +# RUN: lld-link /machine:x64 /def:%S/Inputs/library.def /out:%t.lib +# RUN: llvm-nm %t.lib | FileCheck %s + +CHECK: 00000000 R __imp_constant +CHECK: 00000000 R constant + +CHECK: 00000000 D __imp_data + +CHECK: 00000000 T __imp_function +CHECK: 00000000 T function +