gbl-ctors.h revision 169690
1139825Simp/* Definitions relating to the special __do_global_init function used
21541Srgrimes   for getting g++ file-scope static objects constructed.  This file
31541Srgrimes   will get included either by libgcc2.c (for systems that don't support
41541Srgrimes   a .init section) or by crtstuff.c (for those that do).
51541Srgrimes   Copyright (C) 1991, 1995, 1996, 1998, 1999, 2000, 2003
61541Srgrimes   Free Software Foundation, Inc.
71541Srgrimes   Contributed by Ron Guilmette (rfg@segfault.us.com)
81541Srgrimes
91541SrgrimesThis file is part of GCC.
101541Srgrimes
111541SrgrimesGCC is free software; you can redistribute it and/or modify it under
121541Srgrimesthe terms of the GNU General Public License as published by the Free
131541SrgrimesSoftware Foundation; either version 2, or (at your option) any later
141541Srgrimesversion.
151541Srgrimes
161541SrgrimesGCC is distributed in the hope that it will be useful, but WITHOUT ANY
171541SrgrimesWARRANTY; without even the implied warranty of MERCHANTABILITY or
181541SrgrimesFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
191541Srgrimesfor more details.
201541Srgrimes
211541SrgrimesYou should have received a copy of the GNU General Public License
221541Srgrimesalong with GCC; see the file COPYING.  If not, write to the Free
231541SrgrimesSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
241541Srgrimes02110-1301, USA.  */
251541Srgrimes
261541Srgrimes/* As a special exception, if you link this library with other files,
271541Srgrimes   some of which are compiled with GCC, to produce an executable,
281541Srgrimes   this library does not by itself cause the resulting executable
291541Srgrimes   to be covered by the GNU General Public License.
301541Srgrimes   This exception does not however invalidate any other reasons why
311541Srgrimes   the executable file might be covered by the GNU General Public License.  */
321541Srgrimes
331541Srgrimes/*	This file contains definitions and declarations of things
341541Srgrimes	relating to the normal start-up-time invocation of C++
351541Srgrimes	file-scope static object constructors.  These declarations
361541Srgrimes	and definitions are used by *both* libgcc2.c and by crtstuff.c.
371541Srgrimes
381541Srgrimes	Note that this file should only be compiled with GCC.
39226343Smarcel*/
40226343Smarcel
411541Srgrimes/*  Declare a pointer to void function type.  */
421541Srgrimes
431541Srgrimestypedef void (*func_ptr) (void);
4477139Sjhb
45116226Sobrien/* Declare the set of symbols use as begin and end markers for the lists
46116226Sobrien   of global object constructors and global object destructors.  */
47116226Sobrien
481541Srgrimesextern func_ptr __CTOR_LIST__[];
4976166Smarkmextern func_ptr __DTOR_LIST__[];
5076981Sjhb
511541Srgrimes/* Declare the routine which needs to get invoked at program start time.  */
52220373Strasz
531541Srgrimesextern void __do_global_ctors (void);
54226343Smarcel
5576981Sjhb/* Declare the routine which needs to get invoked at program exit time.  */
5676827Salfred
571541Srgrimesextern void __do_global_dtors (void);
581541Srgrimes
5912662Sdg/* Define a macro with the code which needs to be executed at program
6012662Sdg   start-up time.  This macro is used in two places in crtstuff.c (for
6112662Sdg   systems which support a .init section) and in one place in libgcc2.c
621541Srgrimes   (for those system which do *not* support a .init section).  For all
6312221Sbde   three places where this code might appear, it must be identical, so
641541Srgrimes   we define it once here as a macro to avoid various instances getting
6512206Sbde   out-of-sync with one another.  */
661541Srgrimes
6712221Sbde/* Some systems place the number of pointers
681549Srgrimes   in the first word of the table.
6982697Sdillon   On other systems, that word is -1.
7082697Sdillon   In all cases, the table is null-terminated.
7182697Sdillon   If the length is not recorded, count up to the null.  */
721541Srgrimes
731541Srgrimes/* Some systems use a different strategy for finding the ctors.
74225617Skmacy   For example, svr3.  */
7583366Sjulian#ifndef DO_GLOBAL_CTORS_BODY
761541Srgrimes#define DO_GLOBAL_CTORS_BODY						\
771541Srgrimesdo {									\
7883366Sjulian  unsigned long nptrs = (unsigned long) __CTOR_LIST__[0];		\
79245296Szont  unsigned i;								\
8016679Sdyson  if (nptrs == (unsigned long)-1)				        \
81244384Szont    for (nptrs = 0; __CTOR_LIST__[nptrs + 1] != 0; nptrs++);		\
82226343Smarcel  for (i = nptrs; i >= 1; i--)						\
8379224Sdillon    __CTOR_LIST__[i] ();						\
84118771Sbms} while (0)
851541Srgrimes#endif
86125454Sjhb
87125454Sjhb