[PATCH v3 3/3] winebuild: Find WinMain/wWinMain in static libraries.

Kevin Puetz PuetzKevinA at JohnDeere.com
Wed Nov 25 13:00:28 CST 2020


Signed-off-by: Kevin Puetz <PuetzKevinA at JohnDeere.com>
---
Jacek found this part a bit more controversial and asked me to split it.

Today, winegcc will let you set -mwindows, yet still use main. MinGW gcc
allows this as well. With this change, that will no longer work, since
there will be an undefined symbol referencing WinMain.

MSVC does not allow this; main matches /subsytem:console, and WinMain
matches /subsystem:windows; mismatching flags and symbols is a link error
(consistent with the behavior after this patch).

I think the MinGW behavior is an artifact of a similar runtime structure
to winecrt0: entry at a mainCRTStartup that calls main(), with a default
main() that  calls WinMain unless you replaced it. But I don't think it's
seems intentional (or correct) in either case to allow the mismatch, they
just lacked MSVC's linker support to set subsystem by flavor of main.

However, the use case I had (things like gtest_main) won't use WinMain.
So if this is too controversial you could take just the first two patches.
This one is more "for completeness" than because I have a real need.
---
 tools/winebuild/main.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c
index b37aec9cf6f..0ce7816cd8a 100644
--- a/tools/winebuild/main.c
+++ b/tools/winebuild/main.c
@@ -405,12 +405,16 @@ static const char *get_default_entry_point( const DLLSPEC *spec )
     {
         /* __wine_spec_exe_wentry always calls wmain */
         add_spec_extra_ld_symbol("wmain");
+        if(spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
+            add_spec_extra_ld_symbol("wWinMain");
         return "__wine_spec_exe_wentry";
     }
     else
     {
         /* __wine_spec_exe_entry always calls main */
         add_spec_extra_ld_symbol("main");
+        if(spec->subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI)
+            add_spec_extra_ld_symbol("WinMain");
         return "__wine_spec_exe_entry";
     }
 }
-- 
2.29.2




More information about the wine-devel mailing list