- C99 feature removed
[libfirm] / ir / be / begnuas.c
index bf85fc8..3f4371a 100644 (file)
@@ -78,8 +78,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.dtors,\"aw\",@progbits",
+                       ".section\t.ctors,\"w\"",
+                       ".section\t.dtors,\"w\"",
                        NULL,
                        NULL,
                        NULL
@@ -547,8 +547,7 @@ static int initializer_is_string_const(const ir_initializer_t *initializer)
                tv   = sub_initializer->tarval.value;
                mode = get_tarval_mode(tv);
 
-               if (!mode_is_int(mode)
-                               || get_mode_size_bits(mode) != get_mode_size_bits(mode_Bs))
+               if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
                        return 0;
 
                c = get_tarval_long(tv);
@@ -591,8 +590,7 @@ static int ent_is_string_const(ir_entity *ent)
        /* and the mode of the element type is an int of
         * the same size as the byte mode */
        mode = get_type_mode(element_type);
-       if (!mode_is_int(mode)
-               || get_mode_size_bits(mode) != get_mode_size_bits(mode_Bs))
+       if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
                return 0;
 
        if (ent->has_initializer) {
@@ -1116,15 +1114,23 @@ static void dump_compound_init(be_gas_decl_env_t *env, ir_entity *ent)
        xfree(vals);
 }
 
-static void emit_align(unsigned alignment)
+static void emit_align(unsigned p2alignment)
 {
-       if (!is_po2(alignment))
-               panic("alignment not a power of 2");
-
-       be_emit_irprintf("\t.p2align\t%u\n", log2_floor(alignment));
+       be_emit_irprintf("\t.p2align\t%u\n", log2_floor(p2alignment));
        be_emit_write_line();
 }
 
+static unsigned get_effective_entity_alignment(ir_entity *entity)
+{
+       unsigned alignment = get_entity_alignment(entity);
+       if (alignment == 0) {
+               ir_type *type = get_entity_type(entity);
+               alignment     = get_type_alignment_bytes(type);
+       }
+       return alignment;
+}
+
+
 /**
  * Dump a global entity.
  *
@@ -1135,7 +1141,7 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent)
 {
        ir_type          *type           = get_entity_type(ent);
        ident            *ld_ident       = get_entity_ld_ident(ent);
-       unsigned          align          = get_type_alignment_bytes(type);
+       unsigned          alignment      = get_effective_entity_alignment(ent);
        int               emit_as_common = 0;
        be_gas_section_t  section        = env->section;
        ir_variability    variability    = get_entity_variability(ent);
@@ -1183,10 +1189,12 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent)
                /* we can return now... */
                return;
        }
+       if (!is_po2(alignment))
+               panic("alignment not a power of 2");
        /* alignment */
-       if (align > 1 && !emit_as_common && section != GAS_SECTION_PIC_TRAMPOLINES
+       if (alignment > 1 && !emit_as_common && section != GAS_SECTION_PIC_TRAMPOLINES
                        && section != GAS_SECTION_PIC_SYMBOLS) {
-               emit_align(align);
+               emit_align(alignment);
        }
 
        if (visibility != visibility_external_allocated && !emit_as_common
@@ -1207,16 +1215,20 @@ static void dump_global(be_gas_decl_env_t *env, ir_entity *ent)
        if (variability == variability_uninitialized) {
                if (emit_as_common) {
                        switch (be_gas_flavour) {
-                       case GAS_FLAVOUR_ELF:
                        case GAS_FLAVOUR_MACH_O:
+                               be_emit_irprintf("\t.comm %s,%u,%u\n",
+                                       get_id_str(ld_ident), get_type_size_bytes(type),
+                                       log2_floor(alignment));
+                               break;
+                       case GAS_FLAVOUR_ELF:
                        case GAS_FLAVOUR_YASM:
                                be_emit_irprintf("\t.comm %s,%u,%u\n",
-                                       get_id_str(ld_ident), get_type_size_bytes(type), align);
+                                       get_id_str(ld_ident), get_type_size_bytes(type), alignment);
                                be_emit_write_line();
                                break;
                        case GAS_FLAVOUR_MINGW:
                                be_emit_irprintf("\t.comm %s,%u # %u\n",
-                                       get_id_str(ld_ident), get_type_size_bytes(type), align);
+                                       get_id_str(ld_ident), get_type_size_bytes(type), alignment);
                                be_emit_write_line();
                                break;
                        }