tools/mpy-tool.py: Force native func alignment to halfword/word on ARM.

This is necessary for ARMV6 and V7.  Without this change, calling a frozen
native/viper function that is misaligned will crash.
pull/5027/head
Jim Mussared 2019-08-17 00:32:04 +10:00 zatwierdzone przez Damien George
rodzic ae6fe8b43c
commit 4ab5156c01
1 zmienionych plików z 8 dodań i 0 usunięć

Wyświetl plik

@ -471,6 +471,14 @@ class RawCodeNative(RawCode):
else:
self.fun_data_attributes = '__attribute__((section(".text,\\"ax\\",%progbits @ ")))'
# Allow single-byte alignment by default for x86/x64/xtensa, but on ARM we need halfword- or word- alignment.
if config.native_arch == MP_NATIVE_ARCH_ARMV6:
# ARMV6 -- four byte align.
self.fun_data_attributes += ' __attribute__ ((aligned (4)))'
elif MP_NATIVE_ARCH_ARMV6M <= config.native_arch <= MP_NATIVE_ARCH_ARMV7EMDP:
# ARMVxxM -- two byte align.
self.fun_data_attributes += ' __attribute__ ((aligned (2)))'
def _asm_thumb_rewrite_mov(self, pc, val):
print(' (%u & 0xf0) | (%s >> 12),' % (self.bytecode[pc], val), end='')
print(' (%u & 0xfb) | (%s >> 9 & 0x04),' % (self.bytecode[pc + 1], val), end='')