Skip to content

Commit 4b3cd02

Browse files
bjorniuppsalafabiobaltieri
authored andcommitted
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>
1 parent dff0dba commit 4b3cd02

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

cmake/linker/iar/config_file_script.cmake

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,15 @@ function(section_to_string)
606606
list(APPEND to_be_kept "section ${setting}")
607607
endforeach()
608608
endif()
609+
# In ilink if a block with min_size=X does not match any input sections,
610+
# its _init block may be discarded despite being needed for spacing with
611+
# other _init blocks. To get around tihs, lets tag min_size blocks as keep.
612+
if(CONFIG_IAR_ZEPHYR_INIT
613+
AND DEFINED group_parent_vma AND DEFINED group_parent_lma
614+
AND DEFINED i_min_size
615+
AND NOT ${noinit})
616+
list(APPEND to_be_kept "block ${name_clean}_${idx}_init")
617+
endif()
609618
if(DEFINED symbols)
610619
list(LENGTH symbols symbols_count)
611620
if(${symbols_count} GREATER 0)
@@ -784,47 +793,48 @@ function(section_to_string)
784793
list(JOIN current_sections ", " SELECTORS)
785794
set(TEMP "${TEMP}\ndo not initialize {\n${SELECTORS}\n};")
786795
elseif(DEFINED group_parent_vma AND DEFINED group_parent_lma)
787-
if(DEFINED current_sections)
788-
if(CONFIG_IAR_DATA_INIT)
789-
set(TEMP "${TEMP}\ninitialize by copy\n")
790-
set(TEMP "${TEMP}{\n")
791-
foreach(section ${current_sections})
792-
set(TEMP "${TEMP} ${section},\n")
793-
endforeach()
794-
set(TEMP "${TEMP}};")
796+
if(CONFIG_IAR_DATA_INIT AND DEFINED current_sections)
797+
set(TEMP "${TEMP}\ninitialize by copy\n")
798+
set(TEMP "${TEMP}{\n")
799+
foreach(section ${current_sections})
800+
set(TEMP "${TEMP} ${section},\n")
801+
endforeach()
802+
set(TEMP "${TEMP}};")
795803

796-
set(TEMP "${TEMP}\n\"${name}_init\": place in ${group_parent_lma} {\n")
797-
foreach(section ${current_sections})
798-
set(TEMP "${TEMP} ${section}_init,\n")
799-
endforeach()
800-
set(TEMP "${TEMP}};")
801-
elseif(CONFIG_IAR_ZEPHYR_INIT)
802-
# Generate the _init block and the initialize manually statement.
803-
# Note that we need to have the X_init block defined even if we have
804-
# no sections, since there will come a "place in XXX" statement later.
805-
806-
# "${TEMP}" is there too keep the ';' else it will be a list
807-
string(REGEX REPLACE "(block[ \t\r\n]+)([^ \t\r\n]+)" "\\1\\2_init" INIT_TEMP "${TEMP}")
808-
string(REGEX REPLACE "(rw)([ \t\r\n]+)(section[ \t\r\n]+)([^ \t\r\n,]+)" "\\1\\2\\3\\4_init" INIT_TEMP "${INIT_TEMP}")
809-
string(REGEX REPLACE "(rw)([ \t\r\n]+)(section[ \t\r\n]+)" "ro\\2\\3" INIT_TEMP "${INIT_TEMP}")
810-
string(REGEX REPLACE "alphabetical order, " "" INIT_TEMP "${INIT_TEMP}")
811-
string(REGEX REPLACE "{ readwrite }" "{ }" INIT_TEMP "${INIT_TEMP}")
812-
813-
# If any content is marked as keep, is has to be applied to the init block
814-
# too, esp. for blocks that are not referenced (e.g. empty blocks wiht min_size)
815-
if(to_be_kept)
816-
list(APPEND to_be_kept "block ${name_clean}_init")
817-
endif()
818-
set(TEMP "${TEMP}\n${INIT_TEMP}\n")
804+
set(TEMP "${TEMP}\n\"${name}_init\": place in ${group_parent_lma} {\n")
805+
foreach(section ${current_sections})
806+
set(TEMP "${TEMP} ${section}_init,\n")
807+
endforeach()
808+
set(TEMP "${TEMP}};")
809+
elseif(CONFIG_IAR_ZEPHYR_INIT)
810+
# Generate the _init block and the initialize manually statement.
811+
# Note that we need to have the X_init block defined even if we have
812+
# no sections, since there will come a "place in XXX" statement later.
813+
814+
# "${TEMP}" is there too keep the ';' else it will be a list
815+
string(REGEX REPLACE "(block[ \t\r\n]+)([^ \t\r\n]+)" "\\1\\2_init" INIT_TEMP "${TEMP}")
816+
string(REGEX REPLACE "(rw)([ \t\r\n]+)(section[ \t\r\n]+)([^ \t\r\n,]+)" "\\1\\2\\3\\4_init" INIT_TEMP "${INIT_TEMP}")
817+
string(REGEX REPLACE "(rw)([ \t\r\n]+)(section[ \t\r\n]+)" "ro\\2\\3" INIT_TEMP "${INIT_TEMP}")
818+
string(REGEX REPLACE "alphabetical order, " "" INIT_TEMP "${INIT_TEMP}")
819+
string(REGEX REPLACE "{ readwrite }" "{ }" INIT_TEMP "${INIT_TEMP}")
820+
set(TEMP "${TEMP}\n${INIT_TEMP}\n")
821+
822+
# If any content is marked as keep, is has to be applied to the init block
823+
# too, esp. for blocks that are not referenced (e.g. empty blocks with min_size)
824+
if(to_be_kept)
825+
list(APPEND to_be_kept "block ${name_clean}_init")
826+
endif()
827+
828+
if(DEFINED current_sections)
819829
set(TEMP "${TEMP}\ninitialize manually with copy friendly\n")
820830
set(TEMP "${TEMP}{\n")
821831
foreach(section ${current_sections})
822832
set(TEMP "${TEMP} ${section},\n")
823833
endforeach()
824834
set(TEMP "${TEMP}};")
825835
endif()
826-
set(current_sections)
827836
endif()
837+
set(current_sections)
828838
endif()
829839

830840
# Finally, add the keeps.

0 commit comments

Comments
 (0)