public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/42240]  New: wrong Epilog on nacked function
@ 2009-12-01 16:18 stefan dot dreyer at yahoo dot de
  2009-12-01 16:19 ` [Bug c/42240] " stefan dot dreyer at yahoo dot de
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: stefan dot dreyer at yahoo dot de @ 2009-12-01 16:18 UTC (permalink / raw)
  To: gcc-bugs

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

Hello!

Following code is Producing an infinit loop, so main() is never reached

extern int main(void);
int main(void){
        while(1);
}
#include <avr\io.h>
/*Seed aus SRAM Zellen*/
static uint16_t seedram __attribute__ ((section (".noinit")));
void __init_seed(void) __attribute__ ((naked, section (".init8")));
// Bestimme seed aus zufälligem RAM-Inhalt
// !!! FUNKTION NICHT AUFRUFEN       !!!
// !!! FUNKTION WIRD AUTOMATISCH     !!!
// !!! IN .init8 vor main AUSGEFÜHRT !!!
void __init_seed (void)
{
        uint16_t s = 0;
        uint16_t *p = (uint16_t*) (RAMEND+1);
        extern uint16_t __noinit_start;

        while (p >= &__noinit_start + 1)
                s ^= *(--p);

        seedram = s;
}


is going to 

        while (p >= &__noinit_start + 1)
  8e:   81 e0           ldi     r24, 0x01       ; 1
  90:   e2 30           cpi     r30, 0x02       ; 2
  92:   f8 07           cpc     r31, r24
  94:   c0 f7           brcc    .-16            ; 0x86 <__init_seed+0x12>
                s ^= *(--p);

        seedram = s;
  96:   30 93 01 01     sts     0x0101, r19
  9a:   20 93 00 01     sts     0x0100, r18
}
  9e:   20 e0           ldi     r18, 0x00       ; 0
  a0:   30 e0           ldi     r19, 0x00       ; 0
  a2:   f9 cf           rjmp    .-14            ; 0x96 <__init_seed+0x22>

at line a2: an infinit loop starts and never leaves this function.

the Problem is only an Optimation levels O2 and O3

Orginal thread in german Forum:
http://www.mikrocontroller.net/topic/158516

compiler call:

avr-gcc -c -mmcu=atmega168 -I. -gdwarf-2 -DF_CPU=8000000UL -O2 -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes
-Wa,-adhlns=./main.lst  -std=c99 -MMD -MP -MF .dep/main.o.d main.c -o main.o

linker call:

avr-gcc -mmcu=atmega168 -I. -gdwarf-2 -DF_CPU=8000000UL -O2 -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes
-Wa,-adhlns=main.o  -std=c99 -MMD -MP -MF .dep/main.elf.d main.o --output
main.elf -Wl,-Map=main.map,--cref     -lm

Compiler version:

D:\Daten\Projekte\Eclipse Workspace\test init>avr-gcc -v
Using built-in specs.
Target: avr
Configured with: ../gcc-4.3.2/configure --enable-win32-registry=WinAVR-20090313
--with-gmp=/usr/local --with-mpfr=/usr/local --prefix=/c/WinAVR --target=avr
--enable-languages=c,c++,objc --with-dwarf2 --enable-doc --disable-shared
--disable-libada --disable-libssp --disable-nls
--with-pkgversion='WinAVR20090313'
--with-bugurl='URL:http://sourceforge.net/tracker/?atid=520074&group_id=68108&func=browse'Thread
model: single
gcc version 4.3.2 (WinAVR 20090313)

Greetings Stefan


-- 
           Summary: wrong Epilog on nacked function
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stefan dot dreyer at yahoo dot de
  GCC host triplet: Windows XP
GCC target triplet: AVR


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


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

* [Bug c/42240] wrong Epilog on nacked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
@ 2009-12-01 16:19 ` stefan dot dreyer at yahoo dot de
  2009-12-01 16:44 ` stefan dot dreyer at yahoo dot de
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: stefan dot dreyer at yahoo dot de @ 2009-12-01 16:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from stefan dot dreyer at yahoo dot de  2009-12-01 16:19 -------
Created an attachment (id=19199)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19199&action=view)
Compileable testfile


-- 


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


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

* [Bug c/42240] wrong Epilog on nacked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
  2009-12-01 16:19 ` [Bug c/42240] " stefan dot dreyer at yahoo dot de
