avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Stack usage under heavy inlining


From: Stu Bell
Subject: RE: [avr-gcc-list] Stack usage under heavy inlining
Date: Mon, 8 Sep 2008 08:27:50 -0600

I don't understand your problem.  If I understand your situation, you
have:

int functionD( int d ) __attribute__ ((inline));
int functionC( int c ) __attribute__ ((inline));
int functionB( int b ) __attribute__ ((inline));

int functionD( int d ){
        uint8_t localD[32];
...
        return result;
} 
int functionC( int c ){
        uint8_t localC[32];
...
        return (functionD(c));
} 
int functionB( int b ){
        uint8_t localB[32];
...
        return (functionC(b));
} 
int functionA( int a ){
        uint8_t localA[32];
...
        return (functionB(a));
} 

And you're complaining that when you call functionA that 96 bytes are
allocated on the stack instead of 32?  Isn't that what would happen
through the full execution of the set of functions (plus parameter and
return address pushes as well)? 

I must be missing something from your description.  It seems to me that
you actually *save* the parameter and address pushes on the stack,
saving quite a bit.

Best regards, 

Stu Bell 
DataPlay (DPHI, Inc.) 


-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Paulo Marques
Sent: Monday, September 08, 2008 5:43 AM
To: address@hidden
Subject: [avr-gcc-list] Stack usage under heavy inlining


Hi all,

Yesterday I was tracking down a problem in a personal project of mine
whose symptoms looked like a stack overflow.

As it turned out, it was the same problem with gcc that I had already
read about on LKML: when gcc inlines a function it increases the stack
usage of the caller by almost all the stack usage of the callee.

So, for instance, if function A calls function B, then function C and
then function D, and functions B,C and D use 32 bytes of stack each, it
means function A now uses 96 bytes of stack, whereas the "not-inlined" 
version only used 32 bytes.

Since I was compiling my project with "-combine -fwhole-program", the
main function had almost the entire code and it started by pushing all
call-saved registers and subtracting 126 bytes to the stack pointer :P

Marking the main function as __attribute__((noreturn)) took care of the
push'es, but only -fno-inline reduced the stack usage.

This is not a avr specific problem. See, for instance, Linus complaining
of the same problem on i386 (stack size is a problem for the kernel
too):

http://lkml.org/lkml/2008/8/26/197

I tested this with several versions of gcc, including a gcc-4.4.0 (not a
very recent one, though).

I can try with more recent versions, if someone suspects that this
behavior is better in a more recent gcc, but I just wanted to warn other
developers who might hit the same problem.

--
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

"To know recursion, you must first know recursion."


_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list




reply via email to

[Prev in Thread] Current Thread [Next in Thread]