cgraph.h (FOR_EACH_ALIAS): Avoid shadowing the loop variable.
[official-gcc.git] / libgcc / crtstuff.c
blobc93e1cbcaca7e1d2404ca2f4a30bceda134b665d
1 /* Specialized bits of code needed to support construction and
2 destruction of file-scope objects in C++ code.
3 Copyright (C) 1991-2019 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 /* This file is a bit like libgcc2.c in that it is compiled
28 multiple times and yields multiple .o files.
30 This file is useful on target machines where the object file format
31 supports multiple "user-defined" sections (e.g. COFF, ELF, ROSE). On
32 such systems, this file allows us to avoid running collect (or any
33 other such slow and painful kludge). Additionally, if the target
34 system supports a .init section, this file allows us to support the
35 linking of C++ code with a non-C++ main program.
37 Note that if INIT_SECTION_ASM_OP is defined in the tm.h file, then
38 this file *will* make use of the .init section. If that symbol is
39 not defined however, then the .init section will not be used.
41 Currently, only ELF and COFF are supported. It is likely however that
42 ROSE could also be supported, if someone was willing to do the work to
43 make whatever (small?) adaptations are needed. (Some work may be
44 needed on the ROSE assembler and linker also.)
46 This file must be compiled with gcc. */
48 /* Target machine header files require this define. */
49 #define IN_LIBGCC2
51 /* FIXME: Including auto-host is incorrect, but until we have
52 identified the set of defines that need to go into auto-target.h,
53 this will have to do. */
54 #include "auto-host.h"
55 #undef caddr_t
56 #undef pid_t
57 #undef rlim_t
58 #undef ssize_t
59 #undef vfork
60 #include "tconfig.h"
61 #include "tsystem.h"
62 #include "coretypes.h"
63 #include "tm.h"
64 #include "libgcc_tm.h"
65 #include "unwind-dw2-fde.h"
67 #ifndef FORCE_CODE_SECTION_ALIGN
68 # define FORCE_CODE_SECTION_ALIGN
69 #endif
71 #ifndef CRT_CALL_STATIC_FUNCTION
72 # define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
73 static void __attribute__((__used__)) \
74 call_ ## FUNC (void) \
75 { \
76 asm (SECTION_OP); \
77 FUNC (); \
78 FORCE_CODE_SECTION_ALIGN \
79 asm (__LIBGCC_TEXT_SECTION_ASM_OP__); \
81 #endif
83 #if defined(TARGET_DL_ITERATE_PHDR) && \
84 (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__))
85 #define BSD_DL_ITERATE_PHDR_AVAILABLE
86 #endif
88 #if defined(OBJECT_FORMAT_ELF) \
89 && !defined(OBJECT_FORMAT_FLAT) \
90 && defined(HAVE_LD_EH_FRAME_HDR) \
91 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
92 && defined(BSD_DL_ITERATE_PHDR_AVAILABLE)
93 #include <link.h>
94 # define USE_PT_GNU_EH_FRAME
95 #endif
97 #if defined(OBJECT_FORMAT_ELF) \
98 && !defined(OBJECT_FORMAT_FLAT) \
99 && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR) \
100 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
101 && defined(__sun__) && defined(__svr4__)
102 #include <link.h>
103 # define USE_PT_GNU_EH_FRAME
104 #endif
106 #if defined(OBJECT_FORMAT_ELF) \
107 && !defined(OBJECT_FORMAT_FLAT) \
108 && defined(HAVE_LD_EH_FRAME_HDR) \
109 && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
110 && defined(__GLIBC__) && __GLIBC__ >= 2
111 #include <link.h>
112 /* uClibc pretends to be glibc 2.2 and DT_CONFIG is defined in its link.h.
113 But it doesn't use PT_GNU_EH_FRAME ELF segment currently. */
114 # if !defined(__UCLIBC__) \
115 && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
116 || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
117 # define USE_PT_GNU_EH_FRAME
118 # endif
119 #endif
121 #if defined(OBJECT_FORMAT_ELF) \
122 && !defined(OBJECT_FORMAT_FLAT) \
123 && defined(HAVE_LD_EH_FRAME_HDR) \
124 && !defined(CRTSTUFFT_O) \
125 && defined(inhibit_libc) \
126 && (defined(__GLIBC__) || defined(__gnu_linux__) || defined(__GNU__))
127 /* On systems using glibc, an inhibit_libc build of libgcc is only
128 part of a bootstrap process. Build the same crt*.o as would be
129 built with headers present, so that it is not necessary to build
130 glibc more than once for the bootstrap to converge. */
131 # define USE_PT_GNU_EH_FRAME
132 #endif
134 #ifdef USE_EH_FRAME_REGISTRY_ALWAYS
135 # ifndef __LIBGCC_EH_FRAME_SECTION_NAME__
136 # error "Can't use explicit exception-frame-registration without __LIBGCC_EH_FRAME_SECTION_NAME__"
137 # endif
138 #endif
139 #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) && (!defined(USE_PT_GNU_EH_FRAME) || defined(USE_EH_FRAME_REGISTRY_ALWAYS))
140 # define USE_EH_FRAME_REGISTRY
141 #endif
142 #if defined(__LIBGCC_EH_FRAME_SECTION_NAME__) \
143 && __LIBGCC_EH_TABLES_CAN_BE_READ_ONLY__
144 # define EH_FRAME_SECTION_CONST const
145 #else
146 # define EH_FRAME_SECTION_CONST
147 #endif
149 #if !defined(DTOR_LIST_END) && defined(OBJECT_FORMAT_ELF) \
150 && defined(HAVE_GAS_HIDDEN) && !defined(FINI_ARRAY_SECTION_ASM_OP)
151 # define HIDDEN_DTOR_LIST_END
152 #endif
154 #if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF)
155 # define USE_TM_CLONE_REGISTRY 1
156 #endif
158 /* We do not want to add the weak attribute to the declarations of these
159 routines in unwind-dw2-fde.h because that will cause the definition of
160 these symbols to be weak as well.
162 This exposes a core issue, how to handle creating weak references vs
163 how to create weak definitions. Either we have to have the definition
164 of TARGET_WEAK_ATTRIBUTE be conditional in the shared header files or
165 have a second declaration if we want a function's references to be weak,
166 but not its definition.
168 Making TARGET_WEAK_ATTRIBUTE conditional seems like a good solution until
169 one thinks about scaling to larger problems -- i.e., the condition under
170 which TARGET_WEAK_ATTRIBUTE is active will eventually get far too
171 complicated.
173 So, we take an approach similar to #pragma weak -- we have a second
174 declaration for functions that we want to have weak references.
176 Neither way is particularly good. */
178 /* References to __register_frame_info and __deregister_frame_info should
179 be weak in this file if at all possible. */
180 extern void __register_frame_info (const void *, struct object *)
181 TARGET_ATTRIBUTE_WEAK;
182 extern void __register_frame_info_bases (const void *, struct object *,
183 void *, void *)
184 TARGET_ATTRIBUTE_WEAK;
185 extern void *__deregister_frame_info (const void *)
186 TARGET_ATTRIBUTE_WEAK;
187 extern void *__deregister_frame_info_bases (const void *)
188 TARGET_ATTRIBUTE_WEAK;
189 extern void __do_global_ctors_1 (void);
191 /* Likewise for transactional memory clone tables. */
192 extern void _ITM_registerTMCloneTable (void *, size_t) TARGET_ATTRIBUTE_WEAK;
193 extern void _ITM_deregisterTMCloneTable (void *) TARGET_ATTRIBUTE_WEAK;
195 #ifdef OBJECT_FORMAT_ELF
197 /* Declare a pointer to void function type. */
198 typedef void (*func_ptr) (void);
199 #define STATIC static
201 #else /* OBJECT_FORMAT_ELF */
203 #include "gbl-ctors.h"
205 #define STATIC
207 #endif /* OBJECT_FORMAT_ELF */
209 #ifdef CRT_BEGIN
211 /* NOTE: In order to be able to support SVR4 shared libraries, we arrange
212 to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
213 __DTOR_END__ } per root executable and also one set of these symbols
214 per shared library. So in any given whole process image, we may have
215 multiple definitions of each of these symbols. In order to prevent
216 these definitions from conflicting with one another, and in order to
217 ensure that the proper lists are used for the initialization/finalization
218 of each individual shared library (respectively), we give these symbols
219 only internal (i.e. `static') linkage, and we also make it a point to
220 refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
221 symbol in crtbegin.o, where they are defined. */
223 /* No need for .ctors/.dtors section if linker can place them in
224 .init_array/.fini_array section. */
225 #ifndef USE_INITFINI_ARRAY
226 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
227 does not start with a count of elements. */
228 #ifdef CTOR_LIST_BEGIN
229 CTOR_LIST_BEGIN;
230 #elif defined(__LIBGCC_CTORS_SECTION_ASM_OP__)
231 /* Hack: force cc1 to switch to .data section early, so that assembling
232 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
233 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
234 asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
235 STATIC func_ptr __CTOR_LIST__[1]
236 __attribute__ ((__used__, aligned(__alignof__(func_ptr))))
237 = { (func_ptr) (-1) };
238 #else
239 STATIC func_ptr __CTOR_LIST__[1]
240 __attribute__ ((__used__, section(".ctors"), aligned(__alignof__(func_ptr))))
241 = { (func_ptr) (-1) };
242 #endif /* __CTOR_LIST__ alternatives */
244 #ifdef DTOR_LIST_BEGIN
245 DTOR_LIST_BEGIN;
246 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
247 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
248 STATIC func_ptr __DTOR_LIST__[1]
249 __attribute__ ((aligned(__alignof__(func_ptr))))
250 = { (func_ptr) (-1) };
251 #else
252 STATIC func_ptr __DTOR_LIST__[1]
253 __attribute__((section(".dtors"), aligned(__alignof__(func_ptr))))
254 = { (func_ptr) (-1) };
255 #endif /* __DTOR_LIST__ alternatives */
256 #endif /* USE_INITFINI_ARRAY */
258 #ifdef USE_EH_FRAME_REGISTRY
259 /* Stick a label at the beginning of the frame unwind info so we can register
260 and deregister it with the exception handling library code. */
261 STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
262 __attribute__((section(__LIBGCC_EH_FRAME_SECTION_NAME__), aligned(4)))
263 = { };
264 #endif /* USE_EH_FRAME_REGISTRY */
266 #if USE_TM_CLONE_REGISTRY
267 STATIC func_ptr __TMC_LIST__[]
268 __attribute__((used, section(".tm_clone_table"), aligned(__alignof__(void*))))
269 = { };
270 # ifdef HAVE_GAS_HIDDEN
271 extern func_ptr __TMC_END__[] __attribute__((__visibility__ ("hidden")));
272 # endif
274 static inline void
275 deregister_tm_clones (void)
277 void (*fn) (void *);
279 #ifdef HAVE_GAS_HIDDEN
280 func_ptr *end = __TMC_END__;
281 // Do not optimize the comparison to false.
282 __asm ("" : "+g" (end));
283 if (__TMC_LIST__ == end)
284 return;
285 #else
286 if (__TMC_LIST__[0] == NULL)
287 return;
288 #endif
290 fn = _ITM_deregisterTMCloneTable;
291 __asm ("" : "+r" (fn));
292 if (fn)
293 fn (__TMC_LIST__);
296 static inline void
297 register_tm_clones (void)
299 void (*fn) (void *, size_t);
300 size_t size;
302 #ifdef HAVE_GAS_HIDDEN
303 func_ptr *end = __TMC_END__;
304 // Do not optimize the comparison to false.
305 __asm ("" : "+g" (end));
306 size = (end - __TMC_LIST__) / 2;
307 #else
308 for (size = 0; __TMC_LIST__[size * 2] != NULL; size++)
309 continue;
310 #endif
311 if (size == 0)
312 return;
314 fn = _ITM_registerTMCloneTable;
315 __asm ("" : "+r" (fn));
316 if (fn)
317 fn (__TMC_LIST__, size);
319 #endif /* USE_TM_CLONE_REGISTRY */
321 #if defined(__LIBGCC_INIT_SECTION_ASM_OP__) \
322 || defined(__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
324 #ifdef OBJECT_FORMAT_ELF
326 /* Declare the __dso_handle variable. It should have a unique value
327 in every shared-object; in a main program its value is zero. The
328 object should in any case be protected. This means the instance
329 in one DSO or the main program is not used in another object. The
330 dynamic linker takes care of this. */
332 #ifdef TARGET_LIBGCC_SDATA_SECTION
333 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
334 #endif
335 #ifdef HAVE_GAS_HIDDEN
336 extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
337 #endif
338 #ifdef CRTSTUFFS_O
339 void *__dso_handle = &__dso_handle;
340 #else
341 void *__dso_handle = 0;
342 #endif
344 /* The __cxa_finalize function may not be available so we use only a
345 weak declaration. */
346 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
348 /* Run all the global destructors on exit from the program. */
350 /* Some systems place the number of pointers in the first word of the
351 table. On SVR4 however, that word is -1. In all cases, the table is
352 null-terminated. On SVR4, we start from the beginning of the list and
353 invoke each per-compilation-unit destructor routine in order
354 until we find that null.
356 Note that this function MUST be static. There will be one of these
357 functions in each root executable and one in each shared library, but
358 although they all have the same code, each one is unique in that it
359 refers to one particular associated `__DTOR_LIST__' which belongs to the
360 same particular root executable or shared library file.
362 On some systems, this routine is run more than once from the .fini,
363 when exit is called recursively, so we arrange to remember where in
364 the list we left off processing, and we resume at that point,
365 should we be re-invoked. */
367 static void __attribute__((used))
368 __do_global_dtors_aux (void)
370 static _Bool completed;
372 if (__builtin_expect (completed, 0))
373 return;
375 #ifdef CRTSTUFFS_O
376 if (__cxa_finalize)
377 __cxa_finalize (__dso_handle);
378 #endif
380 #ifdef FINI_ARRAY_SECTION_ASM_OP
381 /* If we are using .fini_array then destructors will be run via that
382 mechanism. */
383 #elif defined(HIDDEN_DTOR_LIST_END)
385 /* Safer version that makes sure only .dtors function pointers are
386 called even if the static variable is maliciously changed. */
387 extern func_ptr __DTOR_END__[] __attribute__((visibility ("hidden")));
388 static size_t dtor_idx;
389 const size_t max_idx = __DTOR_END__ - __DTOR_LIST__ - 1;
390 func_ptr *dtor_list;
392 __asm ("" : "=g" (dtor_list) : "0" (__DTOR_LIST__));
393 while (dtor_idx < max_idx)
394 dtor_list[++dtor_idx] ();
396 #else /* !defined (FINI_ARRAY_SECTION_ASM_OP) */
398 static func_ptr *p = __DTOR_LIST__ + 1;
399 func_ptr f;
401 while ((f = *p))
403 p++;
404 f ();
407 #endif /* !defined(FINI_ARRAY_SECTION_ASM_OP) */
409 #if USE_TM_CLONE_REGISTRY
410 deregister_tm_clones ();
411 #endif /* USE_TM_CLONE_REGISTRY */
413 #ifdef USE_EH_FRAME_REGISTRY
414 #ifdef CRT_GET_RFIB_DATA
415 /* If we used the new __register_frame_info_bases interface,
416 make sure that we deregister from the same place. */
417 if (__deregister_frame_info_bases)
418 __deregister_frame_info_bases (__EH_FRAME_BEGIN__);
419 #else
420 if (__deregister_frame_info)
421 __deregister_frame_info (__EH_FRAME_BEGIN__);
422 #endif
423 #endif
425 completed = 1;
428 /* Stick a call to __do_global_dtors_aux into the .fini section. */
429 #ifdef FINI_SECTION_ASM_OP
430 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
431 #elif defined (FINI_ARRAY_SECTION_ASM_OP)
432 #if defined(__FDPIC__)
433 __asm__("\t.equ\t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");
434 extern char __do_global_dtors_aux_alias;
435 static void *__do_global_dtors_aux_fini_array_entry[]
436 __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))
437 = { &__do_global_dtors_aux_alias };
438 #else /* defined(__FDPIC__) */
439 static func_ptr __do_global_dtors_aux_fini_array_entry[]
440 __attribute__ ((__used__, section(".fini_array"),
441 aligned(__alignof__(func_ptr)))) = { __do_global_dtors_aux };
442 #endif /* defined(__FDPIC__) */
443 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
444 static void __attribute__((used))
445 __do_global_dtors_aux_1 (void)
447 atexit (__do_global_dtors_aux);
449 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__,
450 __do_global_dtors_aux_1)
451 #endif
453 #if defined(USE_EH_FRAME_REGISTRY) \
454 || defined(USE_TM_CLONE_REGISTRY)
455 /* Stick a call to __register_frame_info into the .init section. For some
456 reason calls with no arguments work more reliably in .init, so stick the
457 call in another function. */
459 static void __attribute__((used))
460 frame_dummy (void)
462 #ifdef USE_EH_FRAME_REGISTRY
463 static struct object object;
464 #ifdef CRT_GET_RFIB_DATA
465 void *tbase, *dbase;
466 tbase = 0;
467 CRT_GET_RFIB_DATA (dbase);
468 if (__register_frame_info_bases)
469 __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
470 #else
471 if (__register_frame_info)
472 __register_frame_info (__EH_FRAME_BEGIN__, &object);
473 #endif /* CRT_GET_RFIB_DATA */
474 #endif /* USE_EH_FRAME_REGISTRY */
476 #if USE_TM_CLONE_REGISTRY
477 register_tm_clones ();
478 #endif /* USE_TM_CLONE_REGISTRY */
481 #ifdef __LIBGCC_INIT_SECTION_ASM_OP__
482 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)
483 #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
484 #if defined(__FDPIC__)
485 __asm__("\t.equ\t__frame_dummy_alias, frame_dummy\n");
486 extern char __frame_dummy_alias;
487 static void *__frame_dummy_init_array_entry[]
488 __attribute__ ((__used__, section(".init_array"), aligned(sizeof(void *))))
489 = { &__frame_dummy_alias };
490 #else /* defined(__FDPIC__) */
491 static func_ptr __frame_dummy_init_array_entry[]
492 __attribute__ ((__used__, section(".init_array"),
493 aligned(__alignof__(func_ptr)))) = { frame_dummy };
494 #endif /* defined(__FDPIC__) */
495 #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
496 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
498 #else /* OBJECT_FORMAT_ELF */
500 /* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
501 and once in crtend.o). It must be declared static to avoid a link
502 error. Here, we define __do_global_ctors as an externally callable
503 function. It is externally callable so that __main can invoke it when
504 INVOKE__main is defined. This has the additional effect of forcing cc1
505 to switch to the .text section. */
507 static void __do_global_ctors_aux (void);
508 void
509 __do_global_ctors (void)
511 #ifdef INVOKE__main
512 /* If __main won't actually call __do_global_ctors then it doesn't matter
513 what's inside the function. The inside of __do_global_ctors_aux is
514 called automatically in that case. And the Alliant fx2800 linker
515 crashes on this reference. So prevent the crash. */
516 __do_global_ctors_aux ();
517 #endif
520 asm (__LIBGCC_INIT_SECTION_ASM_OP__); /* cc1 doesn't know that we are switching! */
522 /* A routine to invoke all of the global constructors upon entry to the
523 program. We put this into the .init section (for systems that have
524 such a thing) so that we can properly perform the construction of
525 file-scope static-storage C++ objects within shared libraries. */
527 static void __attribute__((used))
528 __do_global_ctors_aux (void) /* prologue goes in .init section */
530 FORCE_CODE_SECTION_ALIGN /* explicit align before switch to .text */
531 asm (__LIBGCC_TEXT_SECTION_ASM_OP__); /* don't put epilogue and body in .init */
532 DO_GLOBAL_CTORS_BODY;
533 atexit (__do_global_dtors);
536 #endif /* OBJECT_FORMAT_ELF */
538 #elif defined(HAS_INIT_SECTION) /* ! __LIBGCC_INIT_SECTION_ASM_OP__ */
540 extern void __do_global_dtors (void);
542 /* This case is used by the Irix 6 port, which supports named sections but
543 not an SVR4-style .fini section. __do_global_dtors can be non-static
544 in this case because we protect it with -hidden_symbol. */
546 void
547 __do_global_dtors (void)
549 func_ptr *p, f;
550 for (p = __DTOR_LIST__ + 1; (f = *p); p++)
551 f ();
553 #if USE_TM_CLONE_REGISTRY
554 deregister_tm_clones ();
555 #endif /* USE_TM_CLONE_REGISTRY */
557 #ifdef USE_EH_FRAME_REGISTRY
558 if (__deregister_frame_info)
559 __deregister_frame_info (__EH_FRAME_BEGIN__);
560 #endif
563 #if defined(USE_EH_FRAME_REGISTRY) \
564 || defined(USE_TM_CLONE_REGISTRY)
565 /* A helper function for __do_global_ctors, which is in crtend.o. Here
566 in crtbegin.o, we can reference a couple of symbols not visible there.
567 Plus, since we're before libgcc.a, we have no problems referencing
568 functions from there. */
569 void
570 __do_global_ctors_1(void)
572 #ifdef USE_EH_FRAME_REGISTRY
573 static struct object object;
574 if (__register_frame_info)
575 __register_frame_info (__EH_FRAME_BEGIN__, &object);
576 #endif
578 #if USE_TM_CLONE_REGISTRY
579 register_tm_clones ();
580 #endif /* USE_TM_CLONE_REGISTRY */
582 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
584 #else /* ! __LIBGCC_INIT_SECTION_ASM_OP__ && ! HAS_INIT_SECTION */
585 #error "What are you doing with crtstuff.c, then?"
586 #endif
588 #elif defined(CRT_END) /* ! CRT_BEGIN */
590 /* No need for .ctors/.dtors section if linker can place them in
591 .init_array/.fini_array section. */
592 #ifndef USE_INITFINI_ARRAY
593 /* Put a word containing zero at the end of each of our two lists of function
594 addresses. Note that the words defined here go into the .ctors and .dtors
595 sections of the crtend.o file, and since that file is always linked in
596 last, these words naturally end up at the very ends of the two lists
597 contained in these two sections. */
599 #ifdef CTOR_LIST_END
600 CTOR_LIST_END;
601 #elif defined(__LIBGCC_CTORS_SECTION_ASM_OP__)
602 /* Hack: force cc1 to switch to .data section early, so that assembling
603 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
604 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
605 asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
606 STATIC func_ptr __CTOR_END__[1]
607 __attribute__((aligned(__alignof__(func_ptr))))
608 = { (func_ptr) 0 };
609 #else
610 STATIC func_ptr __CTOR_END__[1]
611 __attribute__((section(".ctors"), aligned(__alignof__(func_ptr))))
612 = { (func_ptr) 0 };
613 #endif
615 #ifdef DTOR_LIST_END
616 DTOR_LIST_END;
617 #elif defined(HIDDEN_DTOR_LIST_END)
618 #ifdef __LIBGCC_DTORS_SECTION_ASM_OP__
619 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
620 #endif
621 func_ptr __DTOR_END__[1]
622 __attribute__ ((used,
623 #ifndef __LIBGCC_DTORS_SECTION_ASM_OP__
624 section(".dtors"),
625 #endif
626 aligned(__alignof__(func_ptr)), visibility ("hidden")))
627 = { (func_ptr) 0 };
628 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
629 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
630 STATIC func_ptr __DTOR_END__[1]
631 __attribute__ ((used, aligned(__alignof__(func_ptr))))
632 = { (func_ptr) 0 };
633 #else
634 STATIC func_ptr __DTOR_END__[1]
635 __attribute__((used, section(".dtors"), aligned(__alignof__(func_ptr))))
636 = { (func_ptr) 0 };
637 #endif
638 #endif /* USE_INITFINI_ARRAY */
640 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
641 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
642 this would be the 'length' field in a real FDE. */
643 # if __INT_MAX__ == 2147483647
644 typedef int int32;
645 # elif __LONG_MAX__ == 2147483647
646 typedef long int32;
647 # elif __SHRT_MAX__ == 2147483647
648 typedef short int32;
649 # else
650 # error "Missing a 4 byte integer"
651 # endif
652 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
653 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
654 aligned(__alignof__(int32))))
655 = { 0 };
656 #endif /* __LIBGCC_EH_FRAME_SECTION_NAME__ */
658 #if USE_TM_CLONE_REGISTRY
659 # ifndef HAVE_GAS_HIDDEN
660 static
661 # endif
662 func_ptr __TMC_END__[]
663 __attribute__((used, section(".tm_clone_table"),
664 aligned(__alignof__(void *))))
665 # ifdef HAVE_GAS_HIDDEN
666 __attribute__((__visibility__ ("hidden"))) = { };
667 # else
668 = { 0, 0 };
669 # endif
670 #endif /* USE_TM_CLONE_REGISTRY */
672 #ifdef __LIBGCC_INIT_ARRAY_SECTION_ASM_OP__
674 /* If we are using .init_array, there is nothing to do. */
676 #elif defined(__LIBGCC_INIT_SECTION_ASM_OP__)
678 #ifdef OBJECT_FORMAT_ELF
679 static void __attribute__((used))
680 __do_global_ctors_aux (void)
682 func_ptr *p;
683 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
684 (*p) ();
687 /* Stick a call to __do_global_ctors_aux into the .init section. */
688 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, __do_global_ctors_aux)
689 #else /* OBJECT_FORMAT_ELF */
691 /* Stick the real initialization code, followed by a normal sort of
692 function epilogue at the very end of the .init section for this
693 entire root executable file or for this entire shared library file.
695 Note that we use some tricks here to get *just* the body and just
696 a function epilogue (but no function prologue) into the .init
697 section of the crtend.o file. Specifically, we switch to the .text
698 section, start to define a function, and then we switch to the .init
699 section just before the body code.
701 Earlier on, we put the corresponding function prologue into the .init
702 section of the crtbegin.o file (which will be linked in first).
704 Note that we want to invoke all constructors for C++ file-scope static-
705 storage objects AFTER any other possible initialization actions which
706 may be performed by the code in the .init section contributions made by
707 other libraries, etc. That's because those other initializations may
708 include setup operations for very primitive things (e.g. initializing
709 the state of the floating-point coprocessor, etc.) which should be done
710 before we start to execute any of the user's code. */
712 static void
713 __do_global_ctors_aux (void) /* prologue goes in .text section */
715 asm (__LIBGCC_INIT_SECTION_ASM_OP__);
716 DO_GLOBAL_CTORS_BODY;
717 atexit (__do_global_dtors);
718 } /* epilogue and body go in .init section */
720 FORCE_CODE_SECTION_ALIGN
721 asm (__LIBGCC_TEXT_SECTION_ASM_OP__);
723 #endif /* OBJECT_FORMAT_ELF */
725 #elif defined(HAS_INIT_SECTION) /* ! __LIBGCC_INIT_SECTION_ASM_OP__ */
727 extern void __do_global_ctors (void);
729 /* This case is used by the Irix 6 port, which supports named sections but
730 not an SVR4-style .init section. __do_global_ctors can be non-static
731 in this case because we protect it with -hidden_symbol. */
732 void
733 __do_global_ctors (void)
735 func_ptr *p;
736 #if defined(USE_EH_FRAME_REGISTRY) \
737 || defined(USE_TM_CLONE_REGISTRY)
738 __do_global_ctors_1();
739 #endif
740 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
741 (*p) ();
744 #else /* ! __LIBGCC_INIT_SECTION_ASM_OP__ && ! HAS_INIT_SECTION */
745 #error "What are you doing with crtstuff.c, then?"
746 #endif
748 #else /* ! CRT_BEGIN && ! CRT_END */
749 #error "One of CRT_BEGIN or CRT_END must be defined."
750 #endif