8000 tools/mpy-tool.py: Fix linking qstrs in native code, and multiple files. · shazz/micropython@faf3d3e · GitHub
[go: up one dir, main page]

Skip to content

Commit faf3d3e

Browse files
committed
tools/mpy-tool.py: Fix linking qstrs in native code, and multiple files.
Fixes errors in the tool when 1) linking qstrs in native ARM-M code; 2) freezing multiple files some of which use native code and some which don't. Fixes issue micropython#4829.
1 parent ce8262a commit faf3d3e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tools/mpy-tool.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# The MIT License (MIT)
66
#
7-
# Copyright (c) 2016 Damien P. George
7+
# Copyright (c) 2016-2019 Damien P. George
88
#
99
# Permission is hereby granted, free of charge, to any person obtaining a copy
1010
# of this software and associated documentation files (the "Software"), to deal
@@ -479,18 +479,23 @@ def _asm_thumb_rewrite_mov(self, pc, val):
479479

480480
def _link_qstr(self, pc, kind, qst):
481481
if kind == 0:
482+
# Generic 16-bit link
482483
print(' %s & 0xff, %s >> 8,' % (qst, qst))
483484
else:
484-
if kind == 2:
485+
# Architecture-specific link
486+
is_obj = kind == 2
487+
if is_obj:
485488
qst = '((uintptr_t)MP_OBJ_NEW_QSTR(%s))' % qst
486489
if config.native_arch in (MP_NATIVE_ARCH_X86, MP_NATIVE_ARCH_X64):
487490
print(' %s & 0xff, %s >> 8, 0, 0,' % (qst, qst))
488491
elif MP_NATIVE_ARCH_ARMV6M <= config.native_arch <= MP_NATIVE_ARCH_ARMV7EMDP:
489492
if is_obj:
490-
self._asm_thumb_rewrite_mov(i, qst)
491-
self._asm_thumb_rewrite_mov(i + 4, '(%s >> 16)' % qst)
493+
# qstr object, movw and movt
494+
self._asm_thumb_rewrite_mov(pc, qst)
495+
self._asm_thumb_rewrite_mov(pc + 4, '(%s >> 16)' % qst)
492496
else:
493-
self._asm_thumb_rewrite_mov(i, qst)
497+
# qstr number, movw instruction
498+
self._asm_thumb_rewrite_mov(pc, qst)
494499
else:
495500
assert 0
496501

@@ -663,7 +668,7 @@ def read_raw_code(f, qstr_win):
663668
# load qstr link table
664669
n_qstr_link = read_uint(f)
665670
for _ in range(n_qstr_link):
666-
off = read_uint(f, qstr_win)
671+
off = read_uint(f)
667672
qst = read_qstr(f, qstr_win)
668673
qstr_links.append((off >> 2, off & 3, qst))
669674

@@ -714,7 +719,12 @@ def read_mpy(filename):
714719
qw_size = read_uint(f)
715720
config.MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE = (feature_byte & 1) != 0
716721
config.MICROPY_PY_BUILTINS_STR_UNICODE = (feature_byte & 2) != 0
717-
config.native_arch = feature_byte >> 2
722+
mpy_native_arch = feature_byte >> 2
723+
if mpy_native_arch != MP_NATIVE_ARCH_NONE:
724+
if config.native_arch == MP_NATIVE_ARCH_NONE:
725+
config.native_arch = mpy_native_arch
726+
elif config.native_arch != mpy_native_arch:
727+
raise Exception('native architecture mismatch')
718728
config.mp_small_int_bits = header[3]
719729
qstr_win = QStrWindow(qw_size)
720730
return read_raw_code(f, qstr_win)
@@ -838,6 +848,7 @@ def main():
838848
'mpz':config.MICROPY_LONGINT_IMPL_MPZ,
839849
}[args.mlongint_impl]
840850
config.MPZ_DIG_SIZE = args.mmpz_dig_size
851+
config.native_arch = MP_NATIVE_ARCH_NONE
841852

842853
# set config values for qstrs, and get the existing base set of qstrs
843854
if args.qstr_header:

0 commit comments

Comments
 (0)
0