This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
Re: preloading.
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: Re: preloading.
- From: Artie Gold <agold at bga dot com>
- Date: Thu, 02 Aug 2001 14:13:20 -0500
- CC: Muzaffer Ozakca <muzaffer dot ozakca at bilten dot metu dot edu dot tr>
- Organization: ...is to be devoutly hoped for!
- References: <3B694020.AD7DA2C0@bilten.metu.edu.tr>
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
Muzaffer Ozakca wrote:
>
> Sorry for the dumb question. For a checkpointing system, I'm trying to
> add some code to a process when it is started. I've read that the loader
> (or whatever) is adding a call to the _exit() after main() returns. I
> want to do a similar thing but before main() is called. Where should I
> look for information on this? Should I change libc or any other/better
> method to do this? Thank you for any help.
>
> --
The simplest way to do this is to create an initialization function in
your shared object (it doesn't matter if it is to be linked in of used
with LD_PRELOAD) and mark it with
__attribute__((constructor))
as in:
void my_initialization() __attribute((constructor));
void my_initialization() {
...
}
The other option, which in some instances makes compilation/linking a
little more difficult would be to define a function called `_init' in
your shared object, and compile with the `-nostartfiles' option.
HTH,
--ag
--
Artie Gold, Austin, TX (finger the cs.utexas.edu account for more info)
mailto:agold@bga.com or mailto:agold@cs.utexas.edu
--
"Verbing weirds language." -- Calvin