From 224129a8e64bfa219d35cd03055bf03952f167f6 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 30 Apr 2023 13:38:29 +0200 Subject: [PATCH 1/6] Fix last commit. Reported by PluMGMK. --- src/lib_aux.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib_aux.c b/src/lib_aux.c index 7b01693a6e..4222367d8f 100644 --- a/src/lib_aux.c +++ b/src/lib_aux.c @@ -359,6 +359,7 @@ LUALIB_API lua_State *luaL_newstate(void) lua_pushcfunction(L, error_finalizer); lua_rawseti(L, -2, VMEVENT_HASH(LJ_VMEVENT_ERRFIN)); G(L)->vmevmask = VMEVENT_MASK(LJ_VMEVENT_ERRFIN); + L->top--; #endif } return L; @@ -381,6 +382,7 @@ LUALIB_API lua_State *luaL_newstate(void) lua_pushcfunction(L, error_finalizer); lua_rawseti(L, -2, VMEVENT_HASH(LJ_VMEVENT_ERRFIN)); G(L)->vmevmask = VMEVENT_MASK(LJ_VMEVENT_ERRFIN); + L->top--; #endif } return L; From 8c20c3b1a379f3f8ea34d9a13d3414bce8827e71 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 2 Jun 2023 11:36:24 +0200 Subject: [PATCH 2/6] Fix compiler warning. Reported by Myriachan. --- src/host/buildvm_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/host/buildvm_lib.c b/src/host/buildvm_lib.c index 47195fd4ee..99b8ad3fb9 100644 --- a/src/host/buildvm_lib.c +++ b/src/host/buildvm_lib.c @@ -319,7 +319,8 @@ void emit_lib(BuildCtx *ctx) char *p; /* Simplistic pre-processor. Only handles top-level #if/#endif. */ if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') { - int ok = 1, len = strlen(buf); + int ok = 1; + size_t len = strlen(buf); if (buf[len-1] == '\n') { buf[len-1] = 0; if (buf[len-2] == '\r') { From 9f452bbef5031afc506d8615f5e720c45acd6fdf Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 2 Jun 2023 11:38:45 +0200 Subject: [PATCH 3/6] Fix handling of instable types in TNEW/TDUP load forwarding. Analyzed by Sergey Kaplun. #994 --- src/lj_opt_mem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lj_opt_mem.c b/src/lj_opt_mem.c index 5b1ad898d8..9d83ea4a0a 100644 --- a/src/lj_opt_mem.c +++ b/src/lj_opt_mem.c @@ -197,7 +197,8 @@ static TRef fwd_ahload(jit_State *J, IRRef xref) if (key->o == IR_KSLOT) key = IR(key->op1); lj_ir_kvalue(J->L, &keyv, key); tv = lj_tab_get(J->L, ir_ktab(IR(ir->op1)), &keyv); - lua_assert(itype2irt(tv) == irt_type(fins->t)); + if (itype2irt(tv) != irt_type(fins->t)) + return 0; /* Type instability in loop-carried dependency. */ if (irt_isnum(fins->t)) return lj_ir_knum_u64(J, tv->u64); else if (LJ_DUALNUM && irt_isint(fins->t)) From 2d8300c1944f3a62c10f0829e9b7847c5a6f0482 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 2 Jun 2023 11:42:58 +0200 Subject: [PATCH 4/6] Fix frame for on-trace out-of-memory error. Reported by ruidong007. --- src/lj_err.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lj_err.c b/src/lj_err.c index a497ab113a..3ee70b8642 100644 --- a/src/lj_err.c +++ b/src/lj_err.c @@ -777,6 +777,10 @@ LJ_NOINLINE void lj_err_mem(lua_State *L) { if (L->status == LUA_ERRERR+1) /* Don't touch the stack during lua_open. */ lj_vm_unwind_c(L->cframe, LUA_ERRMEM); + if (LJ_HASJIT) { + TValue *base = tvref(G(L)->jit_base); + if (base) L->base = base; + } if (curr_funcisL(L)) L->top = curr_topL(L); setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRMEM)); lj_err_throw(L, LUA_ERRMEM); From 51fb2f2c3af778f03258fccee9092401ee4a0215 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Fri, 2 Jun 2023 12:54:46 +0200 Subject: [PATCH 5/6] DynASM: Fix warnings. Reported by Ilija Tovilo. --- dynasm/dasm_arm.h | 16 +++++----------- dynasm/dasm_arm64.h | 16 +++++----------- dynasm/dasm_mips.h | 16 +++++----------- dynasm/dasm_ppc.h | 16 +++++----------- dynasm/dasm_x86.h | 18 ++++++------------ 5 files changed, 26 insertions(+), 56 deletions(-) diff --git a/dynasm/dasm_arm.h b/dynasm/dasm_arm.h index fbfebee09f..aa16014e0f 100644 --- a/dynasm/dasm_arm.h +++ b/dynasm/dasm_arm.h @@ -70,7 +70,7 @@ struct dasm_State { size_t lgsize; int *pclabels; /* PC label chains/pos ptrs. */ size_t pcsize; - void **globals; /* Array of globals (bias -10). */ + void **globals; /* Array of globals. */ dasm_Section *section; /* Pointer to active section. */ size_t codesize; /* Total size of all code sections. */ int maxsection; /* 0 <= sectionidx < maxsection. */ @@ -87,7 +87,6 @@ void dasm_init(Dst_DECL, int maxsection) { dasm_State *D; size_t psz = 0; - int i; Dst_REF = NULL; DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); D = Dst_REF; @@ -98,12 +97,7 @@ void dasm_init(Dst_DECL, int maxsection) D->pcsize = 0; D->globals = NULL; D->maxsection = maxsection; - for (i = 0; i < maxsection; i++) { - D->sections[i].buf = NULL; /* Need this for pass3. */ - D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); - D->sections[i].bsize = 0; - D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ - } + memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section)); } /* Free DynASM state. */ @@ -123,7 +117,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = gl; DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } @@ -372,7 +366,7 @@ int dasm_encode(Dst_DECL, void *buffer) break; case DASM_REL_LG: if (n < 0) { - n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp - 4); + n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp - 4); goto patchrel; } /* fallthrough */ @@ -396,7 +390,7 @@ int dasm_encode(Dst_DECL, void *buffer) } break; case DASM_LABEL_LG: - ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n); break; case DASM_LABEL_PC: break; case DASM_IMM: diff --git a/dynasm/dasm_arm64.h b/dynasm/dasm_arm64.h index 47c9c37d63..e04898f1cf 100644 --- a/dynasm/dasm_arm64.h +++ b/dynasm/dasm_arm64.h @@ -72,7 +72,7 @@ struct dasm_State { size_t lgsize; int *pclabels; /* PC label chains/pos ptrs. */ size_t pcsize; - void **globals; /* Array of globals (bias -10). */ + void **globals; /* Array of globals. */ dasm_Section *section; /* Pointer to active section. */ size_t codesize; /* Total size of all code sections. */ int maxsection; /* 0 <= sectionidx < maxsection. */ @@ -89,7 +89,6 @@ void dasm_init(Dst_DECL, int maxsection) { dasm_State *D; size_t psz = 0; - int i; Dst_REF = NULL; DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); D = Dst_REF; @@ -100,12 +99,7 @@ void dasm_init(Dst_DECL, int maxsection) D->pcsize = 0; D->globals = NULL; D->maxsection = maxsection; - for (i = 0; i < maxsection; i++) { - D->sections[i].buf = NULL; /* Need this for pass3. */ - D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); - D->sections[i].bsize = 0; - D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ - } + memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section)); } /* Free DynASM state. */ @@ -125,7 +119,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = gl; DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } @@ -444,7 +438,7 @@ int dasm_encode(Dst_DECL, void *buffer) break; case DASM_REL_LG: if (n < 0) { - ptrdiff_t na = (ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp + 4; + ptrdiff_t na = (ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp + 4; n = (int)na; CK((ptrdiff_t)n == na, RANGE_REL); goto patchrel; @@ -487,7 +481,7 @@ int dasm_encode(Dst_DECL, void *buffer) goto patchrel; } case DASM_LABEL_LG: - ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n); break; case DASM_LABEL_PC: break; case DASM_IMM: diff --git a/dynasm/dasm_mips.h b/dynasm/dasm_mips.h index 3e99a00507..495eaa0ee5 100644 --- a/dynasm/dasm_mips.h +++ b/dynasm/dasm_mips.h @@ -69,7 +69,7 @@ struct dasm_State { size_t lgsize; int *pclabels; /* PC label chains/pos ptrs. */ size_t pcsize; - void **globals; /* Array of globals (bias -10). */ + void **globals; /* Array of globals. */ dasm_Section *section; /* Pointer to active section. */ size_t codesize; /* Total size of all code sections. */ int maxsection; /* 0 <= sectionidx < maxsection. */ @@ -86,7 +86,6 @@ void dasm_init(Dst_DECL, int maxsection) { dasm_State *D; size_t psz = 0; - int i; Dst_REF = NULL; DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); D = Dst_REF; @@ -97,12 +96,7 @@ void dasm_init(Dst_DECL, int maxsection) D->pcsize = 0; D->globals = NULL; D->maxsection = maxsection; - for (i = 0; i < maxsection; i++) { - D->sections[i].buf = NULL; /* Need this for pass3. */ - D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); - D->sections[i].bsize = 0; - D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ - } + memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section)); } /* Free DynASM state. */ @@ -122,7 +116,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = gl; DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } @@ -350,7 +344,7 @@ int dasm_encode(Dst_DECL, void *buffer) break; case DASM_REL_LG: if (n < 0) { - n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp); + n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp); goto patchrel; } /* fallthrough */ @@ -369,7 +363,7 @@ int dasm_encode(Dst_DECL, void *buffer) } break; case DASM_LABEL_LG: - ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n); break; case DASM_LABEL_PC: break; case DASM_IMMS: diff --git a/dynasm/dasm_ppc.h b/dynasm/dasm_ppc.h index fdb89bce4e..30b757e312 100644 --- a/dynasm/dasm_ppc.h +++ b/dynasm/dasm_ppc.h @@ -69,7 +69,7 @@ struct dasm_State { size_t lgsize; int *pclabels; /* PC label chains/pos ptrs. */ size_t pcsize; - void **globals; /* Array of globals (bias -10). */ + void **globals; /* Array of globals. */ dasm_Section *section; /* Pointer to active section. */ size_t codesize; /* Total size of all code sections. */ int maxsection; /* 0 <= sectionidx < maxsection. */ @@ -86,7 +86,6 @@ void dasm_init(Dst_DECL, int maxsection) { dasm_State *D; size_t psz = 0; - int i; Dst_REF = NULL; DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); D = Dst_REF; @@ -97,12 +96,7 @@ void dasm_init(Dst_DECL, int maxsection) D->pcsize = 0; D->globals = NULL; D->maxsection = maxsection; - for (i = 0; i < maxsection; i++) { - D->sections[i].buf = NULL; /* Need this for pass3. */ - D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); - D->sections[i].bsize = 0; - D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ - } + memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section)); } /* Free DynASM state. */ @@ -122,7 +116,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = gl; DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } @@ -354,7 +348,7 @@ int dasm_encode(Dst_DECL, void *buffer) break; case DASM_REL_LG: if (n < 0) { - n = (int)((ptrdiff_t)D->globals[-n] - (ptrdiff_t)cp); + n = (int)((ptrdiff_t)D->globals[-n-10] - (ptrdiff_t)cp); goto patchrel; } /* fallthrough */ @@ -368,7 +362,7 @@ int dasm_encode(Dst_DECL, void *buffer) cp[-1] |= ((n+4) & ((ins & 2048) ? 0x0000fffc: 0x03fffffc)); break; case DASM_LABEL_LG: - ins &= 2047; if (ins >= 20) D->globals[ins-10] = (void *)(base + n); + ins &= 2047; if (ins >= 20) D->globals[ins-20] = (void *)(base + n); break; case DASM_LABEL_PC: break; case DASM_IMM: diff --git a/dynasm/dasm_x86.h b/dynasm/dasm_x86.h index f0327302dc..66a68ea5a4 100644 --- a/dynasm/dasm_x86.h +++ b/dynasm/dasm_x86.h @@ -68,7 +68,7 @@ struct dasm_State { size_t lgsize; int *pclabels; /* PC label chains/pos ptrs. */ size_t pcsize; - void **globals; /* Array of globals (bias -10). */ + void **globals; /* Array of globals. */ dasm_Section *section; /* Pointer to active section. */ size_t codesize; /* Total size of all code sections. */ int maxsection; /* 0 <= sectionidx < maxsection. */ @@ -85,7 +85,6 @@ void dasm_init(Dst_DECL, int maxsection) { dasm_State *D; size_t psz = 0; - int i; Dst_REF = NULL; DASM_M_GROW(Dst, struct dasm_State, Dst_REF, psz, DASM_PSZ(maxsection)); D = Dst_REF; @@ -96,12 +95,7 @@ void dasm_init(Dst_DECL, int maxsection) D->pcsize = 0; D->globals = NULL; D->maxsection = maxsection; - for (i = 0; i < maxsection; i++) { - D->sections[i].buf = NULL; /* Need this for pass3. */ - D->sections[i].rbuf = D->sections[i].buf - DASM_SEC2POS(i); - D->sections[i].bsize = 0; - D->sections[i].epos = 0; /* Wrong, but is recalculated after resize. */ - } + memset((void *)D->sections, 0, maxsection * sizeof(dasm_Section)); } /* Free DynASM state. */ @@ -121,7 +115,7 @@ void dasm_free(Dst_DECL) void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl) { dasm_State *D = Dst_REF; - D->globals = gl - 10; /* Negative bias to compensate for locals. */ + D->globals = gl; DASM_M_GROW(Dst, int, D->lglabels, D->lgsize, (10+maxgl)*sizeof(int)); } @@ -445,7 +439,7 @@ int dasm_encode(Dst_DECL, void *buffer) break; } case DASM_REL_LG: p++; if (n >= 0) goto rel_pc; - b++; n = (int)(ptrdiff_t)D->globals[-n]; + b++; n = (int)(ptrdiff_t)D->globals[-n-10]; /* fallthrough */ case DASM_REL_A: rel_a: n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */ @@ -459,7 +453,7 @@ int dasm_encode(Dst_DECL, void *buffer) } case DASM_IMM_LG: p++; - if (n < 0) { dasma((ptrdiff_t)D->globals[-n]); break; } + if (n < 0) { dasma((ptrdiff_t)D->globals[-n-10]); break; } /* fallthrough */ case DASM_IMM_PC: { int *pb = DASM_POS2PTR(D, n); @@ -469,7 +463,7 @@ int dasm_encode(Dst_DECL, void *buffer) case DASM_LABEL_LG: { int idx = *p++; if (idx >= 10) - D->globals[idx] = (void *)(base + (*p == DASM_SETLABEL ? *b : n)); + D->globals[idx-10] = (void *)(base + (*p == DASM_SETLABEL ? *b : n)); break; } case DASM_LABEL_PC: case DASM_SETLABEL: break; From ff6c496ba1b51ed360065cbc5259f62becd70daa Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 12 Jun 2023 09:19:58 +0200 Subject: [PATCH 6/6] MIPSr6: Add missing files to Makefile install target. Reported by FractalU. --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b0288b4db8..f9952b4361 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,9 @@ FILES_INC= lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h FILES_JITLIB= bc.lua bcsave.lua dump.lua p.lua v.lua zone.lua \ dis_x86.lua dis_x64.lua dis_arm.lua dis_arm64.lua \ dis_arm64be.lua dis_ppc.lua dis_mips.lua dis_mipsel.lua \ - dis_mips64.lua dis_mips64el.lua vmdef.lua + dis_mips64.lua dis_mips64el.lua \ + dis_mips64r6.lua dis_mips64r6el.lua \ + vmdef.lua ifeq (,$(findstring Windows,$(OS))) HOST_SYS:= $(shell uname -s)