Skip to content

Commit a3ff19a

Browse files
gramsay0carlescufi
authored andcommitted
cmake: compiler: Add compiler property for no-builtin
Abstracts these flags for multiple toolchain support Signed-off-by: Grant Ramsay <[email protected]>
1 parent 679d82c commit a3ff19a

File tree

7 files changed

+18
-6
lines changed

7 files changed

+18
-6
lines changed

arch/posix/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ elseif (CONFIG_NATIVE_LIBRARY)
9494

9595
# Do not use the C library from this compiler/host,
9696
# but still use the basic compiler headers
97-
# -fno-builtin to avoid the compiler using builtin replacements for std library functions
97+
# no_builtin to avoid the compiler using builtin replacements for std library functions
9898
zephyr_compile_options(
9999
-nostdinc
100100
-isystem ${COMPILER_OWN_INCLUDE_PATH}
101101
$<TARGET_PROPERTY:compiler,freestanding>
102-
-fno-builtin
102+
$<TARGET_PROPERTY:compiler,no_builtin>
103103
)
104104
endif()
105105
endif()

cmake/compiler/arcmwdt/compiler_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,6 @@ endif()
206206

207207
# Remove after testing that -Wshadow works
208208
set_compiler_property(PROPERTY warning_shadow_variables)
209+
210+
set_compiler_property(PROPERTY no_builtin -fno-builtin)
211+
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)

cmake/compiler/compiler_flags_template.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,7 @@ set_compiler_property(PROPERTY no_global_merge)
133133

134134
# Compiler flag for warning about shadow variables
135135
set_compiler_property(PROPERTY warning_shadow_variables)
136+
137+
# Compiler flags to avoid recognizing built-in functions
138+
set_compiler_property(PROPERTY no_builtin)
139+
set_compiler_property(PROPERTY no_builtin_malloc)

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,6 @@ set_compiler_property(PROPERTY no_position_independent
227227
set_compiler_property(PROPERTY no_global_merge "")
228228

229229
set_compiler_property(PROPERTY warning_shadow_variables -Wshadow)
230+
231+
set_compiler_property(PROPERTY no_builtin -fno-builtin)
232+
set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)

lib/libc/common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_MALLOC source/stdlib/malloc.c)
88
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_STRNLEN source/string/strnlen.c)
99

1010
# Prevent compiler from optimizing calloc into an infinite recursive call
11-
zephyr_library_cc_option(-fno-builtin-malloc)
11+
zephyr_library_compile_options($<TARGET_PROPERTY:compiler,no_builtin_malloc>)

lib/libc/minimal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ zephyr_library()
77
set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated)
88
set(STRERROR_TABLE_H ${GEN_DIR}/libc/minimal/strerror_table.h)
99

10-
zephyr_library_cc_option(-fno-builtin)
10+
zephyr_library_compile_options($<TARGET_PROPERTY:compiler,no_builtin>)
1111

1212
zephyr_library_sources(
1313
source/stdlib/atoi.c

modules/openthread/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ target_compile_definitions(ot-config INTERFACE
547547
# libraries do not include this header. So we add the defines to all
548548
# OpenThread files through the gcc flag -imacros instead.
549549
target_compile_options(ot-config INTERFACE
550-
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS> -fno-builtin
550+
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>
551+
$<TARGET_PROPERTY:compiler,no_builtin>
551552
-imacros ${AUTOCONF_H}
552553
)
553554

@@ -600,7 +601,8 @@ endif()
600601

601602
if(CONFIG_OPENTHREAD_SETTINGS_RAM)
602603
target_compile_options(openthread-platform-utils PRIVATE
603-
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS> -fno-builtin)
604+
$<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>
605+
$<TARGET_PROPERTY:compiler,no_builtin>)
604606
add_dependencies(openthread-platform-utils syscall_list_h_target)
605607

606608
list(APPEND ot_libs openthread-platform-utils-static)

0 commit comments

Comments
 (0)