[COFF] Fix the name type for stdcall functions in import libraries

Since SVN r303491 and r304573, LLD used the COFFImportLibrary
functions from LLVM. These only had two names, Name and ExtName,
which wasn't enough to convey all the details of stdcall functions.

Stdcall functions got the wrong symbol name in the import library
itself in r303491, which is why it was reverted in r304561. When
re-landed and fixed in r304573 (after adding a test in r304572),
the symbol name itself in the import library ended up right, but the
name type of the import library entry was wrong.

This had the effect that linking to the import library succeeded
(contrary to in r303491, where linking to such an import library
failed), but at runtime, the symbol wouldn't be found in the DLL
(since the caller linked to the stdcall decorated name).

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

llvm-svn: 310989
This commit is contained in:
Martin Storsjo 2017-08-16 05:13:25 +00:00
parent a238b20e23
commit a50275cfe5
2 changed files with 4 additions and 3 deletions

View File

@ -461,8 +461,8 @@ static void createImportLibrary(bool AsLib) {
std::vector<COFFShortExport> Exports;
for (Export &E1 : Config->Exports) {
COFFShortExport E2;
// Use SymbolName, which will have any stdcall or fastcall qualifiers.
E2.Name = E1.SymbolName;
E2.Name = E1.Name;
E2.SymbolName = E1.SymbolName;
E2.ExtName = E1.ExtName;
E2.Ordinal = E1.Ordinal;
E2.Noname = E1.Noname;

View File

@ -2,7 +2,8 @@
# RUN: llvm-mc -filetype=obj -triple=i686-windows-msvc %s -o %t.obj
# RUN: echo -e "LIBRARY foo\nEXPORTS\n stdcall" > %t.def
# RUN: lld-link -entry:dllmain -dll -def:%t.def %t.obj -out:%t.dll -implib:%t.lib
# RUN: llvm-nm %t.lib | FileCheck %s
# RUN: llvm-readobj %t.lib | FileCheck %s
# CHECK: Name type: undecorate
# CHECK: __imp__stdcall@8
# CHECK: _stdcall@8