[lld] r305502 - COFF: add support for lib mode usage

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 16:45:08 PDT 2017


Can you send a change to add new behavior to me so that I can review before
you commit? This change seems fine, but in general, I want to keep an eye
on it.

On Thu, Jun 15, 2017 at 1:39 PM, Saleem Abdulrasool via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> 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
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170615/300f9a00/attachment.html>


More information about the llvm-commits mailing list