comparison libgcc/crtstuff.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Specialized bits of code needed to support construction and 1 /* Specialized bits of code needed to support construction and
2 destruction of file-scope objects in C++ code. 2 destruction of file-scope objects in C++ code.
3 Copyright (C) 1991-2018 Free Software Foundation, Inc. 3 Copyright (C) 1991-2020 Free Software Foundation, Inc.
4 Contributed by Ron Guilmette (rfg@monkeys.com). 4 Contributed by Ron Guilmette (rfg@monkeys.com).
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
151 # define HIDDEN_DTOR_LIST_END 151 # define HIDDEN_DTOR_LIST_END
152 #endif 152 #endif
153 153
154 #if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF) 154 #if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF)
155 # define USE_TM_CLONE_REGISTRY 1 155 # define USE_TM_CLONE_REGISTRY 1
156 #elif !defined(USE_TM_CLONE_REGISTRY)
157 # define USE_TM_CLONE_REGISTRY 0
156 #endif 158 #endif
157 159
158 /* We do not want to add the weak attribute to the declarations of these 160 /* 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 161 routines in unwind-dw2-fde.h because that will cause the definition of
160 these symbols to be weak as well. 162 these symbols to be weak as well.
231 /* Hack: force cc1 to switch to .data section early, so that assembling 233 /* 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. */ 234 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
233 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { }; 235 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
234 asm (__LIBGCC_CTORS_SECTION_ASM_OP__); 236 asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
235 STATIC func_ptr __CTOR_LIST__[1] 237 STATIC func_ptr __CTOR_LIST__[1]
236 __attribute__ ((__used__, aligned(sizeof(func_ptr)))) 238 __attribute__ ((__used__, aligned(__alignof__(func_ptr))))
237 = { (func_ptr) (-1) }; 239 = { (func_ptr) (-1) };
238 #else 240 #else
239 STATIC func_ptr __CTOR_LIST__[1] 241 STATIC func_ptr __CTOR_LIST__[1]
240 __attribute__ ((__used__, section(".ctors"), aligned(sizeof(func_ptr)))) 242 __attribute__ ((__used__, section(".ctors"), aligned(__alignof__(func_ptr))))
241 = { (func_ptr) (-1) }; 243 = { (func_ptr) (-1) };
242 #endif /* __CTOR_LIST__ alternatives */ 244 #endif /* __CTOR_LIST__ alternatives */
243 245
244 #ifdef DTOR_LIST_BEGIN 246 #ifdef DTOR_LIST_BEGIN
245 DTOR_LIST_BEGIN; 247 DTOR_LIST_BEGIN;
246 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__) 248 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
247 asm (__LIBGCC_DTORS_SECTION_ASM_OP__); 249 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
248 STATIC func_ptr __DTOR_LIST__[1] 250 STATIC func_ptr __DTOR_LIST__[1]
249 __attribute__ ((aligned(sizeof(func_ptr)))) 251 __attribute__ ((aligned(__alignof__(func_ptr))))
250 = { (func_ptr) (-1) }; 252 = { (func_ptr) (-1) };
251 #else 253 #else
252 STATIC func_ptr __DTOR_LIST__[1] 254 STATIC func_ptr __DTOR_LIST__[1]
253 __attribute__((section(".dtors"), aligned(sizeof(func_ptr)))) 255 __attribute__((section(".dtors"), aligned(__alignof__(func_ptr))))
254 = { (func_ptr) (-1) }; 256 = { (func_ptr) (-1) };
255 #endif /* __DTOR_LIST__ alternatives */ 257 #endif /* __DTOR_LIST__ alternatives */
256 #endif /* USE_INITFINI_ARRAY */ 258 #endif /* USE_INITFINI_ARRAY */
257 259
258 #ifdef USE_EH_FRAME_REGISTRY 260 #ifdef USE_EH_FRAME_REGISTRY
263 = { }; 265 = { };
264 #endif /* USE_EH_FRAME_REGISTRY */ 266 #endif /* USE_EH_FRAME_REGISTRY */
265 267
266 #if USE_TM_CLONE_REGISTRY 268 #if USE_TM_CLONE_REGISTRY
267 STATIC func_ptr __TMC_LIST__[] 269 STATIC func_ptr __TMC_LIST__[]
268 __attribute__((used, section(".tm_clone_table"), aligned(sizeof(void*)))) 270 __attribute__((used, section(".tm_clone_table"), aligned(__alignof__(void*))))
269 = { }; 271 = { };
270 # ifdef HAVE_GAS_HIDDEN 272 # ifdef HAVE_GAS_HIDDEN
271 extern func_ptr __TMC_END__[] __attribute__((__visibility__ ("hidden"))); 273 extern func_ptr __TMC_END__[] __attribute__((__visibility__ ("hidden")));
272 # endif 274 # endif
273 275
321 #if defined(__LIBGCC_INIT_SECTION_ASM_OP__) \ 323 #if defined(__LIBGCC_INIT_SECTION_ASM_OP__) \
322 || defined(__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__) 324 || defined(__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
323 325
324 #ifdef OBJECT_FORMAT_ELF 326 #ifdef OBJECT_FORMAT_ELF
325 327
328 #if DEFAULT_USE_CXA_ATEXIT
326 /* Declare the __dso_handle variable. It should have a unique value 329 /* 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 330 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 331 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 332 in one DSO or the main program is not used in another object. The
330 dynamic linker takes care of this. */ 333 dynamic linker takes care of this.
334 If __cxa_atexit is not being used, __dso_handle will not be used and
335 doesn't need to be defined. */
331 336
332 #ifdef TARGET_LIBGCC_SDATA_SECTION 337 #ifdef TARGET_LIBGCC_SDATA_SECTION
333 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION))); 338 extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
334 #endif 339 #endif
335 #ifdef HAVE_GAS_HIDDEN 340 #ifdef HAVE_GAS_HIDDEN
338 #ifdef CRTSTUFFS_O 343 #ifdef CRTSTUFFS_O
339 void *__dso_handle = &__dso_handle; 344 void *__dso_handle = &__dso_handle;
340 #else 345 #else
341 void *__dso_handle = 0; 346 void *__dso_handle = 0;
342 #endif 347 #endif
348 #endif /* DEFAULT_USE_CXA_ATEXIT */
343 349
344 /* The __cxa_finalize function may not be available so we use only a 350 /* The __cxa_finalize function may not be available so we use only a
345 weak declaration. */ 351 weak declaration. */
346 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK; 352 extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK;
347 353
360 same particular root executable or shared library file. 366 same particular root executable or shared library file.
361 367
362 On some systems, this routine is run more than once from the .fini, 368 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 369 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, 370 the list we left off processing, and we resume at that point,
365 should we be re-invoked. */ 371 should we be re-invoked.
366 372
373 This routine does not need to be run if none of the following clauses are
374 true, as it will not do anything, so can be removed. */
375 #if defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP) \
376 || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY)
367 static void __attribute__((used)) 377 static void __attribute__((used))
368 __do_global_dtors_aux (void) 378 __do_global_dtors_aux (void)
369 { 379 {
370 static _Bool completed; 380 static _Bool completed;
371 381
372 if (__builtin_expect (completed, 0)) 382 if (__builtin_expect (completed, 0))
373 return; 383 return;
374 384
385 #if DEFAULT_USE_CXA_ATEXIT
375 #ifdef CRTSTUFFS_O 386 #ifdef CRTSTUFFS_O
376 if (__cxa_finalize) 387 if (__cxa_finalize)
377 __cxa_finalize (__dso_handle); 388 __cxa_finalize (__dso_handle);
389 #endif
378 #endif 390 #endif
379 391
380 #ifdef FINI_ARRAY_SECTION_ASM_OP 392 #ifdef FINI_ARRAY_SECTION_ASM_OP
381 /* If we are using .fini_array then destructors will be run via that 393 /* If we are using .fini_array then destructors will be run via that
382 mechanism. */ 394 mechanism. */
427 439
428 /* Stick a call to __do_global_dtors_aux into the .fini section. */ 440 /* Stick a call to __do_global_dtors_aux into the .fini section. */
429 #ifdef FINI_SECTION_ASM_OP 441 #ifdef FINI_SECTION_ASM_OP
430 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux) 442 CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
431 #elif defined (FINI_ARRAY_SECTION_ASM_OP) 443 #elif defined (FINI_ARRAY_SECTION_ASM_OP)
444 #if defined(__FDPIC__)
445 __asm__("\t.equ\t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");
446 extern char __do_global_dtors_aux_alias;
447 static void *__do_global_dtors_aux_fini_array_entry[]
448 __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))
449 = { &__do_global_dtors_aux_alias };
450 #else /* defined(__FDPIC__) */
432 static func_ptr __do_global_dtors_aux_fini_array_entry[] 451 static func_ptr __do_global_dtors_aux_fini_array_entry[]
433 __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr)))) 452 __attribute__ ((__used__, section(".fini_array"),
434 = { __do_global_dtors_aux }; 453 aligned(__alignof__(func_ptr)))) = { __do_global_dtors_aux };
454 #endif /* defined(__FDPIC__) */
435 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */ 455 #else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
436 static void __attribute__((used)) 456 static void __attribute__((used))
437 __do_global_dtors_aux_1 (void) 457 __do_global_dtors_aux_1 (void)
438 { 458 {
439 atexit (__do_global_dtors_aux); 459 atexit (__do_global_dtors_aux);
440 } 460 }
441 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, 461 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__,
442 __do_global_dtors_aux_1) 462 __do_global_dtors_aux_1)
443 #endif 463 #endif
444 464 #endif /* defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP)
445 #if defined(USE_EH_FRAME_REGISTRY) \ 465 || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY) */
446 || defined(USE_TM_CLONE_REGISTRY) 466
467 #if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
447 /* Stick a call to __register_frame_info into the .init section. For some 468 /* 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 469 reason calls with no arguments work more reliably in .init, so stick the
449 call in another function. */ 470 call in another function. */
450 471
451 static void __attribute__((used)) 472 static void __attribute__((used))
471 } 492 }
472 493
473 #ifdef __LIBGCC_INIT_SECTION_ASM_OP__ 494 #ifdef __LIBGCC_INIT_SECTION_ASM_OP__
474 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy) 495 CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)
475 #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */ 496 #else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
497 #if defined(__FDPIC__)
498 __asm__("\t.equ\t__frame_dummy_alias, frame_dummy\n");
499 extern char __frame_dummy_alias;
500 static void *__frame_dummy_init_array_entry[]
501 __attribute__ ((__used__, section(".init_array"), aligned(sizeof(void *))))
502 = { &__frame_dummy_alias };
503 #else /* defined(__FDPIC__) */
476 static func_ptr __frame_dummy_init_array_entry[] 504 static func_ptr __frame_dummy_init_array_entry[]
477 __attribute__ ((__used__, section(".init_array"), aligned(sizeof(func_ptr)))) 505 __attribute__ ((__used__, section(".init_array"),
478 = { frame_dummy }; 506 aligned(__alignof__(func_ptr)))) = { frame_dummy };
507 #endif /* defined(__FDPIC__) */
479 #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */ 508 #endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
480 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */ 509 #endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
481 510
482 #else /* OBJECT_FORMAT_ELF */ 511 #else /* OBJECT_FORMAT_ELF */
483 512
542 if (__deregister_frame_info) 571 if (__deregister_frame_info)
543 __deregister_frame_info (__EH_FRAME_BEGIN__); 572 __deregister_frame_info (__EH_FRAME_BEGIN__);
544 #endif 573 #endif
545 } 574 }
546 575
547 #if defined(USE_EH_FRAME_REGISTRY) \ 576 #if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
548 || defined(USE_TM_CLONE_REGISTRY)
549 /* A helper function for __do_global_ctors, which is in crtend.o. Here 577 /* A helper function for __do_global_ctors, which is in crtend.o. Here
550 in crtbegin.o, we can reference a couple of symbols not visible there. 578 in crtbegin.o, we can reference a couple of symbols not visible there.
551 Plus, since we're before libgcc.a, we have no problems referencing 579 Plus, since we're before libgcc.a, we have no problems referencing
552 functions from there. */ 580 functions from there. */
553 void 581 void
586 /* Hack: force cc1 to switch to .data section early, so that assembling 614 /* Hack: force cc1 to switch to .data section early, so that assembling
587 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */ 615 __CTOR_LIST__ does not undo our behind-the-back change to .ctors. */
588 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { }; 616 static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
589 asm (__LIBGCC_CTORS_SECTION_ASM_OP__); 617 asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
590 STATIC func_ptr __CTOR_END__[1] 618 STATIC func_ptr __CTOR_END__[1]
591 __attribute__((aligned(sizeof(func_ptr)))) 619 __attribute__((aligned(__alignof__(func_ptr))))
592 = { (func_ptr) 0 }; 620 = { (func_ptr) 0 };
593 #else 621 #else
594 STATIC func_ptr __CTOR_END__[1] 622 STATIC func_ptr __CTOR_END__[1]
595 __attribute__((section(".ctors"), aligned(sizeof(func_ptr)))) 623 __attribute__((section(".ctors"), aligned(__alignof__(func_ptr))))
596 = { (func_ptr) 0 }; 624 = { (func_ptr) 0 };
597 #endif 625 #endif
598 626
599 #ifdef DTOR_LIST_END 627 #ifdef DTOR_LIST_END
600 DTOR_LIST_END; 628 DTOR_LIST_END;
605 func_ptr __DTOR_END__[1] 633 func_ptr __DTOR_END__[1]
606 __attribute__ ((used, 634 __attribute__ ((used,
607 #ifndef __LIBGCC_DTORS_SECTION_ASM_OP__ 635 #ifndef __LIBGCC_DTORS_SECTION_ASM_OP__
608 section(".dtors"), 636 section(".dtors"),
609 #endif 637 #endif
610 aligned(sizeof(func_ptr)), visibility ("hidden"))) 638 aligned(__alignof__(func_ptr)), visibility ("hidden")))
611 = { (func_ptr) 0 }; 639 = { (func_ptr) 0 };
612 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__) 640 #elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
613 asm (__LIBGCC_DTORS_SECTION_ASM_OP__); 641 asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
614 STATIC func_ptr __DTOR_END__[1] 642 STATIC func_ptr __DTOR_END__[1]
615 __attribute__ ((used, aligned(sizeof(func_ptr)))) 643 __attribute__ ((used, aligned(__alignof__(func_ptr))))
616 = { (func_ptr) 0 }; 644 = { (func_ptr) 0 };
617 #else 645 #else
618 STATIC func_ptr __DTOR_END__[1] 646 STATIC func_ptr __DTOR_END__[1]
619 __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr)))) 647 __attribute__((used, section(".dtors"), aligned(__alignof__(func_ptr))))
620 = { (func_ptr) 0 }; 648 = { (func_ptr) 0 };
621 #endif 649 #endif
622 #endif /* USE_INITFINI_ARRAY */ 650 #endif /* USE_INITFINI_ARRAY */
623 651
624 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__ 652 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
633 # else 661 # else
634 # error "Missing a 4 byte integer" 662 # error "Missing a 4 byte integer"
635 # endif 663 # endif
636 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[] 664 STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
637 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__), 665 __attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
638 aligned(sizeof(int32)))) 666 aligned(__alignof__(int32))))
639 = { 0 }; 667 = { 0 };
640 #endif /* __LIBGCC_EH_FRAME_SECTION_NAME__ */ 668 #endif /* __LIBGCC_EH_FRAME_SECTION_NAME__ */
641 669
642 #if USE_TM_CLONE_REGISTRY 670 #if USE_TM_CLONE_REGISTRY
643 # ifndef HAVE_GAS_HIDDEN 671 # ifndef HAVE_GAS_HIDDEN
644 static 672 static
645 # endif 673 # endif
646 func_ptr __TMC_END__[] 674 func_ptr __TMC_END__[]
647 __attribute__((used, section(".tm_clone_table"), aligned(sizeof(void *)))) 675 __attribute__((used, section(".tm_clone_table"),
676 aligned(__alignof__(void *))))
648 # ifdef HAVE_GAS_HIDDEN 677 # ifdef HAVE_GAS_HIDDEN
649 __attribute__((__visibility__ ("hidden"))) = { }; 678 __attribute__((__visibility__ ("hidden"))) = { };
650 # else 679 # else
651 = { 0, 0 }; 680 = { 0, 0 };
652 # endif 681 # endif
714 in this case because we protect it with -hidden_symbol. */ 743 in this case because we protect it with -hidden_symbol. */
715 void 744 void
716 __do_global_ctors (void) 745 __do_global_ctors (void)
717 { 746 {
718 func_ptr *p; 747 func_ptr *p;
719 #if defined(USE_EH_FRAME_REGISTRY) \ 748 #if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
720 || defined(USE_TM_CLONE_REGISTRY)
721 __do_global_ctors_1(); 749 __do_global_ctors_1();
722 #endif 750 #endif
723 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--) 751 for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)
724 (*p) (); 752 (*p) ();
725 } 753 }