]>
Commit | Line | Data |
---|---|---|
cf234f00 | 1 | /* Definitions relating to the special __do_global_init function used |
2 | for getting g++ file-scope static objects constructed. This file | |
c501243d | 3 | will get included either by libgcc2.c (for systems that don't support |
cf234f00 | 4 | a .init section) or by crtstuff.c (for those that do). |
256d47d0 | 5 | Copyright (C) 1991, 1995, 1996, 1998, 1999, 2000 |
6 | Free Software Foundation, Inc. | |
42990542 | 7 | Contributed by Ron Guilmette (rfg@segfault.us.com) |
cf234f00 | 8 | |
f12b58b3 | 9 | This file is part of GCC. |
cf234f00 | 10 | |
f12b58b3 | 11 | GCC is free software; you can redistribute it and/or modify it under |
12 | the terms of the GNU General Public License as published by the Free | |
13 | Software Foundation; either version 2, or (at your option) any later | |
14 | version. | |
cf234f00 | 15 | |
f12b58b3 | 16 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
17 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
19 | for more details. | |
cf234f00 | 20 | |
21 | You should have received a copy of the GNU General Public License | |
f12b58b3 | 22 | along with GCC; see the file COPYING. If not, write to the Free |
23 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
24 | 02111-1307, USA. */ | |
cf234f00 | 25 | |
26 | /* This file contains definitions and declarations of things | |
27 | relating to the normal start-up-time invocation of C++ | |
28 | file-scope static object constructors. These declarations | |
29 | and definitions are used by *both* libgcc2.c and by crtstuff.c. | |
30 | ||
31 | Note that this file should only be compiled with GCC. | |
32 | */ | |
33 | ||
2d724bcf | 34 | #ifdef NEED_ATEXIT |
42990542 | 35 | extern int atexit (void (*) (void)); |
42990542 | 36 | #endif |
cf234f00 | 37 | |
38 | /* Declare a pointer to void function type. */ | |
39 | ||
40 | typedef void (*func_ptr) (void); | |
41 | ||
42 | /* Declare the set of symbols use as begin and end markers for the lists | |
7d946265 | 43 | of global object constructors and global object destructors. */ |
cf234f00 | 44 | |
45 | extern func_ptr __CTOR_LIST__[]; | |
46 | extern func_ptr __DTOR_LIST__[]; | |
47 | ||
256d47d0 | 48 | /* Declare the routine which needs to get invoked at program start time. */ |
49 | ||
50 | extern void __do_global_ctors (void); | |
51 | ||
52 | /* Declare the routine which needs to get invoked at program exit time. */ | |
cf234f00 | 53 | |
ef99c8e6 | 54 | extern void __do_global_dtors (void); |
cf234f00 | 55 | |
56 | /* Define a macro with the code which needs to be executed at program | |
57 | start-up time. This macro is used in two places in crtstuff.c (for | |
58 | systems which support a .init section) and in one place in libgcc2.c | |
59 | (for those system which do *not* support a .init section). For all | |
60 | three places where this code might appear, it must be identical, so | |
61 | we define it once here as a macro to avoid various instances getting | |
62 | out-of-sync with one another. */ | |
63 | ||
13d40389 | 64 | /* Some systems place the number of pointers |
65 | in the first word of the table. | |
66 | On other systems, that word is -1. | |
cf234f00 | 67 | In all cases, the table is null-terminated. |
13d40389 | 68 | If the length is not recorded, count up to the null. */ |
cf234f00 | 69 | |
70 | /* Some systems use a different strategy for finding the ctors. | |
71 | For example, svr3. */ | |
72 | #ifndef DO_GLOBAL_CTORS_BODY | |
73 | #define DO_GLOBAL_CTORS_BODY \ | |
74 | do { \ | |
2b7ba1b9 | 75 | unsigned long nptrs = (unsigned long) __CTOR_LIST__[0]; \ |
13d40389 | 76 | unsigned i; \ |
02da6382 | 77 | if (nptrs == (unsigned long)-1) \ |
13d40389 | 78 | for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++); \ |
79 | for (i = nptrs; i >= 1; i--) \ | |
80 | __CTOR_LIST__[i] (); \ | |
81 | } while (0) | |
cf234f00 | 82 | #endif |
83 |