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>
This commit is contained in:
Keith Packard 2023-02-08 14:56:50 -08:00 committed by Stephanos Ioannidis
parent e9ee6388f6
commit 6c5d806bcb
3 changed files with 11 additions and 1 deletions

View file

@ -282,7 +282,7 @@ endif()
# @Intent: Set compiler specific macro inclusion of AUTOCONF_H
zephyr_compile_options("SHELL: $<TARGET_PROPERTY:compiler,imacros> ${AUTOCONF_H}")
if(NOT CONFIG_PICOLIBC)
if(CONFIG_COMPILER_FREESTANDING)
# @Intent: Set compiler specific flag for bare metal freestanding option
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,freestanding>>)
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>)

View file

@ -320,6 +320,15 @@ config NATIVE_APPLICATION
Build as a native application that can run on the host and using
resources and libraries provided by the host.
config COMPILER_FREESTANDING
bool "Build in a freestanding compiler mode"
help
Configure the compiler to operate in freestanding mode according to
the C and C++ language specifications. Freestanding mode reduces the
requirements of the compiler and language environment, which can
negatively impact the ability for the compiler to detect errors and
perform optimizations.
choice COMPILER_OPTIMIZATIONS
prompt "Optimization level"
default NO_OPTIMIZATIONS if COVERAGE

View file

@ -37,6 +37,7 @@ config MINIMAL_LIBC
depends on !NATIVE_APPLICATION
depends on !REQUIRES_FULL_LIBC
depends on SUPPORT_MINIMAL_LIBC
imply COMPILER_FREESTANDING
help
Build with minimal C library.