public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "andrew.cooper3 at citrix dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108799] New: Improper deprecation diagnostic for rsp clobber Date: Wed, 15 Feb 2023 10:28:43 +0000 [thread overview] Message-ID: <bug-108799-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108799 Bug ID: 108799 Summary: Improper deprecation diagnostic for rsp clobber Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: andrew.cooper3 at citrix dot com Target Milestone: --- Originally from LKML. https://lore.kernel.org/lkml/Y9LfmQ%2Fr1%2FpEP+uv@biznet-home.integral.gnuweeb.org/ Slightly modified example: https://godbolt.org/z/xx76nEvKM Given: static void clobber_redzone_buggy(void) { register unsigned long rsp asm("rsp"); unsigned long fl; asm volatile ("pushf; popq %[fl]" : [fl] "=r" (fl) , "+r" (rsp) : : //"rsp" ); } static void set_red_zone(long *mem, long val) { __asm__ volatile ("movq %[val], %[mem]" : [mem] "=m" (*mem) : [val] "r" (val)); } static long get_red_zone(long *mem) { long ret; __asm__ volatile ("movq %[in], %[out]" : [out] "=r" (ret) : [in] "m" (*mem)); return ret; } long a_leaf_func_with_red_zone(void) { long x; set_red_zone(&x, 1); clobber_redzone_buggy(); /* The correct retval is 1 */ return get_red_zone(&x); } gcc generates: a_leaf_func_with_red_zone: movl $1, %eax movq %rax, -8(%rsp) pushf popq %rax movq -8(%rsp), %rax ret which is buggy because the asm clobbers the same redzone slot as `x` occupies. Swapping the "+r"(rsp) constraint for an explicit "rsp" clobber generates: a_leaf_func_with_red_zone: pushq %rbp movl $1, %eax movq %rsp, %rbp subq $16, %rsp movq %rax, -8(%rbp) pushf popq %rax movq -8(%rbp), %rax leave ret which seems to do the right thing. It sets up a full stack frame and avoids using the redzone. However, doing so yields: warning: listing the stack pointer register 'rsp' in a clobber list is deprecated [-Wdeprecated] note: the value of the stack pointer after an 'asm' statement must be the same as it was before the statement The note is incorrect. For ABIs with a redzone, the requirement is stricter than simply preserving the value of the stack pointer. The warning suggests that there ought to be a different way to express "this clobbers the redzone", but there doesn't appear to be any other way. If this is the case, why is it deprecated?
next reply other threads:[~2023-02-15 10:28 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-15 10:28 andrew.cooper3 at citrix dot com [this message] 2023-02-15 17:55 ` [Bug middle-end/108799] " pinskia at gcc dot gnu.org 2023-02-15 18:03 ` andrew.cooper3 at citrix dot com 2023-04-01 13:32 ` pskocik at gmail dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-108799-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).