Home | History | Annotate | Line # | Download | only in common
crtbegin.c revision 1.10
      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.10   joerg __RCSID("$NetBSD: crtbegin.c,v 1.10 2016/06/01 21:21:55 joerg Exp $");
     31   1.6   joerg 
     32   1.6   joerg #include "crtbegin.h"
     33   1.1    matt 
     34   1.1    matt typedef void (*fptr_t)(void);
     35   1.1    matt 
     36   1.1    matt __dso_hidden const fptr_t __JCR_LIST__[0] __section(".jcr");
     37   1.3    matt 
     38   1.3    matt __weakref_visible void Jv_RegisterClasses(const fptr_t *)
     39   1.3    matt 	__weak_reference(_Jv_RegisterClasses);
     40   1.3    matt 
     41   1.3    matt #if !defined(HAVE_INITFINI_ARRAY)
     42  1.10   joerg __weakref_visible const fptr_t __CTOR_LIST__start[]
     43  1.10   joerg     __weak_reference(__CTOR_LIST__);
     44  1.10   joerg __weakref_visible const fptr_t __CTOR_LIST__end[]
     45  1.10   joerg     __weak_reference(__CTOR_LIST_END__);
     46  1.10   joerg 
     47   1.7    matt __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
     48   1.1    matt 	(fptr_t) -1,
     49   1.1    matt };
     50   1.1    matt __dso_hidden extern const fptr_t __CTOR_LIST_END__[];
     51   1.3    matt #endif
     52   1.1    matt 
     53   1.1    matt #ifdef SHARED
     54   1.1    matt __dso_hidden void *__dso_handle = &__dso_handle;
     55   1.3    matt 
     56   1.3    matt __weakref_visible void cxa_finalize(void *)
     57   1.3    matt 	__weak_reference(__cxa_finalize);
     58   1.1    matt #else
     59   1.1    matt __dso_hidden void *__dso_handle;
     60   1.1    matt #endif
     61   1.1    matt 
     62   1.9   joerg #if !defined(__ARM_EABI__) || defined(__ARM_DWARF_EH__)
     63   1.5    matt __dso_hidden
     64   1.5    matt #if !defined(__mips__)
     65   1.5    matt 	const
     66   1.5    matt #endif
     67   1.5    matt 	long __EH_FRAME_LIST__[0] __section(".eh_frame");
     68   1.3    matt 
     69   1.1    matt __weakref_visible void register_frame_info(const void *, const void *)
     70   1.1    matt 	__weak_reference(__register_frame_info);
     71   1.1    matt __weakref_visible void deregister_frame_info(const void *)
     72   1.1    matt 	__weak_reference(__deregister_frame_info);
     73   1.1    matt 
     74   1.2    matt static long dwarf_eh_object[8];
     75   1.3    matt #endif
     76   1.1    matt 
     77   1.1    matt static void __do_global_ctors_aux(void) __used;
     78   1.1    matt 
     79   1.4    matt static void __section(".text.startup")
     80   1.1    matt __do_global_ctors_aux(void)
     81   1.1    matt {
     82   1.3    matt 	static unsigned char __initialized;
     83   1.3    matt 
     84   1.1    matt 	if (__initialized)
     85   1.1    matt 		return;
     86   1.1    matt 
     87   1.1    matt 	__initialized = 1;
     88   1.1    matt 
     89   1.9   joerg #if !defined(__ARM_EABI__) || defined(__ARM_DWARF_EH__)
     90   1.1    matt 	if (register_frame_info)
     91   1.1    matt 		register_frame_info(__EH_FRAME_LIST__, &dwarf_eh_object);
     92   1.3    matt #endif
     93   1.1    matt 
     94   1.1    matt 	if (Jv_RegisterClasses && __JCR_LIST__[0] != 0)
     95   1.1    matt 		Jv_RegisterClasses(__JCR_LIST__);
     96   1.1    matt 
     97   1.3    matt #if !defined(HAVE_INITFINI_ARRAY)
     98  1.10   joerg 	for (const fptr_t *p = __CTOR_LIST__end; p > __CTOR_LIST__start + 1; ) {
     99   1.1    matt 		(*(*--p))();
    100   1.1    matt 	}
    101   1.3    matt #endif
    102   1.1    matt }
    103   1.1    matt 
    104   1.9   joerg #if !defined(__ARM_EABI__) || defined(SHARED) || defined(__ARM_DWARF_EH__)
    105   1.3    matt #if !defined(HAVE_INITFINI_ARRAY)
    106  1.10   joerg __weakref_visible const fptr_t __DTOR_LIST__start[]
    107  1.10   joerg     __weak_reference(__DTOR_LIST__);
    108  1.10   joerg __weakref_visible const fptr_t __DTOR_LIST__end[]
    109  1.10   joerg     __weak_reference(__DTOR_LIST_END__);
    110  1.10   joerg 
    111   1.8  bouyer __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = {
    112   1.3    matt 	(fptr_t) -1,
    113   1.3    matt };
    114   1.3    matt __dso_hidden extern const fptr_t __DTOR_LIST_END__[];
    115   1.3    matt #endif
    116   1.3    matt 
    117   1.3    matt static void __do_global_dtors_aux(void) __used;
    118   1.3    matt 
    119   1.4    matt static void __section(".text.exit")
    120   1.1    matt __do_global_dtors_aux(void)
    121   1.1    matt {
    122   1.3    matt 	static unsigned char __finished;
    123   1.3    matt 
    124   1.1    matt 	if (__finished)
    125   1.1    matt 		return;
    126   1.1    matt 
    127   1.1    matt 	__finished = 1;
    128   1.1    matt 
    129   1.3    matt #ifdef SHARED
    130   1.1    matt 	if (cxa_finalize)
    131   1.3    matt 		(*cxa_finalize)(__dso_handle);
    132   1.3    matt #endif
    133   1.3    matt 
    134   1.3    matt #if !defined(HAVE_INITFINI_ARRAY)
    135  1.10   joerg 	for (const fptr_t *p = __DTOR_LIST__start + 1; p < __DTOR_LIST__end; ) {
    136   1.1    matt 		(*(*p++))();
    137   1.1    matt 	}
    138   1.3    matt #endif
    139   1.1    matt 
    140   1.9   joerg #if !defined(__ARM_EABI__) || defined(__ARM_DWARF_EH__)
    141   1.1    matt 	if (deregister_frame_info)
    142   1.1    matt 		deregister_frame_info(__EH_FRAME_LIST__);
    143   1.3    matt #endif
    144   1.1    matt }
    145   1.9   joerg #endif /* !__ARM_EABI__ || SHARED || __ARM_DWARF_EH__ */
    146