Home | History | Annotate | Line # | Download | only in common
crtbegin.c revision 1.2
      1  1.1  matt /*-
      2  1.1  matt  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      3  1.1  matt  * All rights reserved.
      4  1.1  matt  *
      5  1.1  matt  * This code is derived from software contributed to The NetBSD Foundation
      6  1.1  matt  * by Matt Thomas of 3am Software Foundry.
      7  1.1  matt  *
      8  1.1  matt  * Redistribution and use in source and binary forms, with or without
      9  1.1  matt  * modification, are permitted provided that the following conditions
     10  1.1  matt  * are met:
     11  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     12  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     13  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  matt  *    documentation and/or other materials provided with the distribution.
     16  1.1  matt  *
     17  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18  1.1  matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19  1.1  matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20  1.1  matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21  1.1  matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  1.1  matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.1  matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.1  matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  1.1  matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.1  matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.1  matt  * POSSIBILITY OF SUCH DAMAGE.
     28  1.1  matt  */
     29  1.1  matt #include <sys/cdefs.h>
     30  1.2  matt __RCSID("$NetBSD: crtbegin.c,v 1.2 2013/06/24 14:49:13 matt Exp $");
     31  1.1  matt 
     32  1.1  matt typedef void (*fptr_t)(void);
     33  1.1  matt 
     34  1.1  matt __dso_hidden const fptr_t __JCR_LIST__[0] __section(".jcr");
     35  1.1  matt __dso_hidden const long __EH_FRAME_LIST__[0] __section(".eh_frame");
     36  1.1  matt __dso_hidden const fptr_t __CTOR_LIST__[] __section(".ctors") = {
     37  1.1  matt 	(fptr_t) -1,
     38  1.1  matt };
     39  1.1  matt __dso_hidden extern const fptr_t __CTOR_LIST_END__[];
     40  1.1  matt __dso_hidden const fptr_t __DTOR_LIST__[] __section(".dtors") = {
     41  1.1  matt 	(fptr_t) -1,
     42  1.1  matt };
     43  1.1  matt __dso_hidden extern const fptr_t __DTOR_LIST_END__[];
     44  1.1  matt 
     45  1.1  matt #ifdef SHARED
     46  1.1  matt __dso_hidden void *__dso_handle = &__dso_handle;
     47  1.1  matt #else
     48  1.1  matt __dso_hidden void *__dso_handle;
     49  1.1  matt #endif
     50  1.1  matt 
     51  1.1  matt __weakref_visible void cxa_finalize(void *)
     52  1.1  matt 	__weak_reference(__cxa_finalize);
     53  1.1  matt __weakref_visible void Jv_RegisterClasses(const fptr_t *)
     54  1.1  matt 	__weak_reference(_Jv_RegisterClasses);
     55  1.1  matt __weakref_visible void register_frame_info(const void *, const void *)
     56  1.1  matt 	__weak_reference(__register_frame_info);
     57  1.1  matt __weakref_visible void deregister_frame_info(const void *)
     58  1.1  matt 	__weak_reference(__deregister_frame_info);
     59  1.1  matt 
     60  1.2  matt static long dwarf_eh_object[8];
     61  1.1  matt static unsigned char __initialized;
     62  1.1  matt static unsigned char __finished;
     63  1.1  matt 
     64  1.1  matt static void __do_global_ctors_aux(void) __used;
     65  1.1  matt static void __do_global_dtors_aux(void) __used;
     66  1.1  matt 
     67  1.1  matt static void
     68  1.1  matt __do_global_ctors_aux(void)
     69  1.1  matt {
     70  1.1  matt 	if (__initialized)
     71  1.1  matt 		return;
     72  1.1  matt 
     73  1.1  matt 	__initialized = 1;
     74  1.1  matt 
     75  1.1  matt 	if (register_frame_info)
     76  1.1  matt 		register_frame_info(__EH_FRAME_LIST__, &dwarf_eh_object);
     77  1.1  matt 
     78  1.1  matt 	if (Jv_RegisterClasses && __JCR_LIST__[0] != 0)
     79  1.1  matt 		Jv_RegisterClasses(__JCR_LIST__);
     80  1.1  matt 
     81  1.1  matt 	for (const fptr_t *p = __CTOR_LIST_END__; p > __CTOR_LIST__ + 1; ) {
     82  1.1  matt 		(*(*--p))();
     83  1.1  matt 	}
     84  1.1  matt }
     85  1.1  matt 
     86  1.1  matt static void
     87  1.1  matt __do_global_dtors_aux(void)
     88  1.1  matt {
     89  1.1  matt 	if (__finished)
     90  1.1  matt 		return;
     91  1.1  matt 
     92  1.1  matt 	__finished = 1;
     93  1.1  matt 
     94  1.1  matt 	if (cxa_finalize)
     95  1.1  matt 		cxa_finalize(__dso_handle);
     96  1.1  matt 
     97  1.1  matt 	for (const fptr_t *p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__; ) {
     98  1.1  matt 		(*(*p++))();
     99  1.1  matt 	}
    100  1.1  matt 
    101  1.1  matt 	if (deregister_frame_info)
    102  1.1  matt 		deregister_frame_info(__EH_FRAME_LIST__);
    103  1.1  matt }
    104  1.1  matt 
    105  1.1  matt #include "crtbegin.h"
    106