🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sgi.bugs
Article #46

Re: C++ atexit() doesn't work

#46
From: Shankar Unni
Date: Tue, 05 Jan 1993 01:43
59 lines
1852 bytes
Harold Zatz (hzatz@cco.caltech.edu) wrote:

> krazy % CC -o test test.c
> krazy % test

An artifact of the woefully unportable AT&T C++ library. It has a
replacement for "exit()" that is totally bogus (it's pre-ANSI C, and
doesn't look for atexit() functions).

> 	Fixes? Workarounds? Anyone?

Solution (it's a little crude for the moment):

  1.  Create the following compilation unit:

      exit.c:

        /* --- cut here --- */

	extern "C" {
		extern void _exit(int);
		extern void __call_exitfns();
		extern void _cleanup();
	}
	extern void __dtors();

	extern "C" {
	extern void exit(int i);
	}

	extern void exit(int i)
	{
		__call_exitfns();		/* This is the fix */
		__dtors();
		_cleanup();
		_exit(i);
	}

        /* --- cut here --- */
           
  2.  To use this fix:

      (a) Compile it, and link it with your application as the last object
          file in the link list.  CAUTION: ensure that you have at least
	  *ONE* exit() call in your code, otherwise the version of exit()
	  in libC.a will be picked up. (Old-time Unix'ers will know why).

          OR

      (b) Replace the file in /usr/lib/libC.a:

            # ar rv /usr/lib/libC.a exit.o

          Be careful with the last: You may want to save the old libC.a
          before doing this, in case anything goes wrong..

--
Shankar Unni				E-Mail:	shankar@sgi.com
Silicon Graphics Inc.			Phone:	+1-415-390-2072
Technical Details
Message-ID: <1iap46INNbo0@fido.asd.sgi.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!sgigate!odin!fido!shankar
References: <1iad1lINNnn7@gap.caltech.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!sgigate!odin!fido!shankar
From: shankar@sgi.com (Shankar Unni)
Newsgroups: comp.sys.sgi.bugs
Subject: Re: C++ atexit() doesn't work
Message-ID: <1iap46INNbo0@fido.asd.sgi.com>
Date: 5 Jan 93 01:43:34 GMT
References: <1iad1lINNnn7@gap.caltech.edu>
Organization: Silicon Graphics, Inc.
Lines: 59
NNTP-Posting-Host: boris.wpd.sgi.com
X-Newsreader: Tin 1.1 PL5