[lld] r332083 - Merging r327561,327567:

Martin Storsjo via llvm-commits llvm-commits at lists.llvm.org
Thu May 10 23:52:19 PDT 2018


Author: mstorsjo
Date: Thu May 10 23:52:19 2018
New Revision: 332083

URL: http://llvm.org/viewvc/llvm-project?rev=332083&view=rev
Log:
Merging r327561,327567:
------------------------------------------------------------------------
r327561 | mstorsjo | 2018-03-14 22:17:16 +0200 (Wed, 14 Mar 2018) | 16 lines

[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
------------------------------------------------------------------------
r327567 | mstorsjo | 2018-03-14 22:31:31 +0200 (Wed, 14 Mar 2018) | 4 lines

[test] Fix a temp filename in a test from SVN r327561. NFC.

An earlier file name accidentally slipped through into the committed
version.
------------------------------------------------------------------------

Modified:
    lld/branches/release_60/COFF/Config.h
    lld/branches/release_60/COFF/Driver.cpp
    lld/branches/release_60/COFF/DriverUtils.cpp
    lld/branches/release_60/COFF/Options.td
    lld/branches/release_60/test/COFF/def-export-stdcall.s

Modified: lld/branches/release_60/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/COFF/Config.h?rev=332083&r1=332082&r2=332083&view=diff
==============================================================================
--- lld/branches/release_60/COFF/Config.h (original)
+++ lld/branches/release_60/COFF/Config.h Thu May 10 23:52:19 2018
@@ -175,6 +175,7 @@ struct Configuration {
   bool AppContainer = false;
   bool MinGW = false;
   bool WarnLocallyDefinedImported = true;
+  bool KillAt = false;
 };
 
 extern Configuration *Config;

Modified: lld/branches/release_60/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/COFF/Driver.cpp?rev=332083&r1=332082&r2=332083&view=diff
==============================================================================
--- lld/branches/release_60/COFF/Driver.cpp (original)
+++ lld/branches/release_60/COFF/Driver.cpp Thu May 10 23:52:19 2018
@@ -970,6 +970,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/branches/release_60/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/COFF/DriverUtils.cpp?rev=332083&r1=332082&r2=332083&view=diff
==============================================================================
--- lld/branches/release_60/COFF/DriverUtils.cpp (original)
+++ lld/branches/release_60/COFF/DriverUtils.cpp Thu May 10 23:52:19 2018
@@ -561,6 +561,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() {
@@ -593,6 +613,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/branches/release_60/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/COFF/Options.td?rev=332083&r1=332082&r2=332083&view=diff
==============================================================================
--- lld/branches/release_60/COFF/Options.td (original)
+++ lld/branches/release_60/COFF/Options.td Thu May 10 23:52:19 2018
@@ -121,6 +121,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/branches/release_60/test/COFF/def-export-stdcall.s
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_60/test/COFF/def-export-stdcall.s?rev=332083&r1=332082&r2=332083&view=diff
==============================================================================
--- lld/branches/release_60/test/COFF/def-export-stdcall.s (original)
+++ lld/branches/release_60/test/COFF/def-export-stdcall.s Thu May 10 23:52:19 2018
@@ -46,7 +46,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
@@ -57,9 +58,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.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;




More information about the llvm-commits mailing list