Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump LuaJIT to 20231008 #442

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions jni/luajit/koreader-luajit-makefile-tweaks.patch
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
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
+ TARGET_STRIP+= --strip-unneeded
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 $@"
Expand All @@ -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)
Expand Down
44 changes: 22 additions & 22 deletions jni/luajit/koreader-luajit-mcode-debug.patch
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -82,15 +82,15 @@ 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;
+ LJ_LOG("original hint is @ %p (mcarea: %p / last: %p / reserve: %p)", (void *) hint, (void *) J->mcarea, (void *) J->lastmcarea, (void *) reserve);
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<<LJ_TARGET_JUMPRANGE)-0x10000);
Expand All @@ -101,31 +101,31 @@ index 6e83086a..415ae0f3 100644
}
lj_trace_err(J, LJ_TRERR_MCODEAL); /* Give up. OS probably ignores hints? */
return NULL;
@@ -291,6 +298,7 @@ static void mcode_allocarea(jit_State *J)
@@ -295,6 +302,7 @@ static void mcode_allocarea(jit_State *J)
size_t sz = (size_t)J->param[JIT_P_sizemcode] << 10;
sz = (sz + LJ_PAGESIZE-1) & ~(size_t)(LJ_PAGESIZE - 1);
J->mcarea = (MCode *)mcode_alloc(J, sz);
+ LJ_LOG("new %zuK mcarea @ %p (oldarea @ %p)", sz / 1024U, J->mcarea, oldarea);
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;
+ LJ_LOG("mcarea was %p", J->mcarea);
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;
}
+ LJ_LOG("lastmcarea is now %p", J->lastmcarea);
}

/* 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;
Expand All @@ -136,32 +136,32 @@ 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);
+ LJ_LOG("recycled %zuK mcarea @ %p", J->szmcarea / 1024U, J->mcarea);
}

/* -- 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)
{
+ //LJ_LOG("J->mcarea: %p // lim: %p // mctop: %p // mcbot: %p", (void *) J->mcarea, (void *) *lim, (void *) J->mctop, (void *) J->mcbot);
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)
Expand All @@ -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) {
Expand Down
22 changes: 11 additions & 11 deletions jni/luajit/koreader-luajit-mcode-reserve-hack.patch
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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

Expand All @@ -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);
Expand Down Expand Up @@ -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. */
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -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 @@
Expand Down