[LLD] [COFF] Make -export-all-symbols work as intended for EXEs
authorMartin Storsjö <martin@martin.st>
Sun, 18 Jul 2021 19:52:32 +0000 (22:52 +0300)
committerMartin Storsjö <martin@martin.st>
Thu, 22 Jul 2021 20:34:03 +0000 (23:34 +0300)
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.

Differential Revision: https://reviews.llvm.org/D106245

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

index 8e1292f0a5e8ed1b26424f3ae625c4ca9eae8460..9ba0db31507f22a1cff1f7d8d4e21424de4bc15e 100644 (file)
@@ -1203,10 +1203,10 @@ void LinkerDriver::convertResources() {
 // -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))
index 079d0a25d79b833eedddbe720a29127775c33cf3..b370dbe92079edf59c4b3b601300b0ba5f4d538e 100644 (file)
@@ -61,6 +61,10 @@ __imp__unexported:
 # 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.