public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C6X port 7/11: Cope with odd section names
@ 2011-05-10 16:37 Bernd Schmidt
  2011-05-10 18:32 ` Joseph S. Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Schmidt @ 2011-05-10 16:37 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 149 bytes --]

The C6X ELF ABI chooses to use ".const" rather than ".rodata" for
far-readonly data. This patch adds a target hook to deal with the problem.


Bernd

[-- Attachment #2: mrp.diff --]
[-- Type: text/plain, Size: 3572 bytes --]

	* doc/tm.texi.in (TARGET_ASM_MERGEABLE_RODATA_PREFIX): Document.
	* doc/tm.texi: Regenerate.
	* target.def (mergeable_rodata_prefix: New defhookpod.
	* varasm.c (mergeable_string_section, mergeable_constant_section):
	Use it.

Index: doc/tm.texi
===================================================================
--- doc/tm.texi.orig
+++ doc/tm.texi
@@ -7024,6 +7024,12 @@ if function is in @code{.text.name}, and
 otherwise.
 @end deftypefn
 
+@deftypevr {Target Hook} {const char *} TARGET_ASM_MERGEABLE_RODATA_PREFIX
+Usually, the compiler uses the prefix @code{".rodata"} to construct section
+names for mergeable constant data.  Define this macro to override the string
+if a different section name should be used.
+@end deftypevr
+
 @deftypefn {Target Hook} {section *} TARGET_ASM_SELECT_RTX_SECTION (enum machine_mode @var{mode}, rtx @var{x}, unsigned HOST_WIDE_INT @var{align})
 Return the section into which a constant @var{x}, of mode @var{mode},
 should be placed.  You can assume that @var{x} is some kind of
Index: doc/tm.texi.in
===================================================================
--- doc/tm.texi.in.orig
+++ doc/tm.texi.in
@@ -6976,6 +6976,12 @@ if function is in @code{.text.name}, and
 otherwise.
 @end deftypefn
 
+@hook TARGET_ASM_MERGEABLE_RODATA_PREFIX
+Usually, the compiler uses the prefix @code{".rodata"} to construct section
+names for mergeable constant data.  Define this macro to override the string
+if a different section name should be used.
+@end deftypevr
+
 @hook TARGET_ASM_SELECT_RTX_SECTION
 Return the section into which a constant @var{x}, of mode @var{mode},
 should be placed.  You can assume that @var{x} is some kind of
Index: target.def
===================================================================
--- target.def.orig
+++ target.def
@@ -296,6 +296,13 @@ DEFHOOK
  section *, (tree decl),
  default_function_rodata_section)
 
+/* Nonnull if the target wants to override the default ".rodata" prefix
+   for mergeable data sections.  */
+DEFHOOKPOD
+(mergeable_rodata_prefix,
+ "",
+ const char *, NULL)
+
 /* Output a constructor for a symbol with a given priority.  */
 DEFHOOK
 (constructor,
Index: varasm.c
===================================================================
--- varasm.c.orig
+++ varasm.c
@@ -737,7 +737,7 @@ mergeable_string_section (tree decl ATTR
       const char *str;
       HOST_WIDE_INT i;
       int j, unit;
-      char name[30];
+      char name[80];
 
       mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
       modesize = GET_MODE_BITSIZE (mode);
@@ -761,8 +761,10 @@ mergeable_string_section (tree decl ATTR
 	    }
 	  if (i == len - unit)
 	    {
-	      sprintf (name, ".rodata.str%d.%d", modesize / 8,
-		       (int) (align / 8));
+	      sprintf (name, "%s.str%d.%d",
+		       targetm.asm_out.mergeable_rodata_prefix
+		       ? targetm.asm_out.mergeable_rodata_prefix : ".rodata",
+		       modesize / 8, (int) (align / 8));
 	      flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
 	      return get_section (name, flags, NULL);
 	    }
@@ -789,9 +791,12 @@ mergeable_constant_section (enum machine
       && align <= 256
       && (align & (align - 1)) == 0)
     {
-      char name[24];
+      char name[80];
 
-      sprintf (name, ".rodata.cst%d", (int) (align / 8));
+      sprintf (name, "%s.cst%d",
+	       targetm.asm_out.mergeable_rodata_prefix
+	       ? targetm.asm_out.mergeable_rodata_prefix : ".rodata",
+	       (int) (align / 8));
       flags |= (align / 8) | SECTION_MERGE;
       return get_section (name, flags, NULL);
     }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C6X port 7/11: Cope with odd section names
  2011-05-10 16:37 C6X port 7/11: Cope with odd section names Bernd Schmidt
@ 2011-05-10 18:32 ` Joseph S. Myers
  2011-05-12 20:33   ` Bernd Schmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph S. Myers @ 2011-05-10 18:32 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: GCC Patches

On Tue, 10 May 2011, Bernd Schmidt wrote:

> Index: doc/tm.texi.in
> ===================================================================
> --- doc/tm.texi.in.orig
> +++ doc/tm.texi.in
> @@ -6976,6 +6976,12 @@ if function is in @code{.text.name}, and
>  otherwise.
>  @end deftypefn
>  
> +@hook TARGET_ASM_MERGEABLE_RODATA_PREFIX
> +Usually, the compiler uses the prefix @code{".rodata"} to construct section
> +names for mergeable constant data.  Define this macro to override the string
> +if a different section name should be used.
> +@end deftypevr

Unless the documentation is based on pre-existing GFDL-only documentation 
in tm.texi.in, it's preferable for the documentation of a new hook to go 
in the doc string in target.def and get to tm.texi that way, rather than 
putting it directly in tm.texi.in.  (So you'd put the @hook in tm.texi.in, 
but not the main body of the documentation for the hook.)

> +/* Nonnull if the target wants to override the default ".rodata" prefix
> +   for mergeable data sections.  */
> +DEFHOOKPOD
> +(mergeable_rodata_prefix,
> + "",
> + const char *, NULL)

A default of ".rodata" instead of NULL would seem to simplify the rest of 
the patch.

> -      char name[30];
> +      char name[80];

There seems to be some undocumented requirement on the maximum length of 
the string named by the hook, to avoid buffer overruns with these 
fixed-size buffers.  Consider using alloca (or asprintf to avoid needing 
to work out manually how much to add to the length of the string, but then 
you need to free things before returning) to avoid such an undocumented 
bound.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: C6X port 7/11: Cope with odd section names
  2011-05-10 18:32 ` Joseph S. Myers