@ 2009-12-01 16:44 ` stefan dot dreyer at yahoo dot de
  2009-12-01 16:45 ` stefan dot dreyer at yahoo dot de
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: stefan dot dreyer at yahoo dot de @ 2009-12-01 16:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from stefan dot dreyer at yahoo dot de  2009-12-01 16:44 -------
Created an attachment (id=19200)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19200&action=view)
Compileable testfile


-- 


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


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

* [Bug c/42240] wrong Epilog on nacked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
  2009-12-01 16:19 ` [Bug c/42240] " stefan dot dreyer at yahoo dot de
  2009-12-01 16:44 ` stefan dot dreyer at yahoo dot de
@ 2009-12-01 16:45 ` stefan dot dreyer at yahoo dot de
  2009-12-01 16:46 ` stefan dot dreyer at yahoo dot de
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: stefan dot dreyer at yahoo dot de @ 2009-12-01 16:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from stefan dot dreyer at yahoo dot de  2009-12-01 16:44 -------
Created an attachment (id=19201)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=19201&action=view)
generatet assambly file


-- 


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


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

* [Bug c/42240] wrong Epilog on nacked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (2 preceding siblings ...)
  2009-12-01 16:45 ` stefan dot dreyer at yahoo dot de
@ 2009-12-01 16:46 ` stefan dot dreyer at yahoo dot de
  2009-12-01 16:58 ` [Bug target/42240] " j at uriah dot heep dot sax dot de
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: stefan dot dreyer at yahoo dot de @ 2009-12-01 16:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from stefan dot dreyer at yahoo dot de  2009-12-01 16:46 -------
(From update of attachment 19201)
in 
/* epilogue start */

rjmp .L6

infinite, never leaves function


-- 


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


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

* [Bug target/42240] wrong Epilog on nacked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (3 preceding siblings ...)
  2009-12-01 16:46 ` stefan dot dreyer at yahoo dot de
@ 2009-12-01 16:58 ` j at uriah dot heep dot sax dot de
  2009-12-01 19:21 ` [Bug target/42240] wrong epilogue on naked function a dot kaiser at gmx dot net
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: j at uriah dot heep dot sax dot de @ 2009-12-01 16:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from j at uriah dot heep dot sax dot de  2009-12-01 16:58 -------
My first analysis shows that this is likely to be related to the
introduction of RTL prologues/epilogues in GCC 4.3.  GCC 4.2.2
has:

  if (avr_naked_function_p (current_function_decl))
    {
      fputs ("/* epilogue: naked */\n", file);
      goto out;
    }
...
 out:
  fprintf (file, "/* epilogue end (size=%d) */\n", epilogue_size);
  fprintf (file, "/* function %s size %d (%d) */\n", current_function_name (),
           prologue_size + function_size + epilogue_size, function_size);
  commands_in_file += prologue_size + function_size + epilogue_size;
  commands_in_prologues += prologue_size;
  commands_in_epilogues += epilogue_size;
}

GCC 4.3.4 has:

  /* epilogue: naked  */
  if (cfun->machine->is_naked)
    {
      emit_jump_insn (gen_return ());
      return;
    }

So apparently, emit_jump_insn (gen_return ()); is responsible for creating
the infinite loop.


-- 


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


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

* [Bug target/42240] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (4 preceding siblings ...)
  2009-12-01 16:58 ` [Bug target/42240] " j at uriah dot heep dot sax dot de
@ 2009-12-01 19:21 ` a dot kaiser at gmx dot net
  2009-12-01 19:38 ` a dot kaiser at gmx dot net
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: a dot kaiser at gmx dot net @ 2009-12-01 19:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from a dot kaiser at gmx dot net  2009-12-01 19:21 -------
Same for ARM target, when compiled for Thumb instruction set (-fthumb).


-- 

a dot kaiser at gmx dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |a dot kaiser at gmx dot net


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


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

* [Bug target/42240] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (5 preceding siblings ...)
  2009-12-01 19:21 ` [Bug target/42240] wrong epilogue on naked function a dot kaiser at gmx dot net
