diff --git a/CMakeLists.txt b/CMakeLists.txt index 74052ded692..0effc0c381c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1104,10 +1104,19 @@ if(CONFIG_CODE_DATA_RELOCATION) endif() if(CONFIG_USERSPACE) - zephyr_get_compile_options_for_lang_as_string(C compiler_flags_priv) + # Go for raw properties here since zephyr_get_compile_options_for_lang() + # processes the list of options, and wraps it in a $" "" - NO_COVERAGE_FLAGS "${compiler_flags_priv}" - ) + KOBJECT_HASH_COMPILE_OPTIONS "${compiler_flags_priv}") + + list(APPEND KOBJECT_HASH_COMPILE_OPTIONS + $ + $) set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py) endif() @@ -1305,11 +1314,13 @@ if(CONFIG_USERSPACE) add_library( kobj_prebuilt_hash_output_lib OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} - ) + ) - set_source_files_properties(${KOBJECT_PREBUILT_HASH_OUTPUT_SRC} - PROPERTIES COMPILE_FLAGS - "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections") + # set_target_properties sets ALL properties, target_compile_options() adds + # and KOBJECT_HASH_COMPILE_OPTIONS contains all the options. + set_target_properties(kobj_prebuilt_hash_output_lib PROPERTIES + COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}" + ) target_compile_definitions(kobj_prebuilt_hash_output_lib PRIVATE $ @@ -1514,9 +1525,9 @@ if(CONFIG_USERSPACE) OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${KOBJECT_HASH_OUTPUT_SRC} ) - set_source_files_properties(${KOBJECT_HASH_OUTPUT_SRC} - PROPERTIES COMPILE_FLAGS - "${NO_COVERAGE_FLAGS} -fno-function-sections -fno-data-sections") + set_target_properties(kobj_hash_output_lib PROPERTIES + COMPILE_OPTIONS "${KOBJECT_HASH_COMPILE_OPTIONS}" + ) target_compile_definitions(kobj_hash_output_lib PRIVATE $ diff --git a/cmake/compiler/arcmwdt/compiler_flags.cmake b/cmake/compiler/arcmwdt/compiler_flags.cmake index 2827c954e75..fa5370628ea 100644 --- a/cmake/compiler/arcmwdt/compiler_flags.cmake +++ b/cmake/compiler/arcmwdt/compiler_flags.cmake @@ -215,3 +215,9 @@ set_compiler_property(PROPERTY warning_no_array_bounds) set_compiler_property(PROPERTY no_builtin -fno-builtin) set_compiler_property(PROPERTY no_builtin_malloc -fno-builtin-malloc) + +# Compiler flag for not placing functions in their own sections: +set_compiler_property(PROPERTY no_function_sections "-fno-function-sections") + +# Compiler flag for not placing variables in their own sections: +set_compiler_property(PROPERTY no_data_sections "-fno-data-sections") diff --git a/cmake/compiler/compiler_flags_template.cmake b/cmake/compiler/compiler_flags_template.cmake index bd8733ce9d0..34acddfa362 100644 --- a/cmake/compiler/compiler_flags_template.cmake +++ b/cmake/compiler/compiler_flags_template.cmake @@ -161,3 +161,9 @@ set_compiler_property(PROPERTY include_file) set_compiler_property(PROPERTY cmse) set_property(TARGET asm PROPERTY cmse) + +# Compiler flag for not placing functions in their own sections: +set_compiler_property(PROPERTY no_function_sections) + +# Compiler flag for not placing variables in their own sections: +set_compiler_property(PROPERTY no_data_sections) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 53b42823717..9d4989fea47 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -266,3 +266,9 @@ set_compiler_property(PROPERTY include_file -include) set_compiler_property(PROPERTY cmse -mcmse) set_property(TARGET asm PROPERTY cmse -mcmse) + +# Compiler flag for not placing functions in their own sections: +set_compiler_property(PROPERTY no_function_sections "-fno-function-sections") + +# Compiler flag for not placing variables in their own sections: +set_compiler_property(PROPERTY no_data_sections "-fno-data-sections")