[PATCH] D37772: [LLD] [MinGW] Support dllexport on i386
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 12 14:21:01 PDT 2017
mstorsjo created this revision.
In MinGW configurations (GCC, or clang with a `*-windows-gnu` target), the -export directives in the object file contains the undecorated symbol name, while it is decorated in MSVC configurations. (On the command line, link.exe takes an undecorated symbol name for the -export argument though.)
https://reviews.llvm.org/D37772
Files:
COFF/Config.h
COFF/Driver.cpp
COFF/Options.td
MinGW/Driver.cpp
test/COFF/dllexport-gnu.s
Index: test/COFF/dllexport-gnu.s
===================================================================
--- /dev/null
+++ test/COFF/dllexport-gnu.s
@@ -0,0 +1,19 @@
+# REQEUIRES: x86
+
+# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj
+
+# RUN: lld-link -mingw -dll -out:%t.dll -entry:main %t.obj -implib:%t.lib
+# RUN: llvm-readobj %t.lib | FileCheck %s
+
+# CHECK: Symbol: __imp__func
+# CHECK: Symbol: _func
+
+.global _main
+.global _func
+.text
+_main:
+ ret
+_func:
+ ret
+.section .drectve
+.ascii "-export:func"
Index: MinGW/Driver.cpp
===================================================================
--- MinGW/Driver.cpp
+++ MinGW/Driver.cpp
@@ -120,6 +120,7 @@
auto Add = [&](const Twine &S) { LinkArgs.push_back(S.str()); };
Add("lld-link");
+ Add("-mingw");
if (auto *A = Args.getLastArg(OPT_entry)) {
StringRef S = A->getValue();
Index: COFF/Options.td
===================================================================
--- COFF/Options.td
+++ COFF/Options.td
@@ -104,6 +104,7 @@
// LLD extensions
def nopdb : F<"nopdb">, HelpText<"Disable PDB generation for DWARF users">;
def nosymtab : F<"nosymtab">;
+def mingw : F<"mingw">, HelpText<"Switch to MinGW behaviour where necessary">;
def msvclto : F<"msvclto">;
def rsp_quoting : Joined<["--"], "rsp-quoting=">,
HelpText<"Quoting style for response files, 'windows' (default) or 'posix'">;
Index: COFF/Driver.cpp
===================================================================
--- COFF/Driver.cpp
+++ COFF/Driver.cpp
@@ -234,6 +234,12 @@
break;
case OPT_export: {
Export E = parseExport(Arg->getValue());
+ if (Config->Machine == I386 && Config->MinGW) {
+ if (!isDecorated(E.Name))
+ E.Name = Saver.save("_" + E.Name);
+ if (!E.ExtName.empty() && !isDecorated(E.ExtName))
+ E.ExtName = Saver.save("_" + E.ExtName);
+ }
E.Directives = true;
Config->Exports.push_back(E);
break;
@@ -719,6 +725,10 @@
return;
}
+ // Handle /mingw early, since it can potentially affect how other
+ // options are handled.
+ Config->MinGW = Args.hasArg(OPT_mingw);
+
if (auto *Arg = Args.getLastArg(OPT_linkrepro)) {
SmallString<64> Path = StringRef(Arg->getValue());
sys::path::append(Path, "repro.tar");
Index: COFF/Config.h
===================================================================
--- COFF/Config.h
+++ COFF/Config.h
@@ -173,6 +173,8 @@
bool LargeAddressAware = false;
bool HighEntropyVA = false;
bool AppContainer = false;
+
+ bool MinGW = false;
};
extern Configuration *Config;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37772.114909.patch
Type: text/x-patch
Size: 2612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170912/1e984311/attachment.bin>
More information about the llvm-commits
mailing list