[lld] r327561 - [COFF] Add support for the GNU ld flag --kill-at

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 14 14:11:30 PDT 2018


Looks like a new test is failing. This is a log on my machine.

Command Output (stderr):
--
/ssd/b/bin/lld-link: error: could not open
/ssd/b/tools/lld/test/COFF/Output/def-export-stdcall.s.tmp.deco-mingw.def:
No such file or directory


On Wed, Mar 14, 2018 at 1:19 PM Martin Storsjo via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: mstorsjo
> Date: Wed Mar 14 13:17:16 2018
> New Revision: 327561
>
> URL: http://llvm.org/viewvc/llvm-project?rev=327561&view=rev
> Log:
> [COFF] Add support for the GNU ld flag --kill-at
>
> GNU ld has got a number of different flags for adjusting how to
> behave around stdcall functions. The --kill-at flag strips the
> trailing sdcall suffix from exported functions (which otherwise
> is included by default in MinGW setups).
>
> This also strips it from the corresponding import library though.
> That makes it hard to link to such an import library from code
> that calls the functions - but this matches what GNU ld does with
> this flag. Therefore, this flag is probably not sensibly used
> together with import libraries, but probably mostly when creating
> some sort of plugin, or if creating the import library separately
> with dlltool.
>
> Differential Revision: https://reviews.llvm.org/D44292
>
> Modified:
>     lld/trunk/COFF/Config.h
>     lld/trunk/COFF/Driver.cpp
>     lld/trunk/COFF/DriverUtils.cpp
>     lld/trunk/COFF/Options.td
>     lld/trunk/test/COFF/def-export-stdcall.s
>
> Modified: lld/trunk/COFF/Config.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=327561&r1=327560&r2=327561&view=diff
>
> ==============================================================================
> --- lld/trunk/COFF/Config.h (original)
> +++ lld/trunk/COFF/Config.h Wed Mar 14 13:17:16 2018
> @@ -190,6 +190,7 @@ struct Configuration {
>    bool WarnMissingOrderSymbol = true;
>    bool WarnLocallyDefinedImported = true;
>    bool Incremental = true;
> +  bool KillAt = false;
>  };
>
>  extern Configuration *Config;
>
> Modified: lld/trunk/COFF/Driver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=327561&r1=327560&r2=327561&view=diff
>
> ==============================================================================
> --- lld/trunk/COFF/Driver.cpp (original)
> +++ lld/trunk/COFF/Driver.cpp Wed Mar 14 13:17:16 2018
> @@ -1073,6 +1073,10 @@ void LinkerDriver::link(ArrayRef<const c
>    if (Args.hasArg(OPT_lldsavetemps))
>      Config->SaveTemps = true;
>
> +  // Handle /kill-at
> +  if (Args.hasArg(OPT_kill_at))
> +    Config->KillAt = true;
> +
>    // Handle /lldltocache
>    if (auto *Arg = Args.getLastArg(OPT_lldltocache))
>      Config->LTOCache = Arg->getValue();
>
> Modified: lld/trunk/COFF/DriverUtils.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=327561&r1=327560&r2=327561&view=diff
>
> ==============================================================================
> --- lld/trunk/COFF/DriverUtils.cpp (original)
> +++ lld/trunk/COFF/DriverUtils.cpp Wed Mar 14 13:17:16 2018
> @@ -582,6 +582,26 @@ static StringRef undecorate(StringRef Sy
>    return Sym.startswith("_") ? Sym.substr(1) : Sym;
>  }
>
> +// Convert stdcall/fastcall style symbols into unsuffixed symbols,
> +// with or without a leading underscore. (MinGW specific.)
> +static StringRef killAt(StringRef Sym, bool Prefix) {
> +  if (Sym.empty())
> +    return Sym;
> +  // Strip any trailing stdcall suffix
> +  Sym = Sym.substr(0, Sym.find('@', 1));
> +  if (!Sym.startswith("@")) {
> +    if (Prefix && !Sym.startswith("_"))
> +      return Saver.save("_" + Sym);
> +    return Sym;
> +  }
> +  // For fastcall, remove the leading @ and replace it with an
> +  // underscore, if prefixes are used.
> +  Sym = Sym.substr(1);
> +  if (Prefix)
> +    Sym = Saver.save("_" + Sym);
> +  return Sym;
> +}
> +
>  // Performs error checking on all /export arguments.
>  // It also sets ordinals.
>  void fixupExports() {
> @@ -614,6 +634,15 @@ void fixupExports() {
>      }
>    }
>
> +  if (Config->KillAt && Config->Machine == I386) {
> +    for (Export &E : Config->Exports) {
> +      E.Name = killAt(E.Name, true);
> +      E.ExportName = killAt(E.ExportName, false);
> +      E.ExtName = killAt(E.ExtName, true);
> +      E.SymbolName = killAt(E.SymbolName, true);
> +    }
> +  }
> +
>    // Uniquefy by name.
>    DenseMap<StringRef, Export *> Map(Config->Exports.size());
>    std::vector<Export> V;
>
> Modified: lld/trunk/COFF/Options.td
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=327561&r1=327560&r2=327561&view=diff
>
> ==============================================================================
> --- lld/trunk/COFF/Options.td (original)
> +++ lld/trunk/COFF/Options.td Wed Mar 14 13:17:16 2018
> @@ -126,6 +126,7 @@ def help_q : Flag<["/?", "-?"], "">, Ali
>  def debug_ghash : F<"debug:ghash">;
>  def debug_dwarf : F<"debug:dwarf">;
>  def export_all_symbols : F<"export-all-symbols">;
> +def kill_at : F<"kill-at">;
>  def lldmingw : F<"lldmingw">;
>  def msvclto : F<"msvclto">;
>  def output_def : Joined<["/", "-"], "output-def:">;
>
> Modified: lld/trunk/test/COFF/def-export-stdcall.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/def-export-stdcall.s?rev=327561&r1=327560&r2=327561&view=diff
>
> ==============================================================================
> --- lld/trunk/test/COFF/def-export-stdcall.s (original)
> +++ lld/trunk/test/COFF/def-export-stdcall.s Wed Mar 14 13:17:16 2018
> @@ -44,7 +44,8 @@
>  # DECORATED-EXPORTS: Name: vectorcall@@8
>
>
> -# RUN: echo -e "LIBRARY foo\nEXPORTS\n  stdcall at 8\n  @fastcall at 8" >
> %t.def
> +# GNU tools don't support vectorcall at the moment, but test it for
> completeness.
> +# RUN: echo -e "LIBRARY foo\nEXPORTS\n  stdcall at 8\n  @fastcall at 8\n
> vectorcall@@8" > %t.def
>  # RUN: lld-link -lldmingw -entry:dllmain -dll -def:%t.def %t.obj
> -out:%t.dll -implib:%t.lib
>  # RUN: llvm-readobj %t.lib | FileCheck -check-prefix
> DECORATED-MINGW-IMPLIB %s
>  # RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix
> DECORATED-MINGW-EXPORTS %s
> @@ -55,9 +56,39 @@
>  # DECORATED-MINGW-IMPLIB: Name type: noprefix
>  # DECORATED-MINGW-IMPLIB-NEXT: __imp__stdcall at 8
>  # DECORATED-MINGW-IMPLIB-NEXT: _stdcall at 8
> +# GNU tools don't support vectorcall, but this test is just to track that
> +# lld's behaviour remains consistent over time.
> +# DECORATED-MINGW-IMPLIB: Name type: name
> +# DECORATED-MINGW-IMPLIB-NEXT: __imp_vectorcall@@8
> +# DECORATED-MINGW-IMPLIB-NEXT: vectorcall@@8
>
>  # DECORATED-MINGW-EXPORTS: Name: @fastcall at 8
>  # DECORATED-MINGW-EXPORTS: Name: stdcall at 8
> +# DECORATED-MINGW-EXPORTS: Name: vectorcall@@8
> +
> +# RUN: lld-link -lldmingw -kill-at -entry:dllmain -dll
> -def:%t.deco-mingw.def %t.obj -out:%t.dll -implib:%t.lib
> +# RUN: llvm-readobj %t.lib | FileCheck -check-prefix MINGW-KILL-AT-IMPLIB
> %s
> +# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix
> MINGW-KILL-AT-EXPORTS %s
> +
> +# RUN: lld-link -lldmingw -kill-at -entry:dllmain -dll %t.obj -out:%t.dll
> -implib:%t.lib
> +# RUN: llvm-readobj %t.lib | FileCheck -check-prefix MINGW-KILL-AT-IMPLIB
> %s
> +# RUN: llvm-readobj -coff-exports %t.dll | FileCheck -check-prefix
> MINGW-KILL-AT-EXPORTS %s
> +
> +# MINGW-KILL-AT-IMPLIB: Name type: noprefix
> +# MINGW-KILL-AT-IMPLIB: __imp__fastcall
> +# MINGW-KILL-AT-IMPLIB-NEXT: _fastcall
> +# MINGW-KILL-AT-IMPLIB: Name type: noprefix
> +# MINGW-KILL-AT-IMPLIB-NEXT: __imp__stdcall
> +# MINGW-KILL-AT-IMPLIB-NEXT: _stdcall
> +# GNU tools don't support vectorcall, but this test is just to track that
> +# lld's behaviour remains consistent over time.
> +# MINGW-KILL-AT-IMPLIB: Name type: noprefix
> +# MINGW-KILL-AT-IMPLIB-NEXT: __imp__vectorcall
> +# MINGW-KILL-AT-IMPLIB-NEXT: _vectorcall
> +
> +# MINGW-KILL-AT-EXPORTS: Name: fastcall
> +# MINGW-KILL-AT-EXPORTS: Name: stdcall
> +# MINGW-KILL-AT-EXPORTS: Name: vectorcall
>
>
>          .def     _stdcall at 8;
>
>
> _______________________________________________
> 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/20180314/ae15f4a3/attachment.html>


More information about the llvm-commits mailing list