[PATCH] D106245: [LLD] [COFF] Make -export-all-symbols work as intended for EXEs

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 18 12:57:02 PDT 2021


mstorsjo created this revision.
mstorsjo added reviewers: rnk, mati865, jeremyd2019.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

If some symbols are marked with dllexport, we still want to export
all symbols if -export-all-symbols is specified. Previously, this
only worked as it should for DLL output, not for EXE.

This should fix downstream bug
https://github.com/msys2/MINGW-packages/issues/9163.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106245

Files:
  lld/COFF/Driver.cpp
  lld/test/COFF/export-all.s


Index: lld/test/COFF/export-all.s
===================================================================
--- lld/test/COFF/export-all.s
+++ lld/test/COFF/export-all.s
@@ -61,6 +61,10 @@
 # RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=CHECK2 %s
 # RUN: cat %t.def | FileCheck -check-prefix=CHECK2-DEF %s
 
+# RUN: lld-link -safeseh:no -out:%t.exe %t.obj -lldmingw -export-all-symbols -output-def:%t.def -entry:_DllMainCRTStartup
+# RUN: llvm-readobj --coff-exports %t.exe | FileCheck -check-prefix=CHECK2 %s
+# RUN: cat %t.def | FileCheck -check-prefix=CHECK2-DEF %s
+
 # Note, this will actually export _DllMainCRTStartup as well, since
 # it uses the standard spelling in this object file, not the MinGW one.
 
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1203,10 +1203,10 @@
 // -exclude-all-symbols option, so that lld-link behaves like link.exe rather
 // than MinGW in the case that nothing is explicitly exported.
 void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
-  if (!config->dll)
-    return;
-
   if (!args.hasArg(OPT_export_all_symbols)) {
+    if (!config->dll)
+      return;
+
     if (!config->exports.empty())
       return;
     if (args.hasArg(OPT_exclude_all_symbols))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106245.359646.patch
Type: text/x-patch
Size: 1337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210718/1bcc0013/attachment.bin>


More information about the llvm-commits mailing list