public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/43404]  New: ARM: Internal compiler error when using '&foo' in naked function
@ 2010-03-17 15:02 marti at juffo dot org
  2010-03-17 15:03 ` [Bug c/43404] " marti at juffo dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: marti at juffo dot org @ 2010-03-17 15:02 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2589 bytes --]

Tested with GCC 4.4.1 and 4.4.3 (custom built) on Arch Linux
host arch is x86_64 and target is arm-elf

This is the full source code needed to reproduce the bug:

void __data_abort(void) __attribute__ ((naked));
void __data_abort(void)
{
  long foo;
  long* bar = &foo;
}

test.c: In function ‘__data_abort’:
test.c:5: warning: unused variable ‘bar’
test.c:5: internal compiler error: in expand_expr_addr_expr_1, at expr.c:6835

---

% arm-elf-gcc -v -save-temps -Wall -c test.c -o test.o
Using built-in specs.
Target: arm-elf
Configured with: ../configure --prefix=/opt/arm-elf-gcc --target=arm-elf
--enable-interwork --enable-multilib --disable-threads --enable-languages=c,c++
--with-newlib
--with-headers=/home/marti/crosschain/gcc-4.4.3/build/../newlib-1.18.0/newlib/libc/include
Thread model: single
gcc version 4.4.3 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-c' '-o' 'test.o'
 /opt/arm-elf-gcc/libexec/gcc/arm-elf/4.4.3/cc1 -E -quiet -v
-D__USES_INITFINI__ test.c -Wall -fpch-preprocess -o test.i
#include "..." search starts here:
#include <...> search starts here:
 /opt/arm-elf-gcc/lib/gcc/arm-elf/4.4.3/include
 /opt/arm-elf-gcc/lib/gcc/arm-elf/4.4.3/include-fixed
 /opt/arm-elf-gcc/lib/gcc/arm-elf/4.4.3/../../../../arm-elf/sys-include
 /opt/arm-elf-gcc/lib/gcc/arm-elf/4.4.3/../../../../arm-elf/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-c' '-o' 'test.o'
 /opt/arm-elf-gcc/libexec/gcc/arm-elf/4.4.3/cc1 -fpreprocessed test.i -quiet
-dumpbase test.c -auxbase-strip test.o -Wall -version -o test.s
GNU C (GCC) version 4.4.3 (arm-elf)
        compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 913e44b5d872dc5aa4cdba7cf6499b83
test.c: In function ‘__data_abort’:
test.c:5: warning: unused variable ‘bar’
test.c:5: internal compiler error: in expand_expr_addr_expr_1, at expr.c:6835
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


-- 
           Summary: ARM: Internal compiler error when using '&foo' in naked
                    function
           Product: gcc
           Version: 4.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: marti at juffo dot org
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: arm-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug c/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
@ 2010-03-17 15:03 ` marti at juffo dot org
  2010-03-18 17:37 ` [Bug target/43404] " rearnsha at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: marti at juffo dot org @ 2010-03-17 15:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from marti at juffo dot org  2010-03-17 15:03 -------
Created an attachment (id=20128)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20128&action=view)
test.i


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
  2010-03-17 15:03 ` [Bug c/43404] " marti at juffo dot org
@ 2010-03-18 17:37 ` rearnsha at gcc dot gnu dot org
  2010-03-18 17:39 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2010-03-18 17:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rearnsha at gcc dot gnu dot org  2010-03-18 17:37 -------
Native functions aren't expected to work with a 'C' body.


-- 

rearnsha at gcc dot gnu dot org changed:

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


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
  2010-03-17 15:03 ` [Bug c/43404] " marti at juffo dot org
  2010-03-18 17:37 ` [Bug target/43404] " rearnsha at gcc dot gnu dot org
@ 2010-03-18 17:39 ` pinskia at gcc dot gnu dot org
  2010-03-19 12:04 ` ramana at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-03-18 17:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2010-03-18 17:39 -------
Then it should produce an error and not an internal compiler error.


-- 

pinskia at gcc dot gnu dot org changed:

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


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
                   ` (2 preceding siblings ...)
  2010-03-18 17:39 ` pinskia at gcc dot gnu dot org
@ 2010-03-19 12:04 ` ramana at gcc dot gnu dot org
  2010-03-19 13:27 ` rearnsha at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: ramana at gcc dot gnu dot org @ 2010-03-19 12:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from ramana at gcc dot gnu dot org  2010-03-19 12:04 -------
Yes - haven't thought about it much, maybe the backend could give an error if a
frame were allocated for a naked function rather than ICE'ing in an awkward
place.


-- 

ramana at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |error-recovery, ice-on-
                   |                            |invalid-code
           Priority|P3                          |P4
   Last reconfirmed|0000-00-00 00:00:00         |2010-03-19 12:04:16
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
                   ` (3 preceding siblings ...)
  2010-03-19 12:04 ` ramana at gcc dot gnu dot org
@ 2010-03-19 13:27 ` rearnsha at gcc dot gnu dot org
  2010-03-19 14:46 ` marti at juffo dot org
  2010-05-20 20:47 ` torsten at debian dot org
  6 siblings, 0 replies; 10+ messages in thread
From: rearnsha at gcc dot gnu dot org @ 2010-03-19 13:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rearnsha at gcc dot gnu dot org  2010-03-19 13:27 -------
I think the compiler should throw an error if there are any statements in the
naked function other than asm statements.  All such asms should be treated as
volatile.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
                   ` (4 preceding siblings ...)
  2010-03-19 13:27 ` rearnsha at gcc dot gnu dot org
@ 2010-03-19 14:46 ` marti at juffo dot org
  2010-05-20 20:47 ` torsten at debian dot org
  6 siblings, 0 replies; 10+ messages in thread
