|
From: SONE T. <ts...@ts...> - 2000-12-09 15:23:01
|
On Fri, Dec 08, 2000 at 05:25:52PM +0100, Niels Diepeveen wrote:
> SONE Takeshi schreef:
> > alloca() is a built-in function in both GCC and MSVC.
> > (no underscore in GCC)
> > I've been using it without a problem.
> > GCC itself uses it also.
>
> Thanks! That was the hint I needed. I was working on some code written
> for MSVC, which has _alloca instead of alloca. Now this would not be so
> bad if _alloca didn't exist in the library. The problem is that there is
> something called _alloca() in some standard library that does something
> similar to alloca(). This routine does not seem to follow C calling
> conventions and apparently puts its return address in %eax, instead of
> the pointer to the allocated space. You can imagine the hideous results.
> I don't know if this would be easy to fix, but it would certainly save a
> lot of debugging time when porting MSVC code.
Ok, I see the problem.
_alloca() *is* in libgcc.a, but it is not what MSVC people expect.
It's a support function of gcc, not a 'non-oldname version' of alloca().
_alloca() is called implicitly whenever gcc allocates >4096 bytes in stack.
This simple function:
int foo()
{
char mem[9999];
return 1;
}
involves a call to _alloca().
ts1@arndok:/tmp$ ~/GCC/bin/i386-mingw32-gcc -S hoge.c
ts1@arndok:/tmp$ cat hoge.s
.file "hoge.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
.align 4
.globl _foo
.def _foo; .scl 2; .type 32; .endef
_foo:
pushl %ebp
movl %esp,%ebp
movl $10008,%eax
call __alloca
movl $1,%eax
jmp L2
.align 4
L2:
leave
ret
Of cource, it's same when you call alloca() (no underscore) with its
argument more than 4096 (or unknown at compile-time).
IMHO naming it _alloca was Cygnus' fault.
At least, we should have '#define _alloca alloca' in <malloc.h>?
--
Takeshi
|