[Top][All Lists]

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

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

From: Paulo Marques
Subject: [avr-gcc-list] Stack usage under heavy inlining
Date: Mon, 08 Sep 2008 12:43:26 +0100
User-agent: Thunderbird (X11/20071210)

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


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

reply via email to

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