OSDN Git Service

2007-08-05 Andrew Pinski <andrew_pinski@playstation.sony.com>
[pf3gnuchains/gcc-fork.git] / gcc / crtstuff.c
1 /* Specialized bits of code needed to support construction and
2    destruction of file-scope objects in C++ code.
3    Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998,
4    1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5    Contributed by Ron Guilmette (rfg@monkeys.com).
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13
14 In addition to the permissions in the GNU General Public License, the
15 Free Software Foundation gives you unlimited permission to link the
16 compiled version of this file into combinations with other programs,
17 and to distribute those combinations without any restriction coming
18 from the use of this file.  (The General Public License restrictions
19 do apply in other respects; for example, they cover modification of
20 the file, and distribution when not linked into a combine
21 executable.)
22
23 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24 WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26 for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with GCC; see the file COPYING.  If not, write to the Free
30 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
31 02110-1301, USA.  */
32
33 /* This file is a bit like libgcc2.c in that it is compiled
34    multiple times and yields multiple .o files.
35
36    This file is useful on target machines where the object file format
37    supports multiple "user-defined" sections (e.g. COFF, ELF, ROSE).  On
38    such systems, this file allows us to avoid running collect (or any
39    other such slow and painful kludge).  Additionally, if the target
40    system supports a .init section, this file allows us to support the
41    linking of C++ code with a non-C++ main program.
42
43    Note that if INIT_SECTION_ASM_OP is defined in the tm.h file, then
44    this file *will* make use of the .init section.  If that symbol is
45    not defined however, then the .init section will not be used.
46
47    Currently, only ELF and COFF are supported.  It is likely however that
48    ROSE could also be supported, if someone was willing to do the work to
49    make whatever (small?) adaptations are needed.  (Some work may be
50    needed on the ROSE assembler and linker also.)
51
52    This file must be compiled with gcc.  */
53
54 /* Target machine header files require this define. */
55 #define IN_LIBGCC2
56
57 /* FIXME: Including auto-host is incorrect, but until we have
58    identified the set of defines that need to go into auto-target.h,
59    this will have to do.  */
60 #include "auto-host.h"
61 #undef gid_t
62 #undef pid_t
63 #undef rlim_t
64 #undef ssize_t
65 #undef uid_t
66 #undef vfork
67 #include "tconfig.h"
68 #include "tsystem.h"
69 #include "coretypes.h"
70 #include "tm.h"
71 #include "unwind-dw2-fde.h"
72
73 #ifndef FORCE_CODE_SECTION_ALIGN
74 # define FORCE_CODE_SECTION_ALIGN
75 #endif
76
77 #ifndef CRT_CALL_STATIC_FUNCTION
78 # define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC)     \
79 static void __attribute__((__used__))                   \
80 call_ ## FUNC (void)                                    \
81 {                                                       \
82   asm (SECTION_OP);                                     \
83   FUNC ();                                              \
84   FORCE_CODE_SECTION_ALIGN                              \
85   asm (TEXT_SECTION_ASM_OP);                            \
86 }
87 #endif
88
89 #if defined(OBJECT_FORMAT_ELF) \
90     && !defined(OBJECT_FORMAT_FLAT) \
91     && defined(HAVE_LD_EH_FRAME_HDR) \
92     && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
93     && defined(__GLIBC__) && __GLIBC__ >= 2
94 #include <link.h>
95 # if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
96      || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
97 #  define USE_PT_GNU_EH_FRAME
98 # endif
99 #endif
100 #if defined(EH_FRAME_SECTION_NAME) && !defined(USE_PT_GNU_EH_FRAME)
101 # define USE_EH_FRAME_REGISTRY
102 #endif
103 #if defined(EH_FRAME_SECTION_NAME) && EH_TABLES_CAN_BE_READ_ONLY
104 # define EH_FRAME_SECTION_CONST const
105 #else
106 # define EH_FRAME_SECTION_CONST
107 #endif
108
109 #if !defined(DTOR_LIST_END) && defined(OBJECT_FORMAT_ELF) \
110     && defined(HAVE_GAS_HIDDEN) && !defined(FINI_ARRAY_SECTION_ASM_OP)
111 # define HIDDEN_DTOR_LIST_END
112 #endif
113
114 /* We do not want to add the weak attribute to the declarations of these
115    routines in unwind-dw2-fde.h because that will cause the definition of
116    these symbols to be weak as well.
117
118    This exposes a core issue, how to handle creating weak references vs
119    how to create weak definitions.  Either we have to have the definition
120    of TARGET_WEAK_ATTRIBUTE be conditional in the shared header files or
121    have a second declaration if we want a function's references to be weak,
122    but not its definition.
123
124    Making TARGET_WEAK_ATTRIBUTE conditional seems like a good solution until
125    one thinks about scaling to larger problems -- i.e., the condition under
126    which TARGET_WEAK_ATTRIBUTE is active will eventually get far too
127    complicated.
128
129    So, we take an approach similar to #pragma weak -- we have a second
130    declaration for functions that we want to have weak references.
131
132    Neither way is particularly good.  */
133    
134 /* References to __register_frame_info and __deregister_frame_info should
135    be weak in this file if at all possible.  */
136 extern void __register_frame_info (const void *, struct object *)
137                                   TARGET_ATTRIBUTE_WEAK;
138 extern void __register_frame_info_bases (const void *, struct object *,
139                                          void *, void *)
140                                   TARGET_ATTRIBUTE_WEAK;
141 extern void *__deregister_frame_info (const void *)
142                                      TARGET_ATTRIBUTE_WEAK;
143 extern void *__deregister_frame_info_bases (const void *)
144                                      TARGET_ATTRIBUTE_WEAK;
145 extern void __do_global_ctors_1 (void);
146
147 /* Likewise for _Jv_RegisterClasses.  */
148 extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK;
149
150 #ifdef OBJECT_FORMAT_ELF
151
152 /*  Declare a pointer to void function type.  */
153 typedef void (*func_ptr) (void);
154 #define STATIC static
155
156 #else  /* OBJECT_FORMAT_ELF */
157
158 #include "gbl-ctors.h"
159
160 #define STATIC
161
162 #endif /* OBJECT_FORMAT_ELF */
163
164 #ifdef CRT_BEGIN
165
166 /* NOTE:  In order to be able to support SVR4 shared libraries, we arrange
167    to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
168    __DTOR_END__ } per root executable and also one set of these symbols
169    per shared library.  So in any given whole process image, we may have
170    multiple definitions of each of these symbols.  In order to prevent
171    these definitions from conflicting with one another, and in order to
172    ensure that the proper lists are used for the initialization/finalization
173    of each individual shared library (respectively), we give these symbols
174    only internal (i.e. `static') linkage, and we also make it a point to
175    refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
176    symbol in crtbegin.o, where they are defined.  */
177
178 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
179    does not start with a count of elements.  */
180 #ifdef CTOR_LIST_BEGIN
181 CTOR_LIST_BEGIN;
182 #elif defined(CTORS_SECTION_ASM_OP)
183 /* Hack: force cc1 to switch to .data section early, so that assembling
184    __CTOR_LIST__ does not undo our behind-the-back change to .ctors.  */
185 static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
186 asm (CTORS_SECTION_ASM_OP);
187 STATIC func_ptr __CTOR_LIST__[1]
188   __attribute__ ((__unused__, aligned(sizeof(func_ptr))))
189   = { (func_ptr) (-1) };
190 #else
191 STATIC func_ptr __CTOR_LIST__[1]
192   __attribute__ ((__unused__, section(".ctors"), aligned(sizeof(func_ptr))))
193   = { (func_ptr) (-1) };
194 #endif /* __CTOR_LIST__ alternatives */
195
196 #ifdef DTOR_LIST_BEGIN
197 DTOR_LIST_BEGIN;
198 #elif defined(DTORS_SECTION_ASM_OP)
199 asm (DTORS_SECTION_ASM_OP);
200 STATIC func_ptr __DTOR_LIST__[1]
201   __attribute__ ((aligned(sizeof(func_ptr))))
202   = { (func_ptr) (-1) };
203 #else
204 STATIC func_ptr __DTOR_LIST__[1]
205   __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
206   = { (func_ptr) (-1) };
207 #endif /* __DTOR_LIST__ alternatives */
208
209 #ifdef USE_EH_FRAME_REGISTRY
210 /* Stick a label at the beginning of the frame unwind info so we can register
211    and deregister it with the exception handling library code.  */
212 STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
213      __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
214      = { };
215 #endif /* USE_EH_FRAME_REGISTRY */
216
217 #ifdef JCR_SECTION_NAME
218 /* Stick a label at the beginning of the java class registration info
219    so we can register them properly.  */
220 STATIC void *__JCR_LIST__[]
221   __attribute__ ((unused, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
222   = { };
223 #endif /* JCR_SECTION_NAME */
224
225 #if defined(INIT_SECTION_ASM_OP) || defined(INIT_ARRAY_SECTION_ASM_OP)
226
227 #ifdef OBJECT_FORMAT_ELF
228
229 /* Declare the __dso_handle variable.  It should have a unique value
230    in every shared-object; in a main program its value is zero.  The
231    object should in any case be protected.  This means the instance
232    in one DSO or the main program is not used in another object.  The
233    dynamic linker takes care of this.  */
234
235 #ifdef TARGET_LIBGCC_SDATA_SECTION
236 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
237 #endif
238 #ifdef HAVE_GAS_HIDDEN
239 extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
240 #endif
241 #ifdef CRTSTUFFS_O
242 void *__dso_handle = &__dso_handle;
243 #else
244 void *__dso_handle = 0;
245 #endif
246
247 /* The __cxa_finalize function may not be available so we use only a
248    weak declaration.  */
249 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
250
251 /* Run all the global destructors on exit from the program.  */
252  
253 /* Some systems place the number of pointers in the first word of the
254    table.  On SVR4 however, that word is -1.  In all cases, the table is
255    null-terminated.  On SVR4, we start from the beginning of the list and
256    invoke each per-compilation-unit destructor routine in order
257    until we find that null.
258
259    Note that this function MUST be static.  There will be one of these
260    functions in each root executable and one in each shared library, but
261    although they all have the same code, each one is unique in that it
262    refers to one particular associated `__DTOR_LIST__' which belongs to the
263    same particular root executable or shared library file.
264
265    On some systems, this routine is run more than once from the .fini,
266    when exit is called recursively, so we arrange to remember where in
267    the list we left off processing, and we resume at that point,
268    should we be re-invoked.  */
269
270 static void __attribute__((used))
271 __do_global_dtors_aux (void)
272 {
273   static _Bool completed;
274
275   if (__builtin_expect (completed, 0))
276     return;
277
278 #ifdef CRTSTUFFS_O
279   if (__cxa_finalize)
280     __cxa_finalize (__dso_handle);
281 #endif
282
283 #ifdef FINI_ARRAY_SECTION_ASM_OP
284   /* If we are using .fini_array then destructors will be run via that
285      mechanism.  */
286 #elif defined(HIDDEN_DTOR_LIST_END)
287   {
288     /* Safer version that makes sure only .dtors function pointers are
289        called even if the static variable is maliciously changed.  */
290     extern func_ptr __DTOR_END__[] __attribute__((visibility ("hidden")));
291     static size_t dtor_idx;
292     const size_t max_idx = __DTOR_END__ - __DTOR_LIST__ - 1;
293     func_ptr f;
294
295     while (dtor_idx < max_idx)
296       {
297         f = __DTOR_LIST__[++dtor_idx];
298         f ();
299       }
300   }
301 #else /* !defined (FINI_ARRAY_SECTION_ASM_OP) */
302   {
303     static func_ptr *p = __DTOR_LIST__ + 1;
304     func_ptr f;
305
306     while ((f = *p))
307       {
308         p++;
309         f ();
310       }
311   }
312 #endif /* !defined(FINI_ARRAY_SECTION_ASM_OP) */
313
314 #ifdef USE_EH_FRAME_REGISTRY
315 #ifdef CRT_GET_RFIB_DATA
316   /* If we used the new __register_frame_info_bases interface,
317      make sure that we deregister from the same place.  */
318   if (__deregister_frame_info_bases)
319     __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
320 #else
321   if (__deregister_frame_info)
322     __deregister_frame_info (__EH_FRAME_BEGIN__);
323 #endif
324 #endif
325
326   completed = 1;
327 }
328
329 /* Stick a call to __do_global_dtors_aux into the .fini section.  */
330 #ifdef FINI_SECTION_ASM_OP
331 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
332 #else /* !defined(FINI_SECTION_ASM_OP) */
333 static func_ptr __do_global_dtors_aux_fini_array_entry[]
334   __attribute__ ((__unused__, section(".fini_array")))
335   = { __do_global_dtors_aux };
336 #endif /* !defined(FINI_SECTION_ASM_OP) */
337
338 #if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
339 /* Stick a call to __register_frame_info into the .init section.  For some
340    reason calls with no arguments work more reliably in .init, so stick the
341    call in another function.  */
342
343 static void __attribute__((used))
344 frame_dummy (void)
345 {
346 #ifdef USE_EH_FRAME_REGISTRY
347   static struct object object;
348 #ifdef CRT_GET_RFIB_DATA
349   void *tbase, *dbase;
350   tbase = 0;
351   CRT_GET_RFIB_DATA (dbase);
352   if (__register_frame_info_bases)
353     __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
354 #else
355   if (__register_frame_info)
356     __register_frame_info (__EH_FRAME_BEGIN__, &object);
357 #endif /* CRT_GET_RFIB_DATA */
358 #endif /* USE_EH_FRAME_REGISTRY */
359 #ifdef JCR_SECTION_NAME
360   if (__JCR_LIST__[0])
361     {
362       void (*register_classes) (void *) = _Jv_RegisterClasses;
363       __asm ("" : "+r" (register_classes));
364       if (register_classes)
365         register_classes (__JCR_LIST__);
366     }
367 #endif /* JCR_SECTION_NAME */
368 }
369
370 #ifdef INIT_SECTION_ASM_OP
371 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, frame_dummy)
372 #else /* defined(INIT_SECTION_ASM_OP) */
373 static func_ptr __frame_dummy_init_array_entry[]
374   __attribute__ ((__unused__, section(".init_array")))
375   = { frame_dummy };
376 #endif /* !defined(INIT_SECTION_ASM_OP) */
377 #endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME */
378
379 #else  /* OBJECT_FORMAT_ELF */
380
381 /* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
382    and once in crtend.o).  It must be declared static to avoid a link
383    error.  Here, we define __do_global_ctors as an externally callable
384    function.  It is externally callable so that __main can invoke it when
385    INVOKE__main is defined.  This has the additional effect of forcing cc1
386    to switch to the .text section.  */
387
388 static void __do_global_ctors_aux (void);
389 void
390 __do_global_ctors (void)
391 {
392 #ifdef INVOKE__main
393   /* If __main won't actually call __do_global_ctors then it doesn't matter
394      what's inside the function.  The inside of __do_global_ctors_aux is
395      called automatically in that case.  And the Alliant fx2800 linker
396      crashes on this reference.  So prevent the crash.  */
397   __do_global_ctors_aux ();
398 #endif
399 }
400
401 asm (INIT_SECTION_ASM_OP);      /* cc1 doesn't know that we are switching! */
402
403 /* A routine to invoke all of the global constructors upon entry to the
404    program.  We put this into the .init section (for systems that have
405    such a thing) so that we can properly perform the construction of
406    file-scope static-storage C++ objects within shared libraries.  */
407
408 static void __attribute__((used))
409 __do_global_ctors_aux (void)    /* prologue goes in .init section */
410 {
411   FORCE_CODE_SECTION_ALIGN      /* explicit align before switch to .text */
412   asm (TEXT_SECTION_ASM_OP);    /* don't put epilogue and body in .init */
413   DO_GLOBAL_CTORS_BODY;
414   atexit (__do_global_dtors);
415 }
416
417 #endif /* OBJECT_FORMAT_ELF */
418
419 #elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
420
421 extern void __do_global_dtors (void);
422
423 /* This case is used by the Irix 6 port, which supports named sections but
424    not an SVR4-style .fini section.  __do_global_dtors can be non-static
425    in this case because we protect it with -hidden_symbol.  */
426
427 void
428 __do_global_dtors (void)
429 {
430   func_ptr *p, f;
431   for (p = __DTOR_LIST__ + 1; (f = *p); p++)
432     f ();
433
434 #ifdef USE_EH_FRAME_REGISTRY
435   if (__deregister_frame_info)
436     __deregister_frame_info (__EH_FRAME_BEGIN__);
437 #endif
438 }
439
440 #if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
441 /* A helper function for __do_global_ctors, which is in crtend.o.  Here
442    in crtbegin.o, we can reference a couple of symbols not visible there.
443    Plus, since we're before libgcc.a, we have no problems referencing
444    functions from there.  */
445 void
446 __do_global_ctors_1(void)
447 {
448 #ifdef USE_EH_FRAME_REGISTRY
449   static struct object object;
450   if (__register_frame_info)
451     __register_frame_info (__EH_FRAME_BEGIN__, &object);
452 #endif
453 #ifdef JCR_SECTION_NAME
454   if (__JCR_LIST__[0])
455     {
456       void (*register_classes) (void *) = _Jv_RegisterClasses;
457       __asm ("" : "+r" (register_classes));
458       if (register_classes)
459         register_classes (__JCR_LIST__);
460     }
461 #endif
462 }
463 #endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME */
464
465 #else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
466 #error "What are you doing with crtstuff.c, then?"
467 #endif
468
469 #elif defined(CRT_END) /* ! CRT_BEGIN */
470
471 /* Put a word containing zero at the end of each of our two lists of function
472    addresses.  Note that the words defined here go into the .ctors and .dtors
473    sections of the crtend.o file, and since that file is always linked in
474    last, these words naturally end up at the very ends of the two lists
475    contained in these two sections.  */
476
477 #ifdef CTOR_LIST_END
478 CTOR_LIST_END;
479 #elif defined(CTORS_SECTION_ASM_OP)
480 /* Hack: force cc1 to switch to .data section early, so that assembling
481    __CTOR_LIST__ does not undo our behind-the-back change to .ctors.  */
482 static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
483 asm (CTORS_SECTION_ASM_OP);
484 STATIC func_ptr __CTOR_END__[1]
485   __attribute__((aligned(sizeof(func_ptr))))
486   = { (func_ptr) 0 };
487 #else
488 STATIC func_ptr __CTOR_END__[1]
489   __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
490   = { (func_ptr) 0 };
491 #endif
492
493 #ifdef DTOR_LIST_END
494 DTOR_LIST_END;
495 #elif defined(HIDDEN_DTOR_LIST_END)
496 #ifdef DTORS_SECTION_ASM_OP
497 asm (DTORS_SECTION_ASM_OP);
498 #endif
499 func_ptr __DTOR_END__[1]
500   __attribute__ ((unused,
501 #ifndef DTORS_SECTION_ASM_OP
502                   section(".dtors"),
503 #endif
504                   aligned(sizeof(func_ptr)), visibility ("hidden")))
505   = { (func_ptr) 0 };
506 #elif defined(DTORS_SECTION_ASM_OP)
507 asm (DTORS_SECTION_ASM_OP);
508 STATIC func_ptr __DTOR_END__[1]
509   __attribute__ ((unused, aligned(sizeof(func_ptr))))
510   = { (func_ptr) 0 };
511 #else
512 STATIC func_ptr __DTOR_END__[1]
513   __attribute__((unused, section(".dtors"), aligned(sizeof(func_ptr))))
514   = { (func_ptr) 0 };
515 #endif
516
517 #ifdef EH_FRAME_SECTION_NAME
518 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
519    this would be the 'length' field in a real FDE.  */
520 # if __INT_MAX__ == 2147483647
521 typedef int int32;
522 # elif __LONG_MAX__ == 2147483647
523 typedef long int32;
524 # elif __SHRT_MAX__ == 2147483647
525 typedef short int32;
526 # else
527 #  error "Missing a 4 byte integer"
528 # endif
529 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
530      __attribute__ ((unused, section(EH_FRAME_SECTION_NAME),
531                      aligned(sizeof(int32))))
532      = { 0 };
533 #endif /* EH_FRAME_SECTION_NAME */
534
535 #ifdef JCR_SECTION_NAME
536 /* Null terminate the .jcr section array.  */
537 STATIC void *__JCR_END__[1] 
538    __attribute__ ((unused, section(JCR_SECTION_NAME),
539                    aligned(sizeof(void *))))
540    = { 0 };
541 #endif /* JCR_SECTION_NAME */
542
543 #ifdef INIT_ARRAY_SECTION_ASM_OP
544
545 /* If we are using .init_array, there is nothing to do.  */
546
547 #elif defined(INIT_SECTION_ASM_OP)
548
549 #ifdef OBJECT_FORMAT_ELF
550 static void __attribute__((used))
551 __do_global_ctors_aux (void)
552 {
553   func_ptr *p;
554   for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
555     (*p) ();
556 }
557
558 /* Stick a call to __do_global_ctors_aux into the .init section.  */
559 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, __do_global_ctors_aux)
560 #else  /* OBJECT_FORMAT_ELF */
561
562 /* Stick the real initialization code, followed by a normal sort of
563    function epilogue at the very end of the .init section for this
564    entire root executable file or for this entire shared library file.
565
566    Note that we use some tricks here to get *just* the body and just
567    a function epilogue (but no function prologue) into the .init
568    section of the crtend.o file.  Specifically, we switch to the .text
569    section, start to define a function, and then we switch to the .init
570    section just before the body code.
571
572    Earlier on, we put the corresponding function prologue into the .init
573    section of the crtbegin.o file (which will be linked in first).
574
575    Note that we want to invoke all constructors for C++ file-scope static-
576    storage objects AFTER any other possible initialization actions which
577    may be performed by the code in the .init section contributions made by
578    other libraries, etc.  That's because those other initializations may
579    include setup operations for very primitive things (e.g. initializing
580    the state of the floating-point coprocessor, etc.) which should be done
581    before we start to execute any of the user's code.  */
582
583 static void
584 __do_global_ctors_aux (void)    /* prologue goes in .text section */
585 {
586   asm (INIT_SECTION_ASM_OP);
587   DO_GLOBAL_CTORS_BODY;
588   atexit (__do_global_dtors);
589 }                               /* epilogue and body go in .init section */
590
591 FORCE_CODE_SECTION_ALIGN
592 asm (TEXT_SECTION_ASM_OP);
593
594 #endif /* OBJECT_FORMAT_ELF */
595
596 #elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
597
598 extern void __do_global_ctors (void);
599
600 /* This case is used by the Irix 6 port, which supports named sections but
601    not an SVR4-style .init section.  __do_global_ctors can be non-static
602    in this case because we protect it with -hidden_symbol.  */
603 void
604 __do_global_ctors (void)
605 {
606   func_ptr *p;
607 #if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
608   __do_global_ctors_1();
609 #endif
610   for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
611     (*p) ();
612 }
613
614 #else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
615 #error "What are you doing with crtstuff.c, then?"
616 #endif
617
618 #else /* ! CRT_BEGIN && ! CRT_END */
619 #error "One of CRT_BEGIN or CRT_END must be defined."
620 #endif