public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] x86: Disable -mforce-indirect-call for PIC in 32-bit mode
Date: Mon, 16 Jan 2023 21:02:18 +0100	[thread overview]
Message-ID: <CAFULd4Zq5oXdSOOVRR6SUFpSeyx_OpzxSTsahKG+OytHSAifNA@mail.gmail.com> (raw)
In-Reply-To: <20230116185633.159901-1-hjl.tools@gmail.com>

On Mon, Jan 16, 2023 at 7:56 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> -mforce-indirect-call generates invalid instruction in 32-bit MI thunk
> since there are no available scratch registers in 32-bit PIC mode.
> Disable -mforce-indirect-call for PIC in 32-bit mode when generating
> MI thunk.
>
> gcc/
>
>         PR target/105980
>         * config/i386/i386.cc (x86_output_mi_thunk): Disable
>         -mforce-indirect-call for PIC in 32-bit mode.
>
> gcc/testsuite/
>
>         PR target/105980
>         * g++.target/i386/pr105980.C: New test.

OK.

Thanks,
Uros.

> ---
>  gcc/config/i386/i386.cc                  | 6 ++++++
>  gcc/testsuite/g++.target/i386/pr105980.C | 8 ++++++++
>  2 files changed, 14 insertions(+)
>  create mode 100644 gcc/testsuite/g++.target/i386/pr105980.C
>
> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
> index 19fb03cfd44..3cacf738c4a 100644
> --- a/gcc/config/i386/i386.cc
> +++ b/gcc/config/i386/i386.cc
> @@ -21480,6 +21480,7 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
>    rtx this_reg, tmp, fnaddr;
>    unsigned int tmp_regno;
>    rtx_insn *insn;
> +  int saved_flag_force_indirect_call = flag_force_indirect_call;
>
>    if (TARGET_64BIT)
>      tmp_regno = R10_REG;
> @@ -21492,6 +21493,9 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
>         tmp_regno = DX_REG;
>        else
>         tmp_regno = CX_REG;
> +
> +      if (flag_pic)
> +  flag_force_indirect_call = 0;
>      }
>
>    emit_note (NOTE_INSN_PROLOGUE_END);
> @@ -21659,6 +21663,8 @@ x86_output_mi_thunk (FILE *file, tree thunk_fndecl, HOST_WIDE_INT delta,
>    final (insn, file, 1);
>    final_end_function ();
>    assemble_end_function (thunk_fndecl, fnname);
> +
> +  flag_force_indirect_call = saved_flag_force_indirect_call;
>  }
>
>  static void
> diff --git a/gcc/testsuite/g++.target/i386/pr105980.C b/gcc/testsuite/g++.target/i386/pr105980.C
> new file mode 100644
> index 00000000000..d8dbc332ea2
> --- /dev/null
> +++ b/gcc/testsuite/g++.target/i386/pr105980.C
> @@ -0,0 +1,8 @@
> +// { dg-do assemble { target { fpic } } }
> +// { dg-options "-O0 -fpic -mforce-indirect-call" }
> +
> +struct A {
> +  virtual ~A();
> +};
> +struct B : virtual A {};
> +void bar() { B(); }
> --
> 2.39.0
>

      reply	other threads:[~2023-01-16 20:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-16 18:56 H.J. Lu
2023-01-16 20:02 ` Uros Bizjak [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=CAFULd4Zq5oXdSOOVRR6SUFpSeyx_OpzxSTsahKG+OytHSAifNA@mail.gmail.com \
    --to=ubizjak@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hjl.tools@gmail.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).