On Wed, Sep 16, 2020 at 4:47 AM Jakub Jelinek <ja...@redhat.com> wrote: > > On Wed, Sep 16, 2020 at 12:34:50PM +0100, Richard Sandiford wrote: > > Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > > > On Mon, Sep 14, 2020 at 08:57:18AM -0700, H.J. Lu via Gcc-patches wrote: > > >> Something like this for GCC 8 and 9. > > > > > > Guess my preference would be to do this everywhere and then let's discuss > > > if > > > we change the warning into error there or keep it being deprecated. > > > > Agreed FWIW. On turning it into an error: I think it might be better > > to wait a bit longer if we can. > > Ok. The patch is ok for trunk and affected release branches after a week. >
I cherry-picked it to GCC 9 and 10 branches. GCC 8 needs some changes. I am enclosing the backported patch for GCC 8. I will check it in if there are no regressions on Linux/x86-64. Thanks. H.J.
From 97c34eb5f57bb1d37f3feddefefa5f553bcea9fc Mon Sep 17 00:00:00 2001 From: "H.J. Lu" <hjl.to...@gmail.com> Date: Mon, 14 Sep 2020 08:52:27 -0700 Subject: [PATCH] rtl_data: Add sp_is_clobbered_by_asm Add sp_is_clobbered_by_asm to rtl_data to inform backends that the stack pointer is clobbered by asm statement. gcc/ PR target/97032 * cfgexpand.c (expand_asm_stmt): Set sp_is_clobbered_by_asm to true if the stack pointer is clobbered by asm statement. * emit-rtl.h (rtl_data): Add sp_is_clobbered_by_asm. * config/i386/i386.c (ix86_get_drap_rtx): Set need_drap to true if the stack pointer is clobbered by asm statement. gcc/testsuite/ PR target/97032 * gcc.target/i386/pr97032.c: New test. (cherry picked from commit 453a20c65722719b9e2d84339f215e7ec87692dc) --- gcc/cfgexpand.c | 3 +++ gcc/config/i386/i386.c | 6 ++++-- gcc/emit-rtl.h | 3 +++ gcc/testsuite/gcc.target/i386/pr97032.c | 22 ++++++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr97032.c diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 18565bf1dab..dcf491954f1 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -2972,6 +2972,9 @@ expand_asm_stmt (gasm *stmt) regname); return; } + /* Clobbering the stack pointer register. */ + else if (reg == (int) STACK_POINTER_REGNUM) + crtl->sp_is_clobbered_by_asm = true; SET_HARD_REG_BIT (clobbered_regs, reg); rtx x = gen_rtx_REG (reg_raw_mode[reg], reg); diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index f3c722b51e9..ce20bc2ab4e 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -12528,10 +12528,12 @@ ix86_update_stack_boundary (void) static rtx ix86_get_drap_rtx (void) { - /* We must use DRAP if there are outgoing arguments on stack and + /* We must use DRAP if there are outgoing arguments on stack or + the stack pointer register is clobbered by asm statment and ACCUMULATE_OUTGOING_ARGS is false. */ if (ix86_force_drap - || (cfun->machine->outgoing_args_on_stack + || ((cfun->machine->outgoing_args_on_stack + || crtl->sp_is_clobbered_by_asm) && !ACCUMULATE_OUTGOING_ARGS)) crtl->need_drap = true; diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h index 4e7bd1ec26d..55dc3e84e9c 100644 --- a/gcc/emit-rtl.h +++ b/gcc/emit-rtl.h @@ -265,6 +265,9 @@ struct GTY(()) rtl_data { pass_stack_ptr_mod has run. */ bool sp_is_unchanging; + /* True if the stack pointer is clobbered by asm statement. */ + bool sp_is_clobbered_by_asm; + /* Nonzero if function being compiled doesn't contain any calls (ignoring the prologue and epilogue). This is set prior to register allocation in IRA and is valid for the remaining diff --git a/gcc/testsuite/gcc.target/i386/pr97032.c b/gcc/testsuite/gcc.target/i386/pr97032.c new file mode 100644 index 00000000000..b9ef2ad0c05 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr97032.c @@ -0,0 +1,22 @@ +/* { dg-do compile { target { ia32 && fstack_protector } } } */ +/* { dg-options "-O2 -mincoming-stack-boundary=2 -fstack-protector-all" } */ + +#include <stdarg.h> + +extern int *__errno_location (void); + +long +sys_socketcall (int op, ...) +{ + long int res; + va_list ap; + va_start (ap, op); + asm volatile ("push %%ebx; movl %2, %%ebx; int $0x80; pop %%ebx" + : "=a" (res) : "0" (102), "ri" (16), "c" (ap) : "memory", "esp"); + if (__builtin_expect (res > 4294963200UL, 0)) + *__errno_location () = -res; + va_end (ap); + return res; +} + +/* { dg-final { scan-assembler "call\[ \t\]*_?__errno_location" } } */ -- 2.26.2