Winebuild PowerPC Instruction Fix and Other Linker Syntax (Darwin's)

Pierre d'Herbemont stegefin at free.fr
Thu Oct 23 09:48:31 CDT 2003


Hi!

Thanks Alexandre for the last patch you did regarding Mac OS X Support. 
Here is a fix for a typo mistake: "mctr" should be "mtctr" on the 
Assembly PowerPC Code. There is also the part of my patch you didn't 
integrate in yours: the support for the .text section and the .space 
section of Darwin's ld.

Thanks,

Pierre

ChangeLog:
Change mctr PowerPC asm instruction to mtctr. Add Support for the .text 
section and the .space section of darwin's ld.

-------------- next part --------------
? tools/winebuild/.DS_Store
Index: tools/winebuild/build.h
===================================================================
RCS file: /home/wine/wine/tools/winebuild/build.h,v
retrieving revision 1.47
diff -u -r1.47 build.h
--- tools/winebuild/build.h	3 Oct 2003 03:35:20 -0000	1.47
+++ tools/winebuild/build.h	23 Oct 2003 14:15:50 -0000
@@ -124,6 +124,18 @@
 
 #define MAX_ORDINALS  65535
 
+#ifdef __APPLE__
+# define LD_SECTION_TEXT	".text"
+# define LD_SKIP(i)		".space " #i
+#endif  /* __APPLE__ */
+
+#ifndef LD_SECTION_TEXT
+# define LD_SECTION_TEXT  ".section \\\".text\\\""
+#endif
+#ifndef LD_SKIP
+# define LD_SKIP(i)  ".skip " #i
+#endif
+
 /* global functions */
 
 #ifndef __GNUC__
Index: tools/winebuild/import.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/import.c,v
retrieving revision 1.52
diff -u -r1.52 import.c
--- tools/winebuild/import.c	13 Aug 2003 21:57:42 -0000	1.52
+++ tools/winebuild/import.c	23 Oct 2003 14:15:52 -0000
@@ -852,7 +852,7 @@
             fprintf(outfile, "\t\"\\tlis %s, " ppc_high(__ASM_NAME("imports") "+ %d")  "\\n\"\n", ppc_reg[9], pos);
             fprintf(outfile, "\t\"\\tla  %s, " ppc_low (__ASM_NAME("imports") "+ %d") "(%s)\\n\"\n", ppc_reg[8], pos, ppc_reg[9]);
             fprintf(outfile, "\t\"\\tlwz  %s, 0(%s)\\n\"\n", ppc_reg[7], ppc_reg[8]);
-            fprintf(outfile, "\t\"\\tmctr %s\\n\"\n", ppc_reg[7]);
+            fprintf(outfile, "\t\"\\tmtctr %s\\n\"\n", ppc_reg[7]);
 
             fprintf(outfile, "\t\"\\tlwz  %s, 0(%s)\\n\"\n",   ppc_reg[7], ppc_reg[1]);
             fprintf(outfile, "\t\"\\taddi %s, %s, 0x4\\n\"\n", ppc_reg[1], ppc_reg[1]);
@@ -868,7 +868,7 @@
         }
         pos += 4;
     }
-    fprintf( outfile, "\".section\\t\\\".text\\\"\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
+    fprintf( outfile, "\"" LD_SECTION_TEXT "\");\n#ifndef __GNUC__\n}\n#endif\n\n" );
 
  done:
     return nb_imm;
@@ -1142,7 +1142,7 @@
             fprintf( outfile, "\n" );
         }
     }
