From ecead677cedc25a67b5024e45b3b621455629f6a Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 9 Oct 2023 20:13:18 +0200 Subject: [PATCH] Bump LuaJIT to 20231008 (#442) c.f., https://github.com/koreader/koreader-base/pull/1663 --- .../koreader-luajit-makefile-tweaks.patch | 20 ++++----- jni/luajit/koreader-luajit-mcode-debug.patch | 44 +++++++++---------- .../koreader-luajit-mcode-reserve-hack.patch | 22 +++++----- jni/luajit/luajit | 2 +- 4 files changed, 43 insertions(+), 45 deletions(-) diff --git a/jni/luajit/koreader-luajit-makefile-tweaks.patch b/jni/luajit/koreader-luajit-makefile-tweaks.patch index dd30a2247..2a1043ed5 100644 --- a/jni/luajit/koreader-luajit-makefile-tweaks.patch +++ b/jni/luajit/koreader-luajit-makefile-tweaks.patch @@ -1,18 +1,16 @@ diff --git a/src/Makefile b/src/Makefile -index 2538503f..d1ea3f63 100644 +index 224d21e7..18d1d330 100644 --- a/src/Makefile +++ b/src/Makefile -@@ -211,7 +211,8 @@ TARGET_CC= $(STATIC_CC) - TARGET_STCC= $(STATIC_CC) +@@ -211,6 +211,7 @@ TARGET_STCC= $(STATIC_CC) TARGET_DYNCC= $(DYNAMIC_CC) TARGET_LD= $(CROSS)$(CC) --TARGET_AR= $(CROSS)ar rcus -+TARGET_AR= $(CROSS)ar rcus + TARGET_AR= $(CROSS)ar rcus +TARGET_RANLIB= $(CROSS)ranlib TARGET_STRIP= $(CROSS)strip TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib) -@@ -348,6 +349,7 @@ else +@@ -347,6 +348,7 @@ else endif ifeq (Linux,$(TARGET_SYS)) TARGET_XLIBS+= -ldl @@ -20,16 +18,16 @@ index 2538503f..d1ea3f63 100644 endif ifeq (GNU/kFreeBSD,$(TARGET_SYS)) TARGET_XLIBS+= -ldl -@@ -639,7 +641,7 @@ depend: +@@ -651,7 +653,7 @@ depend: $(MINILUA_T): $(MINILUA_O) $(E) "HOSTLINK $@" - $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS) + $(Q)$(HOST_CC) $(HOST_ACFLAGS) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS) - host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) $(DASM_DIR)/*.lua lj_arch.h lua.h luaconf.h - $(E) "DYNASM $@" -@@ -649,7 +651,7 @@ host/buildvm.o: $(DASM_DIR)/dasm_*.h + luajit.h: $(MINILUA_DEP) $(GIT_DEP) luajit_rolling.h + $(E) "VERSION $@" +@@ -666,7 +668,7 @@ host/buildvm.o: $(DASM_DIR)/dasm_*.h $(BUILDVM_T): $(BUILDVM_O) $(E) "HOSTLINK $@" @@ -38,7 +36,7 @@ index 2538503f..d1ea3f63 100644 $(LJVM_BOUT): $(BUILDVM_T) $(E) "BUILDVM $@" -@@ -710,16 +712,17 @@ include Makefile.dep +@@ -727,16 +729,17 @@ include Makefile.dep $(LUAJIT_A): $(LJVMCORE_O) $(E) "AR $@" $(Q)$(TARGET_AR) $@ $(LJVMCORE_O) diff --git a/jni/luajit/koreader-luajit-mcode-debug.patch b/jni/luajit/koreader-luajit-mcode-debug.patch index a5e01c855..d8af3c6f9 100644 --- a/jni/luajit/koreader-luajit-mcode-debug.patch +++ b/jni/luajit/koreader-luajit-mcode-debug.patch @@ -1,8 +1,8 @@ diff --git a/src/lj_api.c b/src/lj_api.c -index e6b67478..71997582 100644 +index d4048d79..3731d952 100644 --- a/src/lj_api.c +++ b/src/lj_api.c -@@ -1045,6 +1045,7 @@ LUA_API int lua_setmetatable(lua_State *L, int idx) +@@ -1050,6 +1050,7 @@ LUA_API int lua_setmetatable(lua_State *L, int idx) lj_gc_objbarrier(L, udataV(o), mt); } else { /* Flush cache, since traces specialize to basemt. But not during __gc. */ @@ -11,10 +11,10 @@ index e6b67478..71997582 100644 lj_err_caller(L, LJ_ERR_NOGCMM); if (tvisbool(o)) { diff --git a/src/lj_asm.c b/src/lj_asm.c -index 7ce2e5d2..14d66367 100644 +index 844910ad..bf37f621 100644 --- a/src/lj_asm.c +++ b/src/lj_asm.c -@@ -141,6 +141,7 @@ static LJ_AINLINE void checkmclim(ASMState *as) +@@ -148,6 +148,7 @@ static LJ_AINLINE void checkmclim(ASMState *as) as->curins+1-REF_BIAS, ir->o, ir->op1-REF_BIAS, ir->op2-REF_BIAS); } #endif @@ -23,7 +23,7 @@ index 7ce2e5d2..14d66367 100644 #ifdef LUA_USE_ASSERT as->mcp_prev = as->mcp; diff --git a/src/lj_def.h b/src/lj_def.h -index 907729e0..908e9ce0 100644 +index 0b245714..992d9cee 100644 --- a/src/lj_def.h +++ b/src/lj_def.h @@ -46,6 +46,15 @@ typedef unsigned int uintptr_t; @@ -43,7 +43,7 @@ index 907729e0..908e9ce0 100644 #define LJ_MAX_MEM32 0x7fffff00 /* Max. 32 bit memory allocation. */ #define LJ_MAX_MEM64 ((uint64_t)1<<47) /* Max. 64 bit memory allocation. */ diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c -index ded382aa..42e59c2e 100644 +index b9748bba..8646ddeb 100644 --- a/src/lj_dispatch.c +++ b/src/lj_dispatch.c @@ -254,6 +254,7 @@ int luaJIT_setmode(lua_State *L, int idx, int mode) @@ -55,10 +55,10 @@ index ded382aa..42e59c2e 100644 } else { if (!(mode & LUAJIT_MODE_ON)) diff --git a/src/lj_mcode.c b/src/lj_mcode.c -index 6e83086a..415ae0f3 100644 +index cd5ddca2..d05c688c 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c -@@ -114,12 +114,14 @@ static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot, b +@@ -118,12 +118,14 @@ static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot, b if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); p = NULL; } @@ -73,7 +73,7 @@ index 6e83086a..415ae0f3 100644 munmap(p, sz); } -@@ -220,6 +222,8 @@ static void *mcode_alloc(jit_State *J, size_t sz) +@@ -224,6 +226,8 @@ static void *mcode_alloc(jit_State *J, size_t sz) uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; #endif const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21); @@ -82,7 +82,7 @@ index 6e83086a..415ae0f3 100644 /* First try a contiguous area below the last one, * then try the same address as the last area we unmapped * (this happens after a flush (either explicit or because the mcarea was filled), -@@ -235,6 +239,7 @@ static void *mcode_alloc(jit_State *J, size_t sz) +@@ -239,6 +243,7 @@ static void *mcode_alloc(jit_State *J, size_t sz) fixed = true; } uintptr_t hint = J->mcarea ? (uintptr_t)J->mcarea - sz : J->lastmcarea ? (uintptr_t)J->lastmcarea : reserve; @@ -90,7 +90,7 @@ index 6e83086a..415ae0f3 100644 int i; /* Limit probing iterations, depending on the available pool size. */ for (i = 0; i < LJ_TARGET_JUMPRANGE; i++) { -@@ -255,8 +260,10 @@ static void *mcode_alloc(jit_State *J, size_t sz) +@@ -259,8 +264,10 @@ static void *mcode_alloc(jit_State *J, size_t sz) /* Next try probing 64K-aligned pseudo-random addresses. */ do { hint = lj_prng_u64(&J2G(J)->prng) & ((1u<param[JIT_P_sizemcode] << 10; sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1); J->mcarea = (MCode *)mcode_alloc(J, sz); @@ -109,7 +109,7 @@ index 6e83086a..415ae0f3 100644 J->szmcarea = sz; J->mcprot = MCPROT_GEN; J->mctop = (MCode *)((char *)J->mcarea + J->szmcarea); -@@ -305,6 +313,7 @@ static void mcode_allocarea(jit_State *J) +@@ -309,6 +317,7 @@ static void mcode_allocarea(jit_State *J) void lj_mcode_free(jit_State *J) { MCode *mc = J->mcarea; @@ -117,7 +117,7 @@ index 6e83086a..415ae0f3 100644 J->mcarea = NULL; J->szallmcarea = 0; while (mc) { -@@ -318,6 +327,7 @@ void lj_mcode_free(jit_State *J) +@@ -322,6 +331,7 @@ void lj_mcode_free(jit_State *J) } mc = next; } @@ -125,7 +125,7 @@ index 6e83086a..415ae0f3 100644 } /* Clear all MCode areas. */ -@@ -337,8 +347,10 @@ void lj_mcode_clear(jit_State *J) +@@ -341,8 +351,10 @@ void lj_mcode_clear(jit_State *J) mcarea = mc; szmcarea = size; szallmcarea += size; @@ -136,7 +136,7 @@ index 6e83086a..415ae0f3 100644 /* A non-contiguous link anywhere in the chain means we scrap the whole chain, to keep things simple */ break; } -@@ -383,6 +395,7 @@ void lj_mcode_clear(jit_State *J) +@@ -387,6 +399,7 @@ void lj_mcode_clear(jit_State *J) ((MCLink *)J->mcarea)->size = J->szmcarea; J->szallmcarea = J->szmcarea; J->mcbot = (MCode *)lj_err_register_mcode(J->mcarea, J->szmcarea, (uint8_t *)J->mcbot); @@ -144,7 +144,7 @@ index 6e83086a..415ae0f3 100644 } /* -- MCode transactions -------------------------------------------------- */ -@@ -390,6 +403,7 @@ void lj_mcode_clear(jit_State *J) +@@ -394,6 +407,7 @@ void lj_mcode_clear(jit_State *J) /* Reserve the remainder of the current MCode area. */ MCode *lj_mcode_reserve(jit_State *J, MCode **lim) { @@ -152,16 +152,16 @@ index 6e83086a..415ae0f3 100644 if (!J->mcarea) mcode_allocarea(J); else -@@ -455,6 +469,7 @@ void lj_mcode_limiterr(jit_State *J, size_t need) +@@ -459,6 +473,7 @@ void lj_mcode_limiterr(jit_State *J, size_t need) sizemcode = (size_t)J->param[JIT_P_sizemcode] << 10; sizemcode = (sizemcode + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1); maxmcode = (size_t)J->param[JIT_P_maxmcode] << 10; -+ LJ_LOG("J->szallmcarea: %zu / sizemcode: %zu / maxmcode: %zu / need: %zu", J->szallmcarea, sizemcode, maxmcode, need); - if ((size_t)need > sizemcode) ++ LJ_LOG("J->szallmcarea: %zu / sizemcode: %zu / maxmcode: %zu / need: %zu / need (in bytes): %zu", J->szallmcarea, sizemcode, maxmcode, need, need * sizeof(MCode)); + if (need * sizeof(MCode) > sizemcode) lj_trace_err(J, LJ_TRERR_MCODEOV); /* Too long for any area. */ if (J->szallmcarea + sizemcode > maxmcode) diff --git a/src/lj_trace.c b/src/lj_trace.c -index 80d57744..b93ca985 100644 +index e99c0c2d..8cb108f7 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -301,6 +301,7 @@ int lj_trace_flushall(lua_State *L) @@ -188,7 +188,7 @@ index 80d57744..b93ca985 100644 lj_trace_flushall(J->L); J->state = LJ_TRACE_IDLE; /* Silently ignored. */ return; -@@ -641,6 +644,7 @@ static int trace_abort(jit_State *J) +@@ -647,6 +650,7 @@ static int trace_abort(jit_State *J) if (e == LJ_TRERR_DOWNREC) return trace_downrec(J); else if (e == LJ_TRERR_MCODEAL) { diff --git a/jni/luajit/koreader-luajit-mcode-reserve-hack.patch b/jni/luajit/koreader-luajit-mcode-reserve-hack.patch index 138ce5e38..b5aff1fba 100644 --- a/jni/luajit/koreader-luajit-mcode-reserve-hack.patch +++ b/jni/luajit/koreader-luajit-mcode-reserve-hack.patch @@ -1,5 +1,5 @@ diff --git a/src/lj_def.h b/src/lj_def.h -index b61297aa..907729e0 100644 +index 0d6c346b..0b245714 100644 --- a/src/lj_def.h +++ b/src/lj_def.h @@ -39,6 +39,7 @@ typedef int intptr_t; @@ -11,7 +11,7 @@ index b61297aa..907729e0 100644 /* Needed everywhere. */ diff --git a/src/lj_jit.h b/src/lj_jit.h -index 0fae60ad..353d33fb 100644 +index 6902fba3..af3f14b6 100644 --- a/src/lj_jit.h +++ b/src/lj_jit.h @@ -508,6 +508,7 @@ typedef struct jit_State { @@ -23,10 +23,10 @@ index 0fae60ad..353d33fb 100644 MCode *mctop; /* Top of current mcode area. */ MCode *mcbot; /* Bottom of current mcode area. */ diff --git a/src/lj_mcode.c b/src/lj_mcode.c -index 163aada4..6e83086a 100644 +index 8a4851dd..cd5ddca2 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c -@@ -103,9 +103,13 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot) +@@ -107,9 +107,13 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot) #define MCPROT_CREATE 0 #endif @@ -42,7 +42,7 @@ index 163aada4..6e83086a 100644 if (p == MAP_FAILED) { if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); p = NULL; -@@ -216,18 +220,37 @@ static void *mcode_alloc(jit_State *J, size_t sz) +@@ -220,18 +224,37 @@ static void *mcode_alloc(jit_State *J, size_t sz) uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff; #endif const uintptr_t range = (1u << (LJ_TARGET_JUMPRANGE-1)) - (1u << 21); @@ -86,7 +86,7 @@ index 163aada4..6e83086a 100644 } /* Next try probing 64K-aligned pseudo-random addresses. */ do { -@@ -246,14 +269,14 @@ static void *mcode_alloc(jit_State *J, size_t sz) +@@ -250,14 +273,14 @@ static void *mcode_alloc(jit_State *J, size_t sz) { #if defined(__OpenBSD__) || defined(__NetBSD__) || LJ_TARGET_UWP /* Allow better executable memory allocation for OpenBSD W^X mode. */ @@ -103,7 +103,7 @@ index 163aada4..6e83086a 100644 #endif } -@@ -289,10 +312,79 @@ void lj_mcode_free(jit_State *J) +@@ -293,10 +316,79 @@ void lj_mcode_free(jit_State *J) size_t sz = ((MCLink *)mc)->size; lj_err_deregister_mcode(mc, sz, (uint8_t *)mc + sizeof(MCLink)); mcode_free(J, mc, sz); @@ -184,7 +184,7 @@ index 163aada4..6e83086a 100644 /* Reserve the remainder of the current MCode area. */ diff --git a/src/lj_mcode.h b/src/lj_mcode.h -index be35925f..d8407242 100644 +index b88be93e..4b90e7db 100644 --- a/src/lj_mcode.h +++ b/src/lj_mcode.h @@ -17,6 +17,7 @@ LJ_FUNC void lj_mcode_sync(void *start, void *end); @@ -196,7 +196,7 @@ index be35925f..d8407242 100644 LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m); LJ_FUNC void lj_mcode_abort(jit_State *J); diff --git a/src/lj_trace.c b/src/lj_trace.c -index e019a79f..80d57744 100644 +index fee78e2e..e99c0c2d 100644 --- a/src/lj_trace.c +++ b/src/lj_trace.c @@ -300,8 +300,8 @@ int lj_trace_flushall(lua_State *L) @@ -210,7 +210,7 @@ index e019a79f..80d57744 100644 memset(J->exitstubgroup, 0, sizeof(J->exitstubgroup)); lj_vmevent_send(L, TRACE, setstrV(L, L->top++, lj_str_newlit(L, "flush")); -@@ -640,8 +640,9 @@ static int trace_abort(jit_State *J) +@@ -646,8 +646,9 @@ static int trace_abort(jit_State *J) L->top--; /* Remove error object */ if (e == LJ_TRERR_DOWNREC) return trace_downrec(J); @@ -222,7 +222,7 @@ index e019a79f..80d57744 100644 } diff --git a/src/ljamalg.c b/src/ljamalg.c -index cae8356c..cbd8e279 100644 +index f1dce6a3..2e19a1b3 100644 --- a/src/ljamalg.c +++ b/src/ljamalg.c @@ -18,6 +18,9 @@ diff --git a/jni/luajit/luajit b/jni/luajit/luajit index 41fb94def..656ecbcf8 160000 --- a/jni/luajit/luajit +++ b/jni/luajit/luajit @@ -1 +1 @@ -Subproject commit 41fb94defa8f830ce69a8122b03f6ac3216d392a +Subproject commit 656ecbcf8f669feb94e0d0ec4b4f59190bcd2e48