diff --git a/cmake/linker/ld/target_base.cmake b/cmake/linker/ld/target_base.cmake index 455f834ac90..b92ec877371 100644 --- a/cmake/linker/ld/target_base.cmake +++ b/cmake/linker/ld/target_base.cmake @@ -34,8 +34,14 @@ macro(toolchain_ld_base) endif() if (CONFIG_LLVM_USE_LD) + if(CONFIG_LIBGCC_RTLIB) + set(runtime_lib "libgcc") + elseif(CONFIG_COMPILER_RT_RTLIB) + set(runtime_lib "compiler_rt") + endif() + zephyr_link_libraries( - --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang.cfg + --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang_${runtime_lib}.cfg ) endif() diff --git a/cmake/linker/lld/target_base.cmake b/cmake/linker/lld/target_base.cmake index bea80290143..82abe1fa142 100644 --- a/cmake/linker/lld/target_base.cmake +++ b/cmake/linker/lld/target_base.cmake @@ -41,7 +41,13 @@ macro(toolchain_ld_base) ) endif() + if(CONFIG_LIBGCC_RTLIB) + set(runtime_lib "libgcc") + elseif(CONFIG_COMPILER_RT_RTLIB) + set(runtime_lib "compiler_rt") + endif() + zephyr_link_libraries( - --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang.cfg + --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang_${runtime_lib}.cfg ) endmacro() diff --git a/cmake/toolchain/llvm/clang_compiler_rt.cfg b/cmake/toolchain/llvm/clang_compiler_rt.cfg new file mode 100644 index 00000000000..cd0d01ef0e9 --- /dev/null +++ b/cmake/toolchain/llvm/clang_compiler_rt.cfg @@ -0,0 +1,4 @@ +# Copyright (c) 2023 The ChromiumOS Authors +# SPDX-License-Identifier: Apache-2.0 + +--rtlib=compiler-rt diff --git a/cmake/toolchain/llvm/clang.cfg b/cmake/toolchain/llvm/clang_libgcc.cfg similarity index 100% rename from cmake/toolchain/llvm/clang.cfg rename to cmake/toolchain/llvm/clang_libgcc.cfg diff --git a/cmake/toolchain/llvm/generic.cmake b/cmake/toolchain/llvm/generic.cmake index f0a8cf45355..0b138c2868c 100644 --- a/cmake/toolchain/llvm/generic.cmake +++ b/cmake/toolchain/llvm/generic.cmake @@ -19,7 +19,4 @@ set(BINTOOLS llvm) set(TOOLCHAIN_HAS_NEWLIB OFF CACHE BOOL "True if toolchain supports newlib") -list(APPEND TOOLCHAIN_C_FLAGS --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang.cfg) -list(APPEND TOOLCHAIN_LD_FLAGS --config ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang.cfg) - message(STATUS "Found toolchain: host (clang/ld)") diff --git a/cmake/toolchain/llvm/target.cmake b/cmake/toolchain/llvm/target.cmake index cef6c3296e7..38097229125 100644 --- a/cmake/toolchain/llvm/target.cmake +++ b/cmake/toolchain/llvm/target.cmake @@ -42,3 +42,14 @@ if(DEFINED triple) unset(triple) endif() + +if(CONFIG_LIBGCC_RTLIB) + set(runtime_lib "libgcc") +elseif(CONFIG_COMPILER_RT_RTLIB) + set(runtime_lib "compiler_rt") +endif() + +list(APPEND TOOLCHAIN_C_FLAGS --config + ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang_${runtime_lib}.cfg) +list(APPEND TOOLCHAIN_LD_FLAGS --config + ${ZEPHYR_BASE}/cmake/toolchain/llvm/clang_${runtime_lib}.cfg) diff --git a/lib/Kconfig b/lib/Kconfig index b57628a759d..761b1393e57 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -18,4 +18,6 @@ source "lib/open-amp/Kconfig" source "lib/smf/Kconfig" source "lib/acpi/Kconfig" + +source "lib/runtime/Kconfig" endmenu diff --git a/lib/runtime/Kconfig b/lib/runtime/Kconfig new file mode 100644 index 00000000000..afb78f5b82b --- /dev/null +++ b/lib/runtime/Kconfig @@ -0,0 +1,26 @@ +# Copyright (c) 2023 The ChromiumOS Authors +# SPDX-License-Identifier: Apache-2.0 + +config COMPILER_RT_SUPPORTED + bool + default y + depends on "${ZEPHYR_TOOLCHAIN_VARIANT}" = "llvm" + help + Selected when the compiler supports compiler-rt runtime library. + +choice RTLIB_IMPLEMENTATION + prompt "Runtime library implementation" + default LIBGCC_RTLIB + +config LIBGCC_RTLIB + bool "GNU Libgcc" + help + Use libgcc as a runtime library. + +config COMPILER_RT_RTLIB + bool "LLVM compiler-rt" + depends on COMPILER_RT_SUPPORTED + help + Use LLVM compiler-rt as a runtime library. + +endchoice diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index 215d91203fb..aa3daf2f572 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -631,6 +631,7 @@ flagged. "CDC_ACM_PORT_NAME_", "CLOCK_STM32_SYSCLK_SRC_", "CMU", + "COMPILER_RT_RTLIB", "BT_6LOWPAN", # Defined in Linux, mentioned in docs "CMD_CACHE", # Defined in U-Boot, mentioned in docs "COUNTER_RTC_STM32_CLOCK_SRC", @@ -647,6 +648,7 @@ flagged. "FOO_SETTING_1", "FOO_SETTING_2", "LSM6DSO_INT_PIN", + "LIBGCC_RTLIB", "LLVM_USE_LD", # Both LLVM_USE_* are in cmake/toolchain/llvm/Kconfig "LLVM_USE_LLD", # which are only included if LLVM is selected but # not other toolchains. Compliance check would complain,