]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/crtstuff.c
Merge basic-improvements-branch to trunk
[thirdparty/gcc.git] / gcc / crtstuff.c
CommitLineData
dc17e9e9
RS
1/* Specialized bits of code needed to support construction and
2 destruction of file-scope objects in C++ code.
5e7b4e25 3 Copyright (C) 1991, 1994, 1995, 1996, 1997, 1998,
cea3bd3e 4 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
d0f8fcea 5 Contributed by Ron Guilmette (rfg@monkeys.com).
dc17e9e9 6
1322177d 7This file is part of GCC.
dc17e9e9 8
1322177d
LB
9GCC is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
11Software Foundation; either version 2, or (at your option) any later
12version.
dc17e9e9 13
f7af368f
JL
14In addition to the permissions in the GNU General Public License, the
15Free Software Foundation gives you unlimited permission to link the
16compiled version of this file into combinations with other programs,
17and to distribute those combinations without any restriction coming
18from the use of this file. (The General Public License restrictions
19do apply in other respects; for example, they cover modification of
20the file, and distribution when not linked into a combine
21executable.)
22
1322177d
LB
23GCC is distributed in the hope that it will be useful, but WITHOUT ANY
24WARRANTY; without even the implied warranty of MERCHANTABILITY or
25FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26for more details.
dc17e9e9
RS
27
28You should have received a copy of the GNU General Public License
1322177d
LB
29along with GCC; see the file COPYING. If not, write to the Free
30Software Foundation, 59 Temple Place - Suite 330, Boston, MA
3102111-1307, USA. */
dc17e9e9 32
7857f134 33/* This file is a bit like libgcc2.c in that it is compiled
dc17e9e9
RS
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
37ce5b86
CH
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.)
dc17e9e9
RS
51
52 This file must be compiled with gcc. */
53
54/* It is incorrect to include config.h here, because this file is being
55 compiled for the target, and hence definitions concerning only the host
56 do not apply. */
57
1b5640cd
KG
58/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
59 supposedly valid even though this is a "target" file. */
60#include "auto-host.h"
eaf4e618 61#include "tconfig.h"
2e39bdbe 62#include "tsystem.h"
4977bab6
ZW
63#include "coretypes.h"
64#include "tm.h"
52a11cbf 65#include "unwind-dw2-fde.h"
dc17e9e9 66
cea3bd3e
RH
67#ifndef FORCE_CODE_SECTION_ALIGN
68# define FORCE_CODE_SECTION_ALIGN
69#endif
70
036cfb36 71#ifndef CRT_CALL_STATIC_FUNCTION
cea3bd3e
RH
72# define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
73static void __attribute__((__used__)) \
74call_ ## FUNC (void) \
75{ \
76 asm (SECTION_OP); \
77 FUNC (); \
78 FORCE_CODE_SECTION_ALIGN \
79 asm (TEXT_SECTION_ASM_OP); \
80}
036cfb36
AO
81#endif
82
275b60d6 83#if defined(OBJECT_FORMAT_ELF) && defined(HAVE_LD_EH_FRAME_HDR) \
72c7c913 84 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
275b60d6
JJ
85 && defined(__GLIBC__) && __GLIBC__ >= 2
86#include <link.h>
87# if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
88 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
89# define USE_PT_GNU_EH_FRAME
90# endif
91#endif
92#if defined(EH_FRAME_SECTION_NAME) && !defined(USE_PT_GNU_EH_FRAME)
93# define USE_EH_FRAME_REGISTRY
94#endif
96d0f4dc
JJ
95#if defined(EH_FRAME_SECTION_NAME) && defined(HAVE_LD_RO_RW_SECTION_MIXING)
96# define EH_FRAME_SECTION_CONST const
97#else
98# define EH_FRAME_SECTION_CONST
99#endif
275b60d6 100
8f08ea1e 101/* We do not want to add the weak attribute to the declarations of these
52a11cbf
RH
102 routines in unwind-dw2-fde.h because that will cause the definition of
103 these symbols to be weak as well.
8f08ea1e
L
104
105 This exposes a core issue, how to handle creating weak references vs
106 how to create weak definitions. Either we have to have the definition
107 of TARGET_WEAK_ATTRIBUTE be conditional in the shared header files or
108 have a second declaration if we want a function's references to be weak,
109 but not its definition.
110
111 Making TARGET_WEAK_ATTRIBUTE conditional seems like a good solution until
112 one thinks about scaling to larger problems -- ie, the condition under
113 which TARGET_WEAK_ATTRIBUTE is active will eventually get far too
114 complicated.
115
116 So, we take an approach similar to #pragma weak -- we have a second
117 declaration for functions that we want to have weak references.
118
119 Neither way is particularly good. */
120
121/* References to __register_frame_info and __deregister_frame_info should
122 be weak in this file if at all possible. */
123extern void __register_frame_info (void *, struct object *)
124 TARGET_ATTRIBUTE_WEAK;
1066e2b5
RH
125extern void __register_frame_info_bases (void *, struct object *,
126 void *, void *)
127 TARGET_ATTRIBUTE_WEAK;
8f08ea1e
L
128extern void *__deregister_frame_info (void *)
129 TARGET_ATTRIBUTE_WEAK;
101fa48c
RH
130extern void *__deregister_frame_info_bases (void *)
131 TARGET_ATTRIBUTE_WEAK;
8f08ea1e 132
213f974a
RH
133/* Likewise for _Jv_RegisterClasses. */
134extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK;
135
68d69835
JM
136#ifdef OBJECT_FORMAT_ELF
137
138/* Declare a pointer to void function type. */
139typedef void (*func_ptr) (void);
140#define STATIC static
141
142#else /* OBJECT_FORMAT_ELF */
143
dc17e9e9
RS
144#include "gbl-ctors.h"
145
68d69835
JM
146#define STATIC
147
148#endif /* OBJECT_FORMAT_ELF */
dc17e9e9
RS
149
150#ifdef CRT_BEGIN
151
213f974a
RH
152/* NOTE: In order to be able to support SVR4 shared libraries, we arrange
153 to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
154 __DTOR_END__ } per root executable and also one set of these symbols
155 per shared library. So in any given whole process image, we may have
156 multiple definitions of each of these symbols. In order to prevent
157 these definitions from conflicting with one another, and in order to
158 ensure that the proper lists are used for the initialization/finalization
159 of each individual shared library (respectively), we give these symbols
160 only internal (i.e. `static') linkage, and we also make it a point to
161 refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
162 symbol in crtbegin.o, where they are defined. */
163
164/* The -1 is a flag to __do_global_[cd]tors indicating that this table
165 does not start with a count of elements. */
166#ifdef CTOR_LIST_BEGIN
167CTOR_LIST_BEGIN;
168#elif defined(CTORS_SECTION_ASM_OP)
169/* Hack: force cc1 to switch to .data section early, so that assembling
170 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
171static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
172asm (CTORS_SECTION_ASM_OP);
173STATIC func_ptr __CTOR_LIST__[1]
174 __attribute__ ((__unused__, aligned(sizeof(func_ptr))))
175 = { (func_ptr) (-1) };
176#else
177STATIC func_ptr __CTOR_LIST__[1]
178 __attribute__ ((__unused__, section(".ctors"), aligned(sizeof(func_ptr))))
179 = { (func_ptr) (-1) };
180#endif /* __CTOR_LIST__ alternatives */
181
182#ifdef DTOR_LIST_BEGIN
183DTOR_LIST_BEGIN;
184#elif defined(DTORS_SECTION_ASM_OP)
185asm (DTORS_SECTION_ASM_OP);
186STATIC func_ptr __DTOR_LIST__[1]
187 __attribute__ ((aligned(sizeof(func_ptr))))
188 = { (func_ptr) (-1) };
189#else
190STATIC func_ptr __DTOR_LIST__[1]
191 __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
192 = { (func_ptr) (-1) };
193#endif /* __DTOR_LIST__ alternatives */
194
618939de 195#ifdef USE_EH_FRAME_REGISTRY
213f974a
RH
196/* Stick a label at the beginning of the frame unwind info so we can register
197 and deregister it with the exception handling library code. */
96d0f4dc 198STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
213f974a
RH
199 __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
200 = { };
618939de 201#endif /* USE_EH_FRAME_REGISTRY */
213f974a
RH
202
203#ifdef JCR_SECTION_NAME
204/* Stick a label at the beginning of the java class registration info
205 so we can register them properly. */
213f974a
RH
206STATIC void *__JCR_LIST__[]
207 __attribute__ ((unused, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
208 = { };
209#endif /* JCR_SECTION_NAME */
210
29d2c7a5
RH
211#ifdef INIT_SECTION_ASM_OP
212
68d69835
JM
213#ifdef OBJECT_FORMAT_ELF
214
fc693822 215/* Declare the __dso_handle variable. It should have a unique value
6a9c5260
UD
216 in every shared-object; in a main program its value is zero. The
217 object should in any case be protected. This means the instance
218 in one DSO or the main program is not used in another object. The
219 dynamic linker takes care of this. */
220
6a9c5260 221#ifdef HAVE_GAS_HIDDEN
47bd70b5 222extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
6a9c5260 223#endif
fc693822
MM
224#ifdef CRTSTUFFS_O
225void *__dso_handle = &__dso_handle;
226#else
227void *__dso_handle = 0;
228#endif
229
230/* The __cxa_finalize function may not be available so we use only a
231 weak declaration. */
232extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
233
68d69835
JM
234/* Run all the global destructors on exit from the program. */
235
236/* Some systems place the number of pointers in the first word of the
237 table. On SVR4 however, that word is -1. In all cases, the table is
238 null-terminated. On SVR4, we start from the beginning of the list and
239 invoke each per-compilation-unit destructor routine in order
240 until we find that null.
241
242 Note that this function MUST be static. There will be one of these
243 functions in each root executable and one in each shared library, but
244 although they all have the same code, each one is unique in that it
245 refers to one particular associated `__DTOR_LIST__' which belongs to the
b40b9d93
MS
246 same particular root executable or shared library file.
247
248 On some systems, this routine is run more than once from the .fini,
249 when exit is called recursively, so we arrange to remember where in
250 the list we left off processing, and we resume at that point,
251 should we be re-invoked. */
68d69835 252
cea3bd3e 253static void __attribute__((used))
3cc22c31 254__do_global_dtors_aux (void)
68d69835 255{
b40b9d93 256 static func_ptr *p = __DTOR_LIST__ + 1;
cea3bd3e 257 static _Bool completed;
1066e2b5 258 func_ptr f;
5041a61c 259
1066e2b5 260 if (__builtin_expect (completed, 0))
5041a61c
JL
261 return;
262
2a14e214
MM
263#ifdef CRTSTUFFS_O
264 if (__cxa_finalize)
fc693822 265 __cxa_finalize (__dso_handle);
2a14e214 266#endif
fc693822 267
1066e2b5 268 while ((f = *p))
b40b9d93
MS
269 {
270 p++;
1066e2b5 271 f ();
b40b9d93 272 }
0021b564 273
275b60d6 274#ifdef USE_EH_FRAME_REGISTRY
101fa48c
RH
275#if defined(CRT_GET_RFIB_TEXT) || defined(CRT_GET_RFIB_DATA)
276 /* If we used the new __register_frame_info_bases interface,
277 make sure that we deregister from the same place. */
278 if (__deregister_frame_info_bases)
279 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
280#else
8f08ea1e
L
281 if (__deregister_frame_info)
282 __deregister_frame_info (__EH_FRAME_BEGIN__);
0021b564 283#endif
101fa48c
RH
284#endif
285
5041a61c 286 completed = 1;
68d69835
JM
287}
288
289/* Stick a call to __do_global_dtors_aux into the .fini section. */
cea3bd3e 290CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
68d69835 291
275b60d6 292#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
6d8ccdbb
JL
293/* Stick a call to __register_frame_info into the .init section. For some
294 reason calls with no arguments work more reliably in .init, so stick the
295 call in another function. */
0021b564 296
cea3bd3e 297static void __attribute__((used))
3cc22c31 298frame_dummy (void)
0021b564 299{
275b60d6 300#ifdef USE_EH_FRAME_REGISTRY
956d6950 301 static struct object object;
1066e2b5
RH
302#if defined(CRT_GET_RFIB_TEXT) || defined(CRT_GET_RFIB_DATA)
303 void *tbase, *dbase;
304#ifdef CRT_GET_RFIB_TEXT
305 CRT_GET_RFIB_TEXT (tbase);
306#else
307 tbase = 0;
308#endif
309#ifdef CRT_GET_RFIB_DATA
310 CRT_GET_RFIB_DATA (dbase);
311#else
312 dbase = 0;
313#endif
314 if (__register_frame_info_bases)
315 __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
316#else
8f08ea1e
L
317 if (__register_frame_info)
318 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1066e2b5 319#endif
4505024e 320#endif /* USE_EH_FRAME_REGISTRY */
213f974a
RH
321#ifdef JCR_SECTION_NAME
322 if (__JCR_LIST__[0] && _Jv_RegisterClasses)
323 _Jv_RegisterClasses (__JCR_LIST__);
324#endif /* JCR_SECTION_NAME */
0021b564
JM
325}
326
cea3bd3e 327CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, frame_dummy)
4505024e 328#endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME */
0021b564 329
68d69835
JM
330#else /* OBJECT_FORMAT_ELF */
331
b335c2cc 332/* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
b71a4aa9 333 and once in crtend.o). It must be declared static to avoid a link
b335c2cc
TW
334 error. Here, we define __do_global_ctors as an externally callable
335 function. It is externally callable so that __main can invoke it when
336 INVOKE__main is defined. This has the additional effect of forcing cc1
337 to switch to the .text section. */
0f41302f 338
d1e51320 339static void __do_global_ctors_aux (void);
3cc22c31
JL
340void
341__do_global_ctors (void)
329d2160 342{
29d2c7a5
RH
343#ifdef INVOKE__main
344 /* If __main won't actually call __do_global_ctors then it doesn't matter
345 what's inside the function. The inside of __do_global_ctors_aux is
346 called automatically in that case. And the Alliant fx2800 linker
347 crashes on this reference. So prevent the crash. */
329d2160
RS
348 __do_global_ctors_aux ();
349#endif
350}
dc17e9e9
RS
351
352asm (INIT_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
353
5378943d
RK
354/* On some svr4 systems, the initial .init section preamble code provided in
355 crti.o may do something, such as bump the stack, which we have to
356 undo before we reach the function prologue code for __do_global_ctors
357 (directly below). For such systems, define the macro INIT_SECTION_PREAMBLE
0f41302f 358 to expand into the code needed to undo the actions of the crti.o file. */
5378943d
RK
359
360#ifdef INIT_SECTION_PREAMBLE
361 INIT_SECTION_PREAMBLE;
362#endif
363
dc17e9e9
RS
364/* A routine to invoke all of the global constructors upon entry to the
365 program. We put this into the .init section (for systems that have
366 such a thing) so that we can properly perform the construction of
6d2f8887 367 file-scope static-storage C++ objects within shared libraries. */
dc17e9e9 368
cea3bd3e 369static void __attribute__((used))
3cc22c31 370__do_global_ctors_aux (void) /* prologue goes in .init section */
dc17e9e9 371{
cea3bd3e 372 FORCE_CODE_SECTION_ALIGN /* explicit align before switch to .text */
dc17e9e9
RS
373 asm (TEXT_SECTION_ASM_OP); /* don't put epilogue and body in .init */
374 DO_GLOBAL_CTORS_BODY;
451fbdf2 375 atexit (__do_global_dtors);
dc17e9e9
RS
376}
377
68d69835 378#endif /* OBJECT_FORMAT_ELF */
fe1fd353 379
29d2c7a5 380#elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
fe1fd353
JM
381
382/* This case is used by the Irix 6 port, which supports named sections but
383 not an SVR4-style .fini section. __do_global_dtors can be non-static
0021b564
JM
384 in this case because we protect it with -hidden_symbol. */
385
fe1fd353 386void
3cc22c31 387__do_global_dtors (void)
fe1fd353 388{
1066e2b5
RH
389 func_ptr *p, f;
390 for (p = __DTOR_LIST__ + 1; (f = *p); p++)
391 f ();
0021b564 392
275b60d6 393#ifdef USE_EH_FRAME_REGISTRY
8f08ea1e
L
394 if (__deregister_frame_info)
395 __deregister_frame_info (__EH_FRAME_BEGIN__);
0021b564 396#endif
fe1fd353 397}
35a42f5f 398
275b60d6 399#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
29d2c7a5
RH
400/* A helper function for __do_global_ctors, which is in crtend.o. Here
401 in crtbegin.o, we can reference a couple of symbols not visible there.
402 Plus, since we're before libgcc.a, we have no problems referencing
403 functions from there. */
35a42f5f 404void
29d2c7a5 405__do_global_ctors_1(void)
35a42f5f 406{
275b60d6 407#ifdef USE_EH_FRAME_REGISTRY
35a42f5f 408 static struct object object;
8f08ea1e
L
409 if (__register_frame_info)
410 __register_frame_info (__EH_FRAME_BEGIN__, &object);
b335c2cc 411#endif
6351543d 412#ifdef JCR_SECTION_NAME
213f974a
RH
413 if (__JCR_LIST__[0] && _Jv_RegisterClasses)
414 _Jv_RegisterClasses (__JCR_LIST__);
415#endif
416}
4505024e 417#endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME */
6351543d 418
29d2c7a5
RH
419#else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
420#error "What are you doing with crtstuff.c, then?"
421#endif
422
423#elif defined(CRT_END) /* ! CRT_BEGIN */
424
425/* Put a word containing zero at the end of each of our two lists of function
426 addresses. Note that the words defined here go into the .ctors and .dtors
427 sections of the crtend.o file, and since that file is always linked in
428 last, these words naturally end up at the very ends of the two lists
429 contained in these two sections. */
430
431#ifdef CTOR_LIST_END
432CTOR_LIST_END;
433#elif defined(CTORS_SECTION_ASM_OP)
434/* Hack: force cc1 to switch to .data section early, so that assembling
435 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
436static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
437asm (CTORS_SECTION_ASM_OP);
438STATIC func_ptr __CTOR_END__[1]
439 __attribute__((aligned(sizeof(func_ptr))))
440 = { (func_ptr) 0 };
441#else
442STATIC func_ptr __CTOR_END__[1]
443 __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
444 = { (func_ptr) 0 };
445#endif
446
447#ifdef DTOR_LIST_END
448DTOR_LIST_END;
449#elif defined(DTORS_SECTION_ASM_OP)
450asm (DTORS_SECTION_ASM_OP);
451STATIC func_ptr __DTOR_END__[1]
452 __attribute__ ((unused, aligned(sizeof(func_ptr))))
453 = { (func_ptr) 0 };
454#else
455STATIC func_ptr __DTOR_END__[1]
456 __attribute__((unused, section(".dtors"), aligned(sizeof(func_ptr))))
457 = { (func_ptr) 0 };
458#endif
dc17e9e9 459
29d2c7a5
RH
460#ifdef EH_FRAME_SECTION_NAME
461/* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
462 this would be the 'length' field in a real FDE. */
96d0f4dc 463STATIC EH_FRAME_SECTION_CONST int __FRAME_END__[]
29d2c7a5
RH
464 __attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME),
465 aligned(4)))
466 = { 0 };
f3a8e4f5 467#endif /* EH_FRAME_SECTION_NAME */
29d2c7a5
RH
468
469#ifdef JCR_SECTION_NAME
470/* Null terminate the .jcr section array. */
471STATIC void *__JCR_END__[1]
472 __attribute__ ((unused, section(JCR_SECTION_NAME),
473 aligned(sizeof(void *))))
474 = { 0 };
475#endif /* JCR_SECTION_NAME */
dc17e9e9
RS
476
477#ifdef INIT_SECTION_ASM_OP
478
68d69835 479#ifdef OBJECT_FORMAT_ELF
cea3bd3e 480static void __attribute__((used))
3cc22c31 481__do_global_ctors_aux (void)
68d69835
JM
482{
483 func_ptr *p;
484 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
485 (*p) ();
486}
487
488/* Stick a call to __do_global_ctors_aux into the .init section. */
cea3bd3e 489CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, __do_global_ctors_aux)
68d69835
JM
490#else /* OBJECT_FORMAT_ELF */
491
492/* Stick the real initialization code, followed by a normal sort of
493 function epilogue at the very end of the .init section for this
494 entire root executable file or for this entire shared library file.
495
496 Note that we use some tricks here to get *just* the body and just
497 a function epilogue (but no function prologue) into the .init
9faa82d8 498 section of the crtend.o file. Specifically, we switch to the .text
68d69835
JM
499 section, start to define a function, and then we switch to the .init
500 section just before the body code.
501
502 Earlier on, we put the corresponding function prologue into the .init
503 section of the crtbegin.o file (which will be linked in first).
504
505 Note that we want to invoke all constructors for C++ file-scope static-
506 storage objects AFTER any other possible initialization actions which
507 may be performed by the code in the .init section contributions made by
508 other libraries, etc. That's because those other initializations may
509 include setup operations for very primitive things (e.g. initializing
510 the state of the floating-point coprocessor, etc.) which should be done
0f41302f 511 before we start to execute any of the user's code. */
dc17e9e9
RS
512
513static void
3cc22c31 514__do_global_ctors_aux (void) /* prologue goes in .text section */
dc17e9e9
RS
515{
516 asm (INIT_SECTION_ASM_OP);
517 DO_GLOBAL_CTORS_BODY;
451fbdf2 518 atexit (__do_global_dtors);
e5e809f4
JL
519} /* epilogue and body go in .init section */
520
cea3bd3e 521FORCE_CODE_SECTION_ALIGN
e5e809f4 522asm (TEXT_SECTION_ASM_OP);
dc17e9e9 523
68d69835
JM
524#endif /* OBJECT_FORMAT_ELF */
525
29d2c7a5 526#elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
fe1fd353
JM
527
528/* This case is used by the Irix 6 port, which supports named sections but
529 not an SVR4-style .init section. __do_global_ctors can be non-static
0021b564 530 in this case because we protect it with -hidden_symbol. */
29d2c7a5 531extern void __do_global_ctors_1(void);
fe1fd353 532void
3cc22c31 533__do_global_ctors (void)
fe1fd353
JM
534{
535 func_ptr *p;
275b60d6 536#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
29d2c7a5 537 __do_global_ctors_1();
0021b564 538#endif
fe1fd353
JM
539 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
540 (*p) ();
541}
68d69835 542
29d2c7a5
RH
543#else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
544#error "What are you doing with crtstuff.c, then?"
b335c2cc 545#endif
dc17e9e9 546
29d2c7a5
RH
547#else /* ! CRT_BEGIN && ! CRT_END */
548#error "One of CRT_BEGIN or CRT_END must be defined."
b335c2cc 549#endif