[lld] 9dbc4b0 - [LLD] [COFF] Make -export-all-symbols work as intended for EXEs

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 22 13:41:23 PDT 2021


Author: Martin Storsjö
Date: 2021-07-22T23:34:03+03:00
New Revision: 9dbc4b09afd4427c2def829f0c8283f732e654a0

URL: https://github.com/llvm/llvm-project/commit/9dbc4b09afd4427c2def829f0c8283f732e654a0
DIFF: https://github.com/llvm/llvm-project/commit/9dbc4b09afd4427c2def829f0c8283f732e654a0.diff

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

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 8e1292f0a5e8e..9ba0db31507f2 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -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))

diff  --git a/lld/test/COFF/export-all.s b/lld/test/COFF/export-all.s
index 079d0a25d79b8..b370dbe92079e 100644
--- a/lld/test/COFF/export-all.s
+++ b/lld/test/COFF/export-all.s
@@ -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.
 


        


More information about the llvm-commits mailing list