public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
@ 2020-05-07 15:59 arnd at linaro dot org
  2020-06-03 16:37 ` [Bug target/94986] " wilco at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: arnd at linaro dot org @ 2020-05-07 15:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94986
           Summary: missing diagnostic on ARM thumb2 compilation with -pg
                    when using r7 in inline asm
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnd at linaro dot org
  Target Milestone: ---

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94986] missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
  2020-05-07 15:59 [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm arnd at linaro dot org
@ 2020-06-03 16:37 ` wilco at gcc dot gnu.org
  2020-06-03 16:49 ` nsz at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: wilco at gcc dot gnu.org @ 2020-06-03 16:37 UTC (permalink / raw)
  To: gcc-bugs

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); }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94986] missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
  2020-05-07 15:59 [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm arnd at linaro dot org
  2020-06-03 16:37 ` [Bug target/94986] " wilco at gcc dot gnu.org
@ 2020-06-03 16:49 ` nsz at gcc dot gnu.org
  2020-06-03 17:00 ` wilco at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: nsz at gcc dot gnu.org @ 2020-06-03 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

nsz at gcc dot gnu.org changed:

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

--- Comment #2 from nsz at gcc dot gnu.org ---
on arm the -pg abi is

func:
  push {lr}
  bl _gnu_mcount_nc
  ...

so no frame pointer is involved, -pg implying
-fno-omit-frame-pointer is a historical mistake i think
(because some targets required fp for -pg, but most don't).

ideally r7 clobber would just work with -pg -fomit-frame-pointer.
the alloca problem is a separate issue (that r7 clobber may not
work with alloca).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94986] missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
  2020-05-07 15:59 [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm arnd at linaro dot org
  2020-06-03 16:37 ` [Bug target/94986] " wilco at gcc dot gnu.org
  2020-06-03 16:49 ` 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
  4 siblings, 0 replies; 6+ messages in thread
From: wilco at gcc dot gnu.org @ 2020-06-03 17:00 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to nsz from comment #2)
> on arm the -pg abi is
> 
> func:
>   push {lr}
>   bl _gnu_mcount_nc
>   ...
> 
> so no frame pointer is involved, -pg implying
> -fno-omit-frame-pointer is a historical mistake i think
> (because some targets required fp for -pg, but most don't).

Right, so the claim that -pg implies -fno-omit-frame-pointer is wrong, and that
means there is no bug in GCC. Looking at the latest docs, there is no mention
of frame pointer for the -pg option, and neither does -fomit-frame-pointer
discuss -pg. So this dependency must have been removed some time ago.

> ideally r7 clobber would just work with -pg -fomit-frame-pointer.
> the alloca problem is a separate issue (that r7 clobber may not
> work with alloca).

GCC correctly reports the error for that. So this can be closed then.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94986] missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
  2020-05-07 15:59 [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm arnd at linaro dot org
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: ndesaulniers at google dot com @ 2020-06-03 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Nick Desaulniers <ndesaulniers at google dot com> ---
(In reply to nsz from comment #2)
> on arm the -pg abi is
> 
> func:
>   push {lr}
>   bl _gnu_mcount_nc
>   ...
> 
> so no frame pointer is involved, -pg implying
> -fno-omit-frame-pointer is a historical mistake i think
> (because some targets required fp for -pg, but most don't).
> 
> ideally r7 clobber would just work with -pg -fomit-frame-pointer.
> the alloca problem is a separate issue (that r7 clobber may not
> work with alloca).

Should GCC change this for aaarch32 then (rather than closing the bug)?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/94986] missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm
  2020-05-07 15:59 [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm arnd at linaro dot org
                   ` (3 preceding siblings ...)
  2020-06-03 17:16 ` ndesaulniers at google dot com
@ 2020-06-03 17:23 ` nsz at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: nsz at gcc dot gnu.org @ 2020-06-03 17:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from nsz at gcc dot gnu.org ---
(In reply to Nick Desaulniers from comment #4)
> (In reply to nsz from comment #2)
> > ideally r7 clobber would just work with -pg -fomit-frame-pointer.
> > the alloca problem is a separate issue (that r7 clobber may not
> > work with alloca).
> 
> Should GCC change this for aaarch32 then (rather than closing the bug)?

yes, but that's bug 69690.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-03 17:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07 15:59 [Bug c/94986] New: missing diagnostic on ARM thumb2 compilation with -pg when using r7 in inline asm arnd at linaro dot org
2020-06-03 16:37 ` [Bug target/94986] " wilco at gcc dot gnu.org
2020-06-03 16:49 ` 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

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).