Hello All!===========================================
[ please cc: me ]
I have observed funny behaviour of both gcc 2.95/322 on ppc32 and i686 platforms.
Have written this routine and compiled it with 'gcc -O2':
int a(int v)
{
char buf[32];
if (v > 5) {
char buf2[32];
printf( buf, buf2 );
} else {
char buf2[32];
printf( buf, buf2 );
}
return 1;
}
I expected that stack on every branch of 'if(v>5)' will be allocated later - but seems that gcc allocate stack space once and in this case it will 'overallocate' 32 bytes - 'char buf2' will be allocated twice for every branch. On i686 gcc allocates 108 bytes, on ppc32 it allocates 116 bytes. (additional space seems to be induced by printf() call)
Adding to this routine something like 'do { char a[32]; } while(0);' several times shows that stack buffers are not reused - and allocated for every this kind of context separately.
As to my understanding - since this buffers do live in different mutually exclusive contextes - they can be reused. But this seems to be not case. Waste of precious kernel stack space - and waste of d-cache.
I have read 'info gcc' - but found nothing relevant to this.
I've checked ppc abi - but found no limitations to reuse of stack space.
Is it expected behaviour of compiler? gcc feature?
[ I have created macro which opens into inline function call which utilizes va_list - on ppc32 va_list adds at least 32 bytes to stack use. Seems to be bad idea for kernel-space, since every use if macro adds to stack use (10 macro calls == 320 bytes). Easy to rewrite to not to use va_list - but have I *NO* stack allocation check script in place - this stuff could easily get into production release. Not nice. ]
disassembling outputs:
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature