[patch] default_function_rodata_section bug

DJ Delorie dj@redhat.com
Tue Mar 31 22:28:00 GMT 2009


> In varasm.c default_function_rodata_section():
> 
> section *
> default_function_rodata_section (tree decl)
> . . .
>
> At this point, we haven't checked to see what the prefix of name is -
> for example, it could be .gnu.* or .text.*.  If the former, you end up
> with sections like ".rodatalinkonce.t.*" which don't match the usual
> .rodata.* linker script patterns.
> 
> Should we do something smarter here?

I propose the following patch to fix this:

	* varasm.c (default_function_rodata_section): Don't assume
	anything about where the first '.' in the section name is.

Index: varasm.c
===================================================================
--- varasm.c	(revision 145374)
+++ varasm.c	(working copy)
@@ -866,17 +866,24 @@ default_function_rodata_section (tree de
   if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
     {
       const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
 
       if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
         {
-	  size_t len = strlen (name) + 3;
-	  char* rname = (char *) alloca (len);
+	  char *dot;
+	  size_t len;
+	  char* rname;
+
+	  dot = strchr (name + 1, '.');
+	  if (!dot)
+	    dot = name;
+	  len = strlen (dot) + 8;
+	  rname = (char *) alloca (len);
 
 	  strcpy (rname, ".rodata");
-	  strcat (rname, name + 5);
+	  strcat (rname, dot);
 	  return get_section (rname, SECTION_LINKONCE, decl);
 	}
       /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo.  */
       else if (DECL_ONE_ONLY (decl)
 	       && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
 	{



More information about the Gcc-patches mailing list