From 77599bb9c646e86d1317a9fa78444f27bcc6c7e6 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 7 Nov 2022 13:50:51 -0800 Subject: [PATCH 1/3] cmake/gcc: Don't use -nostdinc with toolchain picolibc When using picolibc from the toolchain, we need to use the standard include paths to make sure the library headers are found, especially for libstdc++. Add toolchain picolibc to the list of cases for which this is the case. Signed-off-by: Keith Packard --- cmake/compiler/gcc/compiler_flags.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 2dbb1e3e08eae..cfa594d4314de 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -104,6 +104,7 @@ set_compiler_property(PROPERTY warning_error_coding_guideline set_compiler_property(PROPERTY cstd -std=) if (NOT CONFIG_NEWLIB_LIBC AND + NOT (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_USE_MODULE) AND NOT COMPILER STREQUAL "xcc" AND NOT CONFIG_HAS_ESPRESSIF_HAL AND NOT CONFIG_NATIVE_APPLICATION) From 0fd94bbf33d205163d7f3facd6aa85c6fea1cf86 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 2 Nov 2022 13:11:41 -0700 Subject: [PATCH 2/3] libc/picolibc: Clean up Picolibc Kconfig for C++ libstdc++ is supported with Picolibc only when the toolchain version of Picolibc is use -- libstdc++ must be built using a specific Picolibc build and libstdc++ is included with the toolchain. Ideally, we'd allow the use of the Picolibc module whenever we weren't using the GNU libstdc++, including when using the minimal libc++. However, the obvious dependency settings create a loop: config PICOLIBC depends on PICOLIBC_SUPPORTED config PICOLIBC_SUPPORTED depends on !(GLIBCXX_LIBCPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr") config GLIBCXX_LIBCPP depends on NEWLIB_LIBC || PICOLIBC To break this loop, we replace GLIBCXX_LIBCPP in the second block with CPP: config PICOLIBC_SUPPORTED depends on !(CPP && "$(ZEPHYR_TOOCHAIN_VARIANT" = "zephyr") This means that picolibc cannot be used with any C++ apps when using the Zephyr SDK, even when not using the GNU libstdc++. However, Zephyr SDK 0.16 will come with an additional Kconfig file that includes: config PICOLIBC_SUPPORTED def_bool y depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr" This will override the Kconfig bits included in Zephyr and allow use of the Picolibc module with C++ code, including using the minimal libc++ bits. Signed-off-by: Keith Packard --- lib/cpp/Kconfig | 2 +- lib/libc/Kconfig | 3 +++ lib/libc/picolibc/Kconfig | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/cpp/Kconfig b/lib/cpp/Kconfig index b7bfbf24b1a99..131415b87aad2 100644 --- a/lib/cpp/Kconfig +++ b/lib/cpp/Kconfig @@ -85,7 +85,7 @@ config MINIMAL_LIBCPP config GLIBCXX_LIBCPP bool "GNU C++ Standard Library" depends on !NATIVE_APPLICATION - depends on NEWLIB_LIBC || (PICOLIBC && !PICOLIBC_USE_MODULE) + depends on NEWLIB_LIBC || PICOLIBC help Build with GNU C++ Standard Library (libstdc++) provided by the GNU Compiler Collection (GCC)-based toolchain. diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 697a6ee99439d..9e8b618975f40 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -15,10 +15,12 @@ config SUPPORT_MINIMAL_LIBC bool default y +# Picolibc with C++ support in Zephyr SDK is handled by Zephyr SDK's own Kconfig. config PICOLIBC_SUPPORTED bool depends on ARC || ARM || ARM64 || MIPS || RISCV depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" != "arcmwdt" + depends on !(CPP && "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr") default y help Selected when the target has support for picolibc. @@ -42,6 +44,7 @@ config PICOLIBC select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE select LIBC_ERRNO if THREAD_LOCAL_STORAGE depends on !NATIVE_APPLICATION + depends on PICOLIBC_SUPPORTED help Build with picolibc library. The picolibc library is built as a module if PICOLIBC_MODULE is set, otherwise picolibc is diff --git a/lib/libc/picolibc/Kconfig b/lib/libc/picolibc/Kconfig index 492a02a87f03c..b52301fff716a 100644 --- a/lib/libc/picolibc/Kconfig +++ b/lib/libc/picolibc/Kconfig @@ -4,9 +4,10 @@ if PICOLIBC config PICOLIBC_USE_MODULE - bool "Use picolibc module" + bool "Picolibc as module" default y - select PICOLIBC_MODULE + depends on ZEPHYR_PICOLIBC_MODULE + depends on !GLIBCXX_LIBCPP help Use picolibc module instead of picolibc included with toolchain From fe114270b22e3ab33fe79757a5f88f59be1de872 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 6 Jan 2023 13:36:21 -0800 Subject: [PATCH 3/3] subsys/cpp: Also run C++ tests with picolibc when possible When the toolchain has picolibc support, run samples/subsys/cpp/cpp_synchronization and tests/subsys/cpp/libcxx tests using it. Signed-off-by: Keith Packard --- samples/cpp/cpp_synchronization/sample.yaml | 15 +++++++++++++++ tests/lib/cpp/libcxx/testcase.yaml | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/samples/cpp/cpp_synchronization/sample.yaml b/samples/cpp/cpp_synchronization/sample.yaml index e3e9669a1ad09..2b9311e2067c3 100644 --- a/samples/cpp/cpp_synchronization/sample.yaml +++ b/samples/cpp/cpp_synchronization/sample.yaml @@ -13,3 +13,18 @@ tests: - "Create semaphore (.*)" - "main: Hello World!" - "coop_thread_entry: Hello World!" + sample.cpp.synchronization.picolibc: + filter: CONFIG_PICOLIBC_SUPPORTED + extra_configs: + - CONFIG_PICOLIBC=y + tags: cpp + toolchain_exclude: issm xcc + integration_platforms: + - qemu_x86 + harness: console + harness_config: + type: multi_line + regex: + - "Create semaphore (.*)" + - "main: Hello World!" + - "coop_thread_entry: Hello World!" diff --git a/tests/lib/cpp/libcxx/testcase.yaml b/tests/lib/cpp/libcxx/testcase.yaml index 3a1371345b506..a57941b182792 100644 --- a/tests/lib/cpp/libcxx/testcase.yaml +++ b/tests/lib/cpp/libcxx/testcase.yaml @@ -23,6 +23,17 @@ tests: - CONFIG_GLIBCXX_LIBCPP=y integration_platforms: - mps2_an385 + cpp.libcxx.glibcxx.picolibc: + filter: TOOLCHAIN_HAS_PICOLIBC == 1 + toolchain_exclude: xcc + tags: cpp + timeout: 60 + extra_configs: + - CONFIG_PICOLIBC=y + - CONFIG_GLIBCXX_LIBCPP=y + - CONFIG_CPP_EXCEPTIONS=y + integration_platforms: + - mps2_an385 cpp.libcxx.arcmwdtlib: toolchain_allow: arcmwdt min_flash: 54