2002-04-09 02:17:37 +04:00
|
|
|
/* $NetBSD: crtbegin.c,v 1.18 2002/04/08 22:17:37 skrll Exp $ */
|
1996-09-12 20:59:01 +04:00
|
|
|
|
1998-09-05 17:20:07 +04:00
|
|
|
/*-
|
2001-12-31 03:40:11 +03:00
|
|
|
* Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
|
1996-09-12 20:59:01 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-09-05 17:20:07 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2001-12-31 03:40:11 +03:00
|
|
|
* by Paul Kranenburg, Ross Harvey, and Jason R. Thorpe.
|
1998-09-05 17:20:07 +04:00
|
|
|
*
|
1996-09-12 20:59:01 +04:00
|
|
|
* 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:
|
1998-09-05 17:20:07 +04:00
|
|
|
* 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.
|
1996-09-12 20:59:01 +04:00
|
|
|
*
|
1998-09-05 17:20:07 +04:00
|
|
|
* 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.
|
1996-09-12 20:59:01 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1997-03-21 08:47:28 +03:00
|
|
|
* Run-time module which handles constructors and destructors,
|
|
|
|
* and NetBSD identification.
|
1996-09-12 20:59:01 +04:00
|
|
|
*
|
|
|
|
* The linker constructs the following arrays of pointers to global
|
|
|
|
* constructors and destructors. The first element contains the
|
1997-03-21 08:47:28 +03:00
|
|
|
* number of pointers in each or -1 to indicate that the run-time
|
|
|
|
* code should figure out how many there are. The tables are also
|
|
|
|
* null-terminated.
|
1996-09-12 20:59:01 +04:00
|
|
|
*/
|
1997-03-21 08:47:28 +03:00
|
|
|
|
1998-07-28 01:46:49 +04:00
|
|
|
#include <sys/param.h> /* sysident.h requires `NetBSD' constant */
|
1997-03-21 08:47:28 +03:00
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/exec_elf.h>
|
1996-09-12 20:59:01 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-08-03 09:54:43 +04:00
|
|
|
#ifdef DWARF2_EH
|
|
|
|
#include "dwarf2_eh.h"
|
|
|
|
#endif
|
1997-03-21 08:47:28 +03:00
|
|
|
#include "sysident.h"
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
#include "dot_init.h"
|
1997-03-21 08:47:28 +03:00
|
|
|
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
static void (*__CTOR_LIST__[1])(void)
|
1996-09-12 20:59:01 +04:00
|
|
|
__attribute__((section(".ctors"))) = { (void *)-1 }; /* XXX */
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
static void (*__DTOR_LIST__[1])(void)
|
1996-09-12 20:59:01 +04:00
|
|
|
__attribute__((section(".dtors"))) = { (void *)-1 }; /* XXX */
|
|
|
|
|
2001-08-03 09:54:43 +04:00
|
|
|
#ifdef DWARF2_EH
|
|
|
|
static char __EH_FRAME_BEGIN__[]
|
2001-12-31 02:26:20 +03:00
|
|
|
__attribute__((section(".eh_frame"), aligned(4))) = { };
|
2001-08-03 09:54:43 +04:00
|
|
|
#endif
|
|
|
|
|
2001-12-31 02:45:00 +03:00
|
|
|
#if defined(JCR) && defined(__GNUC__)
|
|
|
|
extern void _Jv_RegisterClasses(void *) __attribute__((weak));
|
|
|
|
|
|
|
|
static void *__JCR_LIST__[]
|
|
|
|
__attribute__((section(".jcr"))) = { };
|
|
|
|
#endif
|
|
|
|
|
2001-12-31 03:40:11 +03:00
|
|
|
#if defined(DSO_HANDLE) && defined(__GNUC__)
|
|
|
|
/*
|
|
|
|
* The __dso_handle variable is used to hang C++ local destructors off
|
|
|
|
* of. In the main program (i.e. using crtbegin.o), the value is 0.
|
|
|
|
* In shared objects (i.e. using crtbeginS.o), the value must be unique.
|
|
|
|
* The symbol is hidden, but the dynamic linker will still relocate it.
|
|
|
|
*/
|
|
|
|
#ifdef SHARED
|
|
|
|
void *__dso_handle = &__dso_handle;
|
|
|
|
#else
|
|
|
|
void *__dso_handle = NULL;
|
|
|
|
#endif
|
|
|
|
__asm(".hidden __dso_handle");
|
|
|
|
|
|
|
|
#ifdef SHARED
|
|
|
|
extern void __cxa_finalize(void *) __attribute__((weak));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
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()
|
|
|
|
{
|
2001-10-11 22:02:28 +04:00
|
|
|
unsigned long i = (unsigned long) __CTOR_LIST__[0];
|
1996-09-12 20:59:01 +04:00
|
|
|
void (**p)(void);
|
|
|
|
|
|
|
|
if (i == -1) {
|
2001-10-11 22:02:28 +04:00
|
|
|
for (i = 1; __CTOR_LIST__[i] != NULL; i++)
|
1996-09-12 20:59:01 +04:00
|
|
|
;
|
|
|
|
i--;
|
|
|
|
}
|
2001-10-11 22:02:28 +04:00
|
|
|
p = __CTOR_LIST__ + i;
|
1996-09-12 20:59:01 +04:00
|
|
|
while (i--)
|
|
|
|
(**p--)();
|
|
|
|
}
|
|
|
|
|
2001-10-11 22:02:28 +04:00
|
|
|
static void
|
|
|
|
__dtors()
|
|
|
|
{
|
|
|
|
void (**p)(void) = __DTOR_LIST__ + 1;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
(**p++)();
|
|
|
|
}
|
|
|
|
|
1996-09-12 20:59:01 +04:00
|
|
|
void
|
1998-03-27 12:11:33 +03:00
|
|
|
_init()
|
1996-09-12 20:59:01 +04:00
|
|
|
{
|
|
|
|
static int initialized = 0;
|
2001-08-03 09:54:43 +04:00
|
|
|
#ifdef DWARF2_EH
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
static struct dwarf2_eh_object object;
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* DWARF2_EH */
|
2001-07-17 17:28:05 +04:00
|
|
|
|
1996-09-12 20:59:01 +04:00
|
|
|
/*
|
2002-04-09 02:17:37 +04:00
|
|
|
* Execute code in the .init sections
|
1996-09-12 20:59:01 +04:00
|
|
|
*/
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
INIT_FALLTHRU();
|
1996-09-12 20:59:01 +04:00
|
|
|
if (!initialized) {
|
|
|
|
initialized = 1;
|
2001-08-03 09:54:43 +04:00
|
|
|
|
|
|
|
#ifdef DWARF2_EH
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
if (__register_frame_info != NULL)
|
|
|
|
__register_frame_info(__EH_FRAME_BEGIN__, &object);
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* DWARF2_EH */
|
|
|
|
|
2001-12-31 02:45:00 +03:00
|
|
|
#if defined(JCR) && defined(__GNUC__)
|
|
|
|
if (__JCR_LIST__[0] != NULL && _Jv_RegisterClasses != NULL)
|
|
|
|
_Jv_RegisterClasses(__JCR_LIST__);
|
|
|
|
#endif /* JCR && __GNUC__ */
|
|
|
|
|
2002-04-09 02:17:37 +04:00
|
|
|
/*
|
|
|
|
* Call global constructors.
|
|
|
|
*/
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
__ctors();
|
1996-09-12 20:59:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-27 12:11:33 +03:00
|
|
|
_fini()
|
1996-09-12 20:59:01 +04:00
|
|
|
{
|
2001-07-17 17:28:05 +04:00
|
|
|
|
2001-12-31 03:40:11 +03:00
|
|
|
#if defined(DSO_HANDLE) && defined(__GNUC__) && defined(SHARED)
|
|
|
|
/*
|
|
|
|
* Call local destructors.
|
|
|
|
*/
|
|
|
|
if (__cxa_finalize != NULL)
|
|
|
|
__cxa_finalize(__dso_handle);
|
|
|
|
#endif /* DSO_HANDLE && __GNUC__ && SHARED */
|
|
|
|
|
1996-09-12 20:59:01 +04:00
|
|
|
/*
|
|
|
|
* Call global destructors.
|
|
|
|
*/
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
__dtors();
|
2001-08-03 09:54:43 +04:00
|
|
|
|
|
|
|
#ifdef DWARF2_EH
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
if (__deregister_frame_info != NULL)
|
|
|
|
__deregister_frame_info(__EH_FRAME_BEGIN__);
|
|
|
|
#endif /* __GNUC__ */
|
|
|
|
#endif /* DWARF2_EH */
|
|
|
|
|
2002-04-09 02:17:37 +04:00
|
|
|
/*
|
|
|
|
* Execute code in the .fini sections
|
|
|
|
*/
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
FINI_FALLTHRU();
|
1996-09-12 20:59:01 +04:00
|
|
|
}
|
Reorganization of crtbegin/crtend.
o Primary mod: alpha and i386 code for .init and .fini section fallthroughs
o Actual fallthru is not yet enabled, see csu/{alpha,i386_elf}/Makefile
o When enabled, should fix bin/12865 & should fix at least one WINE bug,
see http://www.winehq.com/hypermail/wine-devel/2001/05/0021.html
o Also, removed the function pointer hack put in to prevent gcc from
incorrectly attempting to do short calls over section boundaries,
on some architectures, rather, simply simply move ctors() and dtors()
into .init and .fini.
Other notes.
o Our crtbegin.c and crtend.c were completely in C, despite
the fact that .init and .fini section fallthroughs require machine code.
These modules implement the gnu ctors/dtors mechanism directly, eliminating
in part the need for the elf .init/.fini section fallthrough. However,
if we ever want to use the gnu-provided constructor support, we need to
do the fallthrough, at least one program (WINE) apparently uses the
feature independently, and other compilers may depend on the mechanism.
o It is amusing that the previous NetBSD _init() and _fini() were put
into the .init and .fini sections, because nothing is gained over
plain .text if they don't fall through. Cargo cult!
o Other elf ports will need to copy the alpha and i386 example mods.
2001-05-12 02:44:14 +04:00
|
|
|
|
|
|
|
MD_INIT_SECTION_PROLOGUE;
|
|
|
|
|
|
|
|
MD_FINI_SECTION_PROLOGUE;
|