From 60fdec616b833727d3da6f0efb1fd8dfccfba42d Mon Sep 17 00:00:00 2001 From: Evgeniy Paltsev Date: Mon, 30 Aug 2021 22:40:45 +0300 Subject: [PATCH] ARC: MWDT: get rid of MWDT startup libs __cxa_atexit implementation provided by MWDT startup code calls malloc which isn't supported right now. As we don't support calling static destructors in Zephyr let's provide our own __cxa_atexit stub and get rid of MWDT startup libs entirely. Signed-off-by: Eugeniy Paltsev Signed-off-by: Evgeniy Paltsev --- arch/arc/CMakeLists.txt | 4 ++++ arch/arc/arcmwdt/CMakeLists.txt | 5 +++++ arch/arc/arcmwdt/arcmwdt-dtr-stubs.c | 22 ++++++++++++++++++++++ cmake/linker/arcmwdt/target.cmake | 6 +----- include/arch/arc/v2/linker.ld | 7 ------- subsys/cpp/cpp_init.c | 4 ++-- 6 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 arch/arc/arcmwdt/CMakeLists.txt create mode 100644 arch/arc/arcmwdt/arcmwdt-dtr-stubs.c diff --git a/arch/arc/CMakeLists.txt b/arch/arc/CMakeLists.txt index 66f4848e23d..3486a721374 100644 --- a/arch/arc/CMakeLists.txt +++ b/arch/arc/CMakeLists.txt @@ -20,3 +20,7 @@ if(CONFIG_ISA_ARCV2) endif() add_subdirectory(core) + +if(COMPILER STREQUAL arcmwdt) + add_subdirectory(arcmwdt) +endif() diff --git a/arch/arc/arcmwdt/CMakeLists.txt b/arch/arc/arcmwdt/CMakeLists.txt new file mode 100644 index 00000000000..9fb901c9b73 --- /dev/null +++ b/arch/arc/arcmwdt/CMakeLists.txt @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +if(CONFIG_ARCMWDT_LIBC OR CONFIG_CPLUSPLUS) + zephyr_sources(arcmwdt-dtr-stubs.c) +endif() diff --git a/arch/arc/arcmwdt/arcmwdt-dtr-stubs.c b/arch/arc/arcmwdt/arcmwdt-dtr-stubs.c new file mode 100644 index 00000000000..5520d891ba1 --- /dev/null +++ b/arch/arc/arcmwdt/arcmwdt-dtr-stubs.c @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 Synopsys. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +__weak void *__dso_handle; + +int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso) +{ + ARG_UNUSED(destructor); + ARG_UNUSED(objptr); + ARG_UNUSED(dso); + return 0; +} + +int atexit(void (*function)(void)) +{ + return 0; +} diff --git a/cmake/linker/arcmwdt/target.cmake b/cmake/linker/arcmwdt/target.cmake index 9c0a6271e08..e93cb47f908 100644 --- a/cmake/linker/arcmwdt/target.cmake +++ b/cmake/linker/arcmwdt/target.cmake @@ -119,13 +119,9 @@ macro(toolchain_ld_baremetal) -Hhostlib= -Hheap=0 -Hnoivt + -Hnocrt ) - # We only use CPP initialization code from crt - if(NOT CONFIG_CPLUSPLUS) - zephyr_ld_options(-Hnocrt) - endif() - # There are two options: # - We have full MWDT libc support and we link MWDT libc - this is default # behavior and we don't need to do something for that. diff --git a/include/arch/arc/v2/linker.ld b/include/arch/arc/v2/linker.ld index 50e96751a66..5b54b2256ad 100644 --- a/include/arch/arc/v2/linker.ld +++ b/include/arch/arc/v2/linker.ld @@ -88,13 +88,6 @@ SECTIONS { #include } GROUP_LINK_IN(ROMABLE_REGION) -#if defined(CONFIG_CPLUSPLUS) && !defined(CONFIG_CPP_STATIC_INIT_GNU) && defined(__MWDT_LINKER_CMD__) - /* .init section with code iterating over static objects constructors */ - SECTION_PROLOGUE(.init,,ALIGN(4)) { - KEEP(*(.init*)) - } GROUP_LINK_IN(ROMABLE_REGION) -#endif /* CONFIG_CPLUSPLUS && !CONFIG_CPP_STATIC_INIT_GNU && __MWDT_LINKER_CMD__ */ - __text_region_end = .; __rodata_region_start = .; diff --git a/subsys/cpp/cpp_init.c b/subsys/cpp/cpp_init.c index a3a67719bb5..c0358b1eaaa 100644 --- a/subsys/cpp/cpp_init.c +++ b/subsys/cpp/cpp_init.c @@ -20,11 +20,11 @@ void z_cpp_init_static(void) #else #ifdef __CCAC__ -void _init(void); +void __do_global_ctors_aux(void); void z_cpp_init_static(void) { - _init(); + __do_global_ctors_aux(); } #endif /* __CCAC__ */