From 578c41ceb73bdf9d97f23c9e0342f8d027c08e77 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 8 Nov 2025 15:41:42 +0100 Subject: ARM64: Enable unaligned accesses if indicated by the toolchain. If you get a crash in jit_init() then you need to fix your toolchain. --- src/lib_jit.c | 9 +++++++++ src/lj_arch.h | 4 ++++ src/lj_asm_arm64.h | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib_jit.c b/src/lib_jit.c index 1b74d957..0f75c5ac 100644 --- a/src/lib_jit.c +++ b/src/lib_jit.c @@ -723,7 +723,16 @@ static void jit_init(lua_State *L) jit_State *J = L2J(L); J->flags = jit_cpudetect() | JIT_F_ON | JIT_F_OPT_DEFAULT; memcpy(J->param, jit_param_default, sizeof(J->param)); +#if LJ_TARGET_UNALIGNED + G(L)->tmptv.u64 = U64x(0000504d,4d500000); +#endif lj_dispatch_update(G(L)); +#if LJ_TARGET_UNALIGNED + /* If you get a crash below then your toolchain indicates unaligned + ** accesses are OK, but your kernel disagrees. I.e. fix your toolchain. + */ + if (*(uint32_t *)((char *)&G(L)->tmptv + 2) != 0x504d4d50u) L->top = NULL; +#endif } #endif diff --git a/src/lj_arch.h b/src/lj_arch.h index 799f9c6c..5f388068 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -304,6 +304,10 @@ #define LJ_PAGESIZE 16384 #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL +#if __ARM_FEATURE_UNALIGNED +#define LJ_TARGET_UNALIGNED 1 +#endif + #define LJ_ARCH_VERSION 80 #elif LUAJIT_TARGET == LUAJIT_ARCH_PPC diff --git a/src/lj_asm_arm64.h b/src/lj_asm_arm64.h index 085f9357..fdcff1db 100644 --- a/src/lj_asm_arm64.h +++ b/src/lj_asm_arm64.h @@ -1056,7 +1056,8 @@ static void asm_fstore(ASMState *as, IRIns *ir) static void asm_xload(ASMState *as, IRIns *ir) { Reg dest = ra_dest(as, ir, irt_isfp(ir->t) ? RSET_FPR : RSET_GPR); - lj_assertA(!(ir->op2 & IRXLOAD_UNALIGNED), "unaligned XLOAD"); + lj_assertA(LJ_TARGET_UNALIGNED || !(ir->op2 & IRXLOAD_UNALIGNED), + "unaligned XLOAD"); asm_fusexref(as, asm_fxloadins(ir), dest, ir->op1, RSET_GPR); } -- cgit v1.2.3-55-g6feb