[COFF] Keep the underscore on exported decorated stdcall functions in MSVC mode

This fixes PR35733.

Differential Revision: https://reviews.llvm.org/D41632

llvm-svn: 323036
This commit is contained in:
Martin Storsjo 2018-01-20 11:44:42 +00:00
parent f641d0d4f2
commit 3b611fa93f
4 changed files with 13 additions and 11 deletions

View File

@ -540,7 +540,7 @@ static void createImportLibrary(bool AsLib) {
}
auto E = writeImportLibrary(getImportName(AsLib), getImplibPath(), Exports,
Config->Machine, false);
Config->Machine, false, Config->MinGW);
handleAllErrors(std::move(E),
[&](ErrorInfoBase &EIB) { error(EIB.message()); });
}

View File

@ -558,6 +558,12 @@ err:
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;
}

View File

@ -32,8 +32,7 @@
# DECORATED-IMPLIB: Name type: name
# DECORATED-IMPLIB-NEXT: __imp_@fastcall@8
# DECORATED-IMPLIB-NEXT: @fastcall@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@8
# DECORATED-IMPLIB-NEXT: _stdcall@8
# DECORATED-IMPLIB: Name type: name
@ -41,8 +40,7 @@
# DECORATED-IMPLIB-NEXT: vectorcall@@8
# DECORATED-EXPORTS: Name: @fastcall@8
# TODO: To match link.exe, this one should actually be _stdcall@8
# DECORATED-EXPORTS: Name: stdcall@8
# DECORATED-EXPORTS: Name: _stdcall@8
# DECORATED-EXPORTS: Name: vectorcall@@8

View File

@ -8,21 +8,19 @@
# DECORATED-IMPLIB: Name type: name
# DECORATED-IMPLIB-NEXT: __imp_@fastcall@8
# DECORATED-IMPLIB-NEXT: @fastcall@8
# DECORATED-IMPLIB: Name type: name
# DECORATED-IMPLIB-NEXT: __imp__stdcall@8
# DECORATED-IMPLIB-NEXT: _stdcall@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@8
# DECORATED-IMPLIB-NEXT: _stdcall@8
# DECORATED-IMPLIB: Name type: name
# DECORATED-IMPLIB-NEXT: __imp_vectorcall@@8
# DECORATED-IMPLIB-NEXT: vectorcall@@8
# DECORATED-EXPORTS: Name: @fastcall@8
# DECORATED-EXPORTS: Name: _stdcall@8
# DECORATED-EXPORTS: Name: _underscored
# TODO: To match link.exe, this one should actually be _stdcall@8
# DECORATED-EXPORTS: Name: stdcall@8
# DECORATED-EXPORTS: Name: vectorcall@@8
.def _stdcall@8;