public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Edelsohn <dje.gcc@gmail.com>
To: HAO CHEN GUI <guihaoc@linux.ibm.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>,
	 Segher Boessenkool <segher@kernel.crashing.org>,
	Peter Bergner <bergner@linux.ibm.com>
Subject: Re: [PATCH v3, rs6000] Enable absolute jump table for PPC AIX and Linux
Date: Tue, 1 Mar 2022 19:38:55 -0500	[thread overview]
Message-ID: <CAGWvnymjaE5=wZAHcQTNRpmjsW-jEqM=xRafQ+HZiHxt+w27yA@mail.gmail.com> (raw)
In-Reply-To: <3cfd526a-174b-5d09-6683-20a7fb002e04@linux.ibm.com>

On Tue, Mar 1, 2022 at 12:41 AM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote:
>
> Hi,
>    This patch enables absolute jump tables on PPC AIX and Linux. For AIX, the jump
> table is placed in data section. For Linux, it is placed in RELRO section when
> relocation is needed.
>
>    Bootstrapped and tested on AIX,Linux BE and LE with no regressions. Is this okay for trunk?
> Any recommendations? Thanks a lot.

Hi, Haochen

Thanks for working on this patch and for revising it.  The patch looks
okay now, but it is not appropriate for the current bug fixing stage
in GCC development -- it needs to wait for GCC Stage 1 later this
Spring.

Also the current code uses the default readonly data section for the
jump table.  The new rs6000_xcoff_function_rodata_section follows the
existing simple behavior, which is correct, but it should support
named data sections instead of placing everything in the default
".data" section, similar to the default ELF code.  I will work on
that.

Thanks, David

