*/
typedef enum {
/**
- * The entity is visible outside the compilation unit, but it is defined
- * here.
+ * The entity is visible across compilation units. It might have an
+ * initializer/graph.
+ * Note that variables with visibility_external but not initializer are
+ * not "uninitialized" but considered to be in another compilation unit.
*/
- ir_visibility_default,
+ ir_visibility_external,
/**
* The entity is local to the compilation unit.
* A local entity is not visible in other compilation units.
*/
ir_visibility_local,
/**
- * The entity is defined outside the compilation unit but potentially used
- * here.
- */
- ir_visibility_external,
- /**
- * This has the same semantic as visibility_local. Additionally the symbol is
- * completely hidden from the linker (it only appears in the assembly).
+ * This has the same semantic as visibility_local. Additionally the symbol
+ * is completely hidden from the linker (it only appears in the assembly).
* While visibility_local is probably still visible to debuggers,
* visibility_private symbols aren't and probably won't appear in the object
* files
*/
- ir_visibility_private
+ ir_visibility_private,
} ir_visibility;
/**
static bool is_extern_entity(const ir_entity *entity)
{
ir_visited_t visibility = get_entity_visibility(entity);
- return visibility == ir_visibility_default
- || visibility == ir_visibility_external;
+ return visibility == ir_visibility_external;
}
static void emit_entity_label(const ir_entity *entity)
static bool entity_is_null(const ir_entity *entity)
{
- if (entity->initializer != NULL) {
- return initializer_is_null(entity->initializer);
- } else if (entity_has_compound_ent_values(entity)) {
- /* I'm too lazy to implement this case as compound graph paths will be
- * remove anyway in the future */
- return false;
- }
- /* uninitialized, NULL is fine */
- return true;
+ ir_initializer_t *initializer = get_entity_initializer(entity);
+ return initializer == NULL || initializer_is_null(initializer);
}
static bool is_comdat(const ir_entity *entity)
if (linkage & IR_LINKAGE_CONSTANT) {
/* mach-o is the only one with a cstring section */
if (be_gas_object_file_format == OBJECT_FILE_FORMAT_MACH_O
- && entity_is_string_const(entity))
+ && entity_is_string_const(entity))
return GAS_SECTION_CSTRING;
return GAS_SECTION_RODATA;
if (get_entity_linkage(entity) & IR_LINKAGE_WEAK) {
emit_weak(entity);
/* Note: .weak seems to imply .globl so no need to output .globl */
- } else if (get_entity_visibility(entity) == ir_visibility_default) {
+ } else if (get_entity_visibility(entity) == ir_visibility_external
+ && entity_has_definition(entity)) {
be_emit_cstring("\t.globl ");
be_gas_emit_entity(entity);
be_emit_char('\n');
case ir_visibility_private:
emit_local_common(entity);
return;
- case ir_visibility_default:
+ case ir_visibility_external:
if (linkage & IR_LINKAGE_MERGE) {
emit_common(entity);
return;
}
break;
- case ir_visibility_external:
- if (linkage & IR_LINKAGE_MERGE)
- panic("merge link semantic not supported for extern entities");
- break;
}
}
emit_visibility(entity);
- if (visibility == ir_visibility_external) {
- /* nothing to do for externally defined values */
+ /* nothing left to do without an initializer */
+ if (!entity_has_definition(entity))
return;
- }
if (!is_po2(alignment))
panic("alignment not a power of 2");
}
if (entity_is_null(entity)) {
+ /* we should use .space for stuff in the bss segment */
unsigned size = get_type_size_bytes(type);
if (size > 0) {
be_emit_irprintf("\t.space %u, 0\n", get_type_size_bytes(type));
be_gas_emit_entity(entity);
if (get_entity_owner(entity) == get_tls_type()) {
- if (get_entity_visibility(entity) == ir_visibility_external) {
+ if (!entity_has_definition(entity)) {
be_emit_cstring("@INDNTPOFF");
} else {
be_emit_cstring("@NTPOFF");
INSERT(tt_visibility, "local", ir_visibility_local);
INSERT(tt_visibility, "external", ir_visibility_external);
- INSERT(tt_visibility, "default", ir_visibility_default);
INSERT(tt_visibility, "private", ir_visibility_private);
INSERT(tt_throws, "throw", true);
switch (visibility) {
case ir_visibility_local: return "local";
case ir_visibility_external: return "external";
- case ir_visibility_default: return "default";
case ir_visibility_private: return "private";
}
panic("INVALID_VISIBILITY");
long entnr = read_long(env);
ident *name = NULL;
ident *ld_name = NULL;
- ir_visibility visibility = ir_visibility_default;
+ ir_visibility visibility = ir_visibility_external;
ir_linkage linkage = IR_LINKAGE_DEFAULT;
ir_type *owner = NULL;
ir_entity *entity = NULL;
for (i = 0; i < n_entities; ++i) {
ir_entity *entity = get_compound_member(segment, i);
- if (get_entity_visibility(entity) != ir_visibility_default
+ if (get_entity_visibility(entity) != ir_visibility_external
&& !(get_entity_linkage(entity) & IR_LINKAGE_HIDDEN_USER))
continue;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
res->compiler_gen = 0;
- res->visibility = ir_visibility_default;
+ res->visibility = ir_visibility_external;
res->offset = -1;
res->offset_bit_remainder = 0;
res->alignment = 0;