diff --git a/cmake/compiler/arcmwdt/compiler_flags.cmake b/cmake/compiler/arcmwdt/compiler_flags.cmake index 8d736ba203f26..00e2233bff338 100644 --- a/cmake/compiler/arcmwdt/compiler_flags.cmake +++ b/cmake/compiler/arcmwdt/compiler_flags.cmake @@ -115,20 +115,19 @@ set_compiler_property(PROPERTY warning_error_misra_sane -Werror=vla) set_compiler_property(PROPERTY cstd -std=) -if (NOT CONFIG_NEWLIB_LIBC AND - NOT CONFIG_NATIVE_APPLICATION) +if (NOT CONFIG_ARCMWDT_LIBC) set_compiler_property(PROPERTY nostdinc -Hno_default_include -Hnoarcexlib) - set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC}) endif() +set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC}) # C++ std options set_property(TARGET compiler-cpp PROPERTY dialect_cpp98 "-std=c++98") set_property(TARGET compiler-cpp PROPERTY dialect_cpp11 "-std=c++11") +set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "-std=c++14") +set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 "-std=c++17") -#no support of C++14, C++17, C++2a, C++20, C++2b -set_property(TARGET compiler-cpp PROPERTY dialect_cpp14 "") -set_property(TARGET compiler-cpp PROPERTY dialect_cpp17 "") +#no support of C++2a, C++20, C++2b set_property(TARGET compiler-cpp PROPERTY dialect_cpp2a "") set_property(TARGET compiler-cpp PROPERTY dialect_cpp20 "") set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "") @@ -173,7 +172,7 @@ set_compiler_property(PROPERTY security_canaries -fstack-protector-all) set_compiler_property(PROPERTY security_fortify "") # Required C++ flags when using mwdt -set_property(TARGET compiler-cpp PROPERTY required "") +set_property(TARGET compiler-cpp PROPERTY required "-Hcplus" "-Hoff=Stackcheck_alloca") # Compiler flag for turning off thread-safe initialization of local statics set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics "-fno-threadsafe-statics") diff --git a/cmake/compiler/arcmwdt/target.cmake b/cmake/compiler/arcmwdt/target.cmake index dd4e693cc2bab..9bed7a511945e 100644 --- a/cmake/compiler/arcmwdt/target.cmake +++ b/cmake/compiler/arcmwdt/target.cmake @@ -26,6 +26,10 @@ set(NOSTDINC "") list(APPEND NOSTDINC ${TOOLCHAIN_HOME}/arc/inc) +if(CONFIG_ARCMWDT_LIBC AND CONFIG_LIB_CPLUSPLUS) + list(APPEND NOSTDINC ${TOOLCHAIN_HOME}/arc/lib/src/c++/inc) +endif() + # For CMake to be able to test if a compiler flag is supported by the # toolchain we need to give CMake the necessary flags to compile and # link a dummy C file. diff --git a/cmake/linker/arcmwdt/target.cmake b/cmake/linker/arcmwdt/target.cmake index 3c5156be89b15..4675f9344d5cd 100644 --- a/cmake/linker/arcmwdt/target.cmake +++ b/cmake/linker/arcmwdt/target.cmake @@ -196,7 +196,7 @@ endmacro() # link C++ libraries macro(toolchain_ld_cpp) zephyr_link_libraries( - -Hcppmw -Hcplus + -Hcplus ) endmacro() diff --git a/include/arch/arc/v2/linker.ld b/include/arch/arc/v2/linker.ld index 9fef45edcdde6..3598eedb5af32 100644 --- a/include/arch/arc/v2/linker.ld +++ b/include/arch/arc/v2/linker.ld @@ -224,6 +224,16 @@ SECTIONS { __kernel_ram_end = .; __kernel_ram_size = __kernel_ram_end - __kernel_ram_start; +#ifdef __MWDT_LINKER_CMD__ +/* mwdt requires _fstack, _estack which will be used in _stkchk. + * _stkchk is inserted by mwdt automatically, if _fstack, _estack is not + * set correctly, the brk_s instruction will be called + * here, we use a trick to deceive the compiler. + */ + _fstack = _image_ram_start; + _estack = .; +#endif /* __MWDT_LINKER_CMD__ */ + GROUP_END(RAMABLE_REGION) /* Located in generated directory. This file is populated by the diff --git a/include/toolchain/mwdt.h b/include/toolchain/mwdt.h index 473193c451b2b..9aeb4d1b69f19 100644 --- a/include/toolchain/mwdt.h +++ b/include/toolchain/mwdt.h @@ -71,6 +71,14 @@ #endif #endif /* _SSIZE_T_DEFINED */ +#ifdef CONFIG_NEWLIB_LIBC + #error "ARC MWDT doesn't support building with CONFIG_NEWLIB_LIBC as it doesn't have newlib" +#endif /* CONFIG_NEWLIB_LIBC */ + +#ifdef CONFIG_NATIVE_APPLICATION + #error "ARC MWDT doesn't support building Zephyr as an native application" +#endif /* CONFIG_NATIVE_APPLICATION */ + #define __no_optimization __attribute__((optnone)) diff --git a/tests/subsys/cpp/libcxx/prj.conf b/tests/subsys/cpp/libcxx/prj.conf index 5bb9a62c4a0e8..2bab79b99fefd 100644 --- a/tests/subsys/cpp/libcxx/prj.conf +++ b/tests/subsys/cpp/libcxx/prj.conf @@ -1,4 +1,3 @@ -CONFIG_NEWLIB_LIBC=y CONFIG_CPLUSPLUS=y CONFIG_LIB_CPLUSPLUS=y CONFIG_STD_CPP17=y diff --git a/tests/subsys/cpp/libcxx/testcase.yaml b/tests/subsys/cpp/libcxx/testcase.yaml index a51228e7bc097..f531fe1546add 100644 --- a/tests/subsys/cpp/libcxx/testcase.yaml +++ b/tests/subsys/cpp/libcxx/testcase.yaml @@ -1,19 +1,29 @@ common: - filter: TOOLCHAIN_HAS_NEWLIB == 1 integration_platforms: - mps2_an385 tests: cpp.libcxx.newlib: + filter: TOOLCHAIN_HAS_NEWLIB == 1 toolchain_exclude: xcc min_flash: 54 tags: cpp extra_configs: + - CONFIG_NEWLIB_LIBC=y - CONFIG_NEWLIB_LIBC_NANO=n - CONFIG_EXCEPTIONS=y cpp.libcxx.newlib_nano: + filter: TOOLCHAIN_HAS_NEWLIB == 1 toolchain_exclude: xcc min_flash: 54 tags: cpp timeout: 30 extra_configs: + - CONFIG_NEWLIB_LIBC=y - CONFIG_NEWLIB_LIBC_NANO=y + cpp.libcxx.arcmwdtlib: + toolchain_allow: arcmwdt + platform_allow: nsim_hs nsim_em + min_flash: 54 + tags: cpp + extra_configs: + - CONFIG_ARCMWDT_LIBC=y