-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kernel: Unify .ctors and .init_array handling
Handle both of these sections in a single chunk of code instead of separately. We don't need to use the legacy .ctors ABI as both the constructors array and startup logic are managed within a single link result. This can now also be used with ARC MWDT which had been using the .ctors sections but with .init_array semantics. For ARC MWDT, we now always discard .dtors and .fini sections as Zephyr will never cause global destructors to execute. Stop discarding .eh_frame sections so that exception handling works as expected. Signed-off-by: Keith Packard <[email protected]>
- Loading branch information
1 parent
2462d0e
commit 9847555
Showing
6 changed files
with
51 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,49 @@ | ||
/* SPDX-License-Identifier: Apache-2.0 */ | ||
|
||
#ifdef CONFIG_STATIC_INIT_GNU | ||
SECTION_PROLOGUE(_CTOR_SECTION_NAME,,) | ||
#ifdef CONFIG_TOOLCHAIN_SUPPORTS_STATIC_INIT_GNU | ||
SECTION_PROLOGUE(init_array,,) | ||
{ | ||
/* | ||
* The compiler fills the constructor pointers table below, | ||
* hence symbol __CTOR_LIST__ must be aligned on word | ||
* boundary. To align with the C++ standard, the first element | ||
* of the array contains the number of actual constructors. The | ||
* last element is NULL. | ||
* | ||
* The __CTOR_LIST__ and __CTOR_END__ symbols are always defined | ||
* to result in an empty list. This is necessary to fix an issue | ||
* where the glibc process initialization code on native_posix | ||
* platforms calls constructors before Zephyr loads (issue #39347). | ||
* | ||
* Zephyr's start-up code uses the __ZEPHYR_CTOR_LIST__ and | ||
* __ZEHPYR_CTOR_END__ symbols, so these need to be correctly set. | ||
* Add all of the GNU-style constructors in priority order. Note | ||
* that this doesn't build the ctors in the "usual" fashion with | ||
* a length value first and NULL terminator, but as we run this | ||
* list ourselves, that doesn't matter. | ||
*/ | ||
__zephyr_init_array_start = .; | ||
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) | ||
SORT_BY_INIT_PRIORITY(.ctors.*))) | ||
KEEP (*(.init_array .ctors)) | ||
__zephyr_init_array_end = .; | ||
#ifdef CONFIG_NATIVE_LIBC | ||
/* | ||
* The __CTOR_LIST__ and __CTOR_END__ symbols are always defined | ||
* to result in an empty list. This is necessary to fix an issue | ||
* where the glibc process initialization code on native_posix | ||
* platforms calls constructors before Zephyr loads (issue #39347). | ||
*/ | ||
#ifdef CONFIG_64BIT | ||
. = ALIGN(8); | ||
__ZEPHYR_CTOR_LIST__ = .; | ||
QUAD((__ZEPHYR_CTOR_END__ - __ZEPHYR_CTOR_LIST__) / 8 - 2) | ||
KEEP(*(SORT_BY_NAME(".ctors*"))) | ||
__CTOR_LIST__ = .; | ||
#ifdef CONFIG_64BIT | ||
QUAD(0) | ||
__ZEPHYR_CTOR_END__ = .; | ||
QUAD(0) | ||
__CTOR_END__ = .; | ||
#else | ||
. = ALIGN(4); | ||
__ZEPHYR_CTOR_LIST__ = .; | ||
LONG((__ZEPHYR_CTOR_END__ - __ZEPHYR_CTOR_LIST__) / 4 - 2) | ||
KEEP(*(SORT_BY_NAME(".ctors*"))) | ||
__CTOR_LIST__ = .; | ||
LONG(0) | ||
__ZEPHYR_CTOR_END__ = .; | ||
LONG(0) | ||
#endif | ||
__CTOR_END__ = .; | ||
#endif | ||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) | ||
|
||
SECTION_PROLOGUE(init_array,,) | ||
{ | ||
/* | ||
* Similar to the schenanigans required for the __CTOR_LIST__ and | ||
* __CTOR_END__ symbols we define __init_array_start and __init_array_end | ||
* to the same address to define an empty list. This prevents the glibc | ||
* startup code from calling any global constructors before Zephyr loads. | ||
* | ||
* Zephyr's start-up code uses the __zephyr_init_array_start and | ||
* __zephyr_init_array_end sybmols, so these need to be set correctly. | ||
*/ | ||
. = ALIGN(4); | ||
__init_array_start = .; | ||
__init_array_end = .; | ||
__zephyr_init_array_start = .; | ||
KEEP(*(SORT_BY_NAME(".init_array*"))) | ||
__zephyr_init_array_end = .; | ||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) | ||
|
||
#elif defined(CONFIG_TOOLCHAIN_SUPPORTS_STATIC_INIT_GNU) && !defined(CONFIG_NATIVE_APPLICATION) | ||
/* | ||
* If the code to invoke constructors is not enabled, | ||
* make sure there aren't any in the application | ||
*/ | ||
SECTION_PROLOGUE(init_array,,) | ||
{ | ||
KEEP(*(SORT_BY_NAME(".ctors*"))) | ||
KEEP(*(SORT_BY_NAME(".init_array*"))) | ||
} GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) | ||
#ifndef CONFIG_STATIC_INIT_GNU | ||
ASSERT(__zephyr_init_array_start == __zephyr_init_array_end, | ||
"GNU-style constructors required but STATIC_INIT_GNU not enabled") | ||
#endif | ||
|
||
ASSERT (SIZEOF(init_array) == 0, | ||
"GNU-style constructors required but STATIC_INIT_GNU not enabled") | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,6 @@ list(APPEND kernel_files | |
errno.c | ||
fatal.c | ||
init.c | ||
init_static.c | ||
kheap.c | ||
mem_slab.c | ||
float.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.