From: "H.J. Lu" <hjl.tools@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "Jeff Law" <law@redhat.com>,
"GCC Patches" <gcc-patches@gcc.gnu.org>,
"Uros Bizjak" <ubizjak@gmail.com>, "Jan Hubicka" <hubicka@ucw.cz>,
刘袋鼠 <crazylht@gmail.com>
Subject: Re: [PATCH] Don't insert ENDBR after NOTE_INSN_DELETED_LABEL
Date: Fri, 31 May 2019 18:26:00 -0000 [thread overview]
Message-ID: <CAMe9rOoRQ=L1=E=AzCELqzFHDXM-P81YAAvXLas8Hn19nfqd-Q@mail.gmail.com> (raw)
In-Reply-To: <20190531174300.GI19695@tucnak>
[-- Attachment #1: Type: text/plain, Size: 646 bytes --]
On Fri, May 31, 2019 at 10:43 AM Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Fri, May 31, 2019 at 09:53:42AM -0700, H.J. Lu wrote:
> > 2019-05-31 H.J. Lu <hongjiu.lu@intel.com>
> > Hongtao Liu <hongtao.liu@intel.com>
> >
> > gcc/
> >
> > PR target/89355
> > * config/i386/i386.c (ix86_init_large_pic_reg): Don't set
> > LABEL_PRESERVE_P.
>
> Why this change? It is both not needed and undesirable, the
> large pic reg label is used magically, not as a normal label, so
> LABEL_PRESERVE_P on it is desirable.
Removed.
> Otherwise LGTM.
>
> Jakub
This is the patch I am checking in.
Thanks.
--
H.J.
[-- Attachment #2: 0001-i386-Don-t-insert-ENDBR-after-NOTE_INSN_DELETED_LABE.patch --]
[-- Type: text/x-patch, Size: 3761 bytes --]
From 57c4c30a5eda286800fd6c4e0101b82d8cfb604f Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 14 Feb 2019 09:12:57 -0800
Subject: [PATCH] i386: Don't insert ENDBR after NOTE_INSN_DELETED_LABEL
NOTE_INSN_DELETED_LABEL is used to mark what used to be a 'code_label',
but was not used for other purposes than taking its address which cannot
be used as target for indirect jumps.
Tested on Linux/x86-64 with -fcf-protection.
For x86-64 libc.so on glibc master branch (commit f43b8dd55588c3),
Before: 2961 endbr64
After: 2943 endbr64
2019-05-31 H.J. Lu <hongjiu.lu@intel.com>
Hongtao Liu <hongtao.liu@intel.com>
gcc/
PR target/89355
* config/i386/i386-features.c (rest_of_insert_endbranch): Remove
NOTE_INSN_DELETED_LABEL check.
gcc/testsuite/
PR target/89355
* gcc.target/i386/cet-label-3.c: New test.
* gcc.target/i386/cet-label-4.c: Likewise.
* gcc.target/i386/cet-label-5.c: Likewise.
---
gcc/config/i386/i386-features.c | 5 +----
gcc/testsuite/gcc.target/i386/cet-label-3.c | 23 +++++++++++++++++++++
gcc/testsuite/gcc.target/i386/cet-label-4.c | 12 +++++++++++
gcc/testsuite/gcc.target/i386/cet-label-5.c | 13 ++++++++++++
4 files changed, 49 insertions(+), 4 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/cet-label-3.c
create mode 100644 gcc/testsuite/gcc.target/i386/cet-label-4.c
create mode 100644 gcc/testsuite/gcc.target/i386/cet-label-5.c
diff --git a/gcc/config/i386/i386-features.c b/gcc/config/i386/i386-features.c
index 60a120f4df7..c8de5261240 100644
--- a/gcc/config/i386/i386-features.c
+++ b/gcc/config/i386/i386-features.c
@@ -1911,10 +1911,7 @@ rest_of_insert_endbranch (void)
continue;
}
- if ((LABEL_P (insn) && LABEL_PRESERVE_P (insn))
- || (NOTE_P (insn)
- && NOTE_KIND (insn) == NOTE_INSN_DELETED_LABEL))
- /* TODO. Check /s bit also. */
+ if (LABEL_P (insn) && LABEL_PRESERVE_P (insn))
{
cet_eb = gen_nop_endbr ();
emit_insn_after (cet_eb, insn);
diff --git a/gcc/testsuite/gcc.target/i386/cet-label-3.c b/gcc/testsuite/gcc.target/i386/cet-label-3.c
new file mode 100644
index 00000000000..9f427a866f3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/cet-label-3.c
@@ -0,0 +1,23 @@
+/* PR target/89355 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection" } */
+/* { dg-final { scan-assembler-times "endbr32" 1 { target ia32 } } } */
+/* { dg-final { scan-assembler-times "endbr64" 1 { target { ! ia32 } } } } */
+int
+test (int* val)
+{
+ int status = 99;
+
+ if (!val)
+ {
+ status = 22;
+ goto end;
+ }
+
+ extern int x;
+ *val = x;
+
+ status = 0;
+end:
+ return status;
+}
diff --git a/gcc/testsuite/gcc.target/i386/cet-label-4.c b/gcc/testsuite/gcc.target/i386/cet-label-4.c
new file mode 100644
index 00000000000..d743d2bf202
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/cet-label-4.c
@@ -0,0 +1,12 @@
+/* PR target/89355 */
+/* { dg-do compile { target { fpic && lp64 } } } */
+/* { dg-options "-O2 -fcf-protection -fPIC -mcmodel=large" } */
+/* { dg-final { scan-assembler-times "endbr64" 1 } } */
+
+extern int val;
+
+int
+test (void)
+{
+ return val;
+}
diff --git a/gcc/testsuite/gcc.target/i386/cet-label-5.c b/gcc/testsuite/gcc.target/i386/cet-label-5.c
new file mode 100644
index 00000000000..862c79b058d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/cet-label-5.c
@@ -0,0 +1,13 @@
+/* PR target/89355 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection -Wno-return-local-addr" } */
+/* { dg-final { scan-assembler-times "endbr32" 1 { target ia32 } } } */
+/* { dg-final { scan-assembler-times "endbr64" 1 { target { ! ia32 } } } } */
+
+void *
+func (void)
+{
+ return &&bar;
+bar:
+ return 0;
+}
--
2.20.1
prev parent reply other threads:[~2019-05-31 18:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-15 4:13 [PATCH] i386: Insert ENDBR for NOTE_INSN_DELETED_LABEL only if needed H.J. Lu
2019-02-16 15:02 ` V2 " H.J. Lu
2019-05-21 21:48 ` PING^1: " H.J. Lu
2019-05-28 7:21 ` Uros Bizjak
2019-05-28 9:22 ` Jakub Jelinek
2019-05-28 15:16 ` H.J. Lu
2019-05-28 15:31 ` Jakub Jelinek
2019-05-28 15:34 ` H.J. Lu
2019-05-28 16:11 ` Jakub Jelinek
2019-05-28 17:37 ` Jeff Law
2019-05-31 17:39 ` [PATCH] Don't insert ENDBR after NOTE_INSN_DELETED_LABEL H.J. Lu
2019-05-31 18:03 ` Jakub Jelinek
2019-05-31 18:26 ` H.J. Lu [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='CAMe9rOoRQ=L1=E=AzCELqzFHDXM-P81YAAvXLas8Hn19nfqd-Q@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=crazylht@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hubicka@ucw.cz \
--cc=jakub@redhat.com \
--cc=law@redhat.com \
--cc=ubizjak@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).