From 3f8f7130e7ca02a9b58c5204c92e1eb7c3fa8880 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Wed, 29 Mar 2023 10:11:46 +0100 Subject: [PATCH] kconfig,toolchain: add an option for compiler save-temps Add a Kconfig option to set the compiler save-temps flag and set the GCC implementation. This is very useful for troubleshooting macro expansion issues, having an option allows a user to set it like any other config option. Signed-off-by: Fabio Baltieri --- CMakeLists.txt | 5 +++++ Kconfig.zephyr | 6 ++++++ cmake/compiler/clang/compiler_flags.cmake | 3 +++ cmake/compiler/compiler_flags_template.cmake | 3 +++ cmake/compiler/gcc/compiler_flags.cmake | 3 +++ 5 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdf21a45135..405b18e2d5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,11 @@ zephyr_compile_options($) # @Intent: Set compiler specific flag for production of debug information zephyr_compile_options($) +if(CONFIG_COMPILER_SAVE_TEMPS) + # @Intent: Set compiler specific flag for saving temporary object files + zephyr_compile_options($) +endif() + if(CONFIG_COMPILER_COLOR_DIAGNOSTICS) # @Intent: Set compiler specific flag for diagnostic messages zephyr_compile_options($) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 54e16ae4f7f..8f9576b7c97 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -363,6 +363,12 @@ config COMPILER_WARNINGS_AS_ERRORS help Turn on "warning as error" toolchain flags +config COMPILER_SAVE_TEMPS + bool "Save temporary object files" + help + Instruct the compiler to save the temporary intermediate files + permanently. These can be useful for troubleshooting build issues. + config COMPILER_COLOR_DIAGNOSTICS bool "Colored diagnostics" default y diff --git a/cmake/compiler/clang/compiler_flags.cmake b/cmake/compiler/clang/compiler_flags.cmake index 8b6dd088741..649aa3e6007 100644 --- a/cmake/compiler/clang/compiler_flags.cmake +++ b/cmake/compiler/clang/compiler_flags.cmake @@ -20,6 +20,9 @@ set_property(TARGET compiler PROPERTY coverage --coverage -fno-inline) # clang flag for colourful diagnostic messages set_compiler_property(PROPERTY diagnostic -fcolor-diagnostics) +# clang flag to save temporary object files +set_compiler_property(PROPERTY save_temps -save-temps) + ####################################################### # This section covers flags related to warning levels # ####################################################### diff --git a/cmake/compiler/compiler_flags_template.cmake b/cmake/compiler/compiler_flags_template.cmake index e03fb6152a6..4614866b2ce 100644 --- a/cmake/compiler/compiler_flags_template.cmake +++ b/cmake/compiler/compiler_flags_template.cmake @@ -103,6 +103,9 @@ set_compiler_property(PROPERTY freestanding) # Flag to include debugging symbol in compilation set_compiler_property(PROPERTY debug) +# Flags to save temporary object files +set_compiler_property(PROPERTY save_temps) + set_compiler_property(PROPERTY no_common) # Flags for imacros. The specific header must be appended by user. diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 0066ee231a1..5d168233b21 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -180,6 +180,9 @@ check_set_compiler_property(PROPERTY freestanding -ffreestanding) # Flag to enable debugging set_compiler_property(PROPERTY debug -g) +# Flags to save temporary object files +set_compiler_property(PROPERTY save_temps -save-temps=obj) + # GCC 11 by default emits DWARF version 5 which cannot be parsed by # pyelftools. Can be removed once pyelftools supports v5. check_set_compiler_property(APPEND PROPERTY debug -gdwarf-4)