Skip to content

Commit

Permalink
llvm: Add support for selecting runtime library
Browse files Browse the repository at this point in the history
This patch adds Kconfig options to select either GNU libgcc or LLVM
compiler-rt. The 'rtlib' flag is provided in a config file, so this
patch introduces 'clang_libgcc.cfg' and 'clang_compiler_rt.cfg' which
enable appropriate library. The file is selected by concatenating
the 'clang_' prefix with library name.

Signed-off-by: Patryk Duda <[email protected]>
  • Loading branch information
duda-patryk authored and carlescufi committed Aug 3, 2023
1 parent 7c76464 commit 4b94fc3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cmake/linker/ld/target_base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 7 additions & 1 deletion cmake/linker/lld/target_base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 4 additions & 0 deletions cmake/toolchain/llvm/clang_compiler_rt.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) 2023 The ChromiumOS Authors
# SPDX-License-Identifier: Apache-2.0

--rtlib=compiler-rt
File renamed without changes.
3 changes: 0 additions & 3 deletions cmake/toolchain/llvm/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
11 changes: 11 additions & 0 deletions cmake/toolchain/llvm/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ source "lib/open-amp/Kconfig"
source "lib/smf/Kconfig"

source "lib/acpi/Kconfig"

source "lib/runtime/Kconfig"
endmenu
26 changes: 26 additions & 0 deletions lib/runtime/Kconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def check_no_undef_outside_kconfig(self, kconf):
"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",
Expand All @@ -647,6 +648,7 @@ def check_no_undef_outside_kconfig(self, kconf):
"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,
Expand Down

0 comments on commit 4b94fc3

Please sign in to comment.