diff --git a/README b/README index 3bc2aef..301ea72 100644 --- a/README +++ b/README @@ -36,12 +36,9 @@ glibc-devel.i386 and libgcc.i386) then try this hack make make install -Syn68k doesn't currently compile under Mac OS X (tested under 10.5.7) -due to the use of leading underscores in the symbol table (this is -easily fixed) and and due to their version of ld not knowing that --2147483648 is a valid 32-bit relative offset (the error message is -ld: rel32 out of range in _code_start_24 in _code_start_24). That's a -little harder to fix. +Syn68k currently doesn't build under Mac OS X (tested under 10.5.7) +do to our unconditional use of "-z execstack" when linking as well as +the fact that i486-cleanup.pl essentially consumes all of syn68k.s. To test syn68k, run test/syngentest and compare the output to test/output/10000. It should be the same. If you want to be diff --git a/TODO b/TODO index 36c7617..eb4b97c 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,9 @@ -$Id: TODO 77 2005-01-04 23:51:13Z ctm $ + Mac OS X fixes: - Make it so that we can install libsyn68k.a and the .h files + Don't link with -z execstack if that's going to fail + + figure out why i486-cleanup.pl basically eats all + of syn68k.s Make so we can build the various debug versions, non-native, etc. diff --git a/configure.ac b/configure.ac index 9fc666f..eca1e81 100644 --- a/configure.ac +++ b/configure.ac @@ -4,7 +4,7 @@ AC_INIT(syn68k, 1.0, ctm@ardi.com) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([syngen/main.c]) -AC_CONFIG_HEADER([config.h]) +AC_CONFIG_HEADERS([include/config.h]) # Checks for programs. AC_PROG_CC @@ -114,6 +114,11 @@ AC_C_INLINE AC_TYPE_SIZE_T AC_C_VOLATILE +AC_LTDL_SYMBOL_USCORE +if test x"$ac_cv_sys_symbol_underscore" = xyes ; then + AC_DEFINE(HAVE_SYMBOL_UNDERSCORE, 1, [Define if C symbols have leading underscores]) +fi + # Checks for library functions. AC_FUNC_ALLOCA AC_FUNC_ERROR_AT_LINE diff --git a/runtime/native/i386/process.c b/runtime/native/i386/process.c index 3f361ec..5608bfd 100644 --- a/runtime/native/i386/process.c +++ b/runtime/native/i386/process.c @@ -1,4 +1,4 @@ -/* $Id: process.c 82 2005-05-11 23:41:32Z ctm $ */ +#include "config.h" #include "template.h" #include "process.h" @@ -291,11 +291,24 @@ typedef struct long value[MAX_VALUE_SET_ENTRIES]; } value_set_t; +/* + * The addition of BROKEN_SIZE_32 (see template.h) and + * immediate_values[3] is a hacky workaround for Mac OS X's ld which + * doesn't recognize 0x80000000 (-2147483648) as a legitimate 32-bit + * relocatable offset. This prevents calls and jumps from being + * properly analyzed. + * + * For now we sacrifice the analysis of that bit pattern in the few + * template entries that would normally have it. We currently do this + * unconditionally because nobody has yet written a configure macro to + * detect this problem and then only use "BROKEN_SIZE_32" when we have + * a broken ld. + */ static int create_asmdata (const template_t *t, int num_operands) { - static const value_set_t immediate_values[3] = + static const value_set_t immediate_values[] = { { 12, { 0, 1, 2, -1, -2, 127, -128, -127, 0x37, -100, 0x12, -97 } }, { 23, { 0, 1, 2, 0xFF, 0xFE, 127, -129, -128, -127, 128, 0x37, -100, 0x12, -97, 32767, -32768, -32767, -1, -2, 0x871, @@ -305,6 +318,12 @@ create_asmdata (const template_t *t, int num_operands) 32767, -32768, -32767, -1, 0xFFFE, 0x871, 0xFA03, 0x1234, 0x8765, 0x7FFFFFFF, 0x80000000, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFE, 0x871529, 0x392332, 0xFA034433, + 0x12345678, 0x87654321 } }, + { 32, { 0, 1, 2, 0xFF, 0xFE, 128, -129, 127, -128, -127, 0x37, -100, + 0x12, -97, + 32767, -32768, -32767, -1, 0xFFFE, 0x871, 0xFA03, + 0x1234, 0x8765, 0x7FFFFFFF, 0x80000001, + 0xFFFFFFFF, 0xFFFFFFFE, 0x871529, 0x392332, 0xFA034433, 0x12345678, 0x87654321 } } }; #if 0 @@ -377,6 +396,11 @@ create_asmdata (const template_t *t, int num_operands) { char code[2][1024]; int new_code = 0; +#if defined(HAVE_SYMBOL_UNDERSCORE) + const char *symbol_prefix = "_"; +#else + const char *symbol_prefix = ""; +#endif strcpy (&code[new_code][0], t->code); for (op = 0; op < num_operands; op++) @@ -394,10 +418,10 @@ create_asmdata (const template_t *t, int num_operands) fprintf (fp, " asm volatile (\"\\n\"\n" - " \"code_start_%d:\\n\\t\"\n" + " \"%scode_start_%d:\\n\\t\"\n" " \"%s\\n\"\n" - " \"code_end_%d:\");\n", - current, code[new_code], current); + " \"%scode_end_%d:\");\n", + symbol_prefix, current, code[new_code], symbol_prefix, current); /* Try the next combination of operands. */ for (op = num_operands - 1; op >= 0; op--) diff --git a/runtime/native/i386/template.c b/runtime/native/i386/template.c index 82676bd..9c0eb29 100644 --- a/runtime/native/i386/template.c +++ b/runtime/native/i386/template.c @@ -1,7 +1,16 @@ +#include "config.h" + #include "template.h" /* $Id: template.c 61 2004-12-21 23:44:50Z ctm $ */ +#if defined(HAVE_SYMBOL_UNDERSCORE) +# define SYMBOL_PREFIX "_" +#else +# define SYMBOL_PREFIX "" +#endif + + const template_t template[] = { #define BINARY_OP(op, dstio, memout) \ @@ -624,9 +633,9 @@ const template_t template[] = { { SIZE_32, REGISTER, INOUT } } }, { "i386_call_abs", "", "", "", "volatile", "v", - "call %P0", + "call " SYMBOL_PREFIX "%P0", { "addr" }, - { { SIZE_32, CONSTANT, IN } } }, + { { BROKEN_SIZE_32, CONSTANT, IN } } }, { "i386_cbtw", "", "", "(reg8 AL)", "(reg16 AX)", "-", "cbtw", @@ -707,9 +716,9 @@ const template_t template[] = #define CONDL_BRANCH(op, flags) \ { "i386_" op, flags, "", "", "volatile", "v", \ - op " %P0", \ + op " " SYMBOL_PREFIX "%P0", \ { "target" }, \ - { { SIZE_32, CONSTANT, IN } } } + { { BROKEN_SIZE_32, CONSTANT, IN } } } CONDL_BRANCH ("jc", "c"), CONDL_BRANCH ("jbe", "cz"), @@ -727,9 +736,9 @@ const template_t template[] = CONDL_BRANCH ("js", "s"), { "i386_jmp", "", "", "", "volatile", "v", - "jmp %P0", + "jmp " SYMBOL_PREFIX "%P0", { "target" }, - { { SIZE_32, CONSTANT, IN } } }, + { { BROKEN_SIZE_32, CONSTANT, IN } } }, { "i386_jmp_reg", "", "", "", "volatile", "-", "jmp *%0", { "target" }, diff --git a/runtime/native/i386/template.h b/runtime/native/i386/template.h index 851a59b..c01f1fb 100644 --- a/runtime/native/i386/template.h +++ b/runtime/native/i386/template.h @@ -16,7 +16,12 @@ typedef enum IN, OUT, INOUT } io_t; -typedef enum { SIZE_8, SIZE_16, SIZE_32 } byte_size_t; +/* BROKEN_SIZE_32 is a variant of SIZE_32 that is only used with addresses + that cause trouble on Mac OS X's ld. The problem ld doesn't recognize + 0x80000000 (-2147483648) as a legitimate 32-bit relative offset. See + the extended comment in process.c for more info */ + +typedef enum { SIZE_8, SIZE_16, SIZE_32, BROKEN_SIZE_32 } byte_size_t; typedef struct {