From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Jakub Jelinek <jakub@redhat.com>, Dimitar Dimitrov <dimitar@dinux.eu>
Cc: Segher Boessenkool <segher@kernel.crashing.org>,
Christophe Lyon <christophe.lyon@linaro.org>,
Thomas Preudhomme <thomas.preudhomme@linaro.org>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
Richard Sandiford <rdsandiford@googlemail.com>
Subject: Re: [PATCH] [RFC] PR target/52813 and target/11807
Date: Mon, 07 Jan 2019 21:51:00 -0000 [thread overview]
Message-ID: <AM6PR07MB5608D7EC0B184E1B3FC17242E4890@AM6PR07MB5608.eurprd07.prod.outlook.com> (raw)
In-Reply-To: <20190107092337.GM30353@tucnak>
[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]
On 1/7/19 10:23 AM, Jakub Jelinek wrote:
> On Sun, Dec 16, 2018 at 06:13:57PM +0200, Dimitar Dimitrov wrote:
>> - /* Clobbering the STACK POINTER register is an error. */
>> + /* Clobbered STACK POINTER register is not saved/restored by GCC,
>> + which is often unexpected by users. See PR52813. */
>> if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
>> {
>> - error ("Stack Pointer register clobbered by %qs in %<asm%>", regname);
>> + warning (0, "Stack Pointer register clobbered by %qs in %<asm%>",
>> + regname);
>> + warning (0, "GCC has always ignored Stack Pointer %<asm%> clobbers");
>
> Why do we write Stack Pointer rather than stack pointer? That is really
> weird. The second warning would be a note based on the first one, i.e.
> if (warning ()) note ();
> and better have some -W* option to silence the warning.
>
Yes, thanks for this suggestion.
Meanwhile I found out, that the stack clobber has only been ignored up to
gcc-5 (at least with lra targets, not really sure about reload targets).
From gcc-6 on, with the exception of PR arm/77904 which was a regression due
to the underlying lra change, but fixed later, and back-ported to gcc-6.3.0,
this works for all targets I tried so far.
To me, it starts to look like a rather unique and useful feature, that I would
like to keep working.
Attached is an updated version if my patch, using the suggested warning option,
and a note with the details.
Bootstrapped on x86_64-pc-linux-gnu.
Is it OK for trunk?
Thanks
Bernd.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-pr52813.diff --]
[-- Type: text/x-patch; name="patch-pr52813.diff", Size: 5703 bytes --]
2018-01-07 Bernd Edlinger <bernd.edlinger@hotmail.de>
* doc/invoke.texi: Document -Wstack-clobber.
* common.opt (-Wstack-clobber): New default-enabled warning.
* cfgexpand.c (asm_clobber_reg_is_valid): Emit only a warning together
with an informative note when the stack pointer is clobbered.
testsuite:
2018-07-01 Bernd Edlinger <bernd.edlinger@hotmail.de>
* gcc.target/arm/pr77904.c: Adjust test.
* gcc.target/i386/pr52813.c: Adjust test.
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c (revision 267653)
+++ gcc/cfgexpand.c (working copy)
@@ -2854,6 +2854,7 @@ tree_conflicts_with_clobbers_p (tree t, HARD_REG_S
asm clobber operand. Some HW registers cannot be
saved/restored, hence they should not be clobbered by
asm statements. */
+
static bool
asm_clobber_reg_is_valid (int regno, int nregs, const char *regname)
{
@@ -2872,11 +2873,22 @@ asm_clobber_reg_is_valid (int regno, int nregs, co
error ("PIC register clobbered by %qs in %<asm%>", regname);
is_valid = false;
}
- /* Clobbering the STACK POINTER register is an error. */
+ /* Clobbering the STACK POINTER register is likely an error.
+ However it is useful to force the use of frame pointer and prevent
+ the use of red zone. Thus without this clobber, pushing temporary
+ values onto the stack might clobber the red zone or make stack based
+ memory references invalid. */
if (overlaps_hard_reg_set_p (regset, Pmode, STACK_POINTER_REGNUM))
{
- error ("Stack Pointer register clobbered by %qs in %<asm%>", regname);
- is_valid = false;
+ if (warning (OPT_Wstack_clobber,
+ "stack pointer register clobbered by %qs in %<asm%>",
+ regname))
+ inform (input_location,
+ "This does likely not do what you would expect."
+ " The stack pointer register still has to be restored to"
+ " the previous value, however it is safe to push values onto"
+ " the stack, when they are popped again from the stack"
+ " before the asm statement terminates");
}
return is_valid;
Index: gcc/common.opt
===================================================================
--- gcc/common.opt (revision 267653)
+++ gcc/common.opt (working copy)
@@ -702,6 +702,10 @@ Warn when one local variable shadows another local
Wshadow-compatible-local
Common Warning Undocumented Alias(Wshadow=compatible-local)
+Wstack-clobber
+Common Warning Var(warn_stack_clobber) Init(1)
+Warn when asm statements try to clobber the stack pointer register.
+
Wstack-protector
Common Var(warn_stack_protect) Warning
Warn when not issuing stack smashing protection for some reason.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi (revision 267653)
+++ gcc/doc/invoke.texi (working copy)
@@ -339,7 +339,7 @@ Objective-C and Objective-C++ Dialects}.
-Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value @gol
-Wsign-compare -Wsign-conversion -Wfloat-conversion @gol
-Wno-scalar-storage-order -Wsizeof-pointer-div @gol
--Wsizeof-pointer-memaccess -Wsizeof-array-argument @gol
+-Wsizeof-pointer-memaccess -Wsizeof-array-argument -Wstack-clobber @gol
-Wstack-protector -Wstack-usage=@var{byte-size} -Wstrict-aliasing @gol
-Wstrict-aliasing=n -Wstrict-overflow -Wstrict-overflow=@var{n} @gol
-Wstringop-overflow=@var{n} -Wstringop-truncation -Wsubobject-linkage @gol
@@ -7560,6 +7560,20 @@ This option is only supported for C and Objective-
@option{-Wall} and by @option{-Wpedantic}, which can be disabled with
@option{-Wno-pointer-sign}.
+@item -Wstack-clobber
+@opindex Wstack-clobber
+@opindex Wno-stack-clobber
+Warn for asm statements that try to clobber the stack pointer.
+Prior to gcc-6 this clobber was ignored, but from gcc-6 on
+this was changed to force the use of the frame pointer in the
+current function even if @option{-fomit-frame-pointer} is in
+effect, additionally this clobber prevents the use of a red-zone
+on some targets. The stack pointer register still has to be
+restored to the previous value, however it is safe to push values
+onto the stack, when they are popped again from the stack before
+the asm statement terminates. Since this might be unexpected,
+the warning is enabled by default.
+
@item -Wstack-protector
@opindex Wstack-protector
@opindex Wno-stack-protector
Index: gcc/testsuite/gcc.target/arm/pr77904.c
===================================================================
--- gcc/testsuite/gcc.target/arm/pr77904.c (revision 267653)
+++ gcc/testsuite/gcc.target/arm/pr77904.c (working copy)
@@ -4,7 +4,7 @@
__attribute__ ((noinline, noclone)) void
clobber_sp (void)
{
- __asm volatile ("" : : : "sp");
+ __asm volatile ("" : : : "sp"); /* { dg-warning "stack pointer register clobbered" } */
}
int
Index: gcc/testsuite/gcc.target/i386/pr52813.c
===================================================================
--- gcc/testsuite/gcc.target/i386/pr52813.c (revision 267653)
+++ gcc/testsuite/gcc.target/i386/pr52813.c (working copy)
@@ -1,9 +1,10 @@
/* Ensure that stack pointer cannot be an asm clobber. */
/* { dg-do compile { target { ! ia32 } } } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O3 -fomit-frame-pointer" } */
void
test1 (void)
{
- asm volatile ("" : : : "%esp"); /* { dg-error "Stack Pointer register clobbered" } */
+ asm volatile ("" : : : "%rsp"); /* { dg-warning "stack pointer register clobbered" } */
}
+/* { dg-final { scan-assembler "(?n)pushq.*%rbp" } } */
next prev parent reply other threads:[~2019-01-07 21:51 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-16 14:36 Bernd Edlinger
2018-12-16 16:14 ` Dimitar Dimitrov
2018-12-17 11:47 ` Richard Sandiford
2018-12-17 12:54 ` Christophe Lyon
2018-12-17 13:35 ` Richard Sandiford
2018-12-17 13:42 ` Christophe Lyon
2018-12-17 14:05 ` Bernd Edlinger
2018-12-17 14:10 ` Bernd Edlinger
2018-12-17 15:55 ` Segher Boessenkool
2018-12-17 18:46 ` Richard Sandiford
2018-12-17 20:15 ` Bernd Edlinger
2018-12-19 6:40 ` Dimitar Dimitrov
2018-12-19 9:29 ` Segher Boessenkool
2018-12-18 14:16 ` Bernd Edlinger
2018-12-18 15:14 ` Bernd Edlinger
2019-01-07 9:23 ` Jakub Jelinek
2019-01-07 21:51 ` Bernd Edlinger [this message]
2019-01-08 12:03 ` Richard Sandiford
2019-01-10 13:21 ` Segher Boessenkool
2019-01-10 21:23 ` Richard Sandiford
2019-01-10 21:26 ` Jakub Jelinek
2019-01-10 21:56 ` Richard Sandiford
2019-01-11 12:26 ` Segher Boessenkool
2019-01-10 22:32 ` Bernd Edlinger
2019-01-11 12:18 ` Segher Boessenkool
2019-01-11 12:23 ` Richard Sandiford
2019-01-11 22:59 ` Jeff Law
2019-01-17 14:27 ` Christophe Lyon
2019-01-18 9:49 ` Richard Sandiford
-- strict thread matches above, loose matches on Subject: below --
2018-12-09 10:09 Dimitar Dimitrov
2018-12-10 11:21 ` Richard Sandiford
2018-12-10 19:36 ` Dimitar Dimitrov
2018-12-11 15:52 ` Richard Sandiford
2018-12-12 9:42 ` Christophe Lyon
2018-12-12 10:03 ` Christophe Lyon
2018-12-12 16:39 ` Dimitar Dimitrov
2018-12-12 10:30 ` Thomas Preudhomme
2018-12-12 11:21 ` Thomas Preudhomme
2018-12-12 13:19 ` Christophe Lyon
2018-12-12 15:13 ` Christophe Lyon
2018-12-12 15:35 ` Thomas Preudhomme
2018-12-12 16:26 ` Dimitar Dimitrov
2018-12-13 14:49 ` Segher Boessenkool
2018-12-13 22:21 ` Dimitar Dimitrov
2018-12-14 8:52 ` Segher Boessenkool
2018-12-16 8:43 ` Dimitar Dimitrov
2018-12-17 15:23 ` Segher Boessenkool
2018-12-14 13:49 ` Richard Sandiford
2018-12-15 15:38 ` Segher Boessenkool
2018-12-12 11:24 ` Andreas Schwab
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=AM6PR07MB5608D7EC0B184E1B3FC17242E4890@AM6PR07MB5608.eurprd07.prod.outlook.com \
--to=bernd.edlinger@hotmail.de \
--cc=christophe.lyon@linaro.org \
--cc=dimitar@dinux.eu \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=rdsandiford@googlemail.com \
--cc=segher@kernel.crashing.org \
--cc=thomas.preudhomme@linaro.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: link
Be 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).