This patch fix (again) the ppc syntax for Mac OS X's ld. I took care of Alexandre suggestion.
Hope it will be ok ;)
Pierre
ModifiedFiles: tools/winebuild/import.c tools/winebuild/spec32.c tools/winebuild/import.h
ChangeLog: - Add support for Mac OS X's ppc assembler syntax.
? tools/winebuild/.DS_Store Index: tools/winebuild/build.h =================================================================== RCS file: /home/wine/wine/tools/winebuild/build.h,v retrieving revision 1.42 diff -u -r1.42 build.h --- tools/winebuild/build.h 23 Mar 2003 01:12:30 -0000 1.42 +++ tools/winebuild/build.h 7 Jul 2003 11:55:40 -0000 @@ -122,6 +122,51 @@ #define MAX_ORDINALS 65535 +/* + * Here are Macros for different syntax (like Mach-O vs Elf) + * LD_* + */ +#ifdef __darwin__ +# define LD_SECTION_TEXT ".text" +# define LD_SKIP(i) +#endif + +#ifndef LD_SECTION_TEXT +# define LD_SECTION_TEXT ".section \\\".text\\\"" +#endif +#ifndef LD_SKIP +# define LD_SKIP(i) ".skip " #i +#endif + +/* + * Here are Macros in order to get a compatibility with different assembler syntax + * ppc_* + */ + +#ifdef __darwin__ +/* Access an integer register */ +# define ppc_reg(i) "r" #i +/* Access he highest half-word of an expression */ +# define ppc_high(mem) "ha16(" mem ")" +/* Access he lowest half-word of an expression */ +# define ppc_low(mem,index) "lo16(" mem ")(" ppc_reg(index) ")" +# define ppc_sym(sym_name) __ASM_NAME(#sym_name) +#endif /* __darwin__ */ + +#ifndef ppc_reg +# define ppc_reg(i) #i +#endif +#ifndef ppc_high +# define ppc_high(mem) "(" mem ")@hi" +#endif +#ifndef ppc_low +# define ppc_low(mem,index) "(" mem ")@l(" ppc_reg(index) ")" +#endif +#ifndef ppc_sym +# define ppc_sym(sym_name) __ASM_NAME(#sym_name) +#endif + + /* global functions */ extern void *xmalloc (size_t size); Index: tools/winebuild/import.c =================================================================== RCS file: /home/wine/wine/tools/winebuild/import.c,v retrieving revision 1.50 diff -u -r1.50 import.c --- tools/winebuild/import.c 14 May 2003 19:36:28 -0000 1.50 +++ tools/winebuild/import.c 7 Jul 2003 11:55:43 -0000 @@ -819,25 +819,28 @@ } #elif defined(__PPC__) - fprintf(outfile, "\taddi 1, 1, -0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tstw 8, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tstw 7, 0(1)\\n\"\n"); - - fprintf(outfile, "\t\"\\tlis 9,imports+%d@ha\\n\"\n", pos); - fprintf(outfile, "\t\"\\tla 8,imports+%d@l(9)\\n\"\n", pos); - fprintf(outfile, "\t\"\\tlwz 7, 0(8)\\n\"\n"); - fprintf(outfile, "\t\"\\tmtctr 7\\n\"\n"); - - fprintf(outfile, "\t\"\\tlwz 7, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tlwz 8, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tlwz 9, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tbctr\\n"); + fprintf( outfile, "\t addi %s, %s, -0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 0(%s) \\n\"\n", ppc_reg(9), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, -0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 0(%s) \\n\"\n", ppc_reg(8), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, -0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 0(%s) \\n\"\n", ppc_reg(7), ppc_reg(1)); + + /* lis r9, hi16(_imports+pos) */ + /* la r8, lo16(_imports+pos)(9) */ + fprintf(outfile, "\t\"\\t lis %s " ppc_high(ppc_sym(imports) "+ %d") "\\n\"\n", ppc_reg(9), pos); + fprintf(outfile, "\t\"\\t la %s " ppc_low (ppc_sym(imports) "+ %d",9)"\\n\"\n", ppc_reg(8), pos); + + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(7), ppc_reg(8)); + fprintf( outfile, "\t\"\\t mctr %s \\n\"\n", ppc_reg(7)); + + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(7), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, 0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(8), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, 0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(9), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, 0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t bctr \\n"); #else #error You need to define import thunks for your architecture! #endif @@ -845,7 +848,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; @@ -983,49 +986,50 @@ fprintf( outfile, " \"\\tjmp %%o0\\n\\trestore\\n\"\n" ); #elif defined(__PPC__) /* Save all callee saved registers into a stackframe. */ - fprintf( outfile, " \"\\tstwu %%r1, -48(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r3, 4(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r4, 8(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r5, 12(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r6, 16(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r7, 20(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r8, 24(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r9, 28(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r10, 32(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r11, 36(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r12, 40(%%r1)\\n\"\n" ); + fprintf( outfile, "\t\"\\t stwu %s, -48, %s \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 4, %s \\n\"\n", ppc_reg(3), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 8, %s \\n\"\n", ppc_reg(4), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 12, %s \\n\"\n", ppc_reg(5), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 16, %s \\n\"\n", ppc_reg(6), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 20, %s \\n\"\n", ppc_reg(7), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 24, %s \\n\"\n", ppc_reg(8), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 28, %s \\n\"\n", ppc_reg(9), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 32, %s \\n\"\n", ppc_reg(10), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 36, %s \\n\"\n", ppc_reg(11), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 40, %s \\n\"\n", ppc_reg(12), ppc_reg(1)); /* r0 -> r3 (arg1) */ - fprintf( outfile, " \"\\tmr %%r3, %%r0\\n\"\n" ); + fprintf( outfile, "\t\"\\t mr %s, %s \\n\"\n", ppc_reg(3), ppc_reg(0)); /* save return address */ - fprintf( outfile, " \"\\tmflr %%r0\\n\"\n" ); - fprintf( outfile, " \"\\tstw %%r0, 44(%%r1)\\n\"\n" ); + fprintf( outfile, "\t\"\\t mflr %s \\n\"\n", ppc_reg(0)); + fprintf( outfile, "\t\"\\t stw %s, 44, %s \\n\"\n", ppc_reg(0), ppc_reg(1)); /* Call the __wine_delay_load function, arg1 is arg1. */ - fprintf( outfile, " \"\\tbl __wine_delay_load\\n\"\n" ); + fprintf( outfile, "\t\"\\t bl %s \\n\"\n", ppc_sym(__wine_delay_load)); /* Load return value from call into ctr register */ - fprintf( outfile, " \"\\tmtctr %%r3\\n\"\n" ); + fprintf( outfile, "\t\"\\t mtctr %s \\n\"\n", ppc_reg(3)); /* restore all saved registers and drop stackframe. */ - fprintf( outfile, " \"\\tlwz %%r3, 4(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r4, 8(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r5, 12(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r6, 16(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r7, 20(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r8, 24(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r9, 28(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r10, 32(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r11, 36(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tlwz %%r12, 40(%%r1)\\n\"\n" ); + fprintf( outfile, "\t\"\\t lwz %s, 4, %s \\n\"\n", ppc_reg(3), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 8, %s \\n\"\n", ppc_reg(4), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 12, %s \\n\"\n", ppc_reg(5), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 16, %s \\n\"\n", ppc_reg(6), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 20, %s \\n\"\n", ppc_reg(7), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 24, %s \\n\"\n", ppc_reg(8), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 28, %s \\n\"\n", ppc_reg(9), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 32, %s \\n\"\n", ppc_reg(10), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 36, %s \\n\"\n", ppc_reg(11), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 40, %s \\n\"\n", ppc_reg(12), ppc_reg(1)); + /* Load return value from call into return register */ - fprintf( outfile, " \"\\tlwz %%r0, 44(%%r1)\\n\"\n" ); - fprintf( outfile, " \"\\tmtlr %%r0\\n\"\n" ); - fprintf( outfile, " \"\\taddi %%r1, %%r1, 48\\n\"\n" ); - /* branch to ctr register. */ - fprintf( outfile, " \"\\tbctr\\n\"\n" ); + fprintf( outfile, "\t\"\\t lwz %s, 44, %s \\n\"\n", ppc_reg(0), ppc_reg(1)); + fprintf( outfile, "\t\"\\t mtlr %s \\n\"\n", ppc_reg(0)); + fprintf( outfile, "\t\"\\t addi %s, %s, 48 \\n\"\n", ppc_reg(1), ppc_reg(1)); + /* branch to ctr register. */ + fprintf( outfile, "\"bctr \\n\"\n"); #else #error You need to defined delayed import thunks for your architecture! #endif @@ -1047,8 +1051,10 @@ fprintf( outfile, " \"\\tb,a __wine_delay_load_asm\\n\"\n" ); #elif defined(__PPC__) /* g0 is a function scratch register or so I understand. */ - fprintf( outfile, " \"\\tli %%r0, %d\\n\"\n", (idx << 16) | j ); - fprintf( outfile, " \"\\tb __wine_delay_load_asm\\n\"\n" ); + /* First load the upper half-word, and then the lower part */ + fprintf( outfile, "\t\"\\t addis %s, 0x%x \\n\"\n", ppc_reg(0), idx); + fprintf( outfile, "\t\"\\t addis %s, 0x%x \\n\"\n", ppc_reg(0), j); + fprintf( outfile, "\t\"\\t b %s \\n\"\n", ppc_sym(__wine_delay_load_asm)); #else #error You need to defined delayed import thunks for your architecture! #endif @@ -1092,37 +1098,35 @@ } #elif defined(__PPC__) - fprintf(outfile, "\t\"addi 1, 1, -0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tstw 9, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tstw 8, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, -0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tstw 7, 0(1)\\n\"\n"); - - fprintf(outfile, "\t\"\\tlis 9,delay_imports+%d@ha\\n\"\n", pos); - fprintf(outfile, "\t\"\\tla 8,delay_imports+%d@l(9)\\n\"\n", pos); - fprintf(outfile, "\t\"\\tlwz 7, 0(8)\\n\"\n"); - fprintf(outfile, "\t\"\\tmtctr 7\\n\"\n"); - - fprintf(outfile, "\t\"\\tlwz 7, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tlwz 8, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tlwz 9, 0(1)\\n\"\n"); - fprintf(outfile, "\t\"\\taddi 1, 1, 0x4\\n\"\n"); - fprintf(outfile, "\t\"\\tbctr\\n\""); - - /*fprintf(outfile, "\t\"li r0,delay_imports\\n\\t\"\n" ); - fprintf(outfile, "\t\"lwz r0, %d(r0)\\n\\t\"\n", pos); - fprintf(outfile, "\t\"mtctr r0\\n\\t\"\n"); - fprintf(outfile, "\t\"bctr\\n\"");*/ + fprintf( outfile, "\t addi %s, %s, -0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 0(%s) \\n\"\n", ppc_reg(9), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, -0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 0(%s) \\n\"\n", ppc_reg(8), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, -0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t stw %s, 0(%s) \\n\"\n", ppc_reg(7), ppc_reg(1)); + + /* lis r9, hi16(_imports+pos) */ + /* la r8, lo16(_imports+pos)(9) */ + fprintf(outfile, "\t\"\\t lis %s " ppc_high(ppc_sym(imports) "+ %d") "\\n\"\n", ppc_reg(9), pos); + fprintf(outfile, "\t\"\\t la %s " ppc_low (ppc_sym(imports) "+ %d",9)"\\n\"\n", ppc_reg(8), pos); + + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(7), ppc_reg(8)); + fprintf( outfile, "\t\"\\t mtctr %s \\n\"\n", ppc_reg(7)); + + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(7), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, 0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(8), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, 0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t lwz %s, 0(%s) \\n\"\n", ppc_reg(9), ppc_reg(1)); + fprintf( outfile, "\t\"\\t addi %s, %s, 0x4 \\n\"\n", ppc_reg(1), ppc_reg(1)); + fprintf( outfile, "\t\"\\t bctr \\n"); #else #error You need to define delayed import thunks for your architecture! #endif 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.65 diff -u -r1.65 spec32.c --- tools/winebuild/spec32.c 3 Apr 2003 18:05:17 -0000 1.65 +++ tools/winebuild/spec32.c 7 Jul 2003 11:55:46 -0000 @@ -429,6 +429,19 @@ fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" ); } #elif defined(__PPC__) +# ifdef __darwin__ +/* Mach-O don't have a init section */ + if (constructor) + { + fprintf( outfile, "asm(\"\\t.section __DATA,__wine_init\\n\"\n" ); + fprintf( outfile, " \"\\t.asciz \\\"%s\\\"\\n\"\n", constructor ); + fprintf( outfile, " \"\\t.text\\n\");\n" ); + } + if (destructor) + { + fprintf( outfile, "void %s(void) __attribute__((destructor));\n", constructor ); + } +# else /* __darwin__ */ if (constructor) { fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" ); @@ -441,6 +454,7 @@ fprintf( outfile, " \"\\tbl " __ASM_NAME("%s") "\\n\"\n", destructor ); fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" ); } +# endif /* __darwin__ */ #else #error You need to define the DLL constructor for your architecture #endif @@ -489,9 +503,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" ); @@ -546,7 +560,11 @@ else { fprintf( outfile, "#ifdef __GNUC__\n" ); + fprintf( outfile, "# ifdef __darwin__\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)" ); @@ -920,7 +938,7 @@ 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