Re: GCC stack size
Re: GCC stack size
- Subject: Re: GCC stack size
- From: Ryan McGann <email@hidden>
- Date: Tue, 03 Mar 2009 13:35:12 -0800
On Tuesday, March 03, 2009, at 12:55PM, "Shawn Erickson" <email@hidden> wrote:
>On Tue, Mar 3, 2009 at 12:08 AM, Ryan McGann <email@hidden> wrote:
>
>> Just to let everybody know (and for the sake of the archives), it appears to
>> be our kernel extension is running into a known limitation of GCC. Just to
>> recap, we have a function in a very portable, very lightweight library, that
>> for some reason is getting compiled with a 1600+ byte stack when compiled
>> on/for Darwin. No matter what compiler options I tried, and what
>> optimization levels I used, the stack was no smaller than 1400 bytes.
>
>I am curious if you could create a simple stand alone code example
>that shows the issue you are seeing?
>
>It would be helpful for others to understand the issue and possibly avoid it.
We do and we don't. We have some code that definitely shows that GCC does not re-use stack slots for variables in a different scope. For example:
void foo(int a)
{
if (a < 100)
{
int array[ 32 ];
<do something>
}
else {
int array[ 48 ];
<do something>
}
}
(sorry the real sample is on another computer, this is a simplified version. I am working on cleaning it up for a bug submission to Apple). But we have a sample like that shows that both array variables get their own stack slots, when they can obviously share most of their stack space.
But, I am not 100% certain that is our problem. There is another case where GCC can mistakenly allocate more stack than necessary, when dealing with temporary variables. For example
int doMath(int b, int c);
void foo(int a)
{
if (a + (doMath( rand(), rand() )) < 100)
{
<do something>
}
else if (a + doMath( rand(), rand() )) < 200 {
<do something>
}
}
We have some sample code that shows that the temporary returned from the function doMath is allocated stack space twice, when it can only be used once. But since the function in our actual production code is pretty complex, it's hard to know hwich problem we are experiencing.
However, the above examples are both well documented cases of GCC problems; I actually got the basic ideas for both examples from Linus Torvald's (sometimes long) emails regarding Linux's problems with GCC stack allocation.
The real problems in GCC are more complex than the above examples, but are easy to reproduce. Once I have the samples cleaned up and I submit my bug I can post them.
Ryan
>-Shawn
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden