allow unloadable bundles on Darwin to call atexit

Geoffrey Keating gkeating@apple.com
Wed Apr 5 00:52:00 GMT 2006


With the previous crt3.o, if you call atexit and then unload the
bundle that called atexit, your program will crash on quit.  That
turns out to be annoying, sometimes you're using a library that really
wants to use atexit but you still want to unload your bundle.  It
turns out to be really easy to make this work, and a crash on quit
isn't very useful, thus this patch.

Tested with bubblestrap & testsuite run on powerpc-darwin8, plus
checking that you actually can create a bundle which calls atexit and
is unloadable.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-darwin-crt3atexitunload.patch=========
2006-04-04  Geoffrey Keating  <geoffk@apple.com>

	* config/darwin-crt3.c (atexit): Pass &__dso_handle rather than
	NULL for dso parameter to atexit_common.

Index: gcc/config/darwin-crt3.c
===================================================================
--- gcc/config/darwin-crt3.c	(revision 112657)
+++ gcc/config/darwin-crt3.c	(working copy)
@@ -518,11 +518,15 @@
 
 int atexit (atexit_callback func) __attribute__((visibility("hidden")));
 
+/* Use __dso_handle to allow even bundles that call atexit() to be unloaded
+   on 10.4.  */
+extern void __dso_handle;
+
 int
 atexit (atexit_callback func)
 {
   struct one_atexit_routine r;
   r.callback.ac = func;
   r.has_arg = 0;
-  return atexit_common (&r, NULL);
+  return atexit_common (&r, &__dso_handle);
 }
============================================================



More information about the Gcc-patches mailing list