Skip to content
Permalink
Browse files

gen_app_partitions.py: make generated/app_smem_*.ld files deterministic

Dictionaries are not ordered in Python 3.5 and before, so building twice
in a row could lead to a different partition order, different
build/zephyr/include/generated/app_smem_*.ld files and different
binaries.

Fix with a minor change to the "for" loop in the output function:
make it iterate on sorted(partitions.items()) instead of the raw and
randomly ordered partitions dictionary.

It is easy to reproduce the issue even without downgrading to an
obsolete Python version; pick a test like samples/userspace/shared_mem/
and simply change the code to this:

--- a/scripts/gen_app_partitions.py
+++ b/scripts/gen_app_partitions.py
@@ -159,10 +159,12 @@ def parse_elf_file(partitions):
                     partitions[partition_name][SZ] += size

+import random
 def generate_final_linker(linker_file, partitions):
     string = linker_start_seq
     size_string = ''
-    for partition, item in sorted(partitions.items()):
+    for partition, item in sorted(partitions.items(),
+                                  key=lambda x: random.random()):
         string += data_template.format(partition)
         if LIB in item:
             for lib in item[LIB]:

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
  • Loading branch information...
marc-hb authored and nashif committed Jun 21, 2019
1 parent 6ccd026 commit 725abdf4304d8aec843ff5be3bb577835b74d239
Showing with 1 addition and 1 deletion.
  1. +1 −1 scripts/gen_app_partitions.py
@@ -162,7 +162,7 @@ def parse_elf_file(partitions):
def generate_final_linker(linker_file, partitions):
string = linker_start_seq
size_string = ''
for partition, item in partitions.items():
for partition, item in sorted(partitions.items()):
string += data_template.format(partition)
if LIB in item:
for lib in item[LIB]:

0 comments on commit 725abdf

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