toolchain: iar: Put KEEP on init-blocks

To circumvent peculiarities in the linker, the _init blocks
(as well as their content) needs to be tagged with keep.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
This commit is contained in:
Björn Bergman 2025-02-17 15:03:54 +00:00 committed by Fabio Baltieri
commit 4b3cd02e6a

View file

@ -606,6 +606,15 @@ function(section_to_string)
list(APPEND to_be_kept "section ${setting}")
endforeach()
endif()
# In ilink if a block with min_size=X does not match any input sections,
# its _init block may be discarded despite being needed for spacing with
# other _init blocks. To get around tihs, lets tag min_size blocks as keep.
if(CONFIG_IAR_ZEPHYR_INIT
AND DEFINED group_parent_vma AND DEFINED group_parent_lma
AND DEFINED i_min_size
AND NOT ${noinit})
list(APPEND to_be_kept "block ${name_clean}_${idx}_init")
endif()
if(DEFINED symbols)
list(LENGTH symbols symbols_count)
if(${symbols_count} GREATER 0)
@ -784,8 +793,7 @@ function(section_to_string)
list(JOIN current_sections ", " SELECTORS)
set(TEMP "${TEMP}\ndo not initialize {\n${SELECTORS}\n};")
elseif(DEFINED group_parent_vma AND DEFINED group_parent_lma)
if(DEFINED current_sections)
if(CONFIG_IAR_DATA_INIT)
if(CONFIG_IAR_DATA_INIT AND DEFINED current_sections)
set(TEMP "${TEMP}\ninitialize by copy\n")
set(TEMP "${TEMP}{\n")
foreach(section ${current_sections})
@ -809,13 +817,15 @@ function(section_to_string)
string(REGEX REPLACE "(rw)([ \t\r\n]+)(section[ \t\r\n]+)" "ro\\2\\3" INIT_TEMP "${INIT_TEMP}")
string(REGEX REPLACE "alphabetical order, " "" INIT_TEMP "${INIT_TEMP}")
string(REGEX REPLACE "{ readwrite }" "{ }" INIT_TEMP "${INIT_TEMP}")
set(TEMP "${TEMP}\n${INIT_TEMP}\n")
# If any content is marked as keep, is has to be applied to the init block
# too, esp. for blocks that are not referenced (e.g. empty blocks wiht min_size)
# too, esp. for blocks that are not referenced (e.g. empty blocks with min_size)
if(to_be_kept)
list(APPEND to_be_kept "block ${name_clean}_init")
endif()
set(TEMP "${TEMP}\n${INIT_TEMP}\n")
if(DEFINED current_sections)
set(TEMP "${TEMP}\ninitialize manually with copy friendly\n")
set(TEMP "${TEMP}{\n")
foreach(section ${current_sections})
@ -823,8 +833,8 @@ function(section_to_string)
endforeach()
set(TEMP "${TEMP}};")
endif()
set(current_sections)
endif()
set(current_sections)
endif()
# Finally, add the keeps.