cmake: compiler: Add compiler property for no-builtin

Abstracts these flags for multiple toolchain support

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
This commit is contained in:
Grant Ramsay 2023-11-13 09:34:50 +13:00 committed by Carles Cufí
commit a3ff19a39e
7 changed files with 18 additions and 6 deletions

View file

@ -94,12 +94,12 @@ elseif (CONFIG_NATIVE_LIBRARY)
# Do not use the C library from this compiler/host, # Do not use the C library from this compiler/host,
# but still use the basic compiler headers # but still use the basic compiler headers
# -fno-builtin to avoid the compiler using builtin replacements for std library functions # no_builtin to avoid the compiler using builtin replacements for std library functions
zephyr_compile_options( zephyr_compile_options(
-nostdinc -nostdinc
-isystem ${COMPILER_OWN_INCLUDE_PATH} -isystem ${COMPILER_OWN_INCLUDE_PATH}
$<TARGET_PROPERTY:compiler,freestanding> $<TARGET_PROPERTY:compiler,freestanding>
-fno-builtin $<TARGET_PROPERTY:compiler,no_builtin>
) )
endif() endif()
endif() endif()

View file

@ -206,3 +206,6 @@ endif()
# Remove after testing that -Wshadow works # Remove after testing that -Wshadow works
set_compiler_property(PROPERTY warning_shadow_variables) set_compiler_property(PROPERTY warning_shadow_variables)
set_compiler_property(PROPERTY no_builtin -fno-builtin)
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)

View file

@ -133,3 +133,7 @@ set_compiler_property(PROPERTY no_global_merge)
# Compiler flag for warning about shadow variables # Compiler flag for warning about shadow variables
set_compiler_property(PROPERTY warning_shadow_variables) set_compiler_property(PROPERTY warning_shadow_variables)
# Compiler flags to avoid recognizing built-in functions
set_compiler_property(PROPERTY no_builtin)
set_compiler_property(PROPERTY no_builtin_malloc)

View file

@ -227,3 +227,6 @@ set_compiler_property(PROPERTY no_position_independent
set_compiler_property(PROPERTY no_global_merge "") set_compiler_property(PROPERTY no_global_merge "")
set_compiler_property(PROPERTY warning_shadow_variables -Wshadow) set_compiler_property(PROPERTY warning_shadow_variables -Wshadow)
set_compiler_property(PROPERTY no_builtin -fno-builtin)
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)

View file

@ -8,4 +8,4 @@ zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_MALLOC source/stdlib/malloc.c)
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_STRNLEN source/string/strnlen.c) zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_STRNLEN source/string/strnlen.c)
# Prevent compiler from optimizing calloc into an infinite recursive call # Prevent compiler from optimizing calloc into an infinite recursive call
zephyr_library_cc_option(-fno-builtin-malloc) zephyr_library_compile_options($<TARGET_PROPERTY:compiler,no_builtin_malloc>)

View file

@ -7,7 +7,7 @@ zephyr_library()
set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated) set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
set(STRERROR_TABLE_H ${GEN_DIR}/libc/minimal/strerror_table.h) set(STRERROR_TABLE_H ${GEN_DIR}/libc/minimal/strerror_table.h)
zephyr_library_cc_option(-fno-builtin) zephyr_library_compile_options($<TARGET_PROPERTY:compiler,no_builtin>)
zephyr_library_sources( zephyr_library_sources(
source/stdlib/atoi.c source/stdlib/atoi.c

View file

@ -547,7 +547,8 @@ target_compile_definitions(ot-config INTERFACE
# libraries do not include this header. So we add the defines to all # libraries do not include this header. So we add the defines to all
# OpenThread files through the gcc flag -imacros instead. # OpenThread files through the gcc flag -imacros instead.
target_compile_options(ot-config INTERFACE target_compile_options(ot-config INTERFACE
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS> -fno-builtin $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>
$<TARGET_PROPERTY:compiler,no_builtin>
-imacros ${AUTOCONF_H} -imacros ${AUTOCONF_H}
) )
@ -600,7 +601,8 @@ endif()
if(CONFIG_OPENTHREAD_SETTINGS_RAM) if(CONFIG_OPENTHREAD_SETTINGS_RAM)
target_compile_options(openthread-platform-utils PRIVATE target_compile_options(openthread-platform-utils PRIVATE
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS> -fno-builtin) $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>
$<TARGET_PROPERTY:compiler,no_builtin>)
add_dependencies(openthread-platform-utils syscall_list_h_target) add_dependencies(openthread-platform-utils syscall_list_h_target)
list(APPEND ot_libs openthread-platform-utils-static) list(APPEND ot_libs openthread-platform-utils-static)