Darwin _init and _fini

Pierre d'Herbemont stegefin at free.fr
Thu Jun 17 12:44:09 CDT 2004


Hi!

In fact on darwin _init and _fini are called automatically at start and 
at end. So calling _init and _fini our wrappers to the functions that 
call all the .mod_init or .mod_term section is not a good idea. (it 
causes a double call of the .mod_init functions). In this patch there 
is also support for darwin .mod_*_func sections for the __wine_dbg_* 
symbols.

Thanks.

Pierre

PS:
This still doesn't make Wine properly working on Mac OS X. I get the 
following error log:
fixme:ntdll:NtQueryVolumeInformationFile device info not properly 
supported on this platform
Warning: the specified Windows directory L"c:\\windows" is not 
accessible.
Warning: the specified System directory L"c:\\windows\\system" is not 
accessible.
environ.c:401: failed assertion `startup_infoA.cb'
wine: Unhandled exception (thread 0015), starting debugger...

And Emmanuel's previous hack is now not working. Any idea?

ChangeLog:
Hide the _init and _fini wrappers on darwin.

-------------- next part --------------
Index: tools/winebuild/spec32.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/spec32.c,v
retrieving revision 1.81
diff -u -r1.81 spec32.c
--- tools/winebuild/spec32.c	8 Apr 2004 04:41:14 -0000	1.81
+++ tools/winebuild/spec32.c	17 Jun 2004 17:36:20 -0000
@@ -574,22 +574,25 @@
     fprintf( outfile, "extern char **__wine_main_environ;\n" );
     fprintf( outfile, "extern unsigned short **__wine_main_wargv;\n" );
 #ifdef __APPLE__
-    fprintf( outfile, "extern _dyld_func_lookup(char *, void *);");
-    fprintf( outfile, "void _init(int argc, char** argv, char** chr)\n" );
-    fprintf( outfile, "{\n");
-    fprintf( outfile, "    void (*init)(void);\n");
-    fprintf( outfile, "    _dyld_func_lookup(\"__dyld_make_delayed_module_initializer_calls\", (unsigned long *)&init);\n");
-    fprintf( outfile, "    init();\n");
-    fprintf( outfile, "}\n");
-    fprintf( outfile, "void _fini()\n" );
-    fprintf( outfile, "{\n");
-    fprintf( outfile, "    void (*fini)(void);\n");
-    fprintf( outfile, "    _dyld_func_lookup(\"__dyld_mod_term_funcs\", (unsigned long *)&fini);\n");
-    fprintf( outfile, "    fini();\n");
-    fprintf( outfile, "}\n");
+    fprintf( outfile, "extern _dyld_func_lookup(char *, void *);" );
+    fprintf( outfile, "void __wine_hidden_init(int argc, char** argv, char** envp)\n" );
+    fprintf( outfile, "{\n" );
+    fprintf( outfile, "    void (*init)(void);\n" ); 
+    fprintf( outfile, "    _dyld_func_lookup(\"__dyld_make_delayed_module_initializer_calls\", (unsigned long *)&init);\n" );
+    fprintf( outfile, "    init();\n" );
+    fprintf( outfile, "}\n" );
+    fprintf( outfile, "void __wine_hidden_fini()\n" );
+    fprintf( outfile, "{\n" );
+    fprintf( outfile, "    void (*fini)(void);\n" ); 
+    fprintf( outfile, "    _dyld_func_lookup(\"__dyld_mod_term_funcs\", (unsigned long *)&fini);\n" );
+    fprintf( outfile, "    fini();\n" );
+    fprintf( outfile, "}\n" );
 #else
     fprintf( outfile, "extern void _init(int, char**, char**);\n" );
     fprintf( outfile, "extern void _fini();\n" );
+/* tweak for environment that use _init as a constructor function */
+	fprintf( outfile, "#define __wine_hidden_init _init;\n" );
+	fprintf( outfile, "#define __wine_hidden_fini _fini;\n" );
 #endif
 
     if (spec->characteristics & IMAGE_FILE_DLL)
@@ -607,9 +610,9 @@
                  "{\n"
                  "    int ret;\n"
                  "    if (reason == %d && __wine_spec_init_state == 1)\n"
-                 "        _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
+                 "        __wine_hidden_init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
                  "    ret = %s ? %s( inst, reason, reserved ) : 1;\n"
-                 "    if (reason == %d && __wine_spec_init_state == 1) _fini();\n"
+                 "    if (reason == %d && __wine_spec_init_state == 1) __wine_hidden_fini();\n"
                  "    return ret;\n"
                  "}\n",
                  DLL_PROCESS_ATTACH, init_func, init_func, DLL_PROCESS_DETACH );
@@ -631,9 +634,9 @@
                  "{\n"
                  "    int ret;\n"
                  "    if (__wine_spec_init_state == 1)\n"
-                 "        _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
+                 "        __wine_hidden_init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n"
                  "    ret = %s ? %s( obj, path ) : 0;\n"
-                 "    if (__wine_spec_init_state == 1) _fini();\n"
+                 "    if (__wine_spec_init_state == 1) __wine_hidden_fini();\n"
                  "    return ret;\n"
                  "}\n",
                  init_func, init_func );
@@ -667,7 +670,7 @@
                  "{\n"
                  "    int ret;\n"
                  "    if (__wine_spec_init_state == 1)\n"
-                 "        _init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n" );
+                 "        __wine_hidden_init( __wine_main_argc, __wine_main_argv, __wine_main_environ );\n" );
         if (init_func)
             fprintf( outfile,
                      "    ret = %s( __wine_main_argc, __wine_main_argv );\n", init_func );
@@ -695,7 +698,7 @@
                      "    else if (wmain) ret = wmain( __wine_main_argc, __wine_main_wargv );\n"
                      "    else ret = main( __wine_main_argc, __wine_main_argv );\n" );
         fprintf( outfile,
-                 "    if (__wine_spec_init_state == 1) _fini();\n"
+                 "    if (__wine_spec_init_state == 1) __wine_hidden_fini();\n"
                  "    ExitProcess( ret );\n"
                  "}\n\n" );
         init_func = "__wine_exe_main";
@@ -947,11 +950,22 @@
     fprintf( outfile, "    \"\\tnop\\n\"\n" );
     fprintf( outfile, "    \"\\t.section\t\\\".text\\\"\\n\");\n" );
 #elif defined(__powerpc__)
+# ifdef __APPLE__
+	fprintf( outfile, "asm(\"\\t.mod_init_func\\n\"\n" );
+	fprintf( outfile, "    \"\\t.align 2\\n\"\n" );
+	fprintf( outfile, "    \"\\t.long " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
+	fprintf( outfile, "    \"\\t.text\\n\");\n" );
+	fprintf( outfile, "asm(\"\\t.mod_term_func\\n\"\n" );
+	fprintf( outfile, "    \"\\t.align 2\\n\"\n" );
+	fprintf( outfile, "    \"\\t.long " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
+	fprintf( outfile, "    \"\\t.text\\n\");\n" );
+# else
     fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
     fprintf( outfile, "    \"\\tbl " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
     fprintf( outfile, "    \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
     fprintf( outfile, "    \"\\tbl " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
     fprintf( outfile, "    \"\\t.text\\n\");\n" );
+# endif
 #else
 #error You need to define the DLL constructor for your architecture
 #endif


More information about the wine-patches mailing list