forked from OSchip/llvm-project
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. llvm-svn: 305502
This commit is contained in:
parent
152277952e
commit
bc7ff7027e
|
@ -703,8 +703,12 @@ void LinkerDriver::link(ArrayRef<const char *> 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<const char *> 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());
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
LIBRARY library
|
||||
EXPORTS
|
||||
function
|
||||
data DATA
|
||||
constant CONSTANT
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue