ARM64: Enable unaligned accesses if indicated by the toolchain.

If you get a crash in jit_init() then you need to fix your toolchain.
This commit is contained in:
Mike Pall
2025-11-08 15:41:42 +01:00
parent 68354f4447
commit 578c41ceb7
3 changed files with 15 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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);
}