public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] x86: Insert ENDBR if function will be called indirectly
@ 2020-09-17 16:56 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 16:56 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:9512d6d3e391f9ce1dd0ac032549831b50668ce7
commit 9512d6d3e391f9ce1dd0ac032549831b50668ce7
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Fri Apr 17 15:23:27 2020 -0700
x86: Insert ENDBR if function will be called indirectly
Since constant_call_address_operand has
;; Test for a pc-relative call operand
(define_predicate "constant_call_address_operand"
(match_code "symbol_ref")
{
if (ix86_cmodel == CM_LARGE || ix86_cmodel == CM_LARGE_PIC
|| flag_force_indirect_call)
return false;
if (TARGET_DLLIMPORT_DECL_ATTRIBUTES && SYMBOL_REF_DLLIMPORT_P (op))
return false;
return true;
})
even if cgraph_node::get (cfun->decl)->only_called_directly_p () returns
false, the fuction may still be called indirectly. Copy the logic from
constant_call_address_operand to rest_of_insert_endbranch to insert ENDBR
at function entry if function will be called indirectly.
NB: gcc.target/i386/pr94417-2.c is updated to expect 4 ENDBRs, instead
of 2, since only GCC 10 has the fix for PR target/89355 not to insert
ENDBR after NOTE_INSN_DELETED_LABEL.
gcc/
Backport from master
PR target/94417
* config/i386/i386.c (rest_of_insert_endbranch): Insert ENDBR at
function entry if function will be called indirectly.
gcc/testsuite/
Backport from master
PR target/94417
* gcc.target/i386/pr94417-1.c: New test.
* gcc.target/i386/pr94417-2.c: Likewise.
* gcc.target/i386/pr94417-3.c: Likewise.
(cherry picked from commit c5f379653964a1d2c7037b2de3e947a48370a198)
Diff:
---
gcc/ChangeLog | 9 +++++++++
gcc/config/i386/i386.c | 7 ++++++-
gcc/testsuite/ChangeLog | 10 ++++++++++
gcc/testsuite/gcc.target/i386/pr94417-1.c | 20 ++++++++++++++++++++
gcc/testsuite/gcc.target/i386/pr94417-2.c | 21 +++++++++++++++++++++
gcc/testsuite/gcc.target/i386/pr94417-3.c | 19 +++++++++++++++++++
6 files changed, 85 insertions(+), 1 deletion(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7ff901cd82e..6027b27b68f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2020-04-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2020-04-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/94417
+ * config/i386/i386.c (rest_of_insert_endbranch): Insert ENDBR at
+ function entry if function will be called indirectly.
+
2020-04-15 Uroš Bizjak <ubizjak@gmail.com>
PR target/94603
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 13943ebf800..89a38f25470 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -2498,7 +2498,12 @@ rest_of_insert_endbranch (void)
if (!lookup_attribute ("nocf_check",
TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl)))
- && !cgraph_node::get (cfun->decl)->only_called_directly_p ())
+ && (!cgraph_node::get (cfun->decl)->only_called_directly_p ()
+ || ix86_cmodel == CM_LARGE
+ || ix86_cmodel == CM_LARGE_PIC
+ || flag_force_indirect_call
+ || (TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ && DECL_DLLIMPORT_P (cfun->decl))))
{
/* Queue ENDBR insertion to x86_function_profiler. */
if (crtl->profile && flag_fentry)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a90697f4c8f..f3e3f5d6142 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2020-04-17 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2020-04-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/94417
+ * gcc.target/i386/pr94417-1.c: New test.
+ * gcc.target/i386/pr94417-2.c: Likewise.
+ * gcc.target/i386/pr94417-3.c: Likewise.
+
2020-04-15 Uroš Bizjak <ubizjak@gmail.com>
PR target/94603
diff --git a/gcc/testsuite/gcc.target/i386/pr94417-1.c b/gcc/testsuite/gcc.target/i386/pr94417-1.c
new file mode 100644
index 00000000000..5bbe057fa8f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr94417-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-options "-O2 -fcf-protection -mcmodel=large" } */
+/* { dg-final { scan-assembler-times {\mendbr} 2 } } */
+
+extern void ext (void);
+
+__attribute((noclone, noinline))
+static
+void
+foo (void)
+{
+ ext ();
+}
+
+void
+bar (void)
+{
+ foo ();
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr94417-2.c b/gcc/testsuite/gcc.target/i386/pr94417-2.c
new file mode 100644
index 00000000000..9e9c277e07f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr94417-2.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target lp64 } */
+/* { dg-require-effective-target fpic } */
+/* { dg-options "-O2 -fpic -mcmodel=large -fcf-protection" } */
+/* { dg-final { scan-assembler-times {\mendbr} 4 } } */
+
+extern void ext (void);
+
+__attribute((noclone, noinline))
+static
+void
+foo (void)
+{
+ ext ();
+}
+
+void
+bar (void)
+{
+ foo ();
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr94417-3.c b/gcc/testsuite/gcc.target/i386/pr94417-3.c
new file mode 100644
index 00000000000..07c451796c2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr94417-3.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection -mforce-indirect-call" } */
+/* { dg-final { scan-assembler-times {\mendbr} 2 } } */
+
+extern void ext (void);
+
+__attribute((noclone, noinline))
+static
+void
+foo (void)
+{
+ ext ();
+}
+
+void
+bar (void)
+{
+ foo ();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-17 16:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 16:56 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] x86: Insert ENDBR if function will be called indirectly Jakub Jelinek
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).