Skip to content

Commit

Permalink
cmake: compiler: Add compiler property for no-builtin
Browse files Browse the repository at this point in the history
Abstracts these flags for multiple toolchain support

Signed-off-by: Grant Ramsay <[email protected]>
  • Loading branch information
gramsay0 authored and carlescufi committed Nov 13, 2023
1 parent 679d82c commit a3ff19a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions arch/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ elseif (CONFIG_NATIVE_LIBRARY)

# Do not use the C library from this compiler/host,
# 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(
-nostdinc
-isystem ${COMPILER_OWN_INCLUDE_PATH}
$<TARGET_PROPERTY:compiler,freestanding>
-fno-builtin
$<TARGET_PROPERTY:compiler,no_builtin>
)
endif()
endif()
Expand Down
3 changes: 3 additions & 0 deletions cmake/compiler/arcmwdt/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,6 @@ endif()

# Remove after testing that -Wshadow works
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)
4 changes: 4 additions & 0 deletions cmake/compiler/compiler_flags_template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,7 @@ set_compiler_property(PROPERTY no_global_merge)

# Compiler flag for warning about 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)
3 changes: 3 additions & 0 deletions cmake/compiler/gcc/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,6 @@ set_compiler_property(PROPERTY no_position_independent
set_compiler_property(PROPERTY no_global_merge "")

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)
2 changes: 1 addition & 1 deletion lib/libc/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# 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>)
2 changes: 1 addition & 1 deletion lib/libc/minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ zephyr_library()
set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
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(
source/stdlib/atoi.c
Expand Down
6 changes: 4 additions & 2 deletions modules/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ target_compile_definitions(ot-config INTERFACE
# libraries do not include this header. So we add the defines to all
# OpenThread files through the gcc flag -imacros instead.
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}
)

Expand Down Expand Up @@ -600,7 +601,8 @@ endif()

if(CONFIG_OPENTHREAD_SETTINGS_RAM)
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)

list(APPEND ot_libs openthread-platform-utils-static)
Expand Down

0 comments on commit a3ff19a

Please sign in to comment.