aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-04-08 09:47:35 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-04-08 09:47:53 -0700
commitc5f379653964a1d2c7037b2de3e947a48370a198 (patch)
tree4c8c0f81228ae562527397802e41a9d0d02e4931 /gcc
parent8bf5faa9c463f0d53ffe835ba03d4502edfb959d (diff)
downloadgcc-c5f379653964a1d2c7037b2de3e947a48370a198.zip
gcc-c5f379653964a1d2c7037b2de3e947a48370a198.tar.gz
gcc-c5f379653964a1d2c7037b2de3e947a48370a198.tar.bz2
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. gcc/ PR target/94417 * config/i386/i386-features.c (rest_of_insert_endbranch): Insert ENDBR at function entry if function will be called indirectly. gcc/testsuite/ 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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/config/i386/i386-features.c7
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.target/i386/pr94417-1.c20
-rw-r--r--gcc/testsuite/gcc.target/i386/pr94417-2.c21
-rw-r--r--gcc/testsuite/gcc.target/i386/pr94417-3.c19
6 files changed, 79 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ec97a1e..ffa8930 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-04-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/94417
+ * config/i386/i386-features.c (rest_of_insert_endbranch): Insert
+ ENDBR at function entry if function will be called indirectly.
+
2020-04-08 Jakub Jelinek <jakub@redhat.com>
PR target/94438
diff --git a/gcc/config/i386/i386-features.c b/gcc/config/i386/i386-features.c
index 66b120d..78fb373 100644
--- a/gcc/config/i386/i386-features.c
+++ b/gcc/config/i386/i386-features.c
@@ -1963,7 +1963,12 @@ rest_of_insert_endbranch (void)
&& (!flag_manual_endbr
|| lookup_attribute ("cf_check",
DECL_ATTRIBUTES (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 e3600e0..e8305cb 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+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-08 Jakub Jelinek <jakub@redhat.com>
PR target/94438
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 0000000..5bbe057
--- /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 0000000..9eb0f5b
--- /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} 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-3.c b/gcc/testsuite/gcc.target/i386/pr94417-3.c
new file mode 100644
index 0000000..07c4517
--- /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 ();
+}