118334Speter/* Definitions relating to the special __do_global_init function used
218334Speter   for getting g++ file-scope static objects constructed.  This file
318334Speter   will get included either by libgcc2.c (for systems that don't support
418334Speter   a .init section) or by crtstuff.c (for those that do).
5132718Skan   Copyright (C) 1991, 1995, 1996, 1998, 1999, 2000, 2003
690075Sobrien   Free Software Foundation, Inc.
718334Speter   Contributed by Ron Guilmette (rfg@segfault.us.com)
818334Speter
990075SobrienThis file is part of GCC.
1018334Speter
1190075SobrienGCC is free software; you can redistribute it and/or modify it under
1290075Sobrienthe terms of the GNU General Public License as published by the Free
1390075SobrienSoftware Foundation; either version 2, or (at your option) any later
1490075Sobrienversion.
1518334Speter
1690075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1790075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1890075SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1990075Sobrienfor more details.
2018334Speter
2118334SpeterYou should have received a copy of the GNU General Public License
2290075Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
23169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
24169689Skan02110-1301, USA.  */
2518334Speter
26117395Skan/* As a special exception, if you link this library with other files,
27117395Skan   some of which are compiled with GCC, to produce an executable,
28117395Skan   this library does not by itself cause the resulting executable
29117395Skan   to be covered by the GNU General Public License.
30117395Skan   This exception does not however invalidate any other reasons why
31117395Skan   the executable file might be covered by the GNU General Public License.  */
32117395Skan
3318334Speter/*	This file contains definitions and declarations of things
3418334Speter	relating to the normal start-up-time invocation of C++
3518334Speter	file-scope static object constructors.  These declarations
3618334Speter	and definitions are used by *both* libgcc2.c and by crtstuff.c.
3718334Speter
3818334Speter	Note that this file should only be compiled with GCC.
3918334Speter*/
4018334Speter
4118334Speter/*  Declare a pointer to void function type.  */
4218334Speter
4318334Spetertypedef void (*func_ptr) (void);
4418334Speter
4518334Speter/* Declare the set of symbols use as begin and end markers for the lists
4618334Speter   of global object constructors and global object destructors.  */
4718334Speter
4818334Speterextern func_ptr __CTOR_LIST__[];
4918334Speterextern func_ptr __DTOR_LIST__[];
5018334Speter
5190075Sobrien/* Declare the routine which needs to get invoked at program start time.  */
5218334Speter
5390075Sobrienextern void __do_global_ctors (void);
5490075Sobrien
5590075Sobrien/* Declare the routine which needs to get invoked at program exit time.  */
5690075Sobrien
5750397Sobrienextern void __do_global_dtors (void);
5818334Speter
5918334Speter/* Define a macro with the code which needs to be executed at program
6018334Speter   start-up time.  This macro is used in two places in crtstuff.c (for
6118334Speter   systems which support a .init section) and in one place in libgcc2.c
6218334Speter   (for those system which do *not* support a .init section).  For all
6318334Speter   three places where this code might appear, it must be identical, so
6418334Speter   we define it once here as a macro to avoid various instances getting
6518334Speter   out-of-sync with one another.  */
6618334Speter
6718334Speter/* Some systems place the number of pointers
6818334Speter   in the first word of the table.
6918334Speter   On other systems, that word is -1.
7018334Speter   In all cases, the table is null-terminated.
7118334Speter   If the length is not recorded, count up to the null.  */
7218334Speter
7318334Speter/* Some systems use a different strategy for finding the ctors.
7418334Speter   For example, svr3.  */
7518334Speter#ifndef DO_GLOBAL_CTORS_BODY
7618334Speter#define DO_GLOBAL_CTORS_BODY						\
7718334Speterdo {									\
7818334Speter  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];		\
7918334Speter  unsigned i;								\
8050397Sobrien  if (nptrs == (unsigned long)-1)				        \
8118334Speter    for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);		\
8218334Speter  for (i = nptrs; i >= 1; i--)						\
8318334Speter    __CTOR_LIST__[i] ();						\
84117395Skan} while (0)
8518334Speter#endif
8618334Speter
87