diff --exclude=CVS /home/odin/initfini/src/lib/csu/common_elf/crtbegin.c lib/csu/common_elf/crtbegin.c --- /home/odin/initfini/src/lib/csu/common_elf/crtbegin.c Sat Feb 16 16:26:58 2002 +++ lib/csu/common_elf/crtbegin.c Fri Aug 22 22:53:57 2003 @@ -2,7 +2,7 @@ /* $NetBSD: crtbegin.c,v 1.1 1996/09/12 16:59:03 cgd Exp $ */ /* - * Copyright (c) 1993 Paul Kranenburg + * Copyright (c) 1993 Paul Kranenburg and Ross Harvey. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,6 +42,7 @@ #include #include "os-note-elf.h" +#include "dot_init.h" static void (*__CTOR_LIST__[1])(void) __attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */ @@ -51,7 +52,24 @@ static void __dtors(void); static void __ctors(void); +INIT_FALLTHRU_DECL; +FINI_FALLTHRU_DECL; + +extern void __init(void) __attribute__((section(".init"))); +extern void __fini(void) __attribute__((section(".fini"))); +static void __ctors(void) __attribute__((section(".init"))); +static void __dtors(void) __attribute__((section(".fini"))); + static void +__ctors() +{ + void (**p)(void) = __CTOR_LIST__ + 1; + + while (*p) + (**p++)(); +} + +static void __dtors() { unsigned long i = (unsigned long) __DTOR_LIST__[0]; @@ -67,18 +85,6 @@ (**p--)(); } -static void -__ctors() -{ - void (**p)(void) = __CTOR_LIST__ + 1; - - while (*p) - (**p++)(); -} - -void __init(void) __attribute__((section(".init"))); -void __fini(void) __attribute__((section(".fini"))); - void __init() { @@ -88,6 +94,7 @@ * Call global constructors. * Arrange to call global destructors at exit. */ + INIT_FALLTHRU(); if (!initialized) { initialized = 1; __ctors(); @@ -103,5 +110,9 @@ * Call global destructors. */ __dtors(); + FINI_FALLTHRU(); } +MD_INIT_SECTION_PROLOGUE; + +MD_FINI_SECTION_PROLOGUE; diff --exclude=CVS /home/odin/initfini/src/lib/csu/common_elf/crtend.c lib/csu/common_elf/crtend.c --- /home/odin/initfini/src/lib/csu/common_elf/crtend.c Sat Feb 16 16:26:58 2002 +++ lib/csu/common_elf/crtend.c Fri Aug 22 22:49:40 2003 @@ -4,6 +4,7 @@ #ifndef ECOFF_COMPAT #include +#include "dot_init.h" static void (*__CTOR_LIST__[1])(void) __attribute__((section(".ctors"))) = { (void *)0 }; /* XXX */ @@ -11,3 +12,7 @@ __attribute__((section(".dtors"))) = { (void *)0 }; /* XXX */ #endif /* !ECOFF_COMPAT */ + +MD_INIT_SECTION_EPILOGUE; + +MD_FINI_SECTION_EPILOGUE; diff --exclude=CVS /home/odin/initfini/src/lib/csu/common_elf/dot_init.h lib/csu/common_elf/dot_init.h --- /home/odin/initfini/src/lib/csu/common_elf/dot_init.h Wed Dec 31 19:00:00 1969 +++ lib/csu/common_elf/dot_init.h Fri Aug 22 22:50:00 2003 @@ -0,0 +1,48 @@ +/* $NetBSD: dot_init.h,v 1.1 2001/05/11 22:44:15 ross Exp $ */ + +/*- + * Copyright (c) 2001 Ross Harvey + * 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 the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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. + */ + +#include /* RCS ID & Copyright macro defns */ + +#define INIT_FALLTHRU_DECL +#define FINI_FALLTHRU_DECL + +#define INIT_FALLTHRU() +#define FINI_FALLTHRU() + +#define MD_INIT_SECTION_PROLOGUE +#define MD_FINI_SECTION_PROLOGUE + +#define MD_INIT_SECTION_EPILOGUE +#define MD_FINI_SECTION_EPILOGUE diff --exclude=CVS /home/odin/initfini/src/lib/csu/i386/Makefile lib/csu/i386/Makefile --- /home/odin/initfini/src/lib/csu/i386/Makefile Fri May 30 15:03:02 2003 +++ lib/csu/i386/Makefile Fri Aug 22 23:08:21 2003 @@ -5,6 +5,9 @@ OBJS= crt0.o gcrt0.o crtbegin.o crtend.o crtbeginS.o crtendS.o SRCS= crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c +#Uncomment the next line to enable the new .init fallthru +CFLAGS+= -I- -I${.CURDIR} + ELFDIR= ${.CURDIR}/../common_elf .PATH: ${ELFDIR} CFLAGS+= -I${ELFDIR} diff --exclude=CVS /home/odin/initfini/src/lib/csu/i386/dot_init.h lib/csu/i386/dot_init.h --- /home/odin/initfini/src/lib/csu/i386/dot_init.h Wed Dec 31 19:00:00 1969 +++ lib/csu/i386/dot_init.h Fri Aug 22 22:52:26 2003 @@ -0,0 +1,70 @@ +/* $NetBSD: dot_init.h,v 1.1 2001/05/11 22:44:15 ross Exp $ */ + +/*- + * Copyright (c) 2001 Ross Harvey + * 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 the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``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 FOUNDATION OR CONTRIBUTORS + * 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. + */ + +#include /* RCS ID & Copyright macro defns */ +#include + +/* + * These must be extern to avoid warnings ("declared static but never defined") + * However, only the declaration is extern, the actually __asm() defines them + * as static. + */ +#define INIT_FALLTHRU_DECL void init_fallthru(void) +#define FINI_FALLTHRU_DECL void fini_fallthru(void) + +#define INIT_FALLTHRU() init_fallthru() +#define FINI_FALLTHRU() fini_fallthru() + +#define MD_SECTION_PROLOGUE(sect, entry_pt) \ + __asm ( \ + ".section "#sect",\"ax\",@progbits \n"\ + #entry_pt": \n"\ + " .align 16 \n"\ + " /* fall thru */ \n"\ + ".previous") + + /* placement of the .align _after_ the label is intentional */ + +#define MD_SECTION_EPILOGUE(sect) \ + __asm ( \ + ".section "#sect",\"ax\",@progbits \n"\ + " ret \n"\ + ".previous") + +#define MD_INIT_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.init, init_fallthru) +#define MD_FINI_SECTION_PROLOGUE MD_SECTION_PROLOGUE(.fini, fini_fallthru) + +#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init) +#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)