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:Re: Help with source code.


>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

Bingo.
I know how alloca works, or better,I know as it could works in a builtin implementation...
Is quite easy by a builtin because  the stack is manipulated by compiler  directly, 
which know how many variables exists , and then is possible to make a "magic" function like alloca.  
But I have read somewhere ( Gcc or Libc manual), that in some non-GNU implementations, alloca is a normal function.  
Hence, the questions are legitimate............How it works???  
How a "human" function manupulates the stack in that fashion ???  
The "extern void * alloca(size_t size); " in alloca.h has convinced to me to searching in Libc source,  
but I have mistaken...the answer is in gcc/libiberty, as you have said.

Thanks.


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