Any way to catch exit()?

T. William Wells bill at proxftl.UUCP
Mon Aug 29 17:05:11 AEST 1988


In article <771 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
:                                               Probably has something to
: do with keeping binary sizes small,

Yes.  Loading the stdio _cleanup means loading a substantial part
of stdio as well.

:                                     but I can't figure out how you can
: have several _cleanup() 's in one library. Anyone knows?
:
:                                Leo.

This is easy on a UNIX system.  You define __iob or whatever the
FILE pointers point to in the file where you want the fancy
_cleanup routine to go.  You then place the exit and then the
dummy _cleanup right after it.  You have to give the two object
files different names, but that is easy.  The names I have seen
are cleanup.o and fakcu.o.  So, if the program references stdio
anywhere, it will reference __iob.  When the linker finds the
first _cleanup, it will load it because of the __iob.  Then exit
comes along and uses the already loaded _cleanup so the second
one is ignored.  On the other hand, if stdio is not referenced,
the first _cleanup is ignored because there is no reference to
it; the exit is loaded because every program references exit, and
that forces the loading of the second _cleanup.

There are several variations on this theme, but as far as I know
they all depend on library ordering tricks.

---
Bill
novavax!proxftl!bill



More information about the Comp.lang.c mailing list