>
> ChangeLog
> 2022-03-01 Haochen Gui <guihaoc@linux.ibm.com>
>
> gcc/
>         * config/rs6000/aix.h (JUMP_TABLES_IN_TEXT_SECTION): Define.
>         * config/rs6000/linux64.h (JUMP_TABLES_IN_TEXT_SECTION): Likewise.
>         * config/rs6000/rs6000.cc (rs6000_option_override_internal): Enable
>         absolute jump tables for AIX and Linux.
>         (rs6000_xcoff_function_rodata_section): Implement.
>         * config/rs6000/xcoff.h (TARGET_ASM_FUNCTION_RODATA_SECTION): Define.
>
> gcc/testsuite
>         * gcc.target/powerpc/absolute-jump-table-section.c: New.
>
>
> patch.diff
> diff --git a/gcc/config/rs6000/aix.h b/gcc/config/rs6000/aix.h
> index ad3238bf09a..cf0708aa08b 100644
> --- a/gcc/config/rs6000/aix.h
> +++ b/gcc/config/rs6000/aix.h
> @@ -251,9 +251,9 @@
>  #define BLOCK_REG_PADDING(MODE, TYPE, FIRST) \
>    (!(FIRST) ? PAD_UPWARD : targetm.calls.function_arg_padding (MODE, TYPE))
>
> -/* Indicate that jump tables go in the text section.  */
> +/* Indicate that jump tables go in the data section.  */
>
> -#define JUMP_TABLES_IN_TEXT_SECTION 1
> +#define JUMP_TABLES_IN_TEXT_SECTION 0
>
>  /* Define any extra SPECS that the compiler needs to generate.  */
>  #undef  SUBTARGET_EXTRA_SPECS
> diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h
> index b2a7afabc73..440e0fde52b 100644
> --- a/gcc/config/rs6000/linux64.h
> +++ b/gcc/config/rs6000/linux64.h
> @@ -237,9 +237,9 @@ extern int dot_symbols;
>  #define TARGET_ALIGN_NATURAL 1
>  #endif
>
> -/* Indicate that jump tables go in the text section.  */
> +/* Indicate that jump tables go in the rodata or RELRO section.  */
>  #undef  JUMP_TABLES_IN_TEXT_SECTION
> -#define JUMP_TABLES_IN_TEXT_SECTION TARGET_64BIT
> +#define JUMP_TABLES_IN_TEXT_SECTION 0
>
>  /* The linux ppc64 ABI isn't explicit on whether aggregates smaller
>     than a doubleword should be padded upward or downward.  You could
> diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
> index bc3ef0721a4..07f78d3a05b 100644
> --- a/gcc/config/rs6000/rs6000.cc
> +++ b/gcc/config/rs6000/rs6000.cc
> @@ -4954,6 +4954,10 @@ rs6000_option_override_internal (bool global_init_p)
>      warning (0, "%qs is deprecated and not recommended in any circumstances",
>              "-mno-speculate-indirect-jumps");
>
> +  /* Enable absolute jump tables for AIX and Linux.  */
> +  if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
> +    rs6000_relative_jumptables = 0;
> +
>    return ret;
>  }
>
> @@ -21419,6 +21423,16 @@ rs6000_xcoff_visibility (tree decl)
>    enum symbol_visibility vis = DECL_VISIBILITY (decl);
>    return visibility_types[vis];
>  }
> +
> +static section *
> +rs6000_xcoff_function_rodata_section (tree decl ATTRIBUTE_UNUSED,
> +                                     bool relocatable)
> +{
> +  if (relocatable)
> +    return data_section;
> +  else
> +    return readonly_data_section;
> +}
>  #endif
>
>
> diff --git a/gcc/config/rs6000/xcoff.h b/gcc/config/rs6000/xcoff.h
> index cd0f99cb9c6..0dacd86eed9 100644
> --- a/gcc/config/rs6000/xcoff.h
> +++ b/gcc/config/rs6000/xcoff.h
> @@ -98,7 +98,7 @@
>  #define TARGET_ASM_SELECT_SECTION  rs6000_xcoff_select_section
>  #define TARGET_ASM_SELECT_RTX_SECTION  rs6000_xcoff_select_rtx_section
>  #define TARGET_ASM_UNIQUE_SECTION  rs6000_xcoff_unique_section
> -#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
> +#define TARGET_ASM_FUNCTION_RODATA_SECTION rs6000_xcoff_function_rodata_section
>  #define TARGET_STRIP_NAME_ENCODING  rs6000_xcoff_strip_name_encoding
>  #define TARGET_SECTION_TYPE_FLAGS  rs6000_xcoff_section_type_flags
>  #ifdef HAVE_AS_TLS
> diff --git a/gcc/testsuite/gcc.target/powerpc/absolute-jump-table-section.c b/gcc/testsuite/gcc.target/powerpc/absolute-jump-table-section.c
> new file mode 100644
> index 00000000000..688a6f42836
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/powerpc/absolute-jump-table-section.c
> @@ -0,0 +1,29 @@
> +/* { dg-do compile { target { *-*-aix* || *-*-linux* } } } */
> +/* { dg-options "-O2 -fPIC" } */
> +
> +/* For Linux, the absolute jump tables are placed in .data.rel.ro.local.
> +   For AIX, they're placed in data section.  */
> +
> +int a;
> +
> +int foo (char c)
> +{
> +  switch (c) {
> +  case 'C':
> +    return a;
> +  case 'D':
> +    return 3;
> +  case 'A':
> +    return 1;
> +  case '%':
> +    return -2;
> +  case '#':
> +    return a+4;
> +  default:
> +    return 100;
> +  }
> +}
> +
> +/* { dg-final { scan-assembler "\\.section\[ \t\]\\.data\\.rel\\.ro\\.local" { target *-*-linux* } } } */
> +/* { dg-final { scan-assembler-times "\\.csect \\.data" 2 { target *-*-aix* } } } */
> +/* { dg-final { scan-assembler-times "\\.csect \\.text" 5 { target *-*-aix* } } } */

      reply	other threads:[~2022-03-02  0:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01  5:41 HAO CHEN GUI
2022-03-02  0:38 ` David Edelsohn [this message]

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='CAGWvnymjaE5=wZAHcQTNRpmjsW-jEqM=xRafQ+HZiHxt+w27yA@mail.gmail.com' \
    --to=dje.gcc@gmail.com \
    --cc=bergner@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=guihaoc@linux.ibm.com \
    --cc=segher@kernel.crashing.org \
    /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).