]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
ARM64: Enable unaligned accesses if indicated by the toolchain.
authorMike Pall <mike>
Sat, 8 Nov 2025 14:41:42 +0000 (15:41 +0100)
committerMike Pall <mike>
Sat, 8 Nov 2025 14:41:42 +0000 (15:41 +0100)
If you get a crash in jit_init() then you need to fix your toolchain.

src/lib_jit.c
src/lj_arch.h
src/lj_asm_arm64.h

index 1b74d957b56588319869ae9b4c3a496f46dea48c..0f75c5ac641f4905b117eb234f84e87febfced1f 100644 (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
 
index 799f9c6cc3c72e35c79c74cb87ca75131a8767e1..5f3880680baf986b6d8fb4d0ce0fc514549d105f 100644 (file)
 #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
index 085f93572890d4df3320e843901758f9daea6fb4..fdcff1db2402237c815ff73250ff8a6ce493624e 100644 (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);
 }