i386: Don't insert ENDBR after NOTE_INSN_DELETED_LABEL
authorH.J. Lu <hongjiu.lu@intel.com>
Fri, 31 May 2019 23:59:16 +0000 (23:59 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Fri, 31 May 2019 23:59:16 +0000 (16:59 -0700)
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

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.

Co-Authored-By: Hongtao Liu <hongtao.liu@intel.com>
From-SVN: r271828

gcc/ChangeLog
gcc/config/i386/i386-features.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/cet-label-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cet-label-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cet-label-5.c [new file with mode: 0644]

index e0a6acefdf0ac0de0687787e5aebe34654baa12e..a1e8127e9e9130b949184ce5518938fb550eafb2 100644 (file)
@@ -1,3 +1,10 @@
+2019-05-31  H.J. Lu  <hongjiu.lu@intel.com>
+           Hongtao Liu  <hongtao.liu@intel.com>
+
+       PR target/89355
+       * config/i386/i386-features.c (rest_of_insert_endbranch): Remove
+       NOTE_INSN_DELETED_LABEL check.
+
 2019-05-31  Prachi Godbole  <prachi.godbole@imgtec.com>
             Robert Suchanek  <robert.suchanek@mips.com>
 
index 60a120f4df7bc384edf9dd6cf9f54bfe392180c6..c8de5261240cc3c71f7969d58e3a76a8633e6a00 100644 (file)
@@ -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);
index e39b064a41aa8a56f7bdfcc8f1b458aec3bbc592..04fb8bc55606490df42c2bd2eb6b603726f2ecf8 100644 (file)
@@ -1,3 +1,10 @@
+2019-05-31  H.J. Lu  <hongjiu.lu@intel.com>
+
+       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.
+
 2019-05-31  Dragan Mladjenovic  <dmladjenovic@wavecomp.com>
 
        * gcc.target/mips/msa-fmadd.c: New.
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 (file)
index 0000000..9f427a8
--- /dev/null
@@ -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 (file)
index 0000000..d743d2b
--- /dev/null
@@ -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 (file)
index 0000000..862c79b
--- /dev/null
@@ -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;
+}