This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu 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]

Re: preloading.


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


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