]> git.ipfire.org Git - thirdparty/gcc.git/blob - libgcc/crtstuff.c
crtstuff.c: Undef caddr_t.
[thirdparty/gcc.git] / libgcc / 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-2014 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com).
5
6 This file is part of GCC.
7
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.
12
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.
17
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.
21
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/>. */
26
27 /* This file is a bit like libgcc2.c in that it is compiled
28 multiple times and yields multiple .o files.
29
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.
36
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.
40
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.)
45
46 This file must be compiled with gcc. */
47
48 /* Target machine header files require this define. */
49 #define IN_LIBGCC2
50
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"
66
67 #ifndef FORCE_CODE_SECTION_ALIGN
68 # define FORCE_CODE_SECTION_ALIGN
69 #endif
70
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 (TEXT_SECTION_ASM_OP); \
80 }
81 #endif
82
83 #if defined(TARGET_DL_ITERATE_PHDR) && \
84 (defined(__DragonFly__) || defined(__FreeBSD__))
85 #define BSD_DL_ITERATE_PHDR_AVAILABLE
86 #endif
87
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
96
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
105
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
120
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
133
134 #if defined(EH_FRAME_SECTION_NAME) && !defined(USE_PT_GNU_EH_FRAME)
135 # define USE_EH_FRAME_REGISTRY
136 #endif
137 #if defined(EH_FRAME_SECTION_NAME) && EH_TABLES_CAN_BE_READ_ONLY
138 # define EH_FRAME_SECTION_CONST const
139 #else
140 # define EH_FRAME_SECTION_CONST
141 #endif
142
143 #if !defined(DTOR_LIST_END) && defined(OBJECT_FORMAT_ELF) \
144 && defined(HAVE_GAS_HIDDEN) && !defined(FINI_ARRAY_SECTION_ASM_OP)
145 # define HIDDEN_DTOR_LIST_END
146 #endif
147
148 #if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF)
149 # define USE_TM_CLONE_REGISTRY 1
150 #endif
151
152 /* We do not want to add the weak attribute to the declarations of these
153 routines in unwind-dw2-fde.h because that will cause the definition of
154 these symbols to be weak as well.
155
156 This exposes a core issue, how to handle creating weak references vs
157 how to create weak definitions. Either we have to have the definition
158 of TARGET_WEAK_ATTRIBUTE be conditional in the shared header files or
159 have a second declaration if we want a function's references to be weak,
160 but not its definition.
161
162 Making TARGET_WEAK_ATTRIBUTE conditional seems like a good solution until
163 one thinks about scaling to larger problems -- i.e., the condition under
164 which TARGET_WEAK_ATTRIBUTE is active will eventually get far too
165 complicated.
166
167 So, we take an approach similar to #pragma weak -- we have a second
168 declaration for functions that we want to have weak references.
169
170 Neither way is particularly good. */
171
172 /* References to __register_frame_info and __deregister_frame_info should
173 be weak in this file if at all possible. */
174 extern void __register_frame_info (const void *, struct object *)
175 TARGET_ATTRIBUTE_WEAK;
176 extern void __register_frame_info_bases (const void *, struct object *,
177 void *, void *)
178 TARGET_ATTRIBUTE_WEAK;
179 extern void *__deregister_frame_info (const void *)
180 TARGET_ATTRIBUTE_WEAK;
181 extern void *__deregister_frame_info_bases (const void *)
182 TARGET_ATTRIBUTE_WEAK;
183 extern void __do_global_ctors_1 (void);
184
185 /* Likewise for _Jv_RegisterClasses. */
186 extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK;
187
188 /* Likewise for transactional memory clone tables. */
189 extern void _ITM_registerTMCloneTable (void *, size_t) TARGET_ATTRIBUTE_WEAK;
190 extern void _ITM_deregisterTMCloneTable (void *) TARGET_ATTRIBUTE_WEAK;
191
192 #ifdef OBJECT_FORMAT_ELF
193
194 /* Declare a pointer to void function type. */
195 typedef void (*func_ptr) (void);
196 #define STATIC static
197
198 #else /* OBJECT_FORMAT_ELF */
199
200 #include "gbl-ctors.h"
201
202 #define STATIC
203
204 #endif /* OBJECT_FORMAT_ELF */
205
206 #ifdef CRT_BEGIN
207
208 /* NOTE: In order to be able to support SVR4 shared libraries, we arrange
209 to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
210 __DTOR_END__ } per root executable and also one set of these symbols
211 per shared library. So in any given whole process image, we may have
212 multiple definitions of each of these symbols. In order to prevent
213 these definitions from conflicting with one another, and in order to
214 ensure that the proper lists are used for the initialization/finalization
215 of each individual shared library (respectively), we give these symbols
216 only internal (i.e. `static') linkage, and we also make it a point to
217 refer to only the __CTOR_END__ symbol in crtend.o and the __DTOR_LIST__
218 symbol in crtbegin.o, where they are defined. */
219
220 /* No need for .ctors/.dtors section if linker can place them in
221 .init_array/.fini_array section. */
222 #ifndef USE_INITFINI_ARRAY
223 /* The -1 is a flag to __do_global_[cd]tors indicating that this table
224 does not start with a count of elements. */
225 #ifdef CTOR_LIST_BEGIN
226 CTOR_LIST_BEGIN;
227 #elif defined(CTORS_SECTION_ASM_OP)
228 /* Hack: force cc1 to switch to .data section early, so that assembling
229 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
230 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
231 asm (CTORS_SECTION_ASM_OP);
232 STATIC func_ptr __CTOR_LIST__[1]
233 __attribute__ ((__used__, aligned(sizeof(func_ptr))))
234 = { (func_ptr) (-1) };
235 #else
236 STATIC func_ptr __CTOR_LIST__[1]
237 __attribute__ ((__used__, section(".ctors"), aligned(sizeof(func_ptr))))
238 = { (func_ptr) (-1) };
239 #endif /* __CTOR_LIST__ alternatives */
240
241 #ifdef DTOR_LIST_BEGIN
242 DTOR_LIST_BEGIN;
243 #elif defined(DTORS_SECTION_ASM_OP)
244 asm (DTORS_SECTION_ASM_OP);
245 STATIC func_ptr __DTOR_LIST__[1]
246 __attribute__ ((aligned(sizeof(func_ptr))))
247 = { (func_ptr) (-1) };
248 #else
249 STATIC func_ptr __DTOR_LIST__[1]
250 __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
251 = { (func_ptr) (-1) };
252 #endif /* __DTOR_LIST__ alternatives */
253 #endif /* USE_INITFINI_ARRAY */
254
255 #ifdef USE_EH_FRAME_REGISTRY
256 /* Stick a label at the beginning of the frame unwind info so we can register
257 and deregister it with the exception handling library code. */
258 STATIC EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[]
259 __attribute__((section(EH_FRAME_SECTION_NAME), aligned(4)))
260 = { };
261 #endif /* USE_EH_FRAME_REGISTRY */
262
263 #ifdef JCR_SECTION_NAME
264 /* Stick a label at the beginning of the java class registration info
265 so we can register them properly. */
266 STATIC void *__JCR_LIST__[]
267 __attribute__ ((used, section(JCR_SECTION_NAME), aligned(sizeof(void*))))
268 = { };
269 #endif /* JCR_SECTION_NAME */
270
271 #if USE_TM_CLONE_REGISTRY
272 STATIC func_ptr __TMC_LIST__[]
273 __attribute__((used, section(".tm_clone_table"), aligned(sizeof(void*))))
274 = { };
275 # ifdef HAVE_GAS_HIDDEN
276 extern func_ptr __TMC_END__[] __attribute__((__visibility__ ("hidden")));
277 # endif
278
279 static inline void
280 deregister_tm_clones (void)
281 {
282 void (*fn) (void *);
283
284 #ifdef HAVE_GAS_HIDDEN
285 if (__TMC_END__ - __TMC_LIST__ == 0)
286 return;
287 #else
288 if (__TMC_LIST__[0] == NULL)
289 return;
290 #endif
291
292 fn = _ITM_deregisterTMCloneTable;
293 __asm ("" : "+r" (fn));
294 if (fn)
295 fn (__TMC_LIST__);
296 }
297
298 static inline void
299 register_tm_clones (void)
300 {
301 void (*fn) (void *, size_t);
302 size_t size;
303
304 #ifdef HAVE_GAS_HIDDEN
305 size = (__TMC_END__ - __TMC_LIST__) / 2;
306 #else
307 for (size = 0; __TMC_LIST__[size * 2] != NULL; size++)
308 continue;
309 #endif
310 if (size == 0)
311 return;
312
313 fn = _ITM_registerTMCloneTable;
314 __asm ("" : "+r" (fn));
315 if (fn)
316 fn (__TMC_LIST__, size);
317 }
318 #endif /* USE_TM_CLONE_REGISTRY */
319
320 #if defined(INIT_SECTION_ASM_OP) || defined(INIT_ARRAY_SECTION_ASM_OP)
321
322 #ifdef OBJECT_FORMAT_ELF
323
324 /* Declare the __dso_handle variable. It should have a unique value
325 in every shared-object; in a main program its value is zero. The
326 object should in any case be protected. This means the instance
327 in one DSO or the main program is not used in another object. The
328 dynamic linker takes care of this. */
329
330 #ifdef TARGET_LIBGCC_SDATA_SECTION
331 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
332 #endif
333 #ifdef HAVE_GAS_HIDDEN
334 extern void *__dso_handle __attribute__ ((__visibility__ ("hidden")));
335 #endif
336 #ifdef CRTSTUFFS_O
337 void *__dso_handle = &__dso_handle;
338 #else
339 void *__dso_handle = 0;
340 #endif
341
342 /* The __cxa_finalize function may not be available so we use only a
343 weak declaration. */
344 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
345
346 /* Run all the global destructors on exit from the program. */
347
348 /* Some systems place the number of pointers in the first word of the
349 table. On SVR4 however, that word is -1. In all cases, the table is
350 null-terminated. On SVR4, we start from the beginning of the list and
351 invoke each per-compilation-unit destructor routine in order
352 until we find that null.
353
354 Note that this function MUST be static. There will be one of these
355 functions in each root executable and one in each shared library, but
356 although they all have the same code, each one is unique in that it
357 refers to one particular associated `__DTOR_LIST__' which belongs to the
358 same particular root executable or shared library file.
359
360 On some systems, this routine is run more than once from the .fini,
361 when exit is called recursively, so we arrange to remember where in
362 the list we left off processing, and we resume at that point,
363 should we be re-invoked. */
364
365 static void __attribute__((used))
366 __do_global_dtors_aux (void)
367 {
368 static _Bool completed;
369
370 if (__builtin_expect (completed, 0))
371 return;
372
373 #ifdef CRTSTUFFS_O
374 if (__cxa_finalize)
375 __cxa_finalize (__dso_handle);
376 #endif
377
378 #ifdef FINI_ARRAY_SECTION_ASM_OP
379 /* If we are using .fini_array then destructors will be run via that
380 mechanism. */
381 #elif defined(HIDDEN_DTOR_LIST_END)
382 {
383 /* Safer version that makes sure only .dtors function pointers are
384 called even if the static variable is maliciously changed. */
385 extern func_ptr __DTOR_END__[] __attribute__((visibility ("hidden")));
386 static size_t dtor_idx;
387 const size_t max_idx = __DTOR_END__ - __DTOR_LIST__ - 1;
388 func_ptr f;
389
390 while (dtor_idx < max_idx)
391 {
392 f = __DTOR_LIST__[++dtor_idx];
393 f ();
394 }
395 }
396 #else /* !defined (FINI_ARRAY_SECTION_ASM_OP) */
397 {
398 static func_ptr *p = __DTOR_LIST__ + 1;
399 func_ptr f;
400
401 while ((f = *p))
402 {
403 p++;
404 f ();
405 }
406 }
407 #endif /* !defined(FINI_ARRAY_SECTION_ASM_OP) */
408
409 #if USE_TM_CLONE_REGISTRY
410 deregister_tm_clones ();
411 #endif /* USE_TM_CLONE_REGISTRY */
412
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
424
425 completed = 1;
426 }
427
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 static func_ptr __do_global_dtors_aux_fini_array_entry[]
433 __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))
434 = { __do_global_dtors_aux };
435 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
436 static void __attribute__((used))
437 __do_global_dtors_aux_1 (void)
438 {
439 atexit (__do_global_dtors_aux);
440 }
441 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, __do_global_dtors_aux_1)
442 #endif
443
444 #if defined(USE_EH_FRAME_REGISTRY) \
445 || defined(JCR_SECTION_NAME) \
446 || defined(USE_TM_CLONE_REGISTRY)
447 /* Stick a call to __register_frame_info into the .init section. For some
448 reason calls with no arguments work more reliably in .init, so stick the
449 call in another function. */
450
451 static void __attribute__((used))
452 frame_dummy (void)
453 {
454 #ifdef USE_EH_FRAME_REGISTRY
455 static struct object object;
456 #ifdef CRT_GET_RFIB_DATA
457 void *tbase, *dbase;
458 tbase = 0;
459 CRT_GET_RFIB_DATA (dbase);
460 if (__register_frame_info_bases)
461 __register_frame_info_bases (__EH_FRAME_BEGIN__, &object, tbase, dbase);
462 #else
463 if (__register_frame_info)
464 __register_frame_info (__EH_FRAME_BEGIN__, &object);
465 #endif /* CRT_GET_RFIB_DATA */
466 #endif /* USE_EH_FRAME_REGISTRY */
467
468 #ifdef JCR_SECTION_NAME
469 void **jcr_list;
470 __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
471 if (__builtin_expect (*jcr_list != NULL, 0))
472 {
473 void (*register_classes) (void *) = _Jv_RegisterClasses;
474 __asm ("" : "+r" (register_classes));
475 if (register_classes)
476 register_classes (jcr_list);
477 }
478 #endif /* JCR_SECTION_NAME */
479
480 #if USE_TM_CLONE_REGISTRY
481 register_tm_clones ();
482 #endif /* USE_TM_CLONE_REGISTRY */
483 }
484
485 #ifdef INIT_SECTION_ASM_OP
486 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, frame_dummy)
487 #else /* defined(INIT_SECTION_ASM_OP) */
488 static func_ptr __frame_dummy_init_array_entry[]
489 __attribute__ ((__used__, section(".init_array"), aligned(sizeof(func_ptr))))
490 = { frame_dummy };
491 #endif /* !defined(INIT_SECTION_ASM_OP) */
492 #endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME || USE_TM_CLONE_REGISTRY */
493
494 #else /* OBJECT_FORMAT_ELF */
495
496 /* The function __do_global_ctors_aux is compiled twice (once in crtbegin.o
497 and once in crtend.o). It must be declared static to avoid a link
498 error. Here, we define __do_global_ctors as an externally callable
499 function. It is externally callable so that __main can invoke it when
500 INVOKE__main is defined. This has the additional effect of forcing cc1
501 to switch to the .text section. */
502
503 static void __do_global_ctors_aux (void);
504 void
505 __do_global_ctors (void)
506 {
507 #ifdef INVOKE__main
508 /* If __main won't actually call __do_global_ctors then it doesn't matter
509 what's inside the function. The inside of __do_global_ctors_aux is
510 called automatically in that case. And the Alliant fx2800 linker
511 crashes on this reference. So prevent the crash. */
512 __do_global_ctors_aux ();
513 #endif
514 }
515
516 asm (INIT_SECTION_ASM_OP); /* cc1 doesn't know that we are switching! */
517
518 /* A routine to invoke all of the global constructors upon entry to the
519 program. We put this into the .init section (for systems that have
520 such a thing) so that we can properly perform the construction of
521 file-scope static-storage C++ objects within shared libraries. */
522
523 static void __attribute__((used))
524 __do_global_ctors_aux (void) /* prologue goes in .init section */
525 {
526 FORCE_CODE_SECTION_ALIGN /* explicit align before switch to .text */
527 asm (TEXT_SECTION_ASM_OP); /* don't put epilogue and body in .init */
528 DO_GLOBAL_CTORS_BODY;
529 atexit (__do_global_dtors);
530 }
531
532 #endif /* OBJECT_FORMAT_ELF */
533
534 #elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
535
536 extern void __do_global_dtors (void);
537
538 /* This case is used by the Irix 6 port, which supports named sections but
539 not an SVR4-style .fini section. __do_global_dtors can be non-static
540 in this case because we protect it with -hidden_symbol. */
541
542 void
543 __do_global_dtors (void)
544 {
545 func_ptr *p, f;
546 for (p = __DTOR_LIST__ + 1; (f = *p); p++)
547 f ();
548
549 #if USE_TM_CLONE_REGISTRY
550 deregister_tm_clones ();
551 #endif /* USE_TM_CLONE_REGISTRY */
552
553 #ifdef USE_EH_FRAME_REGISTRY
554 if (__deregister_frame_info)
555 __deregister_frame_info (__EH_FRAME_BEGIN__);
556 #endif
557 }
558
559 #if defined(USE_EH_FRAME_REGISTRY) \
560 || defined(JCR_SECTION_NAME) \
561 || defined(USE_TM_CLONE_REGISTRY)
562 /* A helper function for __do_global_ctors, which is in crtend.o. Here
563 in crtbegin.o, we can reference a couple of symbols not visible there.
564 Plus, since we're before libgcc.a, we have no problems referencing
565 functions from there. */
566 void
567 __do_global_ctors_1(void)
568 {
569 #ifdef USE_EH_FRAME_REGISTRY
570 static struct object object;
571 if (__register_frame_info)
572 __register_frame_info (__EH_FRAME_BEGIN__, &object);
573 #endif
574
575 #ifdef JCR_SECTION_NAME
576 void **jcr_list
577 __asm ("" : "=g" (jcr_list) : "0" (__JCR_LIST__));
578 if (__builtin_expect (*jcr_list != NULL, 0))
579 {
580 void (*register_classes) (void *) = _Jv_RegisterClasses;
581 __asm ("" : "+r" (register_classes));
582 if (register_classes)
583 register_classes (jcr_list);
584 }
585 #endif
586
587 #if USE_TM_CLONE_REGISTRY
588 register_tm_clones ();
589 #endif /* USE_TM_CLONE_REGISTRY */
590 }
591 #endif /* USE_EH_FRAME_REGISTRY || JCR_SECTION_NAME || USE_TM_CLONE_REGISTRY */
592
593 #else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
594 #error "What are you doing with crtstuff.c, then?"
595 #endif
596
597 #elif defined(CRT_END) /* ! CRT_BEGIN */
598
599 /* No need for .ctors/.dtors section if linker can place them in
600 .init_array/.fini_array section. */
601 #ifndef USE_INITFINI_ARRAY
602 /* Put a word containing zero at the end of each of our two lists of function
603 addresses. Note that the words defined here go into the .ctors and .dtors
604 sections of the crtend.o file, and since that file is always linked in
605 last, these words naturally end up at the very ends of the two lists
606 contained in these two sections. */
607
608 #ifdef CTOR_LIST_END
609 CTOR_LIST_END;
610 #elif defined(CTORS_SECTION_ASM_OP)
611 /* Hack: force cc1 to switch to .data section early, so that assembling
612 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
613 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
614 asm (CTORS_SECTION_ASM_OP);
615 STATIC func_ptr __CTOR_END__[1]
616 __attribute__((aligned(sizeof(func_ptr))))
617 = { (func_ptr) 0 };
618 #else
619 STATIC func_ptr __CTOR_END__[1]
620 __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
621 = { (func_ptr) 0 };
622 #endif
623
624 #ifdef DTOR_LIST_END
625 DTOR_LIST_END;
626 #elif defined(HIDDEN_DTOR_LIST_END)
627 #ifdef DTORS_SECTION_ASM_OP
628 asm (DTORS_SECTION_ASM_OP);
629 #endif
630 func_ptr __DTOR_END__[1]
631 __attribute__ ((used,
632 #ifndef DTORS_SECTION_ASM_OP
633 section(".dtors"),
634 #endif
635 aligned(sizeof(func_ptr)), visibility ("hidden")))
636 = { (func_ptr) 0 };
637 #elif defined(DTORS_SECTION_ASM_OP)
638 asm (DTORS_SECTION_ASM_OP);
639 STATIC func_ptr __DTOR_END__[1]
640 __attribute__ ((used, aligned(sizeof(func_ptr))))
641 = { (func_ptr) 0 };
642 #else
643 STATIC func_ptr __DTOR_END__[1]
644 __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
645 = { (func_ptr) 0 };
646 #endif
647 #endif /* USE_INITFINI_ARRAY */
648
649 #ifdef EH_FRAME_SECTION_NAME
650 /* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
651 this would be the 'length' field in a real FDE. */
652 # if __INT_MAX__ == 2147483647
653 typedef int int32;
654 # elif __LONG_MAX__ == 2147483647
655 typedef long int32;
656 # elif __SHRT_MAX__ == 2147483647
657 typedef short int32;
658 # else
659 # error "Missing a 4 byte integer"
660 # endif
661 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
662 __attribute__ ((used, section(EH_FRAME_SECTION_NAME),
663 aligned(sizeof(int32))))
664 = { 0 };
665 #endif /* EH_FRAME_SECTION_NAME */
666
667 #ifdef JCR_SECTION_NAME
668 /* Null terminate the .jcr section array. */
669 STATIC void *__JCR_END__[1]
670 __attribute__ ((used, section(JCR_SECTION_NAME),
671 aligned(sizeof(void *))))
672 = { 0 };
673 #endif /* JCR_SECTION_NAME */
674
675 #if USE_TM_CLONE_REGISTRY
676 # ifndef HAVE_GAS_HIDDEN
677 static
678 # endif
679 func_ptr __TMC_END__[]
680 __attribute__((used, section(".tm_clone_table"), aligned(sizeof(void *))))
681 # ifdef HAVE_GAS_HIDDEN
682 __attribute__((__visibility__ ("hidden"))) = { };
683 # else
684 = { 0, 0 };
685 # endif
686 #endif /* USE_TM_CLONE_REGISTRY */
687
688 #ifdef INIT_ARRAY_SECTION_ASM_OP
689
690 /* If we are using .init_array, there is nothing to do. */
691
692 #elif defined(INIT_SECTION_ASM_OP)
693
694 #ifdef OBJECT_FORMAT_ELF
695 static void __attribute__((used))
696 __do_global_ctors_aux (void)
697 {
698 func_ptr *p;
699 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
700 (*p) ();
701 }
702
703 /* Stick a call to __do_global_ctors_aux into the .init section. */
704 CRT_CALL_STATIC_FUNCTION (INIT_SECTION_ASM_OP, __do_global_ctors_aux)
705 #else /* OBJECT_FORMAT_ELF */
706
707 /* Stick the real initialization code, followed by a normal sort of
708 function epilogue at the very end of the .init section for this
709 entire root executable file or for this entire shared library file.
710
711 Note that we use some tricks here to get *just* the body and just
712 a function epilogue (but no function prologue) into the .init
713 section of the crtend.o file. Specifically, we switch to the .text
714 section, start to define a function, and then we switch to the .init
715 section just before the body code.
716
717 Earlier on, we put the corresponding function prologue into the .init
718 section of the crtbegin.o file (which will be linked in first).
719
720 Note that we want to invoke all constructors for C++ file-scope static-
721 storage objects AFTER any other possible initialization actions which
722 may be performed by the code in the .init section contributions made by
723 other libraries, etc. That's because those other initializations may
724 include setup operations for very primitive things (e.g. initializing
725 the state of the floating-point coprocessor, etc.) which should be done
726 before we start to execute any of the user's code. */
727
728 static void
729 __do_global_ctors_aux (void) /* prologue goes in .text section */
730 {
731 asm (INIT_SECTION_ASM_OP);
732 DO_GLOBAL_CTORS_BODY;
733 atexit (__do_global_dtors);
734 } /* epilogue and body go in .init section */
735
736 FORCE_CODE_SECTION_ALIGN
737 asm (TEXT_SECTION_ASM_OP);
738
739 #endif /* OBJECT_FORMAT_ELF */
740
741 #elif defined(HAS_INIT_SECTION) /* ! INIT_SECTION_ASM_OP */
742
743 extern void __do_global_ctors (void);
744
745 /* This case is used by the Irix 6 port, which supports named sections but
746 not an SVR4-style .init section. __do_global_ctors can be non-static
747 in this case because we protect it with -hidden_symbol. */
748 void
749 __do_global_ctors (void)
750 {
751 func_ptr *p;
752 #if defined(USE_EH_FRAME_REGISTRY) \
753 || defined(JCR_SECTION_NAME) \
754 || defined(USE_TM_CLONE_REGISTRY)
755 __do_global_ctors_1();
756 #endif
757 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
758 (*p) ();
759 }
760
761 #else /* ! INIT_SECTION_ASM_OP && ! HAS_INIT_SECTION */
762 #error "What are you doing with crtstuff.c, then?"
763 #endif
764
765 #else /* ! CRT_BEGIN && ! CRT_END */
766 #error "One of CRT_BEGIN or CRT_END must be defined."
767 #endif