/* Specialized bits of code needed to support construction and
destruction of file-scope objects in C++ code.
- Copyright (C) 1991-2016 Free Software Foundation, Inc.
+ Copyright (C) 1991-2021 Free Software Foundation, Inc.
Contributed by Ron Guilmette (rfg@monkeys.com).
This file is part of GCC.
#endif
#if defined(TARGET_DL_ITERATE_PHDR) && \
- (defined(__DragonFly__) || defined(__FreeBSD__))
+ (defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__))
#define BSD_DL_ITERATE_PHDR_AVAILABLE
#endif
#if !defined(USE_TM_CLONE_REGISTRY) && defined(OBJECT_FORMAT_ELF)
# define USE_TM_CLONE_REGISTRY 1
+#elif !defined(USE_TM_CLONE_REGISTRY)
+# define USE_TM_CLONE_REGISTRY 0
#endif
/* We do not want to add the weak attribute to the declarations of these
TARGET_ATTRIBUTE_WEAK;
extern void __do_global_ctors_1 (void);
-/* Likewise for _Jv_RegisterClasses. */
-extern void _Jv_RegisterClasses (void *) TARGET_ATTRIBUTE_WEAK;
-
/* Likewise for transactional memory clone tables. */
extern void _ITM_registerTMCloneTable (void *, size_t) TARGET_ATTRIBUTE_WEAK;
extern void _ITM_deregisterTMCloneTable (void *) TARGET_ATTRIBUTE_WEAK;
static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
STATIC func_ptr __CTOR_LIST__[1]
- __attribute__ ((__used__, aligned(sizeof(func_ptr))))
+ __attribute__ ((__used__, aligned(__alignof__(func_ptr))))
= { (func_ptr) (-1) };
#else
STATIC func_ptr __CTOR_LIST__[1]
- __attribute__ ((__used__, section(".ctors"), aligned(sizeof(func_ptr))))
+ __attribute__ ((__used__, section(".ctors"), aligned(__alignof__(func_ptr))))
= { (func_ptr) (-1) };
#endif /* __CTOR_LIST__ alternatives */
#elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
STATIC func_ptr __DTOR_LIST__[1]
- __attribute__ ((aligned(sizeof(func_ptr))))
+ __attribute__ ((aligned(__alignof__(func_ptr))))
= { (func_ptr) (-1) };
#else
STATIC func_ptr __DTOR_LIST__[1]
- __attribute__((section(".dtors"), aligned(sizeof(func_ptr))))
+ __attribute__((section(".dtors"), aligned(__alignof__(func_ptr))))
= { (func_ptr) (-1) };
#endif /* __DTOR_LIST__ alternatives */
#endif /* USE_INITFINI_ARRAY */
#if USE_TM_CLONE_REGISTRY
STATIC func_ptr __TMC_LIST__[]
- __attribute__((used, section(".tm_clone_table"), aligned(sizeof(void*))))
+ __attribute__((used, section(".tm_clone_table"), aligned(__alignof__(void*))))
= { };
# ifdef HAVE_GAS_HIDDEN
extern func_ptr __TMC_END__[] __attribute__((__visibility__ ("hidden")));
void (*fn) (void *);
#ifdef HAVE_GAS_HIDDEN
- if (__TMC_END__ - __TMC_LIST__ == 0)
+ func_ptr *end = __TMC_END__;
+ // Do not optimize the comparison to false.
+ __asm ("" : "+g" (end));
+ if (__TMC_LIST__ == end)
return;
#else
if (__TMC_LIST__[0] == NULL)
size_t size;
#ifdef HAVE_GAS_HIDDEN
- size = (__TMC_END__ - __TMC_LIST__) / 2;
+ func_ptr *end = __TMC_END__;
+ // Do not optimize the comparison to false.
+ __asm ("" : "+g" (end));
+ size = (end - __TMC_LIST__) / 2;
#else
for (size = 0; __TMC_LIST__[size * 2] != NULL; size++)
continue;
#ifdef OBJECT_FORMAT_ELF
+#if DEFAULT_USE_CXA_ATEXIT
/* Declare the __dso_handle variable. It should have a unique value
in every shared-object; in a main program its value is zero. The
object should in any case be protected. This means the instance
in one DSO or the main program is not used in another object. The
- dynamic linker takes care of this. */
+ dynamic linker takes care of this.
+ If __cxa_atexit is not being used, __dso_handle will not be used and
+ doesn't need to be defined. */
#ifdef TARGET_LIBGCC_SDATA_SECTION
extern void *__dso_handle __attribute__ ((__section__ (TARGET_LIBGCC_SDATA_SECTION)));
#else
void *__dso_handle = 0;
#endif
+#endif /* DEFAULT_USE_CXA_ATEXIT */
/* The __cxa_finalize function may not be available so we use only a
weak declaration. */
On some systems, this routine is run more than once from the .fini,
when exit is called recursively, so we arrange to remember where in
the list we left off processing, and we resume at that point,
- should we be re-invoked. */
+ should we be re-invoked.
+ This routine does not need to be run if none of the following clauses are
+ true, as it will not do anything, so can be removed. */
+#if defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP) \
+ || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY)
static void __attribute__((used))
__do_global_dtors_aux (void)
{
if (__builtin_expect (completed, 0))
return;
+#if DEFAULT_USE_CXA_ATEXIT
#ifdef CRTSTUFFS_O
if (__cxa_finalize)
__cxa_finalize (__dso_handle);
#endif
+#endif
#ifdef FINI_ARRAY_SECTION_ASM_OP
/* If we are using .fini_array then destructors will be run via that
#ifdef FINI_SECTION_ASM_OP
CRT_CALL_STATIC_FUNCTION (FINI_SECTION_ASM_OP, __do_global_dtors_aux)
#elif defined (FINI_ARRAY_SECTION_ASM_OP)
+#if defined(__FDPIC__)
+__asm__("\t.equ\t__do_global_dtors_aux_alias, __do_global_dtors_aux\n");
+extern char __do_global_dtors_aux_alias;
+static void *__do_global_dtors_aux_fini_array_entry[]
+__attribute__ ((__used__, section(".fini_array"), aligned(sizeof(void *))))
+ = { &__do_global_dtors_aux_alias };
+#else /* defined(__FDPIC__) */
static func_ptr __do_global_dtors_aux_fini_array_entry[]
- __attribute__ ((__used__, section(".fini_array"), aligned(sizeof(func_ptr))))
- = { __do_global_dtors_aux };
+ __attribute__ ((__used__, section(".fini_array"),
+ aligned(__alignof__(func_ptr)))) = { __do_global_dtors_aux };
+#endif /* defined(__FDPIC__) */
#else /* !FINI_SECTION_ASM_OP && !FINI_ARRAY_SECTION_ASM_OP */
static void __attribute__((used))
__do_global_dtors_aux_1 (void)
CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__,
__do_global_dtors_aux_1)
#endif
+#endif /* defined(CRTSTUFFS_O) || !defined(FINI_ARRAY_SECTION_ASM_OP)
+ || USE_TM_CLONE_REGISTRY || defined(USE_EH_FRAME_REGISTRY) */
-#if defined(USE_EH_FRAME_REGISTRY) \
- || defined(USE_TM_CLONE_REGISTRY)
+#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
/* Stick a call to __register_frame_info into the .init section. For some
reason calls with no arguments work more reliably in .init, so stick the
call in another function. */
#ifdef __LIBGCC_INIT_SECTION_ASM_OP__
CRT_CALL_STATIC_FUNCTION (__LIBGCC_INIT_SECTION_ASM_OP__, frame_dummy)
#else /* defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
+#if defined(__FDPIC__)
+__asm__("\t.equ\t__frame_dummy_alias, frame_dummy\n");
+extern char __frame_dummy_alias;
+static void *__frame_dummy_init_array_entry[]
+__attribute__ ((__used__, section(".init_array"), aligned(sizeof(void *))))
+ = { &__frame_dummy_alias };
+#else /* defined(__FDPIC__) */
static func_ptr __frame_dummy_init_array_entry[]
- __attribute__ ((__used__, section(".init_array"), aligned(sizeof(func_ptr))))
- = { frame_dummy };
+ __attribute__ ((__used__, section(".init_array"),
+ aligned(__alignof__(func_ptr)))) = { frame_dummy };
+#endif /* defined(__FDPIC__) */
#endif /* !defined(__LIBGCC_INIT_SECTION_ASM_OP__) */
#endif /* USE_EH_FRAME_REGISTRY || USE_TM_CLONE_REGISTRY */
#endif
}
-#if defined(USE_EH_FRAME_REGISTRY) \
- || defined(USE_TM_CLONE_REGISTRY)
+#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
/* A helper function for __do_global_ctors, which is in crtend.o. Here
in crtbegin.o, we can reference a couple of symbols not visible there.
Plus, since we're before libgcc.a, we have no problems referencing
static func_ptr force_to_data[1] __attribute__ ((__used__)) = { };
asm (__LIBGCC_CTORS_SECTION_ASM_OP__);
STATIC func_ptr __CTOR_END__[1]
- __attribute__((aligned(sizeof(func_ptr))))
+ __attribute__((aligned(__alignof__(func_ptr))))
= { (func_ptr) 0 };
#else
STATIC func_ptr __CTOR_END__[1]
- __attribute__((section(".ctors"), aligned(sizeof(func_ptr))))
+ __attribute__((section(".ctors"), aligned(__alignof__(func_ptr))))
= { (func_ptr) 0 };
#endif
#ifndef __LIBGCC_DTORS_SECTION_ASM_OP__
section(".dtors"),
#endif
- aligned(sizeof(func_ptr)), visibility ("hidden")))
+ aligned(__alignof__(func_ptr)), visibility ("hidden")))
= { (func_ptr) 0 };
#elif defined(__LIBGCC_DTORS_SECTION_ASM_OP__)
asm (__LIBGCC_DTORS_SECTION_ASM_OP__);
STATIC func_ptr __DTOR_END__[1]
- __attribute__ ((used, aligned(sizeof(func_ptr))))
+ __attribute__ ((used, aligned(__alignof__(func_ptr))))
= { (func_ptr) 0 };
#else
STATIC func_ptr __DTOR_END__[1]
- __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr))))
+ __attribute__((used, section(".dtors"), aligned(__alignof__(func_ptr))))
= { (func_ptr) 0 };
#endif
#endif /* USE_INITFINI_ARRAY */
# endif
STATIC EH_FRAME_SECTION_CONST int32 __FRAME_END__[]
__attribute__ ((used, section(__LIBGCC_EH_FRAME_SECTION_NAME__),
- aligned(sizeof(int32))))
+ aligned(__alignof__(int32))))
= { 0 };
#endif /* __LIBGCC_EH_FRAME_SECTION_NAME__ */
static
# endif
func_ptr __TMC_END__[]
- __attribute__((used, section(".tm_clone_table"), aligned(sizeof(void *))))
+ __attribute__((used, section(".tm_clone_table"),
+ aligned(__alignof__(void *))))
# ifdef HAVE_GAS_HIDDEN
__attribute__((__visibility__ ("hidden"))) = { };
# else
__do_global_ctors (void)
{
func_ptr *p;
-#if defined(USE_EH_FRAME_REGISTRY) \
- || defined(USE_TM_CLONE_REGISTRY)
+#if defined(USE_EH_FRAME_REGISTRY) || USE_TM_CLONE_REGISTRY
__do_global_ctors_1();
#endif
for (p = __CTOR_END__ - 1; *p != (func_ptr) -1; p--)