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()); }); } 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: test/COFF/def-export-stdcall.s =================================================================== --- test/COFF/def-export-stdcall.s +++ test/COFF/def-export-stdcall.s @@ -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 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_@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;