Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!houxm!mhuxt!m10ux!braun From: braun@m10ux.UUCP Newsgroups: comp.os.minix Subject: Re: Hard Disk Problem (actually stdio cleanup) Message-ID: <164@m10ux.UUCP> Date: Mon, 2-Mar-87 11:26:43 EST Article-I.D.: m10ux.164 Posted: Mon Mar 2 11:26:43 1987 Date-Received: Wed, 4-Mar-87 18:46:36 EST References: <496@ubu.warwick.UUCP>, <9490002@hpfclp.HP.COM> Organization: AT&T Bell Labs, Murray Hill, NJ Lines: 51 The way sys V (and 4.2 BSD) allow you to call exit() and only include code to flush stdio's buffers is as follows: Remember, main() is just another function. The actual main program (csu.c or csu.s) works basically like this: /* First diddle stack pointer, etc. so main() can get environ, argc, argv */ r0 = main(); exit (r0); Exit() looks like this: (actually in assembler on sys V) exit(exitval) { _cleanup(); _exit(exitval); } So far, so good. Csu makes it possible to not call exit() and still flush things in _cleanup(). So the problem is: we need to load one of two versions of _cleanup(). If we use stdio, we want a cleanup to flush buffers. Otherwise, it should do nothing. The first version is part of flsbuf.c in the stdio library. Since it is in the same object file, it will be loaded whenever flsbuf.o is loaded, which is whenever you use stdio. Exit.o is located in libc.a after flsbuf.o, so if stdio is not used, there will be no references to _cleanup() when flsbuf.o is searched by the loader, and it will not be loaded. Of course if stdio is used, flsbuf.o (containing _cleanup()) will be loaded. When exit.o is searched by the linker, it will always be loaded, because it is referenced by csu, the actual "main" program. If we have used stdio, we have now loaded everything we need. If not, we not have an outstanding reference to _cleanup(), which must be the non-stdio version. This dummy version of cleanup is located near the end of libc.a, after flsbuf.o and exit.o. This gets loaded only if there is an outstanding reference to _cleanup(), which is only if stdio was not used. Does this make any sense? I imagine it will be obvious to some, and incoherent to most others. The important point is that we can have everything work fine without any compiler switches, or other action on the part of the user. The only assumption is that we have a loader which linearly searches the object library. -- Doug Braun AT+T Bell Labs, Murray Hill, NJ m10ux!braun 201 582-7039