From: Matthias Braun Date: Sun, 30 Mar 2008 18:39:26 +0000 (+0000) Subject: some mach-o related fixes X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=60258990cbbf12fc1ab4802fe4b2c7f9a99afbc2;p=libfirm some mach-o related fixes [r18298] --- diff --git a/ir/be/begnuas.c b/ir/be/begnuas.c index 65e4e35c3..8efcb0321 100644 --- a/ir/be/begnuas.c +++ b/ir/be/begnuas.c @@ -68,7 +68,8 @@ static const char *get_section_name(be_gas_section_t section) { ".section\t.rodata", ".section\t.bss", ".section\t.tbss,\"awT\",@nobits", - ".section\t.ctors,\"aw\",@progbits" + ".section\t.ctors,\"aw\",@progbits", + NULL, }, { /* GAS_FLAVOUR_MINGW */ ".section\t.text", @@ -76,7 +77,8 @@ static const char *get_section_name(be_gas_section_t section) { ".section .rdata,\"dr\"", ".section\t.bss", ".section\t.tbss,\"awT\",@nobits", - ".section\t.ctors,\"aw\",@progbits" + ".section\t.ctors,\"aw\",@progbits", + NULL, }, { /* GAS_FLAVOUR_YASM */ ".section\t.text", @@ -84,15 +86,17 @@ static const char *get_section_name(be_gas_section_t section) { ".section\t.rodata", ".section\t.bss", ".section\t.tbss,\"awT\",@nobits", - ".section\t.ctors,\"aw\",@progbits" + ".section\t.ctors,\"aw\",@progbits", + NULL }, { /* GAS_FLAVOUR_MACH_O */ ".text", ".data", ".const", ".data", - NULL, /* TLS is not supported on Mach-O */ - NULL /* constructors aren't marked with sections in Mach-O */ + NULL, /* TLS is not supported on Mach-O */ + ".mod_init_func", + ".cstring" } }; @@ -481,6 +485,7 @@ static void dump_atomic_init(be_gas_decl_env_t *env, ir_node *init) static int initializer_is_string_const(const ir_initializer_t *initializer) { size_t i, len; + int found_printable = 0; if(initializer->kind != IR_INITIALIZER_COMPOUND) return 0; @@ -506,16 +511,16 @@ static int initializer_is_string_const(const ir_initializer_t *initializer) return 0; c = get_tarval_long(tv); - if (i < len - 1) { - if (!isgraph(c) && !isspace(c)) - return 0; - } else { - if (c != 0) - return 0; - } + if (isgraph(c) || isspace(c)) + found_printable = 1; + else if(c != 0) + return 0; + + if (i == len - 1 && c != '\0') + return 0; } - return 1; + return found_printable; } /** @@ -528,6 +533,7 @@ static int ent_is_string_const(ir_entity *ent) ir_type *type, *element_type; ir_mode *mode; int i, c, n; + int found_printable = 0; type = get_entity_type(ent); @@ -561,14 +567,18 @@ static int ent_is_string_const(ir_entity *ent) c = (int) get_tarval_long(get_Const_tarval(irn)); - if((i < n - 1 && !(isgraph(c) || isspace(c))) - || (i == n - 1 && c != '\0')) + if (isgraph(c) || isspace(c)) + found_printable = 1; + else if(c != 0) + return 0; + + if (i == n - 1 && c != '\0') return 0; } } /* then we can emit it as a string constant */ - return 1; + return found_printable; } /** @@ -584,12 +594,8 @@ static void dump_string_cst(ir_entity *ent) int type_size; int remaining_space; - be_gas_section_t last_section = current_section; len = get_compound_ent_n_values(ent); if (be_gas_flavour == GAS_FLAVOUR_MACH_O) { - if (get_entity_variability(ent) == variability_constant) { - be_gas_emit_switch_section(GAS_SECTION_CSTRING); - } be_emit_cstring("\t.ascii \""); } else { be_emit_cstring("\t.string \""); @@ -627,9 +633,6 @@ static void dump_string_cst(ir_entity *ent) if(remaining_space > 0) { be_emit_irprintf("\t.skip\t%d\n", remaining_space); } - if(be_gas_flavour == GAS_FLAVOUR_MACH_O) { - be_gas_emit_switch_section(last_section); - } } static void dump_string_initializer(const ir_initializer_t *initializer) @@ -638,10 +641,10 @@ static void dump_string_initializer(const ir_initializer_t *initializer) len = initializer->compound.n_initializers; if(be_gas_flavour == GAS_FLAVOUR_MACH_O) { + be_emit_cstring("\t.ascii \""); + } else { be_emit_cstring("\t.string \""); len -= 1; - } else { - be_emit_cstring("\t.ascii \""); } for(i = 0; i < len; ++i) { @@ -1119,6 +1122,10 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons } else if (variability == variability_constant) { /* a constant entity, put it on the rdata */ section = GAS_SECTION_RODATA; + if (be_gas_flavour == GAS_FLAVOUR_MACH_O + && ent_is_string_const(ent)) { + section = GAS_SECTION_CSTRING; + } } else if (variability == variability_uninitialized) { /* uninitialized entity put it in bss segment */ section = GAS_SECTION_COMMON; @@ -1174,7 +1181,7 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons break; } } else { - be_emit_irprintf("\t.zero %u\n", get_type_size_bytes(type)); + be_emit_irprintf("\t.space %u\n", get_type_size_bytes(type)); be_emit_write_line(); } } else { diff --git a/ir/be/begnuas.h b/ir/be/begnuas.h index 447c4b7d7..f46ae139b 100644 --- a/ir/be/begnuas.h +++ b/ir/be/begnuas.h @@ -41,7 +41,7 @@ typedef enum section_t { GAS_SECTION_TLS, /**< thread local storage section */ GAS_SECTION_CTOR, /**< ctor section for instrumentation code init */ GAS_SECTION_CSTRING, /**< section for constant strings */ - GAS_SECTION_LAST = GAS_SECTION_CTOR + GAS_SECTION_LAST = GAS_SECTION_CSTRING } be_gas_section_t; /**