aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/darwin.c
diff options
context:
space:
mode:
authorEric Christopher <echristo@gcc.gnu.org>2006-12-20 00:42:34 +0000
committerEric Christopher <echristo@gcc.gnu.org>2006-12-20 00:42:34 +0000
commit59ff4a1c1cbf5e4f748087b9aebd6c2408f0f9d9 (patch)
tree3d03489462c529086a25f60ecfc7a74fd7ef9c7f /gcc/config/darwin.c
parent91321cd0224ae8cc8864bf45f28c00e1ebe35187 (diff)
downloadgcc-59ff4a1c1cbf5e4f748087b9aebd6c2408f0f9d9.zip
gcc-59ff4a1c1cbf5e4f748087b9aebd6c2408f0f9d9.tar.gz
gcc-59ff4a1c1cbf5e4f748087b9aebd6c2408f0f9d9.tar.bz2
darwin.c (machopic_select_section): Rewrite.
2006-12-19 Eric Christopher <echristo@apple.com> * config/darwin.c (machopic_select_section): Rewrite. (darwin_text_section): New. (darwin_rodata_section): Ditto. (darwin_mergeable_string_section): Ditto. (darwin_mergeable_constant_section): Ditto. * config/darwin-sections.def: Add SECTION_STRINGS for cstring_section. From-SVN: r120066
Diffstat (limited to 'gcc/config/darwin.c')
-rw-r--r--gcc/config/darwin.c251
1 files changed, 164 insertions, 87 deletions
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 9332cc1..385b892 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -1095,138 +1095,215 @@ darwin_mark_decl_preserved (const char *name)
fputc ('\n', asm_out_file);
}
-section *
-machopic_select_section (tree exp, int reloc,
- unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
+static section *
+darwin_text_section (int reloc, int weak)
{
- section *base_section;
- bool weak_p = (DECL_P (exp) && DECL_WEAK (exp)
- && (lookup_attribute ("weak", DECL_ATTRIBUTES (exp))
- || ! lookup_attribute ("weak_import",
- DECL_ATTRIBUTES (exp))));
-
- if (TREE_CODE (exp) == FUNCTION_DECL)
- {
- if (reloc == 1)
- base_section = (weak_p
- ? darwin_sections[text_unlikely_coal_section]
- : unlikely_text_section ());
- else
- base_section = weak_p ? darwin_sections[text_coal_section]
- : text_section;
- }
- else if (decl_readonly_section_1 (exp, reloc, MACHOPIC_INDIRECT))
- base_section = weak_p ? darwin_sections[const_coal_section]
- : darwin_sections[const_section];
- else if (TREE_READONLY (exp) || TREE_CONSTANT (exp))
- base_section = weak_p ? darwin_sections[const_data_coal_section]
- : darwin_sections[const_data_section];
+ if (reloc)
+ return (weak
+ ? darwin_sections[text_unlikely_coal_section]
+ : unlikely_text_section ());
else
- base_section = weak_p ? darwin_sections[data_coal_section] : data_section;
+ return (weak
+ ? darwin_sections[text_coal_section]
+ : text_section);
+}
+
+static section *
+darwin_rodata_section (int weak)
+{
+ return (weak
+ ? darwin_sections[const_coal_section]
+ : darwin_sections[const_section]);
+}
- if (TREE_CODE (exp) == STRING_CST
+static section *
+darwin_mergeable_string_section (tree exp,
+ unsigned HOST_WIDE_INT align)
+{
+ if (flag_merge_constants
+ && TREE_CODE (exp) == STRING_CST
+ && TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
+ && align <= 256
&& ((size_t) TREE_STRING_LENGTH (exp)
== strlen (TREE_STRING_POINTER (exp)) + 1))
return darwin_sections[cstring_section];
- else if ((TREE_CODE (exp) == INTEGER_CST || TREE_CODE (exp) == REAL_CST)
- && flag_merge_constants)
+
+ return readonly_data_section;
+}
+
+static section *
+darwin_mergeable_constant_section (tree exp,
+ unsigned HOST_WIDE_INT align)
+{
+ enum machine_mode mode = DECL_MODE (exp);
+ unsigned int modesize = GET_MODE_BITSIZE (mode);
+
+ if (flag_merge_constants
+ && mode != VOIDmode
+ && mode != BLKmode
+ && modesize <= align
+ && align >= 8
+ && align <= 256
+ && (align & (align -1)) == 0)
{
tree size = TYPE_SIZE_UNIT (TREE_TYPE (exp));
- if (TREE_CODE (size) == INTEGER_CST &&
- TREE_INT_CST_LOW (size) == 4 &&
- TREE_INT_CST_HIGH (size) == 0)
- return darwin_sections[literal4_section];
- else if (TREE_CODE (size) == INTEGER_CST &&
- TREE_INT_CST_LOW (size) == 8 &&
- TREE_INT_CST_HIGH (size) == 0)
- return darwin_sections[literal8_section];
- else if (TARGET_64BIT
- && TREE_CODE (size) == INTEGER_CST
- && TREE_INT_CST_LOW (size) == 16
+ if (TREE_CODE (size) == INTEGER_CST
+ && TREE_INT_CST_LOW (size) == 4
+ && TREE_INT_CST_HIGH (size) == 0)
+ return darwin_sections[literal4_section];
+ else if (TREE_CODE (size) == INTEGER_CST
+ && TREE_INT_CST_LOW (size) == 8
&& TREE_INT_CST_HIGH (size) == 0)
- return darwin_sections[literal16_section];
+ return darwin_sections[literal8_section];
+ else if (TARGET_64BIT
+ && TREE_CODE (size) == INTEGER_CST
+ && TREE_INT_CST_LOW (size) == 16
+ && TREE_INT_CST_HIGH (size) == 0)
+ return darwin_sections[literal16_section];
+ else
+ return readonly_data_section;
+ }
+
+ return readonly_data_section;
+}
+
+section *
+machopic_select_section (tree decl,
+ int reloc,
+ unsigned HOST_WIDE_INT align)
+{
+ bool weak = (DECL_P (decl)
+ && DECL_WEAK (decl)
+ && (lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
+ || ! lookup_attribute ("weak_import",
+ DECL_ATTRIBUTES (decl))));
+ int shlib = flag_pic;
+ section *base_section;
+
+ switch (categorize_decl_for_section (decl, reloc, shlib))
+ {
+ case SECCAT_TEXT:
+ base_section = darwin_text_section (reloc, weak);
+ break;
+
+ case SECCAT_RODATA:
+ case SECCAT_SRODATA:
+ base_section = darwin_rodata_section (weak);
+ break;
+
+ case SECCAT_RODATA_MERGE_STR:
+ base_section = darwin_mergeable_string_section (decl, align);
+ break;
+
+ case SECCAT_RODATA_MERGE_STR_INIT:
+ base_section = darwin_mergeable_string_section (DECL_INITIAL (decl), align);
+ break;
+
+ case SECCAT_RODATA_MERGE_CONST:
+ base_section = darwin_mergeable_constant_section (decl, align);
+ break;
+
+ case SECCAT_DATA:
+ case SECCAT_DATA_REL:
+ case SECCAT_DATA_REL_LOCAL:
+ case SECCAT_DATA_REL_RO:
+ case SECCAT_DATA_REL_RO_LOCAL:
+ case SECCAT_SDATA:
+ case SECCAT_TDATA:
+ case SECCAT_BSS:
+ case SECCAT_SBSS:
+ case SECCAT_TBSS:
+ if (TREE_READONLY (decl) || TREE_CONSTANT (decl))
+ base_section = weak ? darwin_sections[const_data_coal_section]
+ : darwin_sections[const_data_section];
else
- return base_section;
+ base_section = weak ? darwin_sections[data_coal_section] : data_section;
+ break;
+
+ default:
+ gcc_unreachable ();
}
- else if (TREE_CODE (exp) == CONSTRUCTOR
- && TREE_TYPE (exp)
- && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
- && TYPE_NAME (TREE_TYPE (exp)))
+
+ /* Darwin weird special cases. */
+ if (TREE_CODE (decl) == CONSTRUCTOR
+ && TREE_TYPE (decl)
+ && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
+ && TYPE_NAME (TREE_TYPE (decl)))
{
- tree name = TYPE_NAME (TREE_TYPE (exp));
+ tree name = TYPE_NAME (TREE_TYPE (decl));
if (TREE_CODE (name) == TYPE_DECL)
- name = DECL_NAME (name);
+ name = DECL_NAME (name);
if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_ObjCString"))
- {
- if (flag_next_runtime)
- return darwin_sections[objc_constant_string_object_section];
- else
- return darwin_sections[objc_string_object_section];
- }
+ {
+ if (flag_next_runtime)
+ return darwin_sections[objc_constant_string_object_section];
+ else
+ return darwin_sections[objc_string_object_section];
+ }
else
- return base_section;
+ return base_section;
}
- else if (TREE_CODE (exp) == VAR_DECL &&
- DECL_NAME (exp) &&
- TREE_CODE (DECL_NAME (exp)) == IDENTIFIER_NODE &&
- IDENTIFIER_POINTER (DECL_NAME (exp)) &&
- !strncmp (IDENTIFIER_POINTER (DECL_NAME (exp)), "_OBJC_", 6))
+ else if (TREE_CODE (decl) == VAR_DECL
+ && DECL_NAME (decl)
+ && TREE_CODE (DECL_NAME (decl)) == IDENTIFIER_NODE
+ && IDENTIFIER_POINTER (DECL_NAME (decl))
+ && !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), "_OBJC_", 6))
{
- const char *name = IDENTIFIER_POINTER (DECL_NAME (exp));
+ const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
if (!strncmp (name, "_OBJC_CLASS_METHODS_", 20))
- return darwin_sections[objc_cls_meth_section];
+ return darwin_sections[objc_cls_meth_section];
else if (!strncmp (name, "_OBJC_INSTANCE_METHODS_", 23))
- return darwin_sections[objc_inst_meth_section];
+ return darwin_sections[objc_inst_meth_section];
else if (!strncmp (name, "_OBJC_CATEGORY_CLASS_METHODS_", 20))
- return darwin_sections[objc_cat_cls_meth_section];
+ return darwin_sections[objc_cat_cls_meth_section];
else if (!strncmp (name, "_OBJC_CATEGORY_INSTANCE_METHODS_", 23))
- return darwin_sections[objc_cat_inst_meth_section];
+ return darwin_sections[objc_cat_inst_meth_section];
else if (!strncmp (name, "_OBJC_CLASS_VARIABLES_", 22))
- return darwin_sections[objc_class_vars_section];
+ return darwin_sections[objc_class_vars_section];
else if (!strncmp (name, "_OBJC_INSTANCE_VARIABLES_", 25))
- return darwin_sections[objc_instance_vars_section];
+ return darwin_sections[objc_instance_vars_section];
else if (!strncmp (name, "_OBJC_CLASS_PROTOCOLS_", 22))
- return darwin_sections[objc_cat_cls_meth_section];
+ return darwin_sections[objc_cat_cls_meth_section];
else if (!strncmp (name, "_OBJC_CLASS_NAME_", 17))
- return darwin_sections[objc_class_names_section];
+ return darwin_sections[objc_class_names_section];
else if (!strncmp (name, "_OBJC_METH_VAR_NAME_", 20))
- return darwin_sections[objc_meth_var_names_section];
+ return darwin_sections[objc_meth_var_names_section];
else if (!strncmp (name, "_OBJC_METH_VAR_TYPE_", 20))
- return darwin_sections[objc_meth_var_types_section];
+ return darwin_sections[objc_meth_var_types_section];
else if (!strncmp (name, "_OBJC_CLASS_REFERENCES", 22))
- return darwin_sections[objc_cls_refs_section];
+ return darwin_sections[objc_cls_refs_section];
else if (!strncmp (name, "_OBJC_CLASS_", 12))
- return darwin_sections[objc_class_section];
+ return darwin_sections[objc_class_section];
else if (!strncmp (name, "_OBJC_METACLASS_", 16))
- return darwin_sections[objc_meta_class_section];
+ return darwin_sections[objc_meta_class_section];
else if (!strncmp (name, "_OBJC_CATEGORY_", 15))
- return darwin_sections[objc_category_section];
+ return darwin_sections[objc_category_section];
else if (!strncmp (name, "_OBJC_SELECTOR_REFERENCES", 25))
- return darwin_sections[objc_selector_refs_section];
+ return darwin_sections[objc_selector_refs_section];
else if (!strncmp (name, "_OBJC_SELECTOR_FIXUP", 20))
- return darwin_sections[objc_selector_fixup_section];
+ return darwin_sections[objc_selector_fixup_section];
else if (!strncmp (name, "_OBJC_SYMBOLS", 13))
- return darwin_sections[objc_symbols_section];
+ return darwin_sections[objc_symbols_section];
else if (!strncmp (name, "_OBJC_MODULES", 13))
- return darwin_sections[objc_module_info_section];
+ return darwin_sections[objc_module_info_section];
else if (!strncmp (name, "_OBJC_IMAGE_INFO", 16))
- return darwin_sections[objc_image_info_section];
+ return darwin_sections[objc_image_info_section];
else if (!strncmp (name, "_OBJC_PROTOCOL_INSTANCE_METHODS_", 32))
- return darwin_sections[objc_cat_inst_meth_section];
+ return darwin_sections[objc_cat_inst_meth_section];
else if (!strncmp (name, "_OBJC_PROTOCOL_CLASS_METHODS_", 29))
- return darwin_sections[objc_cat_cls_meth_section];
+ return darwin_sections[objc_cat_cls_meth_section];
else if (!strncmp (name, "_OBJC_PROTOCOL_REFS_", 20))
- return darwin_sections[objc_cat_cls_meth_section];
+ return darwin_sections[objc_cat_cls_meth_section];
else if (!strncmp (name, "_OBJC_PROTOCOL_", 15))
- return darwin_sections[objc_protocol_section];
+ return darwin_sections[objc_protocol_section];
else
- return base_section;
+ return base_section;
}
- else
- return base_section;
+
+ return base_section;
}
/* This can be called with address expressions as "rtx".