diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2001-05-28 21:38:14 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2001-05-28 21:38:14 +0000 |
commit | 7e6f4dbf69a9587970ae651fe1b0cb63df771d76 (patch) | |
tree | 3a63a66830f9d4d1e14fadaa4a5a13194b0eaad3 /lib | |
parent | b82317fe64a1fd7041130df16cfcc8ab859ed22d (diff) |
Commonize csu code for elf systems, powerpc now no longer has it's own
versions of these files.
Fixed a bug in ld.so in this, instead of scheduling the fini of each of
the shared libraries with atexit. schedule a function of ld.so itself
and it will walk all of the open libraries when the program exits.
otherwise a shared library could be dl_open()ed and then dl_close()d
and then it would not be mapped for the atexit processing.
TODO:
What if atexit is not found (process did not link against libc?)
Do shared libraries that are dl_closed have their global destructors run?
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csu/crtbeginS.c | 103 | ||||
-rw-r--r-- | lib/csu/crtendS.c | 9 |
2 files changed, 112 insertions, 0 deletions
diff --git a/lib/csu/crtbeginS.c b/lib/csu/crtbeginS.c new file mode 100644 index 00000000000..6945484f55c --- /dev/null +++ b/lib/csu/crtbeginS.c @@ -0,0 +1,103 @@ +/* $OpenBSD: crtbeginS.c,v 1.1 2001/05/28 21:38:13 drahn Exp $ */ +/* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */ + +/* + * Copyright (c) 1993 Paul Kranenburg + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Paul Kranenburg. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Run-time module for GNU C++ compiled shared libraries. + * + * The linker constructs the following arrays of pointers to global + * constructors and destructors. The first element contains the + * number of pointers in each. + * The tables are also null-terminated. + + */ +#include <stdlib.h> + +static void (*__CTOR_LIST__[0]) __P((void)) + __attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */ +static void (*__DTOR_LIST__[0]) __P((void)) + __attribute__((section(".dtors"))) = { (void *)-1 }; /* XXX */ + +static void __dtors __P((void)); +static void __ctors __P((void)); + +void +__dtors() +{ + unsigned long i = (unsigned long) __DTOR_LIST__[0]; + void (**p)(void); + + if (i == -1) { + for (i = 1; __DTOR_LIST__[i] != NULL; i++) + ; + i--; + } + p = __DTOR_LIST__ + i; + while (i--) { + (**p--)(); + } +} + +static void +__ctors() +{ + void (**p)(void) = __CTOR_LIST__ + 1; + + while (*p) { + (**p++)(); + } +} + +void +_init() +{ + static int initialized = 0; + + /* + * Call global constructors. + * Arrange to call global destructors at exit. + */ + if (!initialized) { + initialized = 1; + __ctors(); + } +} + +void +_fini() +{ + /* + * since the _init() function sets up the destructors to be called + * by atexit, do not call the destructors here. + */ + __dtors(); +} diff --git a/lib/csu/crtendS.c b/lib/csu/crtendS.c new file mode 100644 index 00000000000..2b3dbb174a1 --- /dev/null +++ b/lib/csu/crtendS.c @@ -0,0 +1,9 @@ +/* $OpenBSD: crtendS.c,v 1.1 2001/05/28 21:38:13 drahn Exp $ */ +/* $NetBSD: crtend.c,v 1.1 1997/04/16 19:38:24 thorpej Exp $ */ + +#include <sys/cdefs.h> + +static void (*__CTOR_LIST__[1]) __P((void)) + __attribute__((section(".ctors"))) = { (void *)0 }; /* XXX */ +static void (*__DTOR_LIST__[1]) __P((void)) + __attribute__((section(".dtors"))) = { (void *)0 }; /* XXX */ |