This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Link problems with section anchors

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.

Index: gcc/c-common.c
--- 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);
+		  && strncmp (TREE_STRING_POINTER (TREE_VALUE (args)),
+			      ".gnu.linkonce.", 14) == 0)
+		{
+		  MAKE_DECL_ONE_ONLY (decl);
+		  DECL_ONE_ONLY (decl) = 1;
+		}
+	    }

Alan Modra
IBM OzLabs - Linux Technology Centre

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]