Hi,
Shachar Shemesh wrote:
am looking for some documentation on the structure of the stack when
an executable starts. I know the basics - argc, then argv, then envp.
What I'm interested in is what's beyond that. I've tried googling,
reading the sources in the kernel for fs/binfmt_elf.c and the sources
for ld-linux.so. I'm sure what I'm looking for is in there, but I just
couldn't nail it.
...
I found the actual logic just described. It is in the glibc sources,
in elf/rtld.c, in a function called "dl_main". It is the first "if" in
that function. What I have, so far, failed to find is where the
variables referenced by that if are being initialized. I have reason
to believe this is just a struct left on the stack by the kernel, but
what the struct is, and more importantly, where on the stack, I have
not, yet, been able to figure out.
I have not yet given up. I'm just hoping someone will come up and say
"oh, just look at this URL for an explanation". The code is so choke
full of things that look like preprocessor directives but seem to be,
in fact, internal gcc attributes that I find the program flow somewhat
unreadable. My method, right now, is to compile it with debug symbols,
and then use objdump to overlay the source over the actual assembly
code. It has, in fact, come to the point where it is easier to try and
understand what I need that way.
Like anything having to do with the dynamic linker or indeed glibc, the
answer lies in a document by the one and only Ulrich Drepper - in this
particular case, his paper "How To Write Shared Libraries", which
besides the answer to your question contains oodles of arcane knowledge
about the dynamic linker and it's work:
http://people.redhat.com/drepper/dsohowto.pdf
Share && enjoy,
Gilad
--
Gilad Ben-Yossef
Chief Coffee Drinker
Codefidence Ltd.
The code is free, your time isn't.(TM)
Web: http://codefidence.com
Email: [EMAIL PROTECTED]
Office: +972-8-9316883 ext. 201
Fax: +972-8-9316885
Mobile: +972-52-8260388
Q: How many NSA agents does it take to replace a lightbulb?
A: dSva7DrYiY24yeTItKyyogFXD5gRuoRqPNQ9v6WCLLywZPINlu!
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]