Skip to content
Browse files make generated/linker_relocate.ld deterministic

Dictionaries are not ordered in Python 3.5 and before, so building twice
in a row could lead to a different sections order, different
build/zephyr/include/generated/linker_relocate.d and code_relocation.c
and different binaries.

Fix with a minor change to three "for" loops in the output functions:
make them iterate on sorted(list of sections) instead of the raw and
randomly ordered dictionaries of sections.

Signed-off-by: Marc Herbert <>
  • Loading branch information...
marc-hb authored and nashif committed Jun 24, 2019
1 parent 2a63e34 commit 6ccd026f7c6a48d3d70d6f82b5f713e3bfdccab7
Showing with 8 additions and 4 deletions.
  1. +8 −4 scripts/
@@ -197,7 +197,7 @@ def assign_to_correct_mem_region(memory_type,

def print_linker_sections(list_sections):
print_string = ''
for section in list_sections:
for section in sorted(list_sections):
print_string += PRINT_TEMPLATE.format(section)
return print_string

@@ -233,7 +233,9 @@ def generate_linker_script(linker_file, sram_data_linker_file,
gen_string = ''
gen_string_sram_data = ''
gen_string_sram_bss = ''
for memory_type, full_list_of_sections in complete_list_of_sections.items():

for memory_type, full_list_of_sections in \

if memory_type != "SRAM":
gen_string += MPU_RO_REGION_START.format(memory_type.lower(),
@@ -393,7 +395,6 @@ def main():
# Create/or trucate file contents if it already exists
# raw = open(linker_file, "w")

code_generation = {"copy_code": '', "zero_code":'', "extern":''}
#for each memory_type, create text/rodata/data/bss sections for all obj files
for memory_type, files in rel_dict.items():
full_list_of_sections = {"text":[], "rodata":[], "data":[], "bss":[]}
@@ -413,7 +414,10 @@ def main():

generate_linker_script(linker_file, sram_data_linker_file,
sram_bss_linker_file, complete_list_of_sections)
for mem_type, list_of_sections in complete_list_of_sections.items():

code_generation = {"copy_code": '', "zero_code":'', "extern":''}
for mem_type, list_of_sections in \
code_generation = generate_memcpy_code(mem_type,
list_of_sections, code_generation)

0 comments on commit 6ccd026

Please sign in to comment.
You can’t perform that action at this time.