public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christophe Lyon <christophe.lyon@linaro.org>
To: gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] arm: Fix multiple inheritance thunks for thumb-1 with -mpure-code
Date: Tue, 6 Oct 2020 10:30:59 +0200	[thread overview]
Message-ID: <CAKdteOYksfkHUjQwowAUqSSD1wDXcLrugbcK_DKdS=1=_2JULA@mail.gmail.com> (raw)
In-Reply-To: <1601409053-17310-1-git-send-email-christophe.lyon@linaro.org>

ping?

On Tue, 29 Sep 2020 at 21:50, Christophe Lyon
<christophe.lyon@linaro.org> wrote:
>
> When mi_delta is > 255 and -mpure-code is used, we cannot load delta
> from code memory (like we do without -mpure-code).
>
> This patch builds the value of mi_delta into r3 with a series of
> movs/adds/lsls.
>
> We also do some cleanup by not emitting the function address and delta
> via .word directives at the end of the thunk since we don't use them
> with -mpure-code.
>
> No need for new testcases, this bug was already identified by
> eg. pr46287-3.C
>
> 2020-09-29  Christophe Lyon  <christophe.lyon@linaro.org>
>
>         gcc/
>         * config/arm/arm.c (arm_thumb1_mi_thunk): Build mi_delta in r3 and
>         do not emit function address and delta when -mpure-code is used.
>
> k#   (use "git pull" to merge the remote branch into yours)
> ---
>  gcc/config/arm/arm.c | 91 +++++++++++++++++++++++++++++++++++++---------------
>  1 file changed, 66 insertions(+), 25 deletions(-)
>
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index ceeb91f..62abeb5 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -28342,9 +28342,43 @@ arm_thumb1_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta,
>      {
>        if (mi_delta > 255)
>         {
> -         fputs ("\tldr\tr3, ", file);
> -         assemble_name (file, label);
> -         fputs ("+4\n", file);
> +         /* With -mpure-code, we cannot load delta from the constant
> +            pool: we build it explicitly.  */
> +         if (target_pure_code)
> +           {
> +             bool mov_done_p = false;
> +             int i;
> +
> +             /* Emit upper 3 bytes if needed.  */
> +             for (i = 0; i < 3; i++)
> +               {
> +                 int byte = (mi_delta >> (8 * (3 - i))) & 0xff;
> +
> +                 if (byte)
> +                   {
> +                     if (mov_done_p)
> +                       asm_fprintf (file, "\tadds\tr3, #%d\n", byte);
> +                     else
> +                       asm_fprintf (file, "\tmovs\tr3, #%d\n", byte);
> +                     mov_done_p = true;
> +                   }
> +
> +                 if (mov_done_p)
> +                   asm_fprintf (file, "\tlsls\tr3, #8\n");
> +               }
> +
> +             /* Emit lower byte if needed.  */
> +             if (!mov_done_p)
> +               asm_fprintf (file, "\tmovs\tr3, #%d\n", mi_delta & 0xff);
> +             else if (mi_delta & 0xff)
> +               asm_fprintf (file, "\tadds\tr3, #%d\n", mi_delta & 0xff);
> +           }
> +         else
> +           {
> +             fputs ("\tldr\tr3, ", file);
> +             assemble_name (file, label);
> +             fputs ("+4\n", file);
> +           }
>           asm_fprintf (file, "\t%ss\t%r, %r, r3\n",
>                        mi_op, this_regno, this_regno);
>         }
> @@ -28380,30 +28414,37 @@ arm_thumb1_mi_thunk (FILE *file, tree, HOST_WIDE_INT delta,
>         fputs ("\tpop\t{r3}\n", file);
>
>        fprintf (file, "\tbx\tr12\n");
> -      ASM_OUTPUT_ALIGN (file, 2);
> -      assemble_name (file, label);
> -      fputs (":\n", file);
> -      if (flag_pic)
> +
> +      /* With -mpure-code, we don't need to emit literals for the
> +        function address and delta since we emitted code to build
> +        them.  */
> +      if (!target_pure_code)
>         {
> -         /* Output ".word .LTHUNKn-[3,7]-.LTHUNKPCn".  */
> -         rtx tem = XEXP (DECL_RTL (function), 0);
> -         /* For TARGET_THUMB1_ONLY the thunk is in Thumb mode, so the PC
> -            pipeline offset is four rather than eight.  Adjust the offset
> -            accordingly.  */
> -         tem = plus_constant (GET_MODE (tem), tem,
> -                              TARGET_THUMB1_ONLY ? -3 : -7);
> -         tem = gen_rtx_MINUS (GET_MODE (tem),
> -                              tem,
> -                              gen_rtx_SYMBOL_REF (Pmode,
> -                                                  ggc_strdup (labelpc)));
> -         assemble_integer (tem, 4, BITS_PER_WORD, 1);
> -       }
> -      else
> -       /* Output ".word .LTHUNKn".  */
> -       assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1);
> +         ASM_OUTPUT_ALIGN (file, 2);
> +         assemble_name (file, label);
> +         fputs (":\n", file);
> +         if (flag_pic)
> +           {
> +             /* Output ".word .LTHUNKn-[3,7]-.LTHUNKPCn".  */
> +             rtx tem = XEXP (DECL_RTL (function), 0);
> +             /* For TARGET_THUMB1_ONLY the thunk is in Thumb mode, so the PC
> +                pipeline offset is four rather than eight.  Adjust the offset
> +                accordingly.  */
> +             tem = plus_constant (GET_MODE (tem), tem,
> +                                  TARGET_THUMB1_ONLY ? -3 : -7);
> +             tem = gen_rtx_MINUS (GET_MODE (tem),
> +                                  tem,
> +                                  gen_rtx_SYMBOL_REF (Pmode,
> +                                                      ggc_strdup (labelpc)));
> +             assemble_integer (tem, 4, BITS_PER_WORD, 1);
> +           }
> +         else
> +           /* Output ".word .LTHUNKn".  */
> +           assemble_integer (XEXP (DECL_RTL (function), 0), 4, BITS_PER_WORD, 1);
>
> -      if (TARGET_THUMB1_ONLY && mi_delta > 255)
> -       assemble_integer (GEN_INT(mi_delta), 4, BITS_PER_WORD, 1);
> +         if (TARGET_THUMB1_ONLY && mi_delta > 255)
> +           assemble_integer (GEN_INT(mi_delta), 4, BITS_PER_WORD, 1);
> +       }
>      }
>    else
>      {
> --
> 2.7.4
>

  reply	other threads:[~2020-10-06  8:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 19:50 Christophe Lyon
2020-10-06  8:30 ` Christophe Lyon [this message]
2020-10-06 16:02 ` Richard Earnshaw
2020-10-08  9:07   ` Christophe Lyon
2020-10-08  9:58     ` Richard Earnshaw
2020-10-12  7:59       ` Christophe Lyon
2020-10-19 14:39         ` Richard Earnshaw
2020-10-19 16:32           ` Christophe Lyon
2020-10-20 11:22             ` Richard Earnshaw
2020-10-20 11:25               ` Richard Earnshaw
2020-10-21 15:49                 ` Christophe Lyon
2020-10-21 16:07                   ` Richard Earnshaw
2020-10-21 16:11                     ` Christophe Lyon
2020-10-21 17:36                       ` Richard Earnshaw
2020-10-22  8:45                         ` Christophe Lyon
2020-10-22 15:22                           ` Richard Earnshaw
2020-10-26 10:52                             ` Christophe Lyon
2020-10-27 15:42                               ` Richard Earnshaw
2020-10-28 17:44                                 ` Richard Earnshaw
2020-10-28 18:10                                   ` Christophe Lyon
2020-10-29 19:18                                     ` Richard Earnshaw
2020-10-30 12:49                                       ` Richard Earnshaw
2020-11-02 10:24                                         ` Christophe Lyon
2020-11-02 14:28                                           ` Richard Earnshaw

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='CAKdteOYksfkHUjQwowAUqSSD1wDXcLrugbcK_DKdS=1=_2JULA@mail.gmail.com' \
    --to=christophe.lyon@linaro.org \
    --cc=gcc-patches@gcc.gnu.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).