Skip to content

Commit 03fcfcd

Browse files
microbuildernashif
authored andcommitted
cmake: compiler: Add func_instrumentation flag
Adds a new compiler flag to enable function instrumentation injection at compile time for compilers that support it. Adds support for this flag to GCC when `CONFIG_INSTRUMENTATION` is enabled, setting the `-finstrument-functions` flag during compilation. Signed-off-by: Kevin Townsend <[email protected]> Signed-off-by: Gustavo Romero <[email protected]> Signed-off-by: Maciej Sobkowski <[email protected]>
1 parent 9005f86 commit 03fcfcd

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,24 @@ zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,no_p
578578
zephyr_link_libraries_ifndef(CONFIG_NATIVE_LIBRARY
579579
$<TARGET_PROPERTY:linker,no_position_independent>)
580580

581+
if(CONFIG_INSTRUMENTATION)
582+
# @Intent: Enable function instrumentation injection at compile time
583+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,func_instrumentation>>)
584+
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,func_instrumentation>>)
585+
586+
# @Intent: Enable function blocklist for the instrumentation subsystem
587+
if(CONFIG_INSTRUMENTATION_EXCLUDE_FUNCTION_LIST)
588+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,func_instrumentation_exclude_function_list>>)
589+
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,func_instrumentation_exclude_function_list>>)
590+
endif()
591+
592+
# @Intent: Enable file blocklist for the instrumentation subsystem
593+
if(CONFIG_INSTRUMENTATION_EXCLUDE_FILE_LIST)
594+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,func_instrumentation_exclude_file_list>>)
595+
zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,func_instrumentation_exclude_file_list>>)
596+
endif()
597+
endif()
598+
581599
# Allow the user to inject options when calling cmake, e.g.
582600
# 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..'
583601
include(cmake/extra_flags.cmake)

cmake/compiler/compiler_flags_template.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,6 @@ set_compiler_property(PROPERTY no_function_sections)
171171

172172
# Compiler flag for not placing variables in their own sections:
173173
set_compiler_property(PROPERTY no_data_sections)
174+
175+
# Compiler flag to enable function instrumentation
176+
set_compiler_property(PROPERTY func_instrumentation)

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,10 @@ set_compiler_property(PROPERTY no_function_sections "-fno-function-sections")
279279

280280
# Compiler flag for not placing variables in their own sections:
281281
set_compiler_property(PROPERTY no_data_sections "-fno-data-sections")
282+
283+
# Compiler flag to enable function instrumentation
284+
set_compiler_property(PROPERTY func_instrumentation "-finstrument-functions")
285+
set_compiler_property(PROPERTY func_instrumentation_exclude_function_list
286+
"-finstrument-functions-exclude-function-list=${CONFIG_INSTRUMENTATION_EXCLUDE_FUNCTION_LIST}")
287+
set_compiler_property(PROPERTY func_instrumentation_exclude_file_list
288+
"-finstrument-functions-exclude-file-list=${CONFIG_INSTRUMENTATION_EXCLUDE_FILE_LIST}")

0 commit comments

Comments
 (0)