On Thu, Jul 19, 2018 at 10:35:27AM +0200, Richard Biener wrote: > On Wed, Jul 18, 2018 at 5:33 PM H.J. Lu <hongjiu...@intel.com> wrote: > > > > In > > > > struct ucontext; > > typedef struct ucontext ucontext_t; > > > > extern int (*bar) (ucontext_t *__restrict __oucp, > > const ucontext_t *__restrict __ucp) > > __attribute__((__indirect_return__)); > > > > extern int res; > > > > void > > foo (ucontext_t *oucp, ucontext_t *ucp) > > { > > res = bar (oucp, ucp); > > } > > > > bar() may return via indirect branch. This patch changes indirect_return > > to type attribute to allow indirect_return attribute on variable or type > > of function pointer so that ENDBR can be inserted after call to bar(). > > > > Tested on i386 and x86-64. OK for trunk? > > OK. >
The new indirect_return attribute is intended to mark swapcontext in <ucontext.h>. This patch defines __HAVE_INDIRECT_RETURN_ATTRIBUTE__ so that it can be used checked before using indirect_return attribute in <ucontext.h>. It works when the indirect_return attribute is backported to GCC 8. OK for trunk? Thanks. H.J. --- gcc/ PR target/86560 * config/i386/i386-c.c (ix86_target_macros): Define __HAVE_INDIRECT_RETURN_ATTRIBUTE__. gcc/testsuite/ PR target/86560 * gcc.target/i386/pr86560-4.c: New test. --- gcc/config/i386/i386-c.c | 2 ++ gcc/testsuite/gcc.target/i386/pr86560-4.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr86560-4.c diff --git a/gcc/config/i386/i386-c.c b/gcc/config/i386/i386-c.c index 005e1a5b308..041d47c3ee6 100644 --- a/gcc/config/i386/i386-c.c +++ b/gcc/config/i386/i386-c.c @@ -695,6 +695,8 @@ ix86_target_macros (void) if (flag_cf_protection != CF_NONE) cpp_define_formatted (parse_in, "__CET__=%d", flag_cf_protection & ~CF_SET); + + cpp_define (parse_in, "__HAVE_INDIRECT_RETURN_ATTRIBUTE__"); } diff --git a/gcc/testsuite/gcc.target/i386/pr86560-4.c b/gcc/testsuite/gcc.target/i386/pr86560-4.c new file mode 100644 index 00000000000..46ea923fdfc --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr86560-4.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcf-protection" } */ +/* { dg-final { scan-assembler-times {\mendbr} 2 } } */ + +struct ucontext; + +extern int (*bar) (struct ucontext *) +#ifdef __HAVE_INDIRECT_RETURN_ATTRIBUTE__ + __attribute__((__indirect_return__)) +#endif +; + +extern int res; + +void +foo (struct ucontext *oucp) +{ + res = bar (oucp); +} -- 2.17.1