Reverted r27079. Seems to be wrong.
[libfirm] / ir / be / begnuas.c
index b4bffed..0136046 100644 (file)
@@ -93,7 +93,7 @@ static const char *get_section_name(be_gas_section_t section)
                        ".data",
                        NULL,             /* TLS is not supported on Mach-O */
                        ".mod_init_func",
-                       NULL,             /* are there destructors on mach-o? */
+                       ".mod_term_func",
                        ".cstring",
                        ".section\t__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5",
                        ".section\t__IMPORT,__pointers,non_lazy_symbol_pointers"
@@ -273,16 +273,21 @@ static void dump_arith_tarval(tarval *tv, int bytes)
                return;
 
        case 16:
+               /* Beware: Mixed endian output!  One little endian number emitted as
+                * three longs.  Each long initializer is written in big endian. */
                be_emit_irprintf(
-                       "\t.long\t0x%02x%02x%02x%02x0x%02x%02x%02x%02x0x%02x%02x%02x%02x0x%02x%02x%02x%02x",
-                       get_tarval_sub_bits(tv, 15), get_tarval_sub_bits(tv, 16),
-                       get_tarval_sub_bits(tv, 13), get_tarval_sub_bits(tv, 12),
-                       get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
-                       get_tarval_sub_bits(tv,  9), get_tarval_sub_bits(tv,  8),
+                       "\t.long\t0x%02x%02x%02x%02x\n"
+                       "\t.long\t0x%02x%02x%02x%02x\n"
+                       "\t.long\t0x%02x%02x%02x%02x\n"
+                       "\t.long\t0x%02x%02x%02x%02x",
+                       get_tarval_sub_bits(tv,  3), get_tarval_sub_bits(tv,  2),
+                       get_tarval_sub_bits(tv,  1), get_tarval_sub_bits(tv,  0),
                        get_tarval_sub_bits(tv,  7), get_tarval_sub_bits(tv,  6),
                        get_tarval_sub_bits(tv,  5), get_tarval_sub_bits(tv,  4),
-                       get_tarval_sub_bits(tv,  3), get_tarval_sub_bits(tv,  2),
-                       get_tarval_sub_bits(tv,  1), get_tarval_sub_bits(tv,  0)
+                       get_tarval_sub_bits(tv, 11), get_tarval_sub_bits(tv, 10),
+                       get_tarval_sub_bits(tv,  9), get_tarval_sub_bits(tv,  8),
+                       get_tarval_sub_bits(tv, 15), get_tarval_sub_bits(tv, 14),
+                       get_tarval_sub_bits(tv, 13), get_tarval_sub_bits(tv, 12)
                );
                return;
        }
@@ -492,13 +497,10 @@ static void dump_size_type(size_t size) {
 
        case 10:
        case 12:
+       case 16: /* Note: .octa does not work on mac */
                /* handled in arith */
                break;
 
-       case 16:
-               be_emit_cstring("\t.octa\t");
-               break;
-
        default:
                panic("Try to dump a type with %u bytes", (unsigned)size);
        }
@@ -1186,6 +1188,28 @@ static void emit_common(const ir_entity *ent)
        panic("invalid object file format");
 }
 
+static void dump_indirect_symbol(const ir_entity *entity, be_gas_section_t section)
+{
+       /* we can only do PIC code on macho so far */
+       assert(be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O);
+
+       be_emit_ident(get_entity_ld_ident(entity));
+       be_emit_cstring(":\n");
+       be_emit_write_line();
+       be_emit_cstring("\t.indirect_symbol ");
+       be_emit_ident(get_entity_ident(entity));
+       be_emit_char('\n');
+       be_emit_write_line();
+       if (section == GAS_SECTION_PIC_TRAMPOLINES) {
+               be_emit_cstring("\thlt ; hlt ; hlt ; hlt ; hlt\n");
+               be_emit_write_line();
+       } else {
+               assert(section == GAS_SECTION_PIC_SYMBOLS);
+               be_emit_cstring("\t.long 0\n");
+               be_emit_write_line();
+       }
+}
+
 /**
  * Dump a global entity.
  *
@@ -1228,6 +1252,12 @@ static void dump_global(be_gas_decl_env_t *env, const ir_entity *ent)
 
        be_gas_emit_switch_section(section);
 
+       if (section == GAS_SECTION_PIC_TRAMPOLINES
+                       || section == GAS_SECTION_PIC_SYMBOLS) {
+               dump_indirect_symbol(ent, section);
+               return;
+       }
+
        /* alignment */
        if (alignment > 1) {
                emit_align(alignment);
@@ -1243,9 +1273,12 @@ static void dump_global(be_gas_decl_env_t *env, const ir_entity *ent)
                be_emit_ident(ld_ident);
                be_emit_irprintf(", %u\n", get_type_size_bytes(type));
        }
-       be_emit_ident(ld_ident);
-       be_emit_cstring(":\n");
-       be_emit_write_line();
+
+       if (get_id_str(ld_ident)[0] != '\0') {
+               be_emit_ident(ld_ident);
+               be_emit_cstring(":\n");
+               be_emit_write_line();
+       }
 
        if (ent->initializer != NULL) {
                dump_initializer(env, ent);