gbl-ctors.h revision 117395
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).
590075Sobrien   Copyright (C) 1991, 1995, 1996, 1998, 1999, 2000
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
2390075SobrienSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA
2490075Sobrien02111-1307, 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
4150397Sobrien#ifdef NEED_ATEXIT
4218334Speterextern int atexit (void (*) (void));
4318334Speter#endif
4418334Speter
4518334Speter/*  Declare a pointer to void function type.  */
4618334Speter
4718334Spetertypedef void (*func_ptr) (void);
4818334Speter
4918334Speter/* Declare the set of symbols use as begin and end markers for the lists
5018334Speter   of global object constructors and global object destructors.  */
5118334Speter
5218334Speterextern func_ptr __CTOR_LIST__[];
5318334Speterextern func_ptr __DTOR_LIST__[];
5418334Speter
5590075Sobrien/* Declare the routine which needs to get invoked at program start time.  */
5618334Speter
5790075Sobrienextern void __do_global_ctors (void);
5890075Sobrien
5990075Sobrien/* Declare the routine which needs to get invoked at program exit time.  */
6090075Sobrien
6150397Sobrienextern void __do_global_dtors (void);
6218334Speter
6318334Speter/* Define a macro with the code which needs to be executed at program
6418334Speter   start-up time.  This macro is used in two places in crtstuff.c (for
6518334Speter   systems which support a .init section) and in one place in libgcc2.c
6618334Speter   (for those system which do *not* support a .init section).  For all
6718334Speter   three places where this code might appear, it must be identical, so
6818334Speter   we define it once here as a macro to avoid various instances getting
6918334Speter   out-of-sync with one another.  */
7018334Speter
7118334Speter/* Some systems place the number of pointers
7218334Speter   in the first word of the table.
7318334Speter   On other systems, that word is -1.
7418334Speter   In all cases, the table is null-terminated.
7518334Speter   If the length is not recorded, count up to the null.  */
7618334Speter
7718334Speter/* Some systems use a different strategy for finding the ctors.
7818334Speter   For example, svr3.  */
7918334Speter#ifndef DO_GLOBAL_CTORS_BODY
8018334Speter#define DO_GLOBAL_CTORS_BODY						\
8118334Speterdo {									\
8218334Speter  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];		\
8318334Speter  unsigned i;								\
8450397Sobrien  if (nptrs == (unsigned long)-1)				        \
8518334Speter    for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);		\
8618334Speter  for (i = nptrs; i >= 1; i--)						\
8718334Speter    __CTOR_LIST__[i] ();						\
88117395Skan} while (0)
8918334Speter#endif
9018334Speter
91