diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2001-05-28 21:38:15 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2001-05-28 21:38:15 +0000 |
commit | 0f4ee19637361b907ef00b9b8e60ac559bb95989 (patch) | |
tree | 2cb117b60d3ded48c4ddf4123c480da421af771b /lib | |
parent | ef3eb9521d508777e6f29b4faad924d844922b58 (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/common_elf/crtbeginS.c (renamed from lib/csu/powerpc/crtbeginS.c) | 10 | ||||
-rw-r--r-- | lib/csu/common_elf/crtendS.c (renamed from lib/csu/powerpc/crtend.c) | 2 | ||||
-rw-r--r-- | lib/csu/powerpc/Makefile | 1 | ||||
-rw-r--r-- | lib/csu/powerpc/crtbegin.c | 110 | ||||
-rw-r--r-- | lib/csu/powerpc/crtendS.c | 9 |
5 files changed, 5 insertions, 127 deletions
diff --git a/lib/csu/powerpc/crtbeginS.c b/lib/csu/common_elf/crtbeginS.c index bf2ce4498fd..6945484f55c 100644 --- a/lib/csu/powerpc/crtbeginS.c +++ b/lib/csu/common_elf/crtbeginS.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crtbeginS.c,v 1.2 2000/10/13 05:14:03 drahn Exp $ */ +/* $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 $ */ /* @@ -32,10 +32,6 @@ */ /* - * XXX EVENTUALLY SHOULD BE MERGED BACK WITH c++rt0.c - */ - -/* * Run-time module for GNU C++ compiled shared libraries. * * The linker constructs the following arrays of pointers to global @@ -93,10 +89,9 @@ _init() if (!initialized) { initialized = 1; __ctors(); - - atexit(__dtors); } } + void _fini() { @@ -104,4 +99,5 @@ _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/powerpc/crtend.c b/lib/csu/common_elf/crtendS.c index 1b875de471b..2b3dbb174a1 100644 --- a/lib/csu/powerpc/crtend.c +++ b/lib/csu/common_elf/crtendS.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crtend.c,v 1.2 1999/08/20 14:11:36 niklas Exp $ */ +/* $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> diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile index 25094662210..d6621620630 100644 --- a/lib/csu/powerpc/Makefile +++ b/lib/csu/powerpc/Makefile @@ -6,6 +6,7 @@ OBJS= crt0.o gcrt0.o scrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o PICFLAG?=-fpic CLEANFILES+= core a.out +.PATH: ${.CURDIR}/../common_elf all: ${OBJS} diff --git a/lib/csu/powerpc/crtbegin.c b/lib/csu/powerpc/crtbegin.c deleted file mode 100644 index 4160b272ca6..00000000000 --- a/lib/csu/powerpc/crtbegin.c +++ /dev/null @@ -1,110 +0,0 @@ -/* $OpenBSD: crtbegin.c,v 1.2 1999/01/28 05:01:15 rahnds 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. - */ - -#ifndef ECOFF_COMPAT - -/* - * XXX EVENTUALLY SHOULD BE MERGED BACK WITH c++rt0.c - */ - -/* - * 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> - -void (*__CTOR_LIST__[0]) __P((void)) - __attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */ -void (*__DTOR_LIST__[0]) __P((void)) - __attribute__((section(".dtors"))) = { (void *)-1 }; /* XXX */ - -static void __dtors __P((void)); -static void __ctors __P((void)); - -static 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(); - } - atexit(__dtors); - -} - -void -__fini() -{ - /* - * Call global destructors. - */ - __dtors(); -} - -#endif /* !ECOFF_COMPAT */ diff --git a/lib/csu/powerpc/crtendS.c b/lib/csu/powerpc/crtendS.c deleted file mode 100644 index ea35355a16f..00000000000 --- a/lib/csu/powerpc/crtendS.c +++ /dev/null @@ -1,9 +0,0 @@ -/* $OpenBSD: crtendS.c,v 1.1 2000/06/13 04:07:03 rahnds 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 */ |