-    fprintf( outfile, "\".section \\\".text\\\"\");\n" );
+    fprintf( outfile, "\"" LD_SECTION_TEXT "\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
     fprintf( outfile, "#endif\n" );
Index: tools/winebuild/spec32.c
===================================================================
RCS file: /home/wine/wine/tools/winebuild/spec32.c,v
retrieving revision 1.69
diff -u -r1.69 spec32.c
--- tools/winebuild/spec32.c	26 Sep 2003 04:36:46 -0000	1.69
+++ tools/winebuild/spec32.c	23 Oct 2003 14:15:54 -0000
@@ -434,7 +434,24 @@
         fprintf( outfile, "    \"\\tnop\\n\"\n" );
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
-#elif defined(__PPC__)
+#elif defined(__powerpc__)
+# ifdef __APPLE__
+/* Mach-O doesn't have an init section */
+    if (constructor)
+    {
+        fprintf( outfile, "asm(\"\\t.mod_init_func\\n\"\n" );
+        fprintf( outfile, "    \"\\t.align 2\\n\"\n" );
+        fprintf( outfile, "    \"\\t.long " __ASM_NAME("%s") "\\n\"\n", constructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+    if (destructor)
+    {
+        fprintf( outfile, "asm(\"\\t.mod_term_func\\n\"\n" );
+        fprintf( outfile, "    \"\\t.align 2\\n\"\n" );
+        fprintf( outfile, "    \"\\t.long " __ASM_NAME("%s") "\\n\"\n", destructor );
+        fprintf( outfile, "    \"\\t.text\\n\");\n" );
+    }
+# else /* __APPLE__ */
     if (constructor)
     {
         fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
@@ -447,6 +464,7 @@
         fprintf( outfile, "    \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor );
         fprintf( outfile, "    \"\\t.section\\t\\\".text\\\"\\n\");\n" );
     }
+# endif /* __APPLE__ */
 #else
 #error You need to define the DLL constructor for your architecture
 #endif
@@ -495,9 +513,9 @@
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "static void __asm__dummy_header(void) {\n" );
     fprintf( outfile, "#endif\n" );
-    fprintf( outfile, "asm(\".section \\\".text\\\"\\n\\t\"\n" );
+    fprintf( outfile, "asm(\"" LD_SECTION_TEXT "\\n\\t\"\n" );
     fprintf( outfile, "    \".align %d\\n\"\n", get_alignment(page_size) );
-    fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\t.skip 65536\\n\\t\");\n" );
+    fprintf( outfile, "    \"" __ASM_NAME("pe_header") ":\\t" LD_SKIP(65536) "\\n\\t\");\n" );
     fprintf( outfile, "#ifndef __GNUC__\n" );
     fprintf( outfile, "}\n" );
     fprintf( outfile, "#endif\n" );
@@ -551,7 +569,11 @@
         else
         {
             fprintf( outfile, "#ifdef __GNUC__\n" );
+            fprintf( outfile, "# ifdef __APPLE__\n" );
+            fprintf( outfile, "extern void DllMain() __attribute__((weak_import));\n" );
+            fprintf( outfile, "# else\n" );
             fprintf( outfile, "extern void DllMain() __attribute__((weak));\n" );
+            fprintf( outfile, "# endif\n" );
             fprintf( outfile, "#else\n" );
             fprintf( outfile, "extern void DllMain();\n" );
             fprintf( outfile, "static void __asm__dummy_dllmain(void)" );
@@ -741,8 +763,13 @@
     fprintf( outfile, "  } OptionalHeader;\n" );
     fprintf( outfile, "} nt_header = {\n" );
     fprintf( outfile, "  0x%04x,\n", IMAGE_NT_SIGNATURE );   /* Signature */
-
+#ifdef __i386__
     fprintf( outfile, "  { 0x%04x,\n", IMAGE_FILE_MACHINE_I386 );  /* Machine */
+#elif defined(__powerpc__)
+    fprintf( outfile, "  { 0x%04x,\n", IMAGE_FILE_MACHINE_POWERPC ); /* Machine */
+#else
+    fprintf( outfile, "  { 0x%04x,\n", IMAGE_FILE_MACHINE_UNKNOWN );  /* Machine */
+#endif
     fprintf( outfile, "    0, 0, 0, 0,\n" );
     fprintf( outfile, "    sizeof(nt_header.OptionalHeader),\n" ); /* SizeOfOptionalHeader */
     fprintf( outfile, "    0x%04x },\n", characteristics );        /* Characteristics */
@@ -923,12 +950,12 @@
     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(__PPC__)
+#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.section\\t\\\".text\\\"\\n\");\n" );
+    fprintf( outfile, "    \"\\t" LD_SECTION_TEXT "\\n\");\n" );
 #else
 #error You need to define the DLL constructor for your architecture
 #endif


More information about the wine-patches mailing list