[PATCH v3 2/3] winebuild: Find main/wmain in static libraries.

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


Have the winebuild -spec.o include an undefined .globl referencing
symbols we know the winecrt0 entry point will eventually reference,
so ld knows about that need while scanning library archives.

Signed-off-by: Kevin Puetz <PuetzKevinA at JohnDeere.com>
---

wine.exe.so files set __wine_spec_exe_entry as the entry point.
Therefore the linker is not initially looking for main and will pass
over objects in lib.a archives that might provide it. When it gets to
libwinecrt0.a, it finds __wine_spec_exe_entry and learns that it wants
but the resulting rescan will find the winecrt0 default definition
(in terms of WinMain), before rescanning earlier libraries.

So only a direct .o file (which is never passed over) can override
the winecrt0 definition, and libraries like -lgtest_main do not work.

Another way to let the linker see these dependencies would be to split
up libwinecrt0.a, so that we can link the portion containing exe*_entry.o
immediately after the winebuild spec file, before the the user code/libs
and then finish up with a libwinecrtdefs.a (or whatever name) that
contains the remainder (definitions of w?main as wrappers of w?WinMain).

But that takes more change and does not seem particularly more clear.
Opinions?
---
 tools/winebuild/build.h  |  1 +
 tools/winebuild/main.c   | 11 +++++++++++
 tools/winebuild/spec32.c | 12 ++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h
index 26a0539c500..a4b9bc97e3e 100644
--- a/tools/winebuild/build.h
+++ b/tools/winebuild/build.h
@@ -300,6 +300,7 @@ extern void output_gnu_stack_note(void);
 extern void add_import_dll( const char *name, const char *filename );
 extern void add_delayed_import( const char *name );
 extern void add_extra_ld_symbol( const char *name );
+extern void add_spec_extra_ld_symbol( const char *name );
 extern void read_undef_symbols( DLLSPEC *spec, char **argv );
 extern void resolve_imports( DLLSPEC *spec );
 extern int is_undefined( const char *name );
diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c
index b1e6d115717..b37aec9cf6f 100644
--- a/tools/winebuild/main.c
+++ b/tools/winebuild/main.c
@@ -397,11 +397,22 @@ static const char *get_default_entry_point( const DLLSPEC *spec )
     if (spec->characteristics & IMAGE_FILE_DLL) return "DllMain";
     if (spec->subsystem == IMAGE_SUBSYSTEM_NATIVE) return "DriverEntry";
     if (spec->type == SPEC_WIN16)
+    {
+        add_spec_extra_ld_symbol("WinMain16");
         return "__wine_spec_exe16_entry";
+    }
     else if (spec->unicode_app)
+    {
+        /* __wine_spec_exe_wentry always calls wmain */
+        add_spec_extra_ld_symbol("wmain");
         return "__wine_spec_exe_wentry";
+    }
     else
+    {
+        /* __wine_spec_exe_entry always calls main */
+        add_spec_extra_ld_symbol("main");
         return "__wine_spec_exe_entry";
+    }
 }
 
 /* parse options from the argv array and remove all the recognized ones */
diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c
index ba2edfb588f..a12e7d38aac 100644
--- a/tools/winebuild/spec32.c
+++ b/tools/winebuild/spec32.c
@@ -50,6 +50,13 @@ int needs_get_pc_thunk = 0;
 
 static const char builtin_signature[32] = "Wine builtin DLL";
 static const char fakedll_signature[32] = "Wine placeholder DLL";
+static struct strarray spec_extra_ld_symbols = { 0 }; /* list of extra symbols that ld should resolve */
+
+/* add a symbol to the list of extra symbols that ld must resolve */
+void add_spec_extra_ld_symbol( const char *name )
+{
+    strarray_add( &spec_extra_ld_symbols, name, NULL );
+}
 
 static unsigned int hash_filename( const char *name )
 {
@@ -610,6 +617,7 @@ void output_exports( DLLSPEC *spec )
 void output_module( DLLSPEC *spec )
 {
     int machine = 0;
+    int i;
     unsigned int page_size = get_page_size();
     const char *data_dirs[16] = { NULL };
 
@@ -688,6 +696,10 @@ void output_module( DLLSPEC *spec )
     output( "\t.long 0\n" );              /* SizeOfCode */
     output( "\t.long 0\n" );              /* SizeOfInitializedData */
     output( "\t.long 0\n" );              /* SizeOfUninitializedData */
+
+    for (i = 0; i < spec_extra_ld_symbols.count; i++)
+        output( "\t.globl %s\n", asm_name(spec_extra_ld_symbols.str[i]) );
+
     /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
     output( "\t%s %s\n",                  /* AddressOfEntryPoint */
             get_asm_ptr_keyword(), spec->init_func ? asm_name(spec->init_func) : "0" );
-- 
2.29.2




More information about the wine-devel mailing list