Split crtbegin/crtend into crti/crtbegin/crtend/crtn. NetBSD-specific

things like the .note.netbsd.ident section are provided by crti/crtn.
crti/crtn also provide the _init() and _fini() routines.

crtbegin/crtend now only provide support for ctors/dtors.  This paves
the way to using the "crtstuff" provided with GCC (when we upgrade to
GCC 3.3), which provides, among other things, much better C++/Java
exception handling.
This commit is contained in:
thorpej 2002-11-22 06:44:56 +00:00
parent 2cc0cde8f5
commit 6dba3a7439
11 changed files with 194 additions and 49 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: dot_init.h,v 1.1 2001/05/11 22:44:14 ross Exp $ */
/* $NetBSD: dot_init.h,v 1.2 2002/11/22 06:44:58 thorpej Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@ -77,3 +77,12 @@
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)
/* We assume we need to reload our GP. */
#define MD_CALL_STATIC_FUNCTION(section, func) \
asm(".section " #section "\n" \
" br $29, 1f \n" \
"1: ldgp $29, 1f \n" \
" unop \n" \
" jsr $26, " #func "\n" \
" .align 3; .previous");

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile.inc,v 1.18 2002/08/19 09:41:27 lukem Exp $
# $NetBSD: Makefile.inc,v 1.19 2002/11/22 06:44:58 thorpej Exp $
.include <bsd.own.mk>
@ -18,7 +18,7 @@ CPPFLAGS+= -DDSO_HANDLE
.PATH: ${.CURDIR}/../common_elf
OBJS+= crt0.o gcrt0.o crtbegin.o crtend.o
OBJS+= crt0.o gcrt0.o crti.o crtbegin.o crtend.o crtn.o
.if ${MKPIC} != "no"
OBJS+= crtbeginS.o crtendS.o
COPTS+= -fPIC
@ -62,6 +62,18 @@ crtendS.o: crtend.c
@${LD} -X -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
crti.o: crti.c
@echo "${COMPILE.c} ${.ALLSRC} -o ${.TARGET}"
@${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
@${LD} -X -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
crtn.o: crtn.c
@echo "${COMPILE.c} ${.ALLSRC} -o ${.TARGET}"
@${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
@${LD} -X -r -o ${.TARGET} ${.TARGET}.o
@rm -f ${.TARGET}.o
FILES=${OBJS}
FILESDIR=${LIBDIR}

View File

@ -1,7 +1,7 @@
/* $NetBSD: crtbegin.c,v 1.19 2002/11/11 00:44:43 thorpej Exp $ */
/* $NetBSD: crtbegin.c,v 1.20 2002/11/22 06:44:58 thorpej Exp $ */
/*-
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
* Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@ -94,19 +94,23 @@ extern void __cxa_finalize(void *) __attribute__((weak));
#endif
#endif
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")));
#ifndef MD_CALL_STATIC_FUNCTION
#if defined(__GNUC__)
#define MD_CALL_STATIC_FUNCTION(section, func) \
static void __attribute__((__unused__)) \
__call_##func(void) \
{ \
__asm __volatile (".section " #section); \
func(); \
__asm __volatile (".previous"); \
}
#else
#error Need MD_CALL_STATIC_FUNCTION
#endif
#endif /* ! MD_CALL_STATIC_FUNCTION */
static void
__ctors()
__ctors(void)
{
unsigned long i = (unsigned long) __CTOR_LIST__[0];
void (**p)(void);
@ -122,7 +126,7 @@ __ctors()
}
static void
__dtors()
__dtors(void)
{
void (**p)(void) = __DTOR_LIST__ + 1;
@ -130,20 +134,16 @@ __dtors()
(**p++)();
}
void
_init()
static void __attribute__((__unused__))
__do_global_ctors_aux(void)
{
static int initialized = 0;
static int initialized;
#ifdef DWARF2_EH
#if defined(__GNUC__)
static struct dwarf2_eh_object object;
#endif /* __GNUC__ */
#endif /* DWARF2_EH */
/*
* Execute code in the .init sections
*/
INIT_FALLTHRU();
if (!initialized) {
initialized = 1;
@ -165,10 +165,15 @@ _init()
__ctors();
}
}
MD_CALL_STATIC_FUNCTION(.init, __do_global_ctors_aux)
void
_fini()
static void __attribute__((__unused__))
__do_global_dtors_aux(void)
{
static int finished;
if (finished)
return;
#if defined(DSO_HANDLE) && defined(__GNUC__) && defined(SHARED)
/*
@ -190,12 +195,6 @@ _fini()
#endif /* __GNUC__ */
#endif /* DWARF2_EH */
/*
* Execute code in the .fini sections
*/
FINI_FALLTHRU();
finished = 1;
}
MD_INIT_SECTION_PROLOGUE;
MD_FINI_SECTION_PROLOGUE;
MD_CALL_STATIC_FUNCTION(.fini, __do_global_dtors_aux)

View File

@ -1,4 +1,4 @@
/* $NetBSD: crtend.c,v 1.9 2001/12/30 23:45:01 thorpej Exp $ */
/* $NetBSD: crtend.c,v 1.10 2002/11/22 06:44:59 thorpej Exp $ */
#include <sys/cdefs.h>
#include "dot_init.h"
@ -20,7 +20,3 @@ static unsigned int __FRAME_END__[]
static void *__JCR_END__[1]
__attribute__((__unused__, section(".jcr"))) = { (void *) 0 };
#endif
MD_INIT_SECTION_EPILOGUE;
MD_FINI_SECTION_EPILOGUE;

67
lib/csu/common_elf/crti.c Normal file
View File

@ -0,0 +1,67 @@
/* $NetBSD: crti.c,v 1.1 2002/11/22 06:44:59 thorpej Exp $ */
/*-
* Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
*
* 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 <sys/param.h> /* sysident.h requires `NetBSD' constant */
#include <sys/exec.h>
#include <sys/exec_elf.h>
#include "sysident.h"
#include "dot_init.h"
INIT_FALLTHRU_DECL;
FINI_FALLTHRU_DECL;
void _init(void);
void _fini(void);
void
_init(void)
{
INIT_FALLTHRU();
}
void
_fini(void)
{
FINI_FALLTHRU();
}
MD_INIT_SECTION_PROLOGUE;
MD_FINI_SECTION_PROLOGUE;

42
lib/csu/common_elf/crtn.c Normal file
View File

@ -0,0 +1,42 @@
/* $NetBSD: crtn.c,v 1.1 2002/11/22 06:44:59 thorpej Exp $ */
/*-
* Copyright (c) 1998, 2001, 2002 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
*
* 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 "dot_init.h"
MD_INIT_SECTION_EPILOGUE;
MD_FINI_SECTION_EPILOGUE;

View File

@ -1,4 +1,4 @@
/* $NetBSD: dot_init.h,v 1.2 2002/01/14 12:06:49 drochner Exp $ */
/* $NetBSD: dot_init.h,v 1.3 2002/11/22 06:45:00 thorpej Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@ -67,3 +67,6 @@
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)
#define MD_CALL_STATIC_FUNCTION(section, func) \
asm(".section " #section "; call " #func "; .previous");

View File

@ -1,4 +1,4 @@
/* $NetBSD: dot_init.h,v 1.1 2001/07/23 20:43:31 tsubai Exp $ */
/* $NetBSD: dot_init.h,v 1.2 2002/11/22 06:45:00 thorpej Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@ -73,3 +73,17 @@
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)
/*
* We need to put the function pointer in our own constant
* pool (otherwise it might be too far away to reference).
*/
#define MD_CALL_STATIC_FUNCTION(section, func) \
asm(".section " #section "\n" \
" mov.l 1f, r1 \n" \
" mova 2f, r0 \n" \
" braf r1 \n" \
" lds r0, pr \n" \
"0: .p2align 2 \n" \
"1: .long " #func " - 0b \n" \
"2: .previous");

View File

@ -1,4 +1,4 @@
/* $NetBSD: dot_init.h,v 1.1 2002/06/06 19:18:22 fvdl Exp $ */
/* $NetBSD: dot_init.h,v 1.2 2002/11/22 06:45:01 thorpej Exp $ */
/*-
* Copyright (c) 2001 Ross Harvey
@ -67,3 +67,6 @@
#define MD_INIT_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.init)
#define MD_FINI_SECTION_EPILOGUE MD_SECTION_EPILOGUE(.fini)
#define MD_CALL_STATIC_FUNCTION(section, func) \
asm(".section " #section "; call " #func "; .previous");

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.lib.mk,v 1.211 2002/11/10 21:26:44 thorpej Exp $
# $NetBSD: bsd.lib.mk,v 1.212 2002/11/22 06:44:56 thorpej Exp $
# @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
.include <bsd.init.mk>
@ -165,8 +165,8 @@ MKSHLIBOBJS= no
.if ${OBJECT_FMT} == "ELF"
SHLIB_SOVERSION= ${SHLIB_MAJOR}
SHLIB_SHFLAGS= -soname lib${LIB}.so.${SHLIB_SOVERSION}
SHLIB_LDSTARTFILE?= ${DESTDIR}/usr/lib/crtbeginS.o
SHLIB_LDENDFILE?= ${DESTDIR}/usr/lib/crtendS.o
SHLIB_LDSTARTFILE?= ${DESTDIR}/usr/lib/crti.o ${DESTDIR}/usr/lib/crtbeginS.o
SHLIB_LDENDFILE?= ${DESTDIR}/usr/lib/crtendS.o ${DESTDIR}/usr/lib/crtn.o
.endif
CFLAGS+= ${COPTS}

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.prog.mk,v 1.161 2002/11/12 14:33:49 itohy Exp $
# $NetBSD: bsd.prog.mk,v 1.162 2002/11/22 06:44:57 thorpej Exp $
# @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
.include <bsd.init.mk>
@ -17,14 +17,14 @@ CFLAGS+= ${COPTS}
CFLAGS+= -mcmodel=medlow
.endif
# ELF platforms depend on crtbegin.o and crtend.o
# ELF platforms depend on crti.o, crtbegin.o, crtend.o, and crtn.o
.if ${OBJECT_FMT} == "ELF"
.ifndef LIBCRTBEGIN
LIBCRTBEGIN= ${DESTDIR}/usr/lib/crtbegin.o
LIBCRTBEGIN= ${DESTDIR}/usr/lib/crti.o ${DESTDIR}/usr/lib/crtbegin.o
.MADE: ${LIBCRTBEGIN}
.endif
.ifndef LIBCRTEND
LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o
LIBCRTEND= ${DESTDIR}/usr/lib/crtend.o ${DESTDIR}/usr/lib/crtn.o
.MADE: ${LIBCRTEND}
.endif
_SHLINKER= ${SHLINKDIR}/ld.elf_so