[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
Sun Jan 14 14:18:21 PST 2018
mstorsjo updated this revision to Diff 129792.
mstorsjo added a comment.
I figured I could fix this in a much more straightforward fashion, instead of adding a new, very vaguely defined field to the data structures.
https://reviews.llvm.org/D41632
Files:
COFF/Driver.cpp
COFF/DriverUtils.cpp
test/COFF/def-export-stdcall.s
test/COFF/dllexport.s
Index: test/COFF/dllexport.s
===================================================================
--- test/COFF/dllexport.s
+++ 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: test/COFF/def-export-stdcall.s
===================================================================
--- test/COFF/def-export-stdcall.s
+++ 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: COFF/DriverUtils.cpp
===================================================================
--- COFF/DriverUtils.cpp
+++ 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: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -537,7 +537,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.129792.patch
Type: text/x-patch
Size: 3167 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180114/d834f489/attachment.bin>
More information about the llvm-commits
mailing list