PATCH: Fix DLL constructors on OpenBSD

Wim Lewis wiml at underhill.hhhh.org
Thu Jan 1 17:41:23 CST 2004


Some more OpenBSD work: the attribute((constructor)) syntax works on
OBSD3.4, but the inline-asm syntax doesn't. I noticed that another
part of sped32.c was almost identical but already contained the fix I
was making to output_dll_init(), so I combined the two stretches of
code into one.

Changelog:

Use the GCC attribute((constructor)) syntax for DLL initializer hooks
if possible, instead of the inline-asm syntax.


diff --recursive orig/wine-20031212/tools/winebuild/spec32.c wine-20031212/tools/winebuild/spec32.c
--- orig/wine-20031212/tools/winebuild/spec32.c	Mon Nov  3 14:19:44 2003
+++ wine-20031212/tools/winebuild/spec32.c	Thu Jan  1 15:14:25 2004
@@ -410,7 +410,6 @@
 {
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
-    fprintf( outfile, "#endif\n" );
 
 #if defined(__i386__)
     if (constructor)
@@ -472,11 +471,18 @@
     }
 # endif /* __APPLE__ */
 #else
-#error You need to define the DLL constructor for your architecture
+    fprintf( outfile, "#error You need to define the DLL constructor for your architecture\n" );
 #endif
-    fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
+    fprintf( outfile, "#else\n" );
+    if (constructor)
+        fprintf( outfile, "static void %s(void) __attribute__((constructor));\n",
+                 constructor );
+    if (destructor)
+        fprintf( outfile, "static void %s(void) __attribute__((destructor));\n",
+                 destructor );
     fprintf( outfile, "#endif\n" );
+    fprintf( outfile, "\n\n" );
 }
 
 
@@ -822,7 +828,7 @@
     output_dll_init( outfile, constructor, NULL );
 
     fprintf( outfile,
-             "void %s(void)\n"
+             "static void %s(void)\n"
              "{\n"
              "    extern void __wine_dll_register( const struct image_nt_headers *, const char * );\n"
              "    extern void *__wine_dbg_register( char * const *, int );\n"
@@ -915,6 +921,7 @@
 {
     int nr_debug;
     char *prefix, *p;
+    char constructor[100], destructor[100];
 
     while (*argv)
     {
@@ -939,42 +946,13 @@
     else prefix = xstrdup( "_" );
 
     /* Output the DLL constructor */
+    
+    snprintf( constructor, 100, "__wine_dbg_%s_init", prefix );
+    snprintf( destructor,  100, "__wine_dbg_%s_fini", prefix );
+    output_dll_init( outfile, constructor, destructor );
 
     fprintf( outfile,
              "#ifdef __GNUC__\n"
-             "static void __wine_dbg_%s_init(void) __attribute__((constructor));\n"
-             "static void __wine_dbg_%s_fini(void) __attribute__((destructor));\n"
-             "#else\n"
-             "static void __asm__dummy_dll_init(void) {\n",
-             prefix, prefix );
-
-#if defined(__i386__)
-    fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
-    fprintf( outfile, "    \"\\tcall " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
-    fprintf( outfile, "    \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
-    fprintf( outfile, "    \"\\tcall " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
-    fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
-#elif defined(__sparc__)
-    fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
-    fprintf( outfile, "    \"\\tcall " __ASM_NAME("__wine_dbg_%s_init") "\\n\"\n", prefix );
-    fprintf( outfile, "    \"\\tnop\\n\"\n" );
-    fprintf( outfile, "    \"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
-    fprintf( outfile, "    \"\\tcall " __ASM_NAME("__wine_dbg_%s_fini") "\\n\"\n", prefix );
-    fprintf( outfile, "    \"\\tnop\\n\"\n" );
-    fprintf( outfile, "    \"\\t.section\t\\\".text\\\"\\n\");\n" );
-#elif defined(__powerpc__)
-    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" );
-#else
-#error You need to define the DLL constructor for your architecture
-#endif
-    fprintf( outfile, "}\n#endif /* defined(__GNUC__) */\n" );
-
-    fprintf( outfile,
-             "\n#ifdef __GNUC__\n"
              "static\n"
              "#endif\n"
              "void __wine_dbg_%s_init(void)\n"
[EOF]




More information about the wine-patches mailing list