This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help with source code.


On Mon, 2004-09-06 at 14:46, Alfred M. Szmidt wrote:
>    If it isn't in the GNU Libc, then where I can get the source of
>    alloca ??
> 
> As I already told you, it is a built-in provided by GCC.

Since I have the GCC source handy, I made an effort to find alloca in
that tree. Huh, I don't know..., there is a file libiberty/alloca.c with
an implementation, but how can I know, is that something the compiler
code uses for its internal workings, or is that a piece of code that gcc
in-lines into any object being compiled that needs it?

Depending on why you are asking, if you just want a sample
implementation, there you have it; but if you need to know what exactly
the compiler does with your code and how that works, I believe it is
best you ask on a mailing list for GCC code fiddlers.

What I found interesting was to read the comments in the file, and
discover that the original idea of enlarging the stack frame (something
that quite naturally involves the compiler -- it makes sense to make
that a compiler built-in) -- has been abandoned.  Nothing ever stays the
same for a minute. Turn your back, and it changes.  Everything you
learned as a kid now belongs with Santa Claus and the fairies. :~(

So now it appears that alloca calls malloc, and frees the data when it
gets called again (so alloca code gets control) and alloca somehow
determines that the owning stack frame no longer exists.  It tickles my
curiosity, how does this animal know if the stack frame has been
abandoned and later resurrected at the same address, as it naturally
will in a loop?  But I can't afford the time now to read the code.

The comments say that enlarging the stack frame no longer is possible
for "some implementations of C, for example under Gould's UTX/32."  But
why abandon a good idea in other implementations of C?  Perhaps GCC
still plays games with the stack, and libiberty's alloca is just library
bagage. 

Wish you good luck.
-Enrique


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]