Skip to content

Commit 8033ab7

Browse files
cmake: introduce instrumentation flag
Introduce support for enabling the instrumentation flag. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent a17094e commit 8033ab7

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ zephyr_compile_options($<$<COMPILE_LANGUAGE:CXX>:$<TARGET_PROPERTY:compiler,no_p
468468
zephyr_link_libraries_ifndef(CONFIG_NATIVE_LIBRARY
469469
$<TARGET_PROPERTY:linker,no_position_independent>)
470470

471+
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,func_instrumentation>>)
472+
471473
# Allow the user to inject options when calling cmake, e.g.
472474
# 'cmake -DEXTRA_CFLAGS="-Werror -Wno-deprecated-declarations" ..'
473475
include(cmake/extra_flags.cmake)

Kconfig.zephyr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ config NO_OPTIMIZATIONS
538538
default stack sizes in order to avoid stack overflows.
539539
endchoice
540540

541+
config INSTRUMENTATION
542+
bool "Compile instrumentation"
543+
541544
config LTO
542545
bool "Link Time Optimization"
543546
depends on !(GEN_ISR_TABLES || GEN_IRQ_VECTOR_TABLE) || ISR_TABLES_LOCAL_DECLARATION

cmake/compiler/compiler_flags_template.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,6 @@ set_compiler_property(PROPERTY specs)
149149

150150
# Compiler flag for defining preinclude files.
151151
set_compiler_property(PROPERTY include_file)
152+
153+
# Compiler flag to enable function instrumentation
154+
set_compiler_property(PROPERTY func_instrumentation)

cmake/compiler/gcc/compiler_flags.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,8 @@ set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc)
255255
set_compiler_property(PROPERTY specs -specs=)
256256

257257
set_compiler_property(PROPERTY include_file -include)
258+
259+
# Compiler flag to enable function instrumentation
260+
if(CONFIG_INSTRUMENTATION)
261+
set_compiler_property(PROPERTY func_instrumentation -finstrument-functions)
262+
endif()

include/zephyr/toolchain/gcc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ do { \
289289
#define __attribute_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
290290
#endif
291291

292+
#define __no_instrument_function __attribute__((__no_instrument_function__))
293+
292294
/* Builtins with availability that depend on the compiler version. */
293295
#if __GNUC__ >= 5
294296
#define HAS_BUILTIN___builtin_add_overflow 1

0 commit comments

Comments
 (0)