[lld] r305502 - COFF: add support for lib mode usage
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 15 13:39:58 PDT 2017
Author: compnerd
Date: Thu Jun 15 15:39:58 2017
New Revision: 305502
URL: http://llvm.org/viewvc/llvm-project?rev=305502&view=rev
Log:
COFF: add support for lib mode usage
When link is invoked with `/def:` and no input files, it behaves as if
`lib.exe` was invoked. Emulate this behaviour, generating the import
library from the def file that was passed. Because there is no input to
actually generate the dll, we simply process the def file early and exit
once we have created the import library.
Added:
lld/trunk/test/COFF/Inputs/library.def
lld/trunk/test/COFF/lib.test
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/DriverUtils.cpp
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=305502&r1=305501&r2=305502&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Jun 15 15:39:58 2017
@@ -703,8 +703,12 @@ void LinkerDriver::link(ArrayRef<const c
}
}
- 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<const c
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());
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=305502&r1=305501&r2=305502&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Thu Jun 15 15:39:58 2017
@@ -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<Undefined>(Sym))
Added: lld/trunk/test/COFF/Inputs/library.def
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/Inputs/library.def?rev=305502&view=auto
==============================================================================
--- lld/trunk/test/COFF/Inputs/library.def (added)
+++ lld/trunk/test/COFF/Inputs/library.def Thu Jun 15 15:39:58 2017
@@ -0,0 +1,5 @@
+LIBRARY library
+EXPORTS
+ function
+ data DATA
+ constant CONSTANT
Added: lld/trunk/test/COFF/lib.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lib.test?rev=305502&view=auto
==============================================================================
--- lld/trunk/test/COFF/lib.test (added)
+++ lld/trunk/test/COFF/lib.test Thu Jun 15 15:39:58 2017
@@ -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
+
More information about the llvm-commits
mailing list