diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fb025d9abc..ba1cc198b96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -396,7 +396,8 @@ zephyr_ld_options( # Sort the common symbols and each input section by alignment # in descending order to minimize padding between these symbols. -zephyr_ld_options( +zephyr_ld_option_ifdef( + CONFIG_LINKER_SORT_BY_ALIGNMENT ${LINKERFLAGPREFIX},--sort-common=descending ${LINKERFLAGPREFIX},--sort-section=alignment ) diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 99502c9d80d..9ada8a517b1 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -186,6 +186,14 @@ config CHECK_LINK_MAP Run a linker address generation validity checker at the end of the build. +config LINKER_SORT_BY_ALIGNMENT + bool "Sort input sections by alignment" + default y + help + This turns on the linker flag to sort sections by alignment + in decreasing size of symbols. This helps to minimize + padding between symbols. + endmenu menu "Compiler Options"