[PATCH] D36548: [llvm-dlltool] Fix creating stdcall import libraries for MinGW/i386

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 13:23:05 PDT 2017


mstorsjo created this revision.
Herald added subscribers: inglorion, mehdi_amini.

MinGW's def files for i386 contain stdcall functions in this form. In order to get them written to import libraries with the right name type undecorate, we need to set a Name that differs from SymbolName.

With this in place, mingw-w64 for i386 built with llvm-dlltool/clang produces import libraries that actually work.


https://reviews.llvm.org/D36548

Files:
  lib/Object/COFFModuleDefinition.cpp
  test/DllTool/coff-stdcall.def


Index: test/DllTool/coff-stdcall.def
===================================================================
--- /dev/null
+++ test/DllTool/coff-stdcall.def
@@ -0,0 +1,13 @@
+; RUN: llvm-dlltool -m i386 --input-def %s --output-lib %t.a
+; RUN: llvm-readobj %t.a | FileCheck %s
+
+LIBRARY test.dll
+EXPORTS
+TestFunction at 4
+
+; CHECK: File: test.dll
+; CHECK: Format: COFF-import-file
+; CHECK: Type: code
+; CHECK: Name type: undecorate
+; CHECK: Symbol: __imp__TestFunction at 4
+; CHECK: Symbol: _TestFunction at 4
Index: lib/Object/COFFModuleDefinition.cpp
===================================================================
--- lib/Object/COFFModuleDefinition.cpp
+++ lib/Object/COFFModuleDefinition.cpp
@@ -227,6 +227,10 @@
         E.Name = (std::string("_").append(E.Name));
       if (!E.ExtName.empty() && !isDecorated(E.ExtName, MingwDef))
         E.ExtName = (std::string("_").append(E.ExtName));
+      if (MingwDef) {
+        E.SymbolName = E.Name;
+        E.Name = E.Name.substr(0, E.Name.find('@'));
+      }
     }
 
     for (;;) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36548.110465.patch
Type: text/x-patch
Size: 1042 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170809/1425a719/attachment.bin>


More information about the llvm-commits mailing list