Skip to content

Commit 60fdec6

Browse files
evgeniy-paltsevnashif
authored andcommitted
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 <[email protected]> Signed-off-by: Evgeniy Paltsev <[email protected]>
1 parent 9f948a8 commit 60fdec6

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

arch/arc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ if(CONFIG_ISA_ARCV2)
2020
endif()
2121

2222
add_subdirectory(core)
23+
24+
if(COMPILER STREQUAL arcmwdt)
25+
add_subdirectory(arcmwdt)
26+
endif()

arch/arc/arcmwdt/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if(CONFIG_ARCMWDT_LIBC OR CONFIG_CPLUSPLUS)
4+
zephyr_sources(arcmwdt-dtr-stubs.c)
5+
endif()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2021 Synopsys.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <toolchain.h>
8+
9+
__weak void *__dso_handle;
10+
11+
int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso)
12+
{
13+
ARG_UNUSED(destructor);
14+
ARG_UNUSED(objptr);
15+
ARG_UNUSED(dso);
16+
return 0;
17+
}
18+
19+
int atexit(void (*function)(void))
20+
{
21+
return 0;
22+
}

cmake/linker/arcmwdt/target.cmake

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,9 @@ macro(toolchain_ld_baremetal)
119119
-Hhostlib=
120120
-Hheap=0
121121
-Hnoivt
122+
-Hnocrt
122123
)
123124

124-
# We only use CPP initialization code from crt
125-
if(NOT CONFIG_CPLUSPLUS)
126-
zephyr_ld_options(-Hnocrt)
127-
endif()
128-
129125
# There are two options:
130126
# - We have full MWDT libc support and we link MWDT libc - this is default
131127
# behavior and we don't need to do something for that.

include/arch/arc/v2/linker.ld

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ SECTIONS {
8888
#include <linker/kobject-text.ld>
8989
} GROUP_LINK_IN(ROMABLE_REGION)
9090

91-
#if defined(CONFIG_CPLUSPLUS) && !defined(CONFIG_CPP_STATIC_INIT_GNU) && defined(__MWDT_LINKER_CMD__)
92-
/* .init section with code iterating over static objects constructors */
93-
SECTION_PROLOGUE(.init,,ALIGN(4)) {
94-
KEEP(*(.init*))
95-
} GROUP_LINK_IN(ROMABLE_REGION)
96-
#endif /* CONFIG_CPLUSPLUS && !CONFIG_CPP_STATIC_INIT_GNU && __MWDT_LINKER_CMD__ */
97-
9891
__text_region_end = .;
9992
__rodata_region_start = .;
10093

subsys/cpp/cpp_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ void z_cpp_init_static(void)
2020
#else
2121

2222
#ifdef __CCAC__
23-
void _init(void);
23+
void __do_global_ctors_aux(void);
2424

2525
void z_cpp_init_static(void)
2626
{
27-
_init();
27+
__do_global_ctors_aux();
2828
}
2929
#endif /* __CCAC__ */
3030

0 commit comments

Comments
 (0)