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

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 12:51:04 PDT 2017


mstorsjo created this revision.

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).


https://reviews.llvm.org/D36545

Files:
  COFF/Driver.cpp
  test/COFF/def-export-stdcall.s


Index: test/COFF/def-export-stdcall.s
===================================================================
--- test/COFF/def-export-stdcall.s
+++ test/COFF/def-export-stdcall.s
@@ -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 at 8
 # CHECK: _stdcall at 8
 
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -461,8 +461,8 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36545.110460.patch
Type: text/x-patch
Size: 1077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170809/23cc191a/attachment.bin>


More information about the llvm-commits mailing list