OSDN Git Service

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