public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wilco at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/94986] missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
Date: Wed, 03 Jun 2020 16:37:49 +0000	[thread overview]
Message-ID: <bug-94986-4-L1wDA7nZHq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94986-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94986

Wilco <wilco at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wilco at gcc dot gnu.org

--- Comment #1 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Arnd Bergmann from comment #0)
> I reported a bug against clang for a Linux kernel failure, but 
>  it was suggested that the clang behavior is probably correct in this corner
> case while gcc gets it wrong, see https://bugs.llvm.org/show_bug.cgi?id=45826
> 
> echo 'void f(void) { asm("mov r7, #0" ::: "r7"); }' | arm-linux-gnueabi-gcc
> -march=armv7-a -O2  -mthumb -pg -S -xc -
> 
> silently accepts an inline asm statement that clobbers the frame pointer,
> but gcc rejects the same code if any of '-O0', '-fomit-frame-pointer' or
> 'fno-omit-frame-pointer' are used:
> 
> <stdin>: In function 'f':
> <stdin>:1:44: error: r7 cannot be used in 'asm' here
> 
> If using r7 in this case is indeed invalid, we need to ensure the kernel
> does not do this, and having gcc reject it would be helpful.

GCC will reject it if you explicitly enable the frame pointer. The logic seems
wrong in that it doesn't report an error if the frame pointer is implicitly
enabled via -pg. As a workaround for the kernel, just use -pg and
-fno-omit-frame-pointer together.

Corrupting a frame pointer loses the ability to follow the frame chain, similar
to a function built with -fomit-frame-pointer which will use r7 as a general
purpose register.

However this always reports an error since this corruption of the frame pointer
will cause a crash:

int *f(int x) { asm("mov r7, #0" ::: "r7"); return __builtin_alloca (x); }

  reply	other threads:[~2020-06-03 16:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-07 15:59 [Bug c/94986] New: " arnd at linaro dot org
2020-06-03 16:37 ` wilco at gcc dot gnu.org [this message]
2020-06-03 16:49 ` [Bug target/94986] " nsz at gcc dot gnu.org
2020-06-03 17:00 ` wilco at gcc dot gnu.org
2020-06-03 17:16 ` ndesaulniers at google dot com
2020-06-03 17:23 ` nsz at gcc dot gnu.org

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-94986-4-L1wDA7nZHq@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: 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).