public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: HAO CHEN GUI <guihaoc@linux.ibm.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Put absolute address jump table in data.rel.ro.local if targets support relocations
Date: Fri, 13 Nov 2020 09:27:20 +0000	[thread overview]
Message-ID: <mpt8sb561zb.fsf@arm.com> (raw)
In-Reply-To: <c86c8036-f811-5440-6bd2-3d2e2a4e8baa@linux.ibm.com> (HAO CHEN GUI's message of "Thu, 22 Oct 2020 10:53:56 +0800")

Hi,

Sorry for the slow reply.  Just one minor nit:

HAO CHEN GUI <guihaoc@linux.ibm.com> writes:
> diff --git a/gcc/varasm.c b/gcc/varasm.c
> index ea0b59cf44a..40502049b61 100644
> --- a/gcc/varasm.c
> +++ b/gcc/varasm.c
> @@ -727,12 +727,26 @@ switch_to_other_text_partition (void)
>    switch_to_section (current_function_section ());
>  }
>  
> -/* Return the read-only data section associated with function DECL.  */
> +/* Return the read-only or relocated read-only data section
> +   associated with function DECL.  */
>  
>  section *
> -default_function_rodata_section (tree decl)
> +default_function_rodata_section (tree decl, bool relocatable)
>  {
> -  if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
> +  const char* sname;
> +  unsigned int flags;
> +
> +  flags = 0;
> +
> +  if (relocatable)
> +    {
> +      sname = ".data.rel.ro.local";
> +      flags = (SECTION_WRITE | SECTION_RELRO);
> +    }
> +  else
> +    sname = ".rodata";
> +
> +  if (decl && DECL_SECTION_NAME (decl))
>      {
>        const char *name = DECL_SECTION_NAME (decl);
>  
> @@ -745,38 +759,57 @@ default_function_rodata_section (tree decl)
>  	  dot = strchr (name + 1, '.');
>  	  if (!dot)
>  	    dot = name;
> -	  len = strlen (dot) + 8;
> +	  len = strlen (dot) + strlen (sname) + 1;
>  	  rname = (char *) alloca (len);
>  
> -	  strcpy (rname, ".rodata");
> +	  strcpy (rname, sname);
>  	  strcat (rname, dot);
> -	  return get_section (rname, SECTION_LINKONCE, decl);
> +	  return get_section (rname, (SECTION_LINKONCE | flags), decl);
>  	}
> -      /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo.  */
> +      /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
> +	 .gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable.  */
>        else if (DECL_COMDAT_GROUP (decl)
>  	       && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
>  	{
> -	  size_t len = strlen (name) + 1;
> -	  char *rname = (char *) alloca (len);
> +	  size_t len;
> +	  char *rname;
>  
> -	  memcpy (rname, name, len);
> -	  rname[14] = 'r';
> -	  return get_section (rname, SECTION_LINKONCE, decl);
> +	  if (relocatable)
> +	    {
> +	      len = strlen (name) + strlen (".rel.ro.local") + 1;
> +	      rname = (char *) alloca (len);
> +
> +	      strcpy (rname, ".gnu.linkonce.d");
> +	      strcat (rname, ".rel.ro.local");
> +	      strcat (rname, name + 15);

I realise you probably wrote it like this to make the correlation
between the length calculation and the string operations more
obvious, but IMO it would be less surprising to have:

	      strcpy (rname, ".gnu.linkonce.d.rel.ro.local");

OK with that change, thanks.

Richard

  parent reply	other threads:[~2020-11-13  9:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14  3:01 HAO CHEN GUI
2020-09-28  0:52 ` HAO CHEN GUI
2020-10-01 17:47 ` Richard Sandiford
2020-10-22  2:53   ` HAO CHEN GUI
2020-11-06  1:06     ` HAO CHEN GUI
2020-11-13  9:27     ` Richard Sandiford [this message]
2020-11-17  5:57       ` HAO CHEN GUI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mpt8sb561zb.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=guihaoc@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).