]> gcc.gnu.org Git - gcc.git/blame - gcc/crtstuff.c
* mangle.c (get_identifier_nocopy): Add cast.
[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,
d9221e01 4 1999, 2000, 2001, 2002, 2003, 2004 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. */
a30794da 123extern void __register_frame_info (const void *, struct object *)
8f08ea1e 124 TARGET_ATTRIBUTE_WEAK;
a30794da 125extern void __register_frame_info_bases (const void *, struct object *,
1066e2b5
RH
126 void *, void *)
127 TARGET_ATTRIBUTE_WEAK;
a30794da 128extern void *__deregister_frame_info (const void *)
8f08ea1e 129 TARGET_ATTRIBUTE_WEAK;
a30794da 130extern void *__deregister_frame_info_bases (const void *)
101fa48c 131 TARGET_ATTRIBUTE_WEAK;
525996eb 132extern void __do_global_ctors_1 (void);
8f08ea1e 133
213f974a
RH
134/* Likewise for _Jv_RegisterClasses. */
135extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK;
136
68d69835
JM
137#ifdef OBJECT_FORMAT_ELF
138
139/* Declare a pointer to void function type. */
140typedef void (*func_ptr) (void);
141#define STATIC static
142
143#else /* OBJECT_FORMAT_ELF */
144
dc17e9e9
RS
145#include "gbl-ctors.h"
146
68d69835
JM
147#define STATIC
148
149#endif /* OBJECT_FORMAT_ELF */
dc17e9e9
RS
150
151#ifdef CRT_BEGIN
152
213f974a
RH
153/* NOTE: In order to be able to support SVR4 shared libraries, we arrange
154 to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
155 __DTOR_END__ } per root executable and also one set of these symbols
156 per shared library. So in any given whole process image, we may have
157 multiple definitions of each of these symbols. In order to prevent
158 these definitions from conflicting with one another, and in order to
159 ensure that the proper lists are used for the initialization/finalization
160 of each individual shared library (respectively), we give these symbols
161 only internal (i.e. `static') linkage, and we also make it a point to
162 refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
163 symbol in crtbegin.o, where they are defined. */
164
165/* The -1 is a flag to __do_global_[cd]tors indicating that this table
166 does not start with a count of elements. */
167#ifdef CTOR_LIST_BEGIN
168CTOR_LIST_BEGIN;
169#elif defined(CTORS_SECTION_ASM_OP)
170/* Hack: force cc1 to switch to .data section early, so that assembling
171 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
172static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
173asm (CTORS_SECTION_ASM_OP);
174STATIC func_ptr __CTOR_LIST__[1]
175 __attribute__ ((__unused__, aligned(sizeof(func_ptr))))
176 = { (func_ptr) (-1) };
177#else
178STATIC func_ptr __CTOR_LIST__[1]
179 __attribute__ ((__unused__, section(".ctors"), aligned(sizeof(func_ptr))))
180 = { (func_ptr) (-1) };
181#endif /* __CTOR_LIST__ alternatives */
182
183#ifdef DTOR_LIST_BEGIN
184DTOR_LIST_BEGIN;
185#elif defined(DTORS_SECTION_ASM_OP)
186asm (DTORS_SECTION_ASM_OP);
187STATIC func_ptr __DTOR_LIST__[1]
188 __attribute__ ((aligned(sizeof(func_ptr))))
189 = { (func_ptr) (-1) };
190#else
191STATIC func_ptr __DTOR_LIST__[1]
192 __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
193 = { (func_ptr) (-1) };
194#endif /* __DTOR_LIST__ alternatives */
195
618939de 196#ifdef USE_EH_FRAME_REGISTRY
213f974a
RH
197/* Stick a label at the beginning of the frame unwind info so we can register
198 and deregister it with the exception handling library code. */
96d0f4dc 199STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
213f974a
RH
200 __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
201 = { };
618939de 202#endif /* USE_EH_FRAME_REGISTRY */
213f974a
RH
203
204#ifdef JCR_SECTION_NAME
205/* Stick a label at the beginning of the java class registration info
206 so we can register them properly. */
213f974a
RH
207STATIC void *__JCR_LIST__[]
208 __attribute__ ((unused, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
209 = { };
210#endif /* JCR_SECTION_NAME */
211
29d2c7a5
RH
212#ifdef INIT_SECTION_ASM_OP
213
68d69835
JM
214#ifdef OBJECT_FORMAT_ELF
215
fc693822 216/* Declare the __dso_handle variable. It should have a unique value
6a9c5260
UD
217 in every shared-object; in a main program its value is zero. The
218 object should in any case be protected. This means the instance
219 in one DSO or the main program is not used in another object. The
220 dynamic linker takes care of this. */
221
6a9c5260 222#ifdef HAVE_GAS_HIDDEN
47bd70b5 223extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
6a9c5260 224#endif
fc693822
MM
225#ifdef CRTSTUFFS_O
226void *__dso_handle = &__dso_handle;
227#else
228void *__dso_handle = 0;
229#endif
230
231/* The __cxa_finalize function may not be available so we use only a
232 weak declaration. */
233extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
234
68d69835
JM
235/* Run all the global destructors on exit from the program. */
236
237/* Some systems place the number of pointers in the first word of the
238 table. On SVR4 however, that word is -1. In all cases, the table is
239 null-terminated. On SVR4, we start from the beginning of the list and
240 invoke each per-compilation-unit destructor routine in order
241 until we find that null.
242
243 Note that this function MUST be static. There will be one of these
244 functions in each root executable and one in each shared library, but
245 although they all have the same code, each one is unique in that it
246 refers to one particular associated `__DTOR_LIST__' which belongs to the
b40b9d93
MS
247 same particular root executable or shared library file.
248
249 On some systems, this routine is run more than once from the .fini,
250 when exit is called recursively, so we arrange to remember where in
251 the list we left off processing, and we resume at that point,
252 should we be re-invoked. */
68d69835 253
cea3bd3e 254static void __attribute__((used))
3cc22c31 255__do_global_dtors_aux (void)
68d69835 256{
b40b9d93 257 static func_ptr *p = __DTOR_LIST__ + 1;
cea3bd3e 258 static _Bool completed;
1066e2b5 259 func_ptr f;
5041a61c 260
1066e2b5 261 if (__builtin_expect (completed, 0))
5041a61c
JL
262 return;
263
2a14e214
MM
264#ifdef CRTSTUFFS_O
265 if (__cxa_finalize)
fc693822 266 __cxa_finalize (__dso_handle);
2a14e214 267#endif
fc693822 268
1066e2b5 269 while ((f = *p))
b40b9d93
MS
270 {
271 p++;
1066e2b5 272 f ();
b40b9d93 273 }
0021b564 274
275b60d6 275#ifdef USE_EH_FRAME_REGISTRY
f691dc3b 276#ifdef CRT_GET_RFIB_DATA
101fa48c
RH
277 /* If we used the new __register_frame_info_bases interface,
278 make sure that we deregister from the same place. */
279 if (__deregister_frame_info_bases)
280 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
281#else
8f08ea1e
L
282 if (__deregister_frame_info)
283 __deregister_frame_info (__EH_FRAME_BEGIN__);
0021b564 284#endif
101fa48c
RH
285#endif
286
5041a61c 287 completed = 1;
68d69835
JM
288}
289
290/* Stick a call to __do_global_dtors_aux into the .fini section. */
cea3bd3e 291CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
68d69835 292
275b60d6 293#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
6d8ccdbb
JL
294/* Stick a call to __register_frame_info into the .init section. For some
295 reason calls with no arguments work more reliably in .init, so stick the
296 call in another function. */
0021b564 297
cea3bd3e 298static void __attribute__((used))
3cc22c31 299frame_dummy (void)
0021b564 300{
275b60d6 301#ifdef USE_EH_FRAME_REGISTRY
956d6950 302 static struct object object;
f691dc3b 303#ifdef CRT_GET_RFIB_DATA
1066e2b5 304 void *tbase, *dbase;
1066e2b5 305 tbase = 0;
1066e2b5 306 CRT_GET_RFIB_DATA (dbase);
1066e2b5
RH
307 if (__register_frame_info_bases)
308 __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
309#else
8f08ea1e
L
310 if (__register_frame_info)
311 __register_frame_info (__EH_FRAME_BEGIN__, &object);
f691dc3b 312#endif /* CRT_GET_RFIB_DATA */
4505024e 313#endif /* USE_EH_FRAME_REGISTRY */
213f974a 314#ifdef JCR_SECTION_NAME
bfccaa6f
JJ
315 if (__JCR_LIST__[0])
316 {
317 void (*register_classes) (void *) = _Jv_RegisterClasses;
318 __asm ("" : "+r" (register_classes));
319 if (register_classes)
320 register_classes (__JCR_LIST__);
321 }
213f974a 322#endif /* JCR_SECTION_NAME */
0021b564
JM
323}
324
cea3bd3e 325CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, frame_dummy)
4505024e 326#endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME */
0021b564 327
68d69835
JM
328#else /* OBJECT_FORMAT_ELF */
329
b335c2cc 330/* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
b71a4aa9 331 and once in crtend.o). It must be declared static to avoid a link
b335c2cc
TW
332 error. Here, we define __do_global_ctors as an externally callable
333 function. It is externally callable so that __main can invoke it when
334 INVOKE__main is defined. This has the additional effect of forcing cc1
335 to switch to the .text section. */
0f41302f 336
d1e51320 337static void __do_global_ctors_aux (void);
3cc22c31
JL
338void
339__do_global_ctors (void)
329d2160 340{
29d2c7a5
RH
341#ifdef INVOKE__main
342 /* If __main won't actually call __do_global_ctors then it doesn't matter
343 what's inside the function. The inside of __do_global_ctors_aux is
344 called automatically in that case. And the Alliant fx2800 linker
345 crashes on this reference. So prevent the crash. */
329d2160
RS
346 __do_global_ctors_aux ();
347#endif
348}
dc17e9e9
RS
349
350asm (INIT_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
351
352/* A routine to invoke all of the global constructors upon entry to the
353 program. We put this into the .init section (for systems that have
354 such a thing) so that we can properly perform the construction of
6d2f8887 355 file-scope static-storage C++ objects within shared libraries. */
dc17e9e9 356
cea3bd3e 357static void __attribute__((used))
3cc22c31 358__do_global_ctors_aux (void) /* prologue goes in .init section */
dc17e9e9 359{
cea3bd3e 360 FORCE_CODE_SECTION_ALIGN /* explicit align before switch to .text */
dc17e9e9
RS
361 asm (TEXT_SECTION_ASM_OP); /* don't put epilogue and body in .init */
362 DO_GLOBAL_CTORS_BODY;
451fbdf2 363 atexit (__do_global_dtors);
dc17e9e9
RS
364}
365
68d69835 366#endif /* OBJECT_FORMAT_ELF */
fe1fd353 367
29d2c7a5 368#elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
fe1fd353 369
af8e5a0e
RO
370extern void __do_global_dtors (void);
371
fe1fd353
JM
372/* This case is used by the Irix 6 port, which supports named sections but
373 not an SVR4-style .fini section. __do_global_dtors can be non-static
0021b564
JM
374 in this case because we protect it with -hidden_symbol. */
375
fe1fd353 376void
3cc22c31 377__do_global_dtors (void)
fe1fd353 378{
1066e2b5
RH
379 func_ptr *p, f;
380 for (p = __DTOR_LIST__ + 1; (f = *p); p++)
381 f ();
0021b564 382
275b60d6 383#ifdef USE_EH_FRAME_REGISTRY
8f08ea1e
L
384 if (__deregister_frame_info)
385 __deregister_frame_info (__EH_FRAME_BEGIN__);
0021b564 386#endif
fe1fd353 387}
35a42f5f 388
275b60d6 389#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
29d2c7a5
RH
390/* A helper function for __do_global_ctors, which is in crtend.o. Here
391 in crtbegin.o, we can reference a couple of symbols not visible there.
392 Plus, since we're before libgcc.a, we have no problems referencing
393 functions from there. */
35a42f5f 394void
29d2c7a5 395__do_global_ctors_1(void)
35a42f5f 396{
275b60d6 397#ifdef USE_EH_FRAME_REGISTRY
35a42f5f 398 static struct object object;
8f08ea1e
L
399 if (__register_frame_info)
400 __register_frame_info (__EH_FRAME_BEGIN__, &object);
b335c2cc 401#endif
6351543d 402#ifdef JCR_SECTION_NAME
bfccaa6f
JJ
403 if (__JCR_LIST__[0])
404 {
405 void (*register_classes) (void *) = _Jv_RegisterClasses;
406 __asm ("" : "+r" (register_classes));
407 if (register_classes)
408 register_classes (__JCR_LIST__);
409 }
213f974a
RH
410#endif
411}
4505024e 412#endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME */
6351543d 413
29d2c7a5
RH
414#else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
415#error "What are you doing with crtstuff.c, then?"
416#endif
417
418#elif defined(CRT_END) /* ! CRT_BEGIN */
419
420/* Put a word containing zero at the end of each of our two lists of function
421 addresses. Note that the words defined here go into the .ctors and .dtors
422 sections of the crtend.o file, and since that file is always linked in
423 last, these words naturally end up at the very ends of the two lists
424 contained in these two sections. */
425
426#ifdef CTOR_LIST_END
427CTOR_LIST_END;
428#elif defined(CTORS_SECTION_ASM_OP)
429/* Hack: force cc1 to switch to .data section early, so that assembling
430 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
431static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };
432asm (CTORS_SECTION_ASM_OP);
433STATIC func_ptr __CTOR_END__[1]
434 __attribute__((aligned(sizeof(func_ptr))))
435 = { (func_ptr) 0 };
436#else
437STATIC func_ptr __CTOR_END__[1]
438 __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
439 = { (func_ptr) 0 };
440#endif
441
442#ifdef DTOR_LIST_END
443DTOR_LIST_END;
444#elif defined(DTORS_SECTION_ASM_OP)
445asm (DTORS_SECTION_ASM_OP);
446STATIC func_ptr __DTOR_END__[1]
447 __attribute__ ((unused, aligned(sizeof(func_ptr))))
448 = { (func_ptr) 0 };
449#else
450STATIC func_ptr __DTOR_END__[1]
451 __attribute__((unused, section(".dtors"), aligned(sizeof(func_ptr))))
452 = { (func_ptr) 0 };
453#endif
dc17e9e9 454
29d2c7a5
RH
455#ifdef EH_FRAME_SECTION_NAME
456/* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
457 this would be the 'length' field in a real FDE. */
96d0f4dc 458STATIC EH_FRAME_SECTION_CONST int __FRAME_END__[]
29d2c7a5
RH
459 __attribute__ ((unused, mode(SI), section(EH_FRAME_SECTION_NAME),
460 aligned(4)))
461 = { 0 };
f3a8e4f5 462#endif /* EH_FRAME_SECTION_NAME */
29d2c7a5
RH
463
464#ifdef JCR_SECTION_NAME
465/* Null terminate the .jcr section array. */
466STATIC void *__JCR_END__[1]
467 __attribute__ ((unused, section(JCR_SECTION_NAME),
468 aligned(sizeof(void *))))
469 = { 0 };
470#endif /* JCR_SECTION_NAME */
dc17e9e9
RS
471
472#ifdef INIT_SECTION_ASM_OP
473
68d69835 474#ifdef OBJECT_FORMAT_ELF
cea3bd3e 475static void __attribute__((used))
3cc22c31 476__do_global_ctors_aux (void)
68d69835
JM
477{
478 func_ptr *p;
479 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
480 (*p) ();
481}
482
483/* Stick a call to __do_global_ctors_aux into the .init section. */
cea3bd3e 484CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, __do_global_ctors_aux)
68d69835
JM
485#else /* OBJECT_FORMAT_ELF */
486
487/* Stick the real initialization code, followed by a normal sort of
488 function epilogue at the very end of the .init section for this
489 entire root executable file or for this entire shared library file.
490
491 Note that we use some tricks here to get *just* the body and just
492 a function epilogue (but no function prologue) into the .init
9faa82d8 493 section of the crtend.o file. Specifically, we switch to the .text
68d69835
JM
494 section, start to define a function, and then we switch to the .init
495 section just before the body code.
496
497 Earlier on, we put the corresponding function prologue into the .init
498 section of the crtbegin.o file (which will be linked in first).
499
500 Note that we want to invoke all constructors for C++ file-scope static-
501 storage objects AFTER any other possible initialization actions which
502 may be performed by the code in the .init section contributions made by
503 other libraries, etc. That's because those other initializations may
504 include setup operations for very primitive things (e.g. initializing
505 the state of the floating-point coprocessor, etc.) which should be done
0f41302f 506 before we start to execute any of the user's code. */
dc17e9e9
RS
507
508static void
3cc22c31 509__do_global_ctors_aux (void) /* prologue goes in .text section */
dc17e9e9
RS
510{
511 asm (INIT_SECTION_ASM_OP);
512 DO_GLOBAL_CTORS_BODY;
451fbdf2 513 atexit (__do_global_dtors);
e5e809f4
JL
514} /* epilogue and body go in .init section */
515
cea3bd3e 516FORCE_CODE_SECTION_ALIGN
e5e809f4 517asm (TEXT_SECTION_ASM_OP);
dc17e9e9 518
68d69835
JM
519#endif /* OBJECT_FORMAT_ELF */
520
29d2c7a5 521#elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
fe1fd353 522
af8e5a0e
RO
523extern void __do_global_ctors (void);
524
fe1fd353
JM
525/* This case is used by the Irix 6 port, which supports named sections but
526 not an SVR4-style .init section. __do_global_ctors can be non-static
0021b564 527 in this case because we protect it with -hidden_symbol. */
fe1fd353 528void
3cc22c31 529__do_global_ctors (void)
fe1fd353
JM
530{
531 func_ptr *p;
275b60d6 532#if defined(USE_EH_FRAME_REGISTRY) || defined(JCR_SECTION_NAME)
29d2c7a5 533 __do_global_ctors_1();
0021b564 534#endif
fe1fd353
JM
535 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
536 (*p) ();
537}
68d69835 538
29d2c7a5
RH
539#else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
540#error "What are you doing with crtstuff.c, then?"
b335c2cc 541#endif
dc17e9e9 542
29d2c7a5
RH
543#else /* ! CRT_BEGIN && ! CRT_END */
544#error "One of CRT_BEGIN or CRT_END must be defined."
b335c2cc 545#endif
This page took 1.556521 seconds and 5 git commands to generate.