Commit 59ff4a1c by Eric Christopher

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
parent 91321cd0
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.
2006-12-19 Steve Ellcey <sje@cup.hp.com>
* config/pa/pa64-hpux.h (ASM_OUTPUT_EXTERNAL): Add undef.
......
......@@ -11,7 +11,7 @@ DEF_SECTION (const_data_coal_section, 0,
".section __DATA,__const_coal,coalesced", 0)
DEF_SECTION (data_coal_section, SECTION_WRITE,
".section __DATA,__datacoal_nt,coalesced", 0)
DEF_SECTION (cstring_section, SECTION_MERGE, ".cstring", 0)
DEF_SECTION (cstring_section, SECTION_MERGE | SECTION_STRINGS, ".cstring", 0)
DEF_SECTION (literal4_section, SECTION_MERGE, ".literal4", 0)
DEF_SECTION (literal8_section, SECTION_MERGE, ".literal8", 0)
DEF_SECTION (literal16_section, SECTION_MERGE, ".literal16", 0)
......
......@@ -1095,51 +1095,66 @@ 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
if (reloc)
return (weak
? 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];
else
base_section = weak_p ? darwin_sections[data_coal_section] : data_section;
return (weak
? darwin_sections[text_coal_section]
: text_section);
}
if (TREE_CODE (exp) == STRING_CST
static section *
darwin_rodata_section (int weak)
{
return (weak
? darwin_sections[const_coal_section]
: darwin_sections[const_section]);
}
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)
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)
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
......@@ -1147,14 +1162,76 @@ machopic_select_section (tree exp, int reloc,
&& TREE_INT_CST_HIGH (size) == 0)
return darwin_sections[literal16_section];
else
return base_section;
return readonly_data_section;
}
else if (TREE_CODE (exp) == CONSTRUCTOR
&& TREE_TYPE (exp)
&& TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
&& TYPE_NAME (TREE_TYPE (exp)))
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
base_section = weak ? darwin_sections[data_coal_section] : data_section;
break;
default:
gcc_unreachable ();
}
/* 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);
......@@ -1168,13 +1245,13 @@ machopic_select_section (tree exp, int reloc,
else
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];
......@@ -1225,7 +1302,7 @@ machopic_select_section (tree exp, int reloc,
else
return base_section;
}
else
return base_section;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment