diff options
author | Martin Storsjo <martin@martin.st> | 2017-09-13 19:29:39 +0000 |
---|---|---|
committer | Martin Storsjo <martin@martin.st> | 2017-09-13 19:29:39 +0000 |
commit | 31fe4cd25d1781d8d1437fc47da5384a724bf2cc (patch) | |
tree | 28d446ee254e1af733ec71ff7dd1a8e1e8ebb67d | |
parent | b5d0cd89a5a2bdafc119753122e86df09c624aa9 (diff) | |
download | bcm5719-llvm-31fe4cd25d1781d8d1437fc47da5384a724bf2cc.tar.gz bcm5719-llvm-31fe4cd25d1781d8d1437fc47da5384a724bf2cc.zip |
[MinGW] Support dllexport on i386
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.)
Differential Revision: https://reviews.llvm.org/D37772
llvm-svn: 313174
-rw-r--r-- | lld/COFF/Config.h | 1 | ||||
-rw-r--r-- | lld/COFF/Driver.cpp | 10 | ||||
-rw-r--r-- | lld/COFF/Options.td | 1 | ||||
-rw-r--r-- | lld/MinGW/Driver.cpp | 1 | ||||
-rw-r--r-- | lld/test/COFF/dllexport-mingw.s | 19 | ||||
-rw-r--r-- | lld/test/MinGW/driver.test | 3 |
6 files changed, 35 insertions, 0 deletions
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h index 215dad91d97..0b8489b7c53 100644 --- a/lld/COFF/Config.h +++ b/lld/COFF/Config.h @@ -173,6 +173,7 @@ struct Configuration { bool LargeAddressAware = false; bool HighEntropyVA = false; bool AppContainer = false; + bool MinGW = false; }; extern Configuration *Config; diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index e0efb796981..c3dfdb2a399 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -234,6 +234,12 @@ void LinkerDriver::parseDirectives(StringRef S) { 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 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { return; } + // Handle /lldmingw early, since it can potentially affect how other + // options are handled. + Config->MinGW = Args.hasArg(OPT_lldmingw); + if (auto *Arg = Args.getLastArg(OPT_linkrepro)) { SmallString<64> Path = StringRef(Arg->getValue()); sys::path::append(Path, "repro.tar"); diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td index 813686129b0..694639e15dc 100644 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -104,6 +104,7 @@ def help_q : Flag<["/?", "-?"], "">, Alias<help>; // LLD extensions def nopdb : F<"nopdb">, HelpText<"Disable PDB generation for DWARF users">; def nosymtab : F<"nosymtab">; +def lldmingw : F<"lldmingw">; def msvclto : F<"msvclto">; def rsp_quoting : Joined<["--"], "rsp-quoting=">, HelpText<"Quoting style for response files, 'windows' (default) or 'posix'">; diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp index d0574b8f6ae..41b39b9011a 100644 --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -120,6 +120,7 @@ bool mingw::link(ArrayRef<const char *> ArgsArr, raw_ostream &Diag) { auto Add = [&](const Twine &S) { LinkArgs.push_back(S.str()); }; Add("lld-link"); + Add("-lldmingw"); if (auto *A = Args.getLastArg(OPT_entry)) { StringRef S = A->getValue(); diff --git a/lld/test/COFF/dllexport-mingw.s b/lld/test/COFF/dllexport-mingw.s new file mode 100644 index 00000000000..06c2e225817 --- /dev/null +++ b/lld/test/COFF/dllexport-mingw.s @@ -0,0 +1,19 @@ +# REQEUIRES: x86 + +# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj + +# RUN: lld-link -lldmingw -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" diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test index b408d1d142b..daf08613a06 100644 --- a/lld/test/MinGW/driver.test +++ b/lld/test/MinGW/driver.test @@ -53,3 +53,6 @@ I386-ENTRY: -entry:DllMainCRTStartup@12 RUN: ld.lld -### -m i386pep foo.o --whole-archive bar.a --no-whole-archive baz.a | FileCheck -check-prefix WHOLE-ARCHIVE %s WHOLE-ARCHIVE: foo.o -wholearchive:bar.a baz.a + +RUN: ld.lld -### -m i386pep foo.o | FileCheck -check-prefix MINGW-FLAG %s +MINGW-FLAG: -lldmingw |