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.
This commit is contained in:
Jim Mussared 2019-08-17 00:32:04 +10:00 committed by Damien George
parent ae6fe8b43c
commit 4ab5156c01
1 changed files with 8 additions and 0 deletions

View File

@ -471,6 +471,14 @@ class RawCodeNative(RawCode):
else: else:
self.fun_data_attributes = '__attribute__((section(".text,\\"ax\\",%progbits @ ")))' 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): def _asm_thumb_rewrite_mov(self, pc, val):
print(' (%u & 0xf0) | (%s >> 12),' % (self.bytecode[pc], val), end='') print(' (%u & 0xf0) | (%s >> 12),' % (self.bytecode[pc], val), end='')
print(' (%u & 0xfb) | (%s >> 9 & 0x04),' % (self.bytecode[pc + 1], val), end='') print(' (%u & 0xfb) | (%s >> 9 & 0x04),' % (self.bytecode[pc + 1], val), end='')