From: marti at juffo dot org @ 2010-03-19 14:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from marti at juffo dot org  2010-03-19 14:46 -------
(In reply to comment #5)
> I think the compiler should throw an error if there are any statements in the
> naked function other than asm statements.

This would break a lot of code; there are use cases where you want to
save/restore the stack frame yourself, but still use C code in the middle. And
on ARM you can go a long way without needing to spill over to the stack.

For example:
* Nut/OS context switching code,
http://www.ethernut.de/api/context_8c-source.html#l00156
* Interrupt handlers that use macros which also push r0-r3 and spsr, which
otherwise not stored in GCC's stack frame:
http://www.ethernut.de/api/ih__at91ssc_8c-source.html#l00068


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
  2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
                   ` (5 preceding siblings ...)
  2010-03-19 14:46 ` marti at juffo dot org
@ 2010-05-20 20:47 ` torsten at debian dot org
  6 siblings, 0 replies; 10+ messages in thread
From: torsten at debian dot org @ 2010-05-20 20:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from torsten at debian dot org  2010-05-20 20:47 -------
This also hit me. I wanted to build a simple data logger for an ARM board. Of
course I wanted to give gcc 4.4 a go (I used a compiler from the 3.x series
before...), combined with current FreeRTOS (from www.freertos.org).

The interrupt handlers do not compile just as for Nut/OS. I found a discussion
about the issue at the arm-gnu archives. Quoting the post at 
http://www.codesourcery.com/archives/arm-gnu/msg02517.html by Mark Mitchell:

-----
This code makes invalid use of the "naked" attribute.

>From the manual:

"The only statements that can be safely included in naked functions are
asm statements that do not have operands. All other statements,
including declarations of local variables, if statements, and so forth,
should be avoided. Naked functions should be used to implement the body
of an assembly function, while allowing the compiler to construct the
requisite function declaration for the assembler."
-----

I disagree with this interpretation. "should" be avoided is different from
"must". For me this is just an indication that nothing is guaranteed about the
generated code - which is fine, interrupt handlers will naturally have to
revised for compiler updates.

Disregarding this as "invalid code" basically sends the signal that gcc is
unusable for small embedded systems. Of course it is possible to create a
trampoline function in assembler for each interrupt handler, but for small
systems, the overhead is relevant. So I'd rather set up the required registers
manually using some asm instructions but write the body of the function in C.

Looking at FreeRTOS' Subversion repository, they already started to add an
extra indirection to all interrupt handlers. :-(


-- 

torsten at debian dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |torsten at debian dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43404


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
       [not found] <bug-43404-4@http.gcc.gnu.org/bugzilla/>
  2015-08-03 19:35 ` law at gcc dot gnu.org
@ 2015-08-03 19:36 ` law at redhat dot com
  1 sibling, 0 replies; 10+ messages in thread
From: law at redhat dot com @ 2015-08-03 19:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |law at redhat dot com
         Resolution|---                         |FIXED

--- Comment #9 from Jeffrey A. Law <law at redhat dot com> ---
Fixed on the trunk.


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

* [Bug target/43404] ARM: Internal compiler error when using '&foo' in naked function
       [not found] <bug-43404-4@http.gcc.gnu.org/bugzilla/>
@ 2015-08-03 19:35 ` law at gcc dot gnu.org
  2015-08-03 19:36 ` law at redhat dot com
  1 sibling, 0 replies; 10+ messages in thread
From: law at gcc dot gnu.org @ 2015-08-03 19:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jeffrey A. Law <law at gcc dot gnu.org> ---
Author: law
Date: Mon Aug  3 19:34:31 2015
New Revision: 226528

URL: https://gcc.gnu.org/viewcvs?rev=226528&root=gcc&view=rev
Log:
        PR middle-end/64744
        PR middle-end/48470
        PR middle-end/43404
        * cfgexpand.c (expand_one_var): Add check if stack is going to
        be used in naked function.
        * expr.c (expand_expr_addr_expr_1): Remove excess checking
        whether expression should not reside in MEM.
        * function.c (use_register_for_decl): Do not use registers for
        non-register things (volatile, float, BLKMode) in naked functions.

        PR middle-end/64744
        PR middle-end/48470
        PR middle-end/43404
        * gcc.target/arm/pr43404.c : New testcase.
        * gcc.target/arm/pr48470.c : New testcase.
        * gcc.target/arm/pr64744-1.c : New testcase.
        * gcc.target/arm/pr64744-2.c : New testcase.

Added:
    trunk/gcc/testsuite/gcc.target/arm/pr43404.c
    trunk/gcc/testsuite/gcc.target/arm/pr48470.c
    trunk/gcc/testsuite/gcc.target/arm/pr64744-1.c
    trunk/gcc/testsuite/gcc.target/arm/pr64744-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cfgexpand.c
    trunk/gcc/expr.c
    trunk/gcc/function.c
    trunk/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2015-08-03 19:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-17 15:02 [Bug c/43404] New: ARM: Internal compiler error when using '&foo' in naked function marti at juffo dot org
2010-03-17 15:03 ` [Bug c/43404] " marti at juffo dot org
2010-03-18 17:37 ` [Bug target/43404] " rearnsha at gcc dot gnu dot org
2010-03-18 17:39 ` pinskia at gcc dot gnu dot org
2010-03-19 12:04 ` ramana at gcc dot gnu dot org
2010-03-19 13:27 ` rearnsha at gcc dot gnu dot org
2010-03-19 14:46 ` marti at juffo dot org
2010-05-20 20:47 ` torsten at debian dot org
     [not found] <bug-43404-4@http.gcc.gnu.org/bugzilla/>
2015-08-03 19:35 ` law at gcc dot gnu.org
2015-08-03 19:36 ` law at redhat dot com

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