home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / sys / sgi / bugs / 67 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.7 KB  |  72 lines

  1. Path: sparky!uunet!olivea!sgigate!odin!fido!shankar
  2. From: shankar@sgi.com (Shankar Unni)
  3. Newsgroups: comp.sys.sgi.bugs
  4. Subject: Re: C++ atexit() doesn't work
  5. Message-ID: <1iap46INNbo0@fido.asd.sgi.com>
  6. Date: 5 Jan 93 01:43:34 GMT
  7. References: <1iad1lINNnn7@gap.caltech.edu>
  8. Organization: Silicon Graphics, Inc.
  9. Lines: 59
  10. NNTP-Posting-Host: boris.wpd.sgi.com
  11. X-Newsreader: Tin 1.1 PL5
  12.  
  13. Harold Zatz (hzatz@cco.caltech.edu) wrote:
  14.  
  15. > krazy % CC -o test test.c
  16. > krazy % test
  17.  
  18. An artifact of the woefully unportable AT&T C++ library. It has a
  19. replacement for "exit()" that is totally bogus (it's pre-ANSI C, and
  20. doesn't look for atexit() functions).
  21.  
  22. >     Fixes? Workarounds? Anyone?
  23.  
  24. Solution (it's a little crude for the moment):
  25.  
  26.   1.  Create the following compilation unit:
  27.  
  28.       exit.c:
  29.  
  30.         /* --- cut here --- */
  31.  
  32.     extern "C" {
  33.         extern void _exit(int);
  34.         extern void __call_exitfns();
  35.         extern void _cleanup();
  36.     }
  37.     extern void __dtors();
  38.  
  39.     extern "C" {
  40.     extern void exit(int i);
  41.     }
  42.  
  43.     extern void exit(int i)
  44.     {
  45.         __call_exitfns();        /* This is the fix */
  46.         __dtors();
  47.         _cleanup();
  48.         _exit(i);
  49.     }
  50.  
  51.         /* --- cut here --- */
  52.            
  53.   2.  To use this fix:
  54.  
  55.       (a) Compile it, and link it with your application as the last object
  56.           file in the link list.  CAUTION: ensure that you have at least
  57.       *ONE* exit() call in your code, otherwise the version of exit()
  58.       in libC.a will be picked up. (Old-time Unix'ers will know why).
  59.  
  60.           OR
  61.  
  62.       (b) Replace the file in /usr/lib/libC.a:
  63.  
  64.             # ar rv /usr/lib/libC.a exit.o
  65.  
  66.           Be careful with the last: You may want to save the old libC.a
  67.           before doing this, in case anything goes wrong..
  68.  
  69. --
  70. Shankar Unni                E-Mail:    shankar@sgi.com
  71. Silicon Graphics Inc.            Phone:    +1-415-390-2072
  72.