@ 2011-05-12 20:33   ` Bernd Schmidt
  0 siblings, 0 replies; 3+ messages in thread
From: Bernd Schmidt @ 2011-05-12 20:33 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 1055 bytes --]

On 05/10/2011 06:55 PM, Joseph S. Myers wrote:
> 
> Unless the documentation is based on pre-existing GFDL-only documentation 
> in tm.texi.in, it's preferable for the documentation of a new hook to go 
> in the doc string in target.def and get to tm.texi that way, rather than 
> putting it directly in tm.texi.in.  (So you'd put the @hook in tm.texi.in, 
> but not the main body of the documentation for the hook.)

Changed.

> A default of ".rodata" instead of NULL would seem to simplify the rest of 
> the patch.

Changed.

>> -      char name[30];
>> +      char name[80];
> 
> There seems to be some undocumented requirement on the maximum length of 
> the string named by the hook, to avoid buffer overruns with these 
> fixed-size buffers.  Consider using alloca (or asprintf to avoid needing 
> to work out manually how much to add to the length of the string, but then 
> you need to free things before returning) to avoid such an undocumented 
> bound.

Changed.

New version below; tests running now on i686-linux after a bootstrap.


Bernd


[-- Attachment #2: mrp.diff --]
[-- Type: text/plain, Size: 3633 bytes --]

	* doc/tm.texi.in (TARGET_ASM_MERGEABLE_RODATA_PREFIX): Add hook.
	* doc/tm.texi: Regenerate.
	* target.def (mergeable_rodata_prefix: New defhookpod.
	* varasm.c (mergeable_string_section, mergeable_constant_section):
	Use it. Allocate name with alloca.

Index: gcc/doc/tm.texi
===================================================================
--- gcc/doc/tm.texi.orig
+++ gcc/doc/tm.texi
@@ -7030,6 +7030,12 @@ if function is in @code{.text.name}, and
 otherwise.
 @end deftypefn
 
+@deftypevr {Target Hook} {const char *} TARGET_ASM_MERGEABLE_RODATA_PREFIX
+Usually, the compiler uses the prefix @code{".rodata"} to construct
+section names for mergeable constant data.  Define this macro to override
+the string if a different section name should be used.
+@end deftypevr
+
 @deftypefn {Target Hook} {section *} TARGET_ASM_SELECT_RTX_SECTION (enum machine_mode @var{mode}, rtx @var{x}, unsigned HOST_WIDE_INT @var{align})
 Return the section into which a constant @var{x}, of mode @var{mode},
 should be placed.  You can assume that @var{x} is some kind of
Index: gcc/doc/tm.texi.in
===================================================================
--- gcc/doc/tm.texi.in.orig
+++ gcc/doc/tm.texi.in
@@ -6978,6 +6978,8 @@ if function is in @code{.text.name}, and
 otherwise.
 @end deftypefn
 
+@hook TARGET_ASM_MERGEABLE_RODATA_PREFIX
+
 @hook TARGET_ASM_SELECT_RTX_SECTION
 Return the section into which a constant @var{x}, of mode @var{mode},
 should be placed.  You can assume that @var{x} is some kind of
Index: gcc/target.def
===================================================================
--- gcc/target.def.orig
+++ gcc/target.def
@@ -296,6 +296,15 @@ DEFHOOK
  section *, (tree decl),
  default_function_rodata_section)
 
+/* Nonnull if the target wants to override the default ".rodata" prefix
+   for mergeable data sections.  */
+DEFHOOKPOD
+(mergeable_rodata_prefix,
+ "Usually, the compiler uses the prefix @code{\".rodata\"} to construct\n\
+section names for mergeable constant data.  Define this macro to override\n\
+the string if a different section name should be used.",
+ const char *, ".rodata")
+
 /* Output a constructor for a symbol with a given priority.  */
 DEFHOOK
 (constructor,
Index: gcc/varasm.c
===================================================================
--- gcc/varasm.c.orig
+++ gcc/varasm.c
@@ -737,7 +737,8 @@ mergeable_string_section (tree decl ATTR
       const char *str;
       HOST_WIDE_INT i;
       int j, unit;
-      char name[30];
+      const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
+      char *name = (char *) alloca (strlen (prefix) + 30);
 
       mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
       modesize = GET_MODE_BITSIZE (mode);
@@ -761,8 +762,8 @@ mergeable_string_section (tree decl ATTR
 	    }
 	  if (i == len - unit)
 	    {
-	      sprintf (name, ".rodata.str%d.%d", modesize / 8,
-		       (int) (align / 8));
+	      sprintf (name, "%s.str%d.%d", prefix,
+		       modesize / 8, (int) (align / 8));
 	      flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
 	      return get_section (name, flags, NULL);
 	    }
@@ -789,9 +790,10 @@ mergeable_constant_section (enum machine
       && align <= 256
       && (align & (align - 1)) == 0)
     {
-      char name[24];
+      const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
+      char *name = (char *) alloca (strlen (prefix) + 30);
 
-      sprintf (name, ".rodata.cst%d", (int) (align / 8));
+      sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
       flags |= (align / 8) | SECTION_MERGE;
       return get_section (name, flags, NULL);
     }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-05-12 16:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-10 16:37 C6X port 7/11: Cope with odd section names Bernd Schmidt
2011-05-10 18:32 ` Joseph S. Myers
2011-05-12 20:33   ` Bernd Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).