From eb74a883e812fc1a05fbf9cfa572043c4ee5af39 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 21 Feb 2019 13:41:53 +0000 Subject: [PATCH] i386: Check -mindirect-branch/-mfunction-return with -fcf-protection Issue an error when -mindirect-branch or -mfunction-return are used with incompatible -fcf-protection. gcc/ PR target/87412 * config/i386/i386.c (ix86_set_indirect_branch_type): Issue an error for -mindirect-branch/-mfunction-return with incompatible -fcf-protection. gcc/testsuite/ PR target/87412 * gcc.target/i386/pr87412-1.c: New file. * gcc.target/i386/pr87412-2.c: Likewise. * gcc.target/i386/pr87412-3.c: Likewise. * gcc.target/i386/pr87412-4.c: Likewise. From-SVN: r269068 --- gcc/ChangeLog | 7 +++++++ gcc/config/i386/i386.c | 10 ++++++++++ gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/gcc.target/i386/pr87412-1.c | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr87412-2.c | 10 ++++++++++ gcc/testsuite/gcc.target/i386/pr87412-3.c | 9 +++++++++ gcc/testsuite/gcc.target/i386/pr87412-4.c | 7 +++++++ 7 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr87412-4.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 46c918b1666..82890730e1c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-02-21 H.J. Lu + + PR target/87412 + * config/i386/i386.c (ix86_set_indirect_branch_type): Issue an + error for -mindirect-branch/-mfunction-return with incompatible + -fcf-protection. + 2019-02-21 Jakub Jelinek PR bootstrap/88714 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index a58ddca3fab..81dfed12837 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -5667,6 +5667,11 @@ ix86_set_indirect_branch_type (tree fndecl) ((cfun->machine->indirect_branch_type == indirect_branch_thunk_extern) ? "thunk-extern" : "thunk")); + + if (cfun->machine->indirect_branch_type != indirect_branch_keep + && (flag_cf_protection & CF_RETURN)) + error ("%<-mindirect-branch%> and %<-fcf-protection%> are not " + "compatible"); } if (cfun->machine->function_return_type == indirect_branch_unset) @@ -5705,6 +5710,11 @@ ix86_set_indirect_branch_type (tree fndecl) ((cfun->machine->function_return_type == indirect_branch_thunk_extern) ? "thunk-extern" : "thunk")); + + if (cfun->machine->function_return_type != indirect_branch_keep + && (flag_cf_protection & CF_RETURN)) + error ("%<-mfunction-return%> and %<-fcf-protection%> are not " + "compatible"); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2068a41ed7f..138d6034f49 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2019-02-21 H.J. Lu + + PR target/87412 + * gcc.target/i386/pr87412-1.c: New file. + * gcc.target/i386/pr87412-2.c: Likewise. + * gcc.target/i386/pr87412-3.c: Likewise. + * gcc.target/i386/pr87412-4.c: Likewise. + 2019-02-20 Jakub Jelinek PR c++/89403 diff --git a/gcc/testsuite/gcc.target/i386/pr87412-1.c b/gcc/testsuite/gcc.target/i386/pr87412-1.c new file mode 100644 index 00000000000..e04f1fbe96c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection -mfunction-return=thunk -mindirect-branch=thunk" } */ + +void +bar (void) +{ +/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */ +/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr87412-2.c b/gcc/testsuite/gcc.target/i386/pr87412-2.c new file mode 100644 index 00000000000..33a9e8aed4e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection -mfunction-return=keep -mindirect-branch=keep" } */ + +void + __attribute__ ((indirect_branch("thunk"), function_return("thunk"))) +bar (void) +{ +/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */ +/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr87412-3.c b/gcc/testsuite/gcc.target/i386/pr87412-3.c new file mode 100644 index 00000000000..e67d727d871 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-3.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection=return -mfunction-return=thunk -mindirect-branch=thunk" } */ + +void +bar (void) +{ +/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */ +/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */ +} diff --git a/gcc/testsuite/gcc.target/i386/pr87412-4.c b/gcc/testsuite/gcc.target/i386/pr87412-4.c new file mode 100644 index 00000000000..f90d2f2fe8e --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr87412-4.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection=branch -mfunction-return=thunk -mindirect-branch=thunk" } */ + +void +bar (void) +{ +} -- 2.30.2