gbl-ctors.h revision 132718
189099Sfjoe/* Definitions relating to the special __do_global_init function used
289099Sfjoe   for getting g++ file-scope static objects constructed.  This file
3119418Sobrien   will get included either by libgcc2.c (for systems that don't support
4119418Sobrien   a .init section) or by crtstuff.c (for those that do).
5119418Sobrien   Copyright (C) 1991, 1995, 1996, 1998, 1999, 2000, 2003
689099Sfjoe   Free Software Foundation, Inc.
789099Sfjoe   Contributed by Ron Guilmette (rfg@segfault.us.com)
889099Sfjoe
989099SfjoeThis file is part of GCC.
1089099Sfjoe
1189099SfjoeGCC is free software; you can redistribute it and/or modify it under
1289099Sfjoethe terms of the GNU General Public License as published by the Free
1389099SfjoeSoftware Foundation; either version 2, or (at your option) any later
1489099Sfjoeversion.
1589099Sfjoe
1689099SfjoeGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1789099SfjoeWARRANTY; without even the implied warranty of MERCHANTABILITY or
1889099SfjoeFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1989099Sfjoefor more details.
2089099Sfjoe
2189099SfjoeYou should have received a copy of the GNU General Public License
2289099Sfjoealong with GCC; see the file COPYING.  If not, write to the Free
2389099SfjoeSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA
2489099Sfjoe02111-1307, USA.  */
2589099Sfjoe
2689099Sfjoe/* As a special exception, if you link this library with other files,
2789099Sfjoe   some of which are compiled with GCC, to produce an executable,
2889099Sfjoe   this library does not by itself cause the resulting executable
2989099Sfjoe   to be covered by the GNU General Public License.
3089099Sfjoe   This exception does not however invalidate any other reasons why
3189099Sfjoe   the executable file might be covered by the GNU General Public License.  */
3289099Sfjoe
3389099Sfjoe/*	This file contains definitions and declarations of things
3489099Sfjoe	relating to the normal start-up-time invocation of C++
3589099Sfjoe	file-scope static object constructors.  These declarations
3689099Sfjoe	and definitions are used by *both* libgcc2.c and by crtstuff.c.
3789099Sfjoe
3889099Sfjoe	Note that this file should only be compiled with GCC.
3989099Sfjoe*/
4089099Sfjoe
4189099Sfjoe/*  Declare a pointer to void function type.  */
42109771Sfjoe
4389099Sfjoetypedef void (*func_ptr) (void);
4489099Sfjoe
4589099Sfjoe/* Declare the set of symbols use as begin and end markers for the lists
4689099Sfjoe   of global object constructors and global object destructors.  */
4789099Sfjoe
4889099Sfjoeextern func_ptr __CTOR_LIST__[];
4989099Sfjoeextern func_ptr __DTOR_LIST__[];
5089099Sfjoe
5189099Sfjoe/* Declare the routine which needs to get invoked at program start time.  */
5289099Sfjoe
5389099Sfjoeextern void __do_global_ctors (void);
5489099Sfjoe
5589099Sfjoe/* Declare the routine which needs to get invoked at program exit time.  */
5689099Sfjoe
5789099Sfjoeextern void __do_global_dtors (void);
5889099Sfjoe
59257176Sglebius/* Define a macro with the code which needs to be executed at program
6089099Sfjoe   start-up time.  This macro is used in two places in crtstuff.c (for
6189099Sfjoe   systems which support a .init section) and in one place in libgcc2.c
6289099Sfjoe   (for those system which do *not* support a .init section).  For all
6389099Sfjoe   three places where this code might appear, it must be identical, so
6489099Sfjoe   we define it once here as a macro to avoid various instances getting
6589099Sfjoe   out-of-sync with one another.  */
6689099Sfjoe
6789099Sfjoe/* Some systems place the number of pointers
6889099Sfjoe   in the first word of the table.
6989099Sfjoe   On other systems, that word is -1.
7089099Sfjoe   In all cases, the table is null-terminated.
7189099Sfjoe   If the length is not recorded, count up to the null.  */
7289099Sfjoe
7389099Sfjoe/* Some systems use a different strategy for finding the ctors.
7489099Sfjoe   For example, svr3.  */
7589099Sfjoe#ifndef DO_GLOBAL_CTORS_BODY
7689099Sfjoe#define DO_GLOBAL_CTORS_BODY						\
7789099Sfjoedo {									\
7889099Sfjoe  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];		\
7989099Sfjoe  unsigned i;								\
8089099Sfjoe  if (nptrs == (unsigned long)-1)				        \
8189099Sfjoe    for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);		\
8289099Sfjoe  for (i = nptrs; i >= 1; i--)						\
8389099Sfjoe    __CTOR_LIST__[i] ();						\
8489099Sfjoe} while (0)
8589099Sfjoe#endif
8689099Sfjoe
8789099Sfjoe