[PATCH] D41632: [LLD] [COFF] Keep the underscore on exported decorated stdcall functions

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 20 03:47:26 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL323036: [COFF] Keep the underscore on exported decorated stdcall functions in MSVC mode (authored by mstorsjo, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41632?vs=129792&id=130758#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41632

Files:
  lld/trunk/COFF/Driver.cpp
  lld/trunk/COFF/DriverUtils.cpp
  lld/trunk/test/COFF/def-export-stdcall.s
  lld/trunk/test/COFF/dllexport.s


Index: lld/trunk/test/COFF/dllexport.s
===================================================================
--- lld/trunk/test/COFF/dllexport.s
+++ lld/trunk/test/COFF/dllexport.s
@@ -8,21 +8,19 @@
 # DECORATED-IMPLIB: Name type: name
 # DECORATED-IMPLIB-NEXT: __imp_ at fastcall@8
 # DECORATED-IMPLIB-NEXT: @fastcall at 8
+# DECORATED-IMPLIB: Name type: name
+# DECORATED-IMPLIB-NEXT: __imp__stdcall at 8
+# DECORATED-IMPLIB-NEXT: _stdcall at 8
 # DECORATED-IMPLIB: Name type: noprefix
 # DECORATED-IMPLIB-NEXT: __imp___underscored
 # DECORATED-IMPLIB-NEXT: __underscored
-# TODO: To match link.exe, this one should also be Name type: name.
-# DECORATED-IMPLIB: Name type: noprefix
-# DECORATED-IMPLIB-NEXT: __imp__stdcall at 8
-# DECORATED-IMPLIB-NEXT: _stdcall at 8
 # DECORATED-IMPLIB: Name type: name
 # DECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-IMPLIB-NEXT: vectorcall@@8
 
 # DECORATED-EXPORTS: Name: @fastcall at 8
+# DECORATED-EXPORTS: Name: _stdcall at 8
 # DECORATED-EXPORTS: Name: _underscored
-# TODO: To match link.exe, this one should actually be _stdcall at 8
-# DECORATED-EXPORTS: Name: stdcall at 8
 # DECORATED-EXPORTS: Name: vectorcall@@8
 
         .def     _stdcall at 8;
Index: lld/trunk/test/COFF/def-export-stdcall.s
===================================================================
--- lld/trunk/test/COFF/def-export-stdcall.s
+++ lld/trunk/test/COFF/def-export-stdcall.s
@@ -32,17 +32,15 @@
 # DECORATED-IMPLIB: Name type: name
 # DECORATED-IMPLIB-NEXT: __imp_ at fastcall@8
 # DECORATED-IMPLIB-NEXT: @fastcall at 8
-# TODO: To match link.exe, this one should also be Name type: name.
-# DECORATED-IMPLIB: Name type: noprefix
+# DECORATED-IMPLIB: Name type: name
 # DECORATED-IMPLIB-NEXT: __imp__stdcall at 8
 # DECORATED-IMPLIB-NEXT: _stdcall at 8
 # DECORATED-IMPLIB: Name type: name
 # DECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
 # DECORATED-IMPLIB-NEXT: vectorcall@@8
 
 # DECORATED-EXPORTS: Name: @fastcall at 8
-# TODO: To match link.exe, this one should actually be _stdcall at 8
-# DECORATED-EXPORTS: Name: stdcall at 8
+# DECORATED-EXPORTS: Name: _stdcall at 8
 # DECORATED-EXPORTS: Name: vectorcall@@8
 
 
Index: lld/trunk/COFF/DriverUtils.cpp
===================================================================
--- lld/trunk/COFF/DriverUtils.cpp
+++ lld/trunk/COFF/DriverUtils.cpp
@@ -558,6 +558,12 @@
 static StringRef undecorate(StringRef Sym) {
   if (Config->Machine != I386)
     return Sym;
+  // In MSVC mode, a fully decorated stdcall function is exported
+  // as-is with the leading underscore (with type IMPORT_NAME).
+  // In MinGW mode, a decorated stdcall function gets the underscore
+  // removed, just like normal cdecl functions.
+  if (Sym.startswith("_") && Sym.contains('@') && !Config->MinGW)
+    return Sym;
   return Sym.startswith("_") ? Sym.substr(1) : Sym;
 }
 
Index: lld/trunk/COFF/Driver.cpp
===================================================================
--- lld/trunk/COFF/Driver.cpp
+++ lld/trunk/COFF/Driver.cpp
@@ -540,7 +540,7 @@
   }
 
   auto E = writeImportLibrary(getImportName(AsLib), getImplibPath(), Exports,
-                              Config->Machine, false);
+                              Config->Machine, false, Config->MinGW);
   handleAllErrors(std::move(E),
                   [&](ErrorInfoBase &EIB) { error(EIB.message()); });
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41632.130758.patch
Type: text/x-patch
Size: 3287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180120/911619fe/attachment.bin>


More information about the llvm-commits mailing list