diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f654bf224b..ad65b6a1d1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1792,6 +1792,17 @@ if(CONFIG_BUILD_OUTPUT_STRIPPED) ) endif() +if(CONFIG_BUILD_OUTPUT_COMPRESS_DEBUG_SECTIONS) + list(APPEND + post_build_commands + COMMAND $ + $ + $ + $${KERNEL_ELF_NAME} + $ +) +endif() + if(CONFIG_BUILD_OUTPUT_EXE) if (NOT CONFIG_NATIVE_LIBRARY) list(APPEND diff --git a/Kconfig.zephyr b/Kconfig.zephyr index fd9076a38d9..e44cd327cb5 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -784,6 +784,11 @@ config BUILD_OUTPUT_STRIPPED Build a stripped binary zephyr/zephyr.strip in the build directory. The name of this file can be customized with CONFIG_KERNEL_BIN_NAME. +config BUILD_OUTPUT_COMPRESS_DEBUG_SECTIONS + bool "Compress debug sections in the ELF file" + help + Compress debug sections in the ELF file to reduce the file size. + config BUILD_OUTPUT_ADJUST_LMA string help diff --git a/cmake/bintools/bintools_template.cmake b/cmake/bintools/bintools_template.cmake index 4b48ffe005a..6fa63080dd9 100644 --- a/cmake/bintools/bintools_template.cmake +++ b/cmake/bintools/bintools_template.cmake @@ -66,6 +66,7 @@ # elfconvert_flag_final : Flags that must always be applied last at the elfconvert command # elfconvert_flag_strip_all : Flag that is used for stripping all symbols when converting # elfconvert_flag_strip_debug : Flag that is used to strip debug symbols when converting +# elfconvert_flag_compress_debug_sections: Flag that is used to compress debug sections when converting # elfconvert_flag_intarget : Flag for specifying target used for infile # elfconvert_flag_outtarget : Flag for specifying target to use for converted file. # Target value must be one of those listed described by: elfconvert_formats @@ -141,6 +142,7 @@ set_property(TARGET bintools PROPERTY elfconvert_command ${CMAKE_COMMAND} -E ech set_property(TARGET bintools PROPERTY elfconvert_formats "") set_property(TARGET bintools PROPERTY elfconvert_flag "") set_property(TARGET bintools PROPERTY elfconvert_flag_final "") +set_property(TARGET bintools PROPERTY elfconvert_flag_compress_debug_sections "") set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "") set_property(TARGET bintools PROPERTY elfconvert_flag_section_remove "") set_property(TARGET bintools PROPERTY elfconvert_flag_gapfill "") diff --git a/cmake/bintools/gnu/target_bintools.cmake b/cmake/bintools/gnu/target_bintools.cmake index 8aac55b0400..f61860b31da 100644 --- a/cmake/bintools/gnu/target_bintools.cmake +++ b/cmake/bintools/gnu/target_bintools.cmake @@ -7,6 +7,7 @@ # elfconvert_flag_final : empty # elfconvert_flag_strip_all : -S # elfconvert_flag_strip_debug : -g +# elfconvert_flag_compress_debug_sections: --compress-debug-sections # elfconvert_flag_intarget : --input-target= # elfconvert_flag_outtarget : --output-target= # elfconvert_flag_section_remove: --remove-section= @@ -34,6 +35,8 @@ set_property(TARGET bintools PROPERTY elfconvert_flag_final "") set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-S") set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-g") +set_property(TARGET bintools PROPERTY elfconvert_flag_compress_debug_sections "--compress-debug-sections") + set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "--input-target=") set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "--output-target=") diff --git a/cmake/bintools/llvm/target_bintools.cmake b/cmake/bintools/llvm/target_bintools.cmake index 3a3e04e4388..cd3d55342b5 100644 --- a/cmake/bintools/llvm/target_bintools.cmake +++ b/cmake/bintools/llvm/target_bintools.cmake @@ -7,6 +7,7 @@ # elfconvert_flag_final : empty # elfconvert_flag_strip_all : -S # elfconvert_flag_strip_debug : -g +# elfconvert_flag_compress_debug_sections: --compress-debug-sections # elfconvert_flag_intarget : --input-target= # elfconvert_flag_outtarget : --output-target= # elfconvert_flag_section_remove: --remove-section= @@ -34,6 +35,8 @@ set_property(TARGET bintools PROPERTY elfconvert_flag_final "") set_property(TARGET bintools PROPERTY elfconvert_flag_strip_all "-S") set_property(TARGET bintools PROPERTY elfconvert_flag_strip_debug "-g") +set_property(TARGET bintools PROPERTY elfconvert_flag_compress_debug_sections "--compress-debug-sections") + set_property(TARGET bintools PROPERTY elfconvert_flag_intarget "--input-target=") set_property(TARGET bintools PROPERTY elfconvert_flag_outtarget "--output-target=")