1/* Startup routines for NetWare. 2 Contributed by Jan Beulich (jbeulich@novell.com) 3 Copyright (C) 2004 Free Software Foundation, Inc. 4 5This file is part of GCC. 6 7GCC is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GCC is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GCC; see the file COPYING. If not, write to 19the Free Software Foundation, 51 Franklin Street, Fifth Floor, 20Boston, MA 02110-1301, USA. */ 21 22#include <stddef.h> 23#include <stdint.h> 24#include "unwind-dw2-fde.h" 25 26int __init_environment (void *); 27int __deinit_environment (void *); 28 29 30#define SECTION_DECL(name, decl) decl __attribute__((__section__(name))) 31 32SECTION_DECL(".ctors", void(*const __CTOR_LIST__)(void)) 33 = (void(*)(void))(intptr_t)-1; 34SECTION_DECL(".ctors$_", void(*const __CTOR_END__)(void)) = NULL; 35 36SECTION_DECL(".dtors", void(*const __DTOR_LIST__)(void)) 37 = (void(*)(void))(intptr_t)-1; 38SECTION_DECL(".dtors$_", void(*const __DTOR_END__)(void)) = NULL; 39 40/* No need to use the __[de]register_frame_info_bases functions since 41 for us the bases are NULL always anyway. */ 42void __register_frame_info (const void *, struct object *) 43 __attribute__((__weak__)); 44void *__deregister_frame_info (const void *) __attribute__((__weak__)); 45 46SECTION_DECL(".eh_frame", /*const*/ uint32_t __EH_FRAME_BEGIN__[]) = { }; 47SECTION_DECL(".eh_frame$_", /*const*/ uint32_t __EH_FRAME_END__[]) = {0}; 48 49int 50__init_environment (void *unused __attribute__((__unused__))) 51{ 52 void (* const * pctor)(void); 53 static struct object object; 54 55 if (__register_frame_info) 56 __register_frame_info (__EH_FRAME_BEGIN__, &object); 57 58 for (pctor = &__CTOR_END__ - 1; pctor > &__CTOR_LIST__; --pctor) 59 if (*pctor != NULL) 60 (*pctor)(); 61 62 return 0; 63} 64 65int 66__deinit_environment (void *unused __attribute__((__unused__))) 67{ 68 /* This should be static to prevent calling the same destructor 69 twice (just in case where we get here multiple times). */ 70 static void (* const * pdtor)(void) = &__DTOR_LIST__ + 1; 71 72 while (pdtor < &__DTOR_END__) 73 if (*pdtor++ != NULL) 74 pdtor[-1] (); 75 76 if (__deregister_frame_info) 77 __deregister_frame_info(__EH_FRAME_BEGIN__); 78 79 return 0; 80} 81