This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, RFC] give the target a better opportunity to chose sections for zero items.
- From: IainS <developer at sandoe-acoustics dot co dot uk>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Richard Henderson <rth at redhat dot com>
- Date: Sun, 14 Nov 2010 14:18:12 +0000
- Subject: [Patch, RFC] give the target a better opportunity to chose sections for zero items.
Hi,
A (quite long) while ago I was discussing with Richard why, under some
circumstances, ObjC meta-data items end up in a different section from
that expected - and I've tracked down why that happens...
At this juncture, in addition to wanting to tidy up that - I am also
trying to resolve several PRs that relate to Darwin's BSS/Local/etc.
allocators.
.... the following code at the end of varasm.c: get_variable_section ()
if (ADDR_SPACE_GENERIC_P (as)
&& !DECL_THREAD_LOCAL_P (decl)
&& !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
&& bss_initializer_p (decl))
{
if (!TREE_PUBLIC (decl))
return lcomm_section;
if (bss_noswitch_section)
return bss_noswitch_section;
}
return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN
(decl));
}
.... does not give the target much chance to step in when the item is
zero-valued.
(so, in the ObjC meta-data case we find that an empty string ends up
in BSS instead of the objc string section).
When working on darwin's allocators - I also saw coalescable items
appearing in my BSS allocator.
(I also wonder about whether we are missing something allowing
TREE_CONSTANT).
Anyway, as a means of giving the target a better chance to choose the
right section would the following patch be acceptable for trunk?
cheers,
Iain
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c (revision 166732)
+++ gcc/varasm.c (working copy)
@@ -951,6 +951,9 @@ get_variable_section (tree decl, bool prefer_noswi
if (ADDR_SPACE_GENERIC_P (as)
&& !DECL_THREAD_LOCAL_P (decl)
+ && !DECL_WEAK (decl)
+ && !DECL_ONE_ONLY (decl)
+ && !DECL_ATTRIBUTES (decl)
&& !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
&& bss_initializer_p (decl))
{
@@ -6093,7 +6096,9 @@ categorize_decl_for_section (const_tree decl, int
}
else if (TREE_CODE (decl) == VAR_DECL)
{
- if (bss_initializer_p (decl))
+ if (!DECL_WEAK (decl)
+ && !DECL_ONE_ONLY (decl)
+ && bss_initializer_p (decl))
ret = SECCAT_BSS;
else if (! TREE_READONLY (decl)
|| TREE_SIDE_EFFECTS (decl)