@ 2009-12-01 19:38 ` a dot kaiser at gmx dot net
  2009-12-01 22:50 ` a dot kaiser at gmx dot net
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: a dot kaiser at gmx dot net @ 2009-12-01 19:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from a dot kaiser at gmx dot net  2009-12-01 19:37 -------
Confirmed for 4.4.2.


-- 


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


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

* [Bug target/42240] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (6 preceding siblings ...)
  2009-12-01 19:38 ` a dot kaiser at gmx dot net
@ 2009-12-01 22:50 ` a dot kaiser at gmx dot net
  2010-07-22 11:26 ` anitha dot boyapati at atmel dot com
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: a dot kaiser at gmx dot net @ 2009-12-01 22:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from a dot kaiser at gmx dot net  2009-12-01 22:50 -------
For the ARM target, falling off the end of the function does not make sense
anyway, since the last byte usually is followed by the constant pool. So the
AVR target finally caught up with the ARM target and doesn't work that way
either.


-- 


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


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

* [Bug target/42240] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (7 preceding siblings ...)
  2009-12-01 22:50 ` a dot kaiser at gmx dot net
@ 2010-07-22 11:26 ` anitha dot boyapati at atmel dot com
  2010-07-26  6:49 ` anitha dot boyapati at atmel dot com
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: anitha dot boyapati at atmel dot com @ 2010-07-22 11:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from anitha dot boyapati at atmel dot com  2010-07-22 11:26 -------
I think the bug is not due to 'naked' function. When the naked attribute is
removed for __init_seed(void), the following diff can be observed in the
assembly file.

====================================================
--- test_without_naked.s        2010-07-22 15:53:13.178956400 +0530
+++ test_with_naked.s           2010-07-22 15:52:52.474373900 +0530
@@ -14,10 +14,11 @@
 .L2:
        rjmp .L2
        .size   main, .-main
+       .section        .init8,"ax",@progbits
 .global        __init_seed
        .type   __init_seed, @function
 __init_seed:
-/* prologue: function */
+/* prologue: naked */
 /* frame size = 0 */
        ldi r24,lo8(__noinit_start+2)
        ldi r25,hi8(__noinit_start+2)
@@ -41,7 +42,6 @@
        sts (seedram)+1,r19
        sts seedram,r18
 /* epilogue start */
-       ret
 .L11:
        ldi r18,lo8(0)
        ldi r19,hi8(0)

=======================================================

It can be seen that in case of naked function, 'ret' is not generated. Hence
the execution goes into infinite loop. The code generated for epilogue is wrong
in few cases for either for naked/normal functions with -O2 enabled. However
incase of normal functions, execution is not affected as 'ret' is executed
before entering into block labelled .L11 (of main.s).

.L11:
        ldi r18,lo8(0)
        ldi r19,hi8(0)
        rjmp .L6


-- 

anitha dot boyapati at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anitha dot boyapati at atmel
                   |                            |dot com


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


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

* [Bug target/42240] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (8 preceding siblings ...)
  2010-07-22 11:26 ` anitha dot boyapati at atmel dot com
@ 2010-07-26  6:49 ` anitha dot boyapati at atmel dot com
  2010-07-26 17:37 ` eric dot weddington at atmel dot com
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: anitha dot boyapati at atmel dot com @ 2010-07-26  6:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from anitha dot boyapati at atmel dot com  2010-07-26 06:49 -------
Bug can be confirmed with 4.4.3 version also (With -O2)


-- 


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


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

* [Bug target/42240] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (9 preceding siblings ...)
  2010-07-26  6:49 ` anitha dot boyapati at atmel dot com
