From: Uros Bizjak <ubizjak@gmail.com>
To: Hongtao Liu <crazylht@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>, "H. J. Lu" <hjl.tools@gmail.com>
Subject: Re: [PATCH] [PR target/96350]Force ENDBR immediate into memory to avoid fake ENDBR opcode.
Date: Fri, 14 Aug 2020 12:03:46 +0200 [thread overview]
Message-ID: <CAFULd4Z+1kQNMJiGJL8-zzf+pJKWh1WMv-UKdHu0Vi91yWQPoA@mail.gmail.com> (raw)
In-Reply-To: <CAMZc-bwSzN7ebWdO=C=XVOhRUS4zYM99VT1TPqcjKPSWmBwaeg@mail.gmail.com>
On Fri, Aug 14, 2020 at 6:54 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Tue, Aug 11, 2020 at 5:56 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > On Tue, Aug 11, 2020 at 11:36 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Tue, Aug 11, 2020 at 4:38 PM Uros Bizjak <ubizjak@gmail.com> wrote:
> > > >
> > > > On Tue, Aug 11, 2020 at 5:30 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > > > >
> > > > > Hi:
> > > > > The issue is described in the bugzilla.
> > > > > Bootstrap is ok, regression test for i386/x86-64 backend is ok.
> > > > > Ok for trunk?
> > > > >
> > > > > ChangeLog
> > > > > gcc/
> > > > > PR target/96350
> > > > > * config/i386/i386.c (ix86_legitimate_constant_p): Return
> > > > > false for ENDBR immediate.
> > > > > (ix86_legitimate_address_p): Ditto.
> > > > > * config/i386/predicated.md
> > > > > (x86_64_immediate_operand): Exclude ENDBR immediate.
> > > > > (x86_64_zext_immediate_operand): Ditto.
> > > > > (x86_64_dwzext_immediate_operand): Ditto.
> > > > > (ix86_not_endbr_immediate_operand): New predicate.
> > > > >
> > > > > gcc/testsuite
> > > > > * gcc.target/i386/endbr_immediate.c: New test.
> > > >
> > > > +;; Return true if VALUE isn't an ENDBR opcode in immediate field.
> > > > +(define_predicate "ix86_not_endbr_immediate_operand"
> > > > + (match_test "1")
> > > >
> > > > Please reverse the above logic to introduce
> > > > ix86_endbr_immediate_operand, that returns true for unwanted
> > > > immediate. Something like:
> > > >
> > > > (define_predicate "ix86_endbr_immediate_operand"
> > > > (match_code "const_int")
> > > > ...
> > > >
> > > > And you will be able to use it like:
> > > >
> > > > if (ix86_endbr_immediate_operand (x, VOIDmode)
> > > > return false;
> > > >
> > >
> > > Changed.
> >
> > No, it is not.
> >
> > + if ((flag_cf_protection & CF_BRANCH)
> > + && CONST_INT_P (op))
> >
> > You don't need to check for const ints here.
> >
> > And please rewrite the body of the function to something like (untested):
> >
> > {
> > unsigned HOST_WIDE_INT val = TARGET_64BIT ? 0xfa1e0ff3 : 0xfb1e0ff3;
> >
> > if (x == val)
> > return 1;
> >
> > if (TARGET_64BIT)
> > for (; x >= val; x >>= 8)
> > if (x == val)
> > return 1;
> >
> > return 0;
> > }
> >
> > so it will at least *look* like some thoughts have been spent on this.
> > I don't plan to review the code where it is obvious from the first
> > look that it was thrown together in a hurry. Please get some internal
> > company signoff first. Ping me in a week for a review.
> >
>
> Sorry for the hurry, i know your time is precious.
>
> > Uros.
> > >
> > > > /* Otherwise we handle everything else in the move patterns. */
> > > > - return true;
> > > > + return ix86_not_endbr_immediate_operand (x, VOIDmode);
> > > > }
> > > >
> > > > Please handle this in CASE_CONST_SCALAR_INT: part.
> > > >
> > > > + if (disp && !ix86_not_endbr_immediate_operand (disp, VOIDmode))
> > > > + return false;
> > > >
> > > > And this in:
> > > >
> > > > /* Validate displacement. */
> > > > if (disp)
> > > > {
> > > >
> > >
> > > Changed.
> >
> > A better place for these new special cases is at the beginning of the
> > part I referred, not at the end.
> >
>
> Yes.
>
> > Uros.
>
> Update patch.
OK with two nits below.
Thanks,
Uros.
+ if (flag_cf_protection & CF_BRANCH)
+ {
+ unsigned HOST_WIDE_INT imm = INTVAL (op);
UINTVAL, just for the consistency.
+ unsigned HOST_WIDE_INT val = TARGET_64BIT ? 0xfa1e0ff3 : 0xfb1e0ff3;
@@ -374,6 +402,8 @@
(define_predicate "x86_64_dwzext_immediate_operand"
(match_code "const_int,const_wide_int")
{
+ if (ix86_endbr_immediate_operand (op, VOIDmode))
+ return false;
vertical space here.
switch (GET_CODE (op))
>
> --
> BR,
> Hongtao
prev parent reply other threads:[~2020-08-14 10:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-11 3:31 Hongtao Liu
2020-08-11 8:38 ` Uros Bizjak
2020-08-11 9:36 ` Hongtao Liu
2020-08-11 9:56 ` Uros Bizjak
2020-08-14 4:54 ` Hongtao Liu
2020-08-14 10:03 ` 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=CAFULd4Z+1kQNMJiGJL8-zzf+pJKWh1WMv-UKdHu0Vi91yWQPoA@mail.gmail.com \
--to=ubizjak@gmail.com \
--cc=crazylht@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).