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