This is the mail archive of the
mailing list for the GCC project.
Re: Link problems with section anchors
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: gcc-patches at gcc dot gnu dot org
- Cc: David Edelsohn <dje at watson dot ibm dot com>, Steven Munroe <munroesj at us dot ibm dot com>, mark at codesourcery dot com, richard at codesourcery dot com
- Date: Wed, 9 Aug 2006 13:41:55 +0930
- Subject: Re: Link problems with section anchors
- References: <44D2755E.email@example.com> <20060804013032.GB23605@bubble.grove.modra.org> <firstname.lastname@example.org> <200608041354.k74DsG832840@makai.watson.ibm.com> <email@example.com> <200608041411.k74EBg832682@makai.watson.ibm.com>
On Fri, Aug 04, 2006 at 10:11:42AM -0400, David Edelsohn wrote:
> >>>>> Richard Sandiford writes:
> Richard> Ick. I really have to question whether that's valid. GCC does care
> Richard> whether something is link-once or not -- as this PR proves -- so changing
> Richard> it behind GCC's back seems like a very bad idea.
Err, it's hardly behind GCC's back. The .gnu.linkonce is there quite
plainly in the attribute, and expecting GCC to notice the special
section isn't unreasonable. It's not like the situation with asm
strings, where it would be well nigh impossible for gcc to divine the
meaning of user asm.
> Yes, as is being discussed on #gcc, changing sections with GCC
> __attribute__ is fine, but this code is changing section semantics behind
> the compiler's back. One simply cannot expect that to work. Linkonce
> sections are not just a blackbox string value for GCC to emit.
Well, yes, currently GCC itself only sets DECL_ONE_ONLY due to C++
language constructs. Is there some reason why we can't notice
".gnu.linkonce." in a section attribute and set the flag as in the
following patch? I'll note that other parts of GCC act on certain
section names set via an attribute. eg. see rs60000_elf_in_small_data_p
where ".sdata", ".sbss" and other similar section names are tested.
* c-common.c (handle_section_attribute): Recognise .gnu.linkonce
sections as making the decl DECL_ONE_ONLY.
Bootstrapped and regression tested i686-linux. Does the right thing on
the strtoul testcase but I'm not totally sure as to whether
DECL_ONE_ONLY is legal on non-public decls. My testing seems to say it
is.. If so, then the comment in tree.h above DECL_ONE_ONLY would
need modifying if this patch is acceptable.
--- gcc/c-common.c (revision 115995)
+++ gcc/c-common.c (working copy)
@@ -4643,7 +4643,19 @@ handle_section_attribute (tree *node, tr
*no_add_attrs = true;
- DECL_SECTION_NAME (decl) = TREE_VALUE (args);
+ DECL_SECTION_NAME (decl) = TREE_VALUE (args);
+ if (SUPPORTS_ONE_ONLY
+ && strncmp (TREE_STRING_POINTER (TREE_VALUE (args)),
+ ".gnu.linkonce.", 14) == 0)
+ MAKE_DECL_ONE_ONLY (decl);
+ DECL_ONE_ONLY (decl) = 1;
IBM OzLabs - Linux Technology Centre