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