Browse Source
* Move ctors and init_array from the CPP library to the kernel library, as this is common for both C and C++ and it is the kernel who is running it. * Rename the hidden kconfig option CPP_STATIC_INIT_GNU STATIC_INIT_GNU instead. * If STATIC_INIT_GNU is not selected verify there is constructors left behind. * Rename common-rom-cpp.ld to common-rom-init.ld * Rename z_cpp_init_static to z_init_static, and have the kernel always call it. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no> Signed-off-by: Keith Packard <keithp@keithp.com>pull/75003/head
22 changed files with 149 additions and 131 deletions
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2015 Wind River Systems, Inc. |
||||
* Copyright (c) 2021 Synopsys, Inc. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
void __do_global_ctors_aux(void); |
||||
void __do_init_array_aux(void); |
||||
|
||||
void z_init_static(void) |
||||
{ |
||||
#if defined(CONFIG_STATIC_INIT_GNU) |
||||
__do_global_ctors_aux(); |
||||
__do_init_array_aux(); |
||||
#elif defined(__CCAC__) /* ARC MWDT */ |
||||
__do_global_ctors_aux(); |
||||
#endif |
||||
} |
||||
|
||||
/**
|
||||
* @section - Constructor module |
||||
* @brief |
||||
* The ctors section contains a list of function pointers that execute both the C++ constructors of |
||||
* static global objects, as well as either C or C++ initializer functions (declared with the |
||||
* attribute constructor). These must be executed before the application's main() routine. |
||||
* |
||||
* NOTE: Not all compilers put those function pointers into the ctors section; |
||||
* some put them into the init_array section instead. |
||||
*/ |
||||
|
||||
#ifdef CONFIG_STATIC_INIT_GNU |
||||
|
||||
/* What a constructor function pointer looks like */ |
||||
|
||||
typedef void (*CtorFuncPtr)(void); |
||||
|
||||
/* Constructor function pointer list is generated by the linker script. */ |
||||
|
||||
extern CtorFuncPtr __ZEPHYR_CTOR_LIST__[]; |
||||
extern CtorFuncPtr __ZEPHYR_CTOR_END__[]; |
||||
|
||||
/**
|
||||
* |
||||
* @brief Invoke all C++ style global object constructors |
||||
* |
||||
* This routine is invoked by the kernel prior to the execution of the |
||||
* application's main(). |
||||
*/ |
||||
void __do_global_ctors_aux(void) |
||||
{ |
||||
unsigned int nCtors; |
||||
|
||||
nCtors = (unsigned long)__ZEPHYR_CTOR_LIST__[0]; |
||||
|
||||
while (nCtors >= 1U) { |
||||
__ZEPHYR_CTOR_LIST__[nCtors--](); |
||||
} |
||||
} |
||||
|
||||
#endif |
||||
|
||||
/*
|
||||
* @section |
||||
* @brief Execute initialization routines referenced in .init_array section |
||||
*/ |
||||
|
||||
#ifdef CONFIG_STATIC_INIT_GNU |
||||
|
||||
typedef void (*func_ptr)(void); |
||||
|
||||
extern func_ptr __zephyr_init_array_start[]; |
||||
extern func_ptr __zephyr_init_array_end[]; |
||||
|
||||
/**
|
||||
* @brief Execute initialization routines referenced in .init_array section |
||||
*/ |
||||
void __do_init_array_aux(void) |
||||
{ |
||||
for (func_ptr *func = __zephyr_init_array_start; |
||||
func < __zephyr_init_array_end; |
||||
func++) { |
||||
(*func)(); |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -1,9 +1,5 @@
@@ -1,9 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0 |
||||
|
||||
zephyr_sources(cpp_init.c) |
||||
|
||||
zephyr_sources_ifdef(CONFIG_CPP_STATIC_INIT_GNU |
||||
cpp_init_array.c |
||||
cpp_ctors.c |
||||
zephyr_sources_ifdef(CONFIG_STATIC_INIT_GNU |
||||
cpp_dtors.c |
||||
) |
||||
|
@ -1,43 +0,0 @@
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012-2014 Wind River Systems, Inc. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
/**
|
||||
* @file - Constructor module |
||||
* @brief |
||||
* The ctors section contains a list of function pointers that execute the |
||||
* C++ constructors of static global objects. These must be executed before |
||||
* the application's main() routine. |
||||
* |
||||
* NOTE: Not all compilers put those function pointers into the ctors section; |
||||
* some put them into the init_array section instead. |
||||
*/ |
||||
|
||||
/* What a constructor function pointer looks like */ |
||||
|
||||
typedef void (*CtorFuncPtr)(void); |
||||
|
||||
/* Constructor function pointer list is generated by the linker script. */ |
||||
|
||||
extern CtorFuncPtr __ZEPHYR_CTOR_LIST__[]; |
||||
extern CtorFuncPtr __ZEPHYR_CTOR_END__[]; |
||||
|
||||
/**
|
||||
* |
||||
* @brief Invoke all C++ style global object constructors |
||||
* |
||||
* This routine is invoked by the kernel prior to the execution of the |
||||
* application's main(). |
||||
*/ |
||||
void __do_global_ctors_aux(void) |
||||
{ |
||||
unsigned int nCtors; |
||||
|
||||
nCtors = (unsigned long)__ZEPHYR_CTOR_LIST__[0]; |
||||
|
||||
while (nCtors >= 1U) { |
||||
__ZEPHYR_CTOR_LIST__[nCtors--](); |
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Synopsys, Inc. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
* |
||||
* Author: Evgeniy Paltsev |
||||
*/ |
||||
|
||||
#ifdef CONFIG_CPP_STATIC_INIT_GNU |
||||
|
||||
void __do_global_ctors_aux(void); |
||||
void __do_init_array_aux(void); |
||||
|
||||
void z_cpp_init_static(void) |
||||
{ |
||||
__do_global_ctors_aux(); |
||||
__do_init_array_aux(); |
||||
} |
||||
|
||||
#else |
||||
|
||||
#ifdef __CCAC__ |
||||
void __do_global_ctors_aux(void); |
||||
|
||||
void z_cpp_init_static(void) |
||||
{ |
||||
__do_global_ctors_aux(); |
||||
} |
||||
#endif /* __CCAC__ */ |
||||
|
||||
#endif /* CONFIG_CPP_STATIC_INIT_GNU */ |
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2015 Wind River Systems, Inc. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
|
||||
/*
|
||||
* @file |
||||
* @brief Execute initialization routines referenced in .init_array section |
||||
*/ |
||||
|
||||
typedef void (*func_ptr)(void); |
||||
|
||||
extern func_ptr __zephyr_init_array_start[]; |
||||
extern func_ptr __zephyr_init_array_end[]; |
||||
|
||||
/**
|
||||
* @brief Execute initialization routines referenced in .init_array section |
||||
*/ |
||||
void __do_init_array_aux(void) |
||||
{ |
||||
for (func_ptr *func = __zephyr_init_array_start; |
||||
func < __zephyr_init_array_end; |
||||
func++) { |
||||
(*func)(); |
||||
} |
||||
} |
Loading…
Reference in new issue