@ 2010-07-26 17:37 ` eric dot weddington at atmel dot com
  2010-07-26 17:41 ` [Bug target/42240] [4.3/4.4 Regression, avr] " eric dot weddington at atmel dot com
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: eric dot weddington at atmel dot com @ 2010-07-26 17:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from eric dot weddington at atmel dot com  2010-07-26 17:37 -------
Anitha, can you please check 4.5.x and HEAD?


-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
      Known to fail|4.3.2 4.3.4                 |4.3.2 4.3.4 4.4.3
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-26 17:37:41
               date|                            |


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


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

* [Bug target/42240] [4.3/4.4 Regression, avr] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (10 preceding siblings ...)
  2010-07-26 17:37 ` eric dot weddington at atmel dot com
@ 2010-07-26 17:41 ` eric dot weddington at atmel dot com
  2010-07-27 11:35 ` anitha dot boyapati at atmel dot com
  2010-07-31 10:22 ` [Bug target/42240] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: eric dot weddington at atmel dot com @ 2010-07-26 17:41 UTC (permalink / raw)
  To: gcc-bugs



-- 

eric dot weddington at atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major
 GCC target triplet|                            |avr
            Summary|wrong epilogue on naked     |[4.3/4.4 Regression, avr]
                   |function                    |wrong epilogue on naked
                   |                            |function


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


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

* [Bug target/42240] [4.3/4.4 Regression, avr] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (11 preceding siblings ...)
  2010-07-26 17:41 ` [Bug target/42240] [4.3/4.4 Regression, avr] " eric dot weddington at atmel dot com
@ 2010-07-27 11:35 ` anitha dot boyapati at atmel dot com
  2010-07-31 10:22 ` [Bug target/42240] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: anitha dot boyapati at atmel dot com @ 2010-07-27 11:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from anitha dot boyapati at atmel dot com  2010-07-27 11:35 -------
confirmed for 4.5.0. Yet to verify for HEAD.


-- 


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


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

* [Bug target/42240] [4.3/4.4 Regression] wrong epilogue on naked function
  2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
                   ` (12 preceding siblings ...)
  2010-07-27 11:35 ` anitha dot boyapati at atmel dot com
@ 2010-07-31 10:22 ` rguenth at gcc dot gnu dot org
  13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-07-31 10:22 UTC (permalink / raw)
  To: gcc-bugs



-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.3/4.4 Regression, avr]   |[4.3/4.4 Regression] wrong
                   |wrong epilogue on naked     |epilogue on naked function
                   |function                    |
   Target Milestone|---                         |4.3.6


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


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

end of thread, other threads:[~2010-07-31 10:22 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-01 16:18 [Bug c/42240] New: wrong Epilog on nacked function stefan dot dreyer at yahoo dot de
2009-12-01 16:19 ` [Bug c/42240] " stefan dot dreyer at yahoo dot de
2009-12-01 16:44 ` stefan dot dreyer at yahoo dot de
2009-12-01 16:45 ` stefan dot dreyer at yahoo dot de
2009-12-01 16:46 ` stefan dot dreyer at yahoo dot de
2009-12-01 16:58 ` [Bug target/42240] " j at uriah dot heep dot sax dot de
2009-12-01 19:21 ` [Bug target/42240] wrong epilogue on naked function a dot kaiser at gmx dot net
2009-12-01 19:38 ` a dot kaiser at gmx dot net
2009-12-01 22:50 ` a dot kaiser at gmx dot net
2010-07-22 11:26 ` anitha dot boyapati at atmel dot com
2010-07-26  6:49 ` anitha dot boyapati at atmel dot com
2010-07-26 17:37 ` eric dot weddington at atmel dot com
2010-07-26 17:41 ` [Bug target/42240] [4.3/4.4 Regression, avr] " eric dot weddington at atmel dot com
2010-07-27 11:35 ` anitha dot boyapati at atmel dot com
2010-07-31 10:22 ` [Bug target/42240] [4.3/4.4 Regression] " rguenth at gcc dot gnu dot 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).