".section\t.bss",
".section\t.tbss,\"awT\",@nobits",
".section\t.ctors,\"aw\",@progbits",
+ NULL, /* no cstring section */
NULL,
+ NULL
},
{ /* GAS_FLAVOUR_MINGW */
".section\t.text",
".section\t.tbss,\"awT\",@nobits",
".section\t.ctors,\"aw\",@progbits",
NULL,
+ NULL,
+ NULL
},
{ /* GAS_FLAVOUR_YASM */
".section\t.text",
".section\t.bss",
".section\t.tbss,\"awT\",@nobits",
".section\t.ctors,\"aw\",@progbits",
+ NULL,
+ NULL,
NULL
},
{ /* GAS_FLAVOUR_MACH_O */
".data",
NULL, /* TLS is not supported on Mach-O */
".mod_init_func",
- ".cstring"
+ ".cstring",
+ ".section\t__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5",
+ ".section\t__IMPORT,__pointers,non_lazy_symbol_pointers"
}
};
be_emit_write_line();
/* gcc fills space between function with 0x90, no idea if this is needed */
- if(be_gas_flavour == GAS_FLAVOUR_MACH_O) {
+ if (be_gas_flavour == GAS_FLAVOUR_MACH_O) {
fill_byte = "0x90";
}
- maximum_skip = (1 << alignment) - 1;
- be_emit_cstring("\t.p2align ");
- be_emit_irprintf("%u,%s,%u\n", alignment, fill_byte, maximum_skip);
- be_emit_write_line();
-
+ if (alignment > 0) {
+ maximum_skip = (1 << alignment) - 1;
+ be_emit_cstring("\t.p2align ");
+ be_emit_irprintf("%u,%s,%u\n", alignment, fill_byte, maximum_skip);
+ be_emit_write_line();
+ }
if (get_entity_visibility(entity) == visibility_external_visible) {
be_emit_cstring(".globl ");
be_emit_string(name);
*/
typedef struct _be_gas_decl_env {
const be_main_env_t *main_env; /**< The main backend environment, used for it's debug handle. */
- int dump_tls;
- waitq *worklist; /**< A worklist we use to place not yet handled entities on. */
+ be_gas_section_t section;
+ waitq *worklist; /**< A worklist we use to place not yet handled entities on. */
} be_gas_decl_env_t;
/************************************************************************/
switch (bytes) {
case 1:
be_emit_irprintf("0x%02x", get_tarval_sub_bits(tv, 0));
- break;
+ return;
case 2:
be_emit_irprintf("0x%02x%02x", get_tarval_sub_bits(tv, 1), get_tarval_sub_bits(tv, 0));
- break;
+ return;
case 4:
be_emit_irprintf("0x%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));
- break;
+ return;
case 8:
be_emit_irprintf("0x%02x%02x%02x%02x%02x%02x%02x%02x",
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));
- break;
+ return;
- case 10:
case 12:
- break;
+ be_emit_irprintf("0x%02x%02x%02x%02x%02x%02x%02x%02x"
+ "%02x%02x%02x%02x", 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, 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));
+ return;
case 16:
be_emit_irprintf("0x%02x%02x%02x%02x%02x%02x%02x%02x"
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));
- break;
-
-
- default:
- fprintf(stderr, "Try to dump an tarval with %d bytes\n", bytes);
- assert(0);
+ return;
}
+
+ panic("Can't dump a tarval with %d bytes\n", bytes);
}
/**
*
* @param env the gas output environment
* @param ent the entity to be dumped
- * @param emit_commons if non-zero, emit commons (non-local uninitialized entities)
*/
-static void dump_global(be_gas_decl_env_t *env, ir_entity *ent, int emit_commons)
+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);
int emit_as_common = 0;
- be_gas_section_t section;
- ir_variability variability;
- ir_visibility visibility;
-
- if (is_Method_type(type)) {
- if (be_gas_flavour != GAS_FLAVOUR_MACH_O
- && get_method_img_section(ent) == section_constructors) {
- be_gas_emit_switch_section(GAS_SECTION_CTOR);
- emit_align(align);
- dump_size_type(align);
- be_emit_ident(ld_ident);
- be_emit_char('\n');
- be_emit_write_line();
- }
+ be_gas_section_t section = env->section;
+ ir_variability variability = get_entity_variability(ent);
+ ir_visibility visibility = get_entity_visibility(ent);
+ if (is_Method_type(type) && section != GAS_SECTION_PIC_TRAMPOLINES) {
return;
}
- variability = get_entity_variability(ent);
- visibility = get_entity_visibility(ent);
- section = GAS_SECTION_DATA;
- if (env->dump_tls) {
- section = GAS_SECTION_TLS;
+ if (section != (be_gas_section_t) -1) {
emit_as_common = 0;
} else if (variability == variability_constant) {
/* a constant entity, put it on the rdata */
} else if (variability == variability_uninitialized) {
/* uninitialized entity put it in bss segment */
section = GAS_SECTION_COMMON;
- if (emit_commons && visibility != visibility_local)
+ if (visibility != visibility_local)
emit_as_common = 1;
+ } else {
+ section = GAS_SECTION_DATA;
}
if(!emit_as_common) {
return;
}
/* alignment */
- if (align > 1 && !emit_as_common) {
+ if (align > 1 && !emit_as_common && section != GAS_SECTION_PIC_TRAMPOLINES
+ && section != GAS_SECTION_PIC_SYMBOLS) {
emit_align(align);
}
be_emit_write_line();
break;
}
+ } else if (section == GAS_SECTION_PIC_TRAMPOLINES) {
+ if (be_gas_flavour == GAS_FLAVOUR_MACH_O) {
+ be_emit_cstring("\t.indirect_symbol ");
+ be_emit_ident(get_entity_ident(ent));
+ be_emit_char('\n');
+ be_emit_write_line();
+ be_emit_cstring("\thlt ; hlt ; hlt ; hlt ; hlt\n");
+ be_emit_write_line();
+ } else {
+ panic("PIC trampolines not yet supported in this gas mode");
+ }
} else {
be_emit_irprintf("\t.space %u\n", get_type_size_bytes(type));
be_emit_write_line();
*
* @param gt a global like type, either the global or the TLS one
* @param env an environment
- * @param emit_commons if non-zero, emit commons (non-local uninitialized entities)
* @param only_emit_marked if non-zero, external allocated entities that do not have
* its visited flag set are ignored
*/
static void be_gas_dump_globals(ir_type *gt, be_gas_decl_env_t *env,
- int emit_commons, int only_emit_marked)
+ int only_emit_marked)
{
int i, n = get_compound_n_members(gt);
waitq *worklist = new_waitq();
while (!waitq_empty(worklist)) {
ir_entity *ent = waitq_get(worklist);
- dump_global(env, ent, emit_commons);
+ dump_global(env, ent);
}
del_waitq(worklist);
env.main_env = main_env;
/* dump global type */
- be_gas_dump_globals(get_glob_type(), &env, 1, only_emit_marked_entities);
-
- /* dump the Thread Local Storage */
- env.dump_tls = 1;
- be_gas_dump_globals(get_tls_type(), &env, 0, only_emit_marked_entities);
- env.dump_tls = 0;
+ env.section = (be_gas_section_t) -1;
+ be_gas_dump_globals(get_glob_type(), &env, only_emit_marked_entities);
+ env.section = GAS_SECTION_TLS;
+ be_gas_dump_globals(get_tls_type(), &env, only_emit_marked_entities);
+ env.section = GAS_SECTION_CTOR;
+ be_gas_dump_globals(get_constructors_type(), &env,
+ only_emit_marked_entities);
+ env.section = GAS_SECTION_PIC_SYMBOLS;
+ be_gas_dump_globals(main_env->pic_symbols_type, &env,
+ only_emit_marked_entities);
+
+ if (get_compound_n_members(main_env->pic_trampolines_type) > 0) {
+ env.section = GAS_SECTION_PIC_TRAMPOLINES;
+ be_gas_dump_globals(main_env->pic_trampolines_type, &env,
+ only_emit_marked_entities);
+ if (be_gas_flavour == GAS_FLAVOUR_MACH_O) {
+ be_emit_cstring("\t.subsections_via_symbols\n");
+ be_emit_write_line();
+ }
+ }
}