Skip to content

Commit 36bb00d

Browse files
tejlmandnashif
authored andcommitted
armclang: ARM Compiler C library support
Support for ARM Compiler C library. This commit add support for the ARM Compiler C libary in: - Kconfig - libc/armstdc A new Kconfig symbol is added to allow a toolchain to specify if they support linking with the minimal C library. Also the CMake variable `TOOLCHAIN_HAS_NEWLIB` is exported to Kconfig so that CONFIG_NEWLIB_LIBS can only be enabled if the toolchain has newlib. The armclang toolchain selects the CMake scatter file generator and disables support for the LD linker template which is not supported by armlink. For the ARM Compiler C library, a corresponding lib/libc/armstc/ folder with a minimal implementation to work with the ARM Compiler C library is added. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent 28ba86d commit 36bb00d

File tree

18 files changed

+377
-9
lines changed

18 files changed

+377
-9
lines changed

Kconfig.zephyr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ source "$(BOARD_DIR)/Kconfig.defconfig"
2525
osource "$(KCONFIG_BINARY_DIR)/Kconfig.soc.defconfig"
2626
# This loads Zephyr base SoC root defconfigs
2727
osource "soc/$(ARCH)/*/Kconfig.defconfig"
28+
# This loads the toolchain defconfigs
29+
osource "$(TOOLCHAIN_KCONFIG_DIR)/Kconfig.defconfig"
2830

2931
menu "Modules"
3032

cmake/compiler/armclang/compiler_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake)
44
# Required ASM flags when using armclang, this should be handled by CMake, but
55
# fails because of: https://gitlab.kitware.com/cmake/cmake/-/issues/19963
66
set_property(TARGET asm APPEND PROPERTY required "--target=${triple}")
7+
8+
# Only the ARM Compiler C library is currently supported.
9+
set_compiler_property(PROPERTY nostdinc)

cmake/compiler/armclang/target.cmake

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ foreach(isystem_include_dir ${NOSTDINC})
6767
list(APPEND isystem_include_flags -isystem ${isystem_include_dir})
6868
endforeach()
6969

70-
set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags})
70+
set(CMAKE_REQUIRED_FLAGS ${isystem_include_flags})
7171
string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
7272

73-
# Load toolchain_cc-family macros
74-
75-
macro(toolchain_cc_nostdinc)
76-
if(NOT "${ARCH}" STREQUAL "posix")
77-
zephyr_compile_options( -nostdinc)
78-
endif()
79-
endmacro()
73+
if(CONFIG_ARMCLANG_STD_LIBC)
74+
# Zephyr requires AEABI portability to ensure correct functioning of the C
75+
# library, for example error numbers, errno.h.
76+
list(APPEND TOOLCHAIN_C_FLAGS -D_AEABI_PORTABILITY_LEVEL=1)
77+
endif()

cmake/kconfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
103103
BOARD_DIR=${BOARD_DIR}
104104
KCONFIG_BINARY_DIR=${KCONFIG_BINARY_DIR}
105105
TOOLCHAIN_KCONFIG_DIR=${TOOLCHAIN_KCONFIG_DIR}
106+
TOOLCHAIN_HAS_NEWLIB=$<IF:$<BOOL:${TOOLCHAIN_HAS_NEWLIB}>,y,n>
106107
EDT_PICKLE=${EDT_PICKLE}
107108
# Export all Zephyr modules to Kconfig
108109
${ZEPHYR_KCONFIG_MODULES_DIR}

cmake/toolchain/armclang/Kconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config LD_LINKER_SCRIPT_SUPPORTED
5+
bool
6+
default n
7+
8+
choice LINKER_SCRIPT
9+
default CMAKE_LINKER_GENERATOR
10+
endchoice
11+
12+
choice LIBC_IMPLEMENTATION
13+
prompt "C Library Implementation"
14+
default ARMCLANG_STD_LIBC
15+
16+
config ARMCLANG_STD_LIBC
17+
bool "ARM Compiler C library"
18+
help
19+
Use the full Arm Compiler runtime libraries.
20+
A reduced Zephyr minimal libc will be used for library functionality
21+
not provided by ARM Compiler standard libraries.
22+
23+
endchoice
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SUPPORT_MINIMAL_LIBC
5+
bool
6+
default n

doc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ add_custom_target(
142142
ARCH=*
143143
ARCH_DIR=arch
144144
SOC_DIR=soc
145+
TOOLCHAIN_HAS_NEWLIB=y
145146
KCONFIG_BINARY_DIR=${KCONFIG_BINARY_DIR}
146147
KCONFIG_WARN_UNDEF=y
147148
KCONFIG_TURBO_MODE=${KCONFIG_TURBO_MODE}

lib/libc/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ if(CONFIG_NEWLIB_LIBC)
44
add_subdirectory(newlib)
55
elseif(CONFIG_ARCMWDT_LIBC)
66
add_subdirectory(arcmwdt)
7-
else()
7+
elseif(CONFIG_MINIMAL_LIBC)
88
add_subdirectory(minimal)
9+
elseif(CONFIG_ARMCLANG_STD_LIBC)
10+
add_subdirectory(armstdc)
911
endif()

lib/libc/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ config REQUIRES_FULL_LIBC
1111
Helper symbol to indicate some feature requires a C library implementation
1212
with more functionality than what MINIMAL_LIBC provides
1313

14+
config SUPPORT_MINIMAL_LIBC
15+
bool
16+
default y
17+
1418
choice LIBC_IMPLEMENTATION
1519
prompt "C Library Implementation"
1620
default EXTERNAL_LIBC if NATIVE_APPLICATION
@@ -21,6 +25,7 @@ config MINIMAL_LIBC
2125
bool "Minimal C library"
2226
depends on !NATIVE_APPLICATION
2327
depends on !REQUIRES_FULL_LIBC
28+
depends on SUPPORT_MINIMAL_LIBC
2429
help
2530
Build with minimal C library.
2631

lib/libc/armstdc/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_library()
4+
zephyr_library_sources(src/errno.c)
5+
zephyr_library_sources(src/string.c)
6+
zephyr_library_sources(src/libc-hooks.c)
7+
8+
zephyr_system_include_directories(include)

0 commit comments

Comments
 (0)