+
+
+void be_gas_emit_switch_section(be_gas_section_t section)
+{
+ /* you have to produce a switch_section call with entity manually
+ * for comdat sections */
+ assert( !(section & GAS_SECTION_FLAG_COMDAT));
+
+ emit_section(section, NULL);
+}
+
+static ir_tarval *get_initializer_tarval(const ir_initializer_t *initializer)
+{
+ if (initializer->kind == IR_INITIALIZER_TARVAL)
+ return initializer->tarval.value;
+ if (initializer->kind == IR_INITIALIZER_CONST) {
+ ir_node *node = initializer->consti.value;
+ if (is_Const(node)) {
+ return get_Const_tarval(node);
+ }
+ }
+ return get_tarval_undefined();
+}
+
+static bool initializer_is_string_const(const ir_initializer_t *initializer)
+{
+ size_t i, len;
+ bool found_printable = false;
+
+ if (initializer->kind != IR_INITIALIZER_COMPOUND)
+ return false;
+
+ len = initializer->compound.n_initializers;
+ if (len < 1)
+ return false;
+ for (i = 0; i < len; ++i) {
+ int c;
+ ir_tarval *tv;
+ ir_mode *mode;
+ ir_initializer_t *sub_initializer
+ = initializer->compound.initializers[i];
+
+ tv = get_initializer_tarval(sub_initializer);
+ if (!tarval_is_constant(tv))
+ return false;
+
+ mode = get_tarval_mode(tv);
+ if (!mode_is_int(mode) || get_mode_size_bits(mode) != 8)
+ return false;
+
+ c = get_tarval_long(tv);
+ if (isgraph(c) || isspace(c))
+ found_printable = true;
+ else if (c != 0)
+ return false;
+
+ if (i == len - 1 && c != '\0')
+ return false;
+ }
+
+ return found_printable;
+}
+
+static bool initializer_is_null(const ir_initializer_t *initializer)
+{
+ switch (initializer->kind) {
+ case IR_INITIALIZER_NULL:
+ return true;
+ case IR_INITIALIZER_TARVAL: {
+ ir_tarval *tv = initializer->tarval.value;
+ return tarval_is_null(tv);
+ }
+ case IR_INITIALIZER_CONST: {
+ ir_node *value = initializer->consti.value;
+ if (!is_Const(value))
+ return false;
+ return is_Const_null(value);
+ }
+ case IR_INITIALIZER_COMPOUND: {
+ size_t i;
+ for (i = 0; i < initializer->compound.n_initializers; ++i) {
+ ir_initializer_t *subinitializer
+ = initializer->compound.initializers[i];
+ if (!initializer_is_null(subinitializer))
+ return false;
+ }
+ return true;
+ }
+ }
+ panic("invalid initializer in initializer_is_null");
+}
+
+/**
+ * Determine if an entity is a string constant
+ * @param ent The entity
+ * @return 1 if it is a string constant, 0 otherwise
+ */
+static int entity_is_string_const(const ir_entity *ent)
+{
+ ir_type *type, *element_type;
+ ir_mode *mode;
+ int i, c, n;
+
+ type = get_entity_type(ent);
+
+ /* if it's an array */
+ if (!is_Array_type(type))
+ return 0;
+
+ element_type = get_array_element_type(type);
+
+ /* and the array's element type is primitive */
+ if (!is_Primitive_type(element_type))
+ return 0;
+
+ /* 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) != 8)
+ return 0;
+
+ if (ent->initializer != NULL) {
+ return initializer_is_string_const(ent->initializer);
+ } else if (entity_has_compound_ent_values(ent)) {
+ int found_printable = 0;
+ /* if it contains only printable chars and a 0 at the end */
+ n = get_compound_ent_n_values(ent);
+ for (i = 0; i < n; ++i) {
+ ir_node *irn = get_compound_ent_value(ent, i);
+ if (! is_Const(irn))
+ return 0;
+
+ c = (int) get_tarval_long(get_Const_tarval(irn));
+
+ if (isgraph(c) || isspace(c))
+ found_printable = 1;
+ else if (c != 0)
+ return 0;
+
+ if (i == n - 1 && c != '\0')
+ return 0;
+ }
+ return found_printable;
+ }
+
+ return 0;
+}
+
+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;
+}
+
+static bool is_comdat(const ir_entity *entity)