Skip to content

Commit 6c5d806

Browse files
keith-packardstephanosio
authored andcommitted
toolchain: Add COMPILER_FREESTANDING to control use of -ffreestanding
Add an explicit compiler configuration, COMPILER_FREESTANDING, which controls whether the compiler should operate in freestanding or hosted mode (according to the C and C++ language specifications. This depends on having a C library which conforms with the language specification, and the minimal C library does not. Have the minimal C library select COMPILER_FREESTANDING to continue using freestanding mode with that library. For other C libraries, leave this disabled by default while allowing users to enable it if they want to go back to the previous configuration. Signed-off-by: Keith Packard <keithp@keithp.com>
1 parent e9ee638 commit 6c5d806

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ endif()
282282
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
283283
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}")
284284

285-
if(NOT CONFIG_PICOLIBC)
285+
if(CONFIG_COMPILER_FREESTANDING)
286286
# @Intent: Set compiler specific flag for bare metal freestanding option
287287
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,freestanding>>)
288288
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>)

Kconfig.zephyr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ config NATIVE_APPLICATION
320320
Build as a native application that can run on the host and using
321321
resources and libraries provided by the host.
322322

323+
config COMPILER_FREESTANDING
324+
bool "Build in a freestanding compiler mode"
325+
help
326+
Configure the compiler to operate in freestanding mode according to
327+
the C and C++ language specifications. Freestanding mode reduces the
328+
requirements of the compiler and language environment, which can
329+
negatively impact the ability for the compiler to detect errors and
330+
perform optimizations.
331+
323332
choice COMPILER_OPTIMIZATIONS
324333
prompt "Optimization level"
325334
default NO_OPTIMIZATIONS if COVERAGE

lib/libc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ config MINIMAL_LIBC
3737
depends on !NATIVE_APPLICATION
3838
depends on !REQUIRES_FULL_LIBC
3939
depends on SUPPORT_MINIMAL_LIBC
40+
imply COMPILER_FREESTANDING
4041
help
4142
Build with minimal C library.
4243

0 commit comments

Comments
 (0)