On Wed, Jun 14, 2023 at 10:49:32PM +0200, Peter N. M. Hansteen wrote:
> A similar situation with hexchat, after a fresh sysupgrade and reinstall of 
> that package:
> 
> [Wed Jun 14 22:43:33] peter@zaida:~$ egdb hexchat hexchat.core
> GNU gdb (GDB) 9.2
> Copyright (C) 2020 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> Type "show copying" and "show warranty" for details.
> This GDB was configured as "x86_64-unknown-openbsd7.3".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
>     <http://www.gnu.org/software/gdb/documentation/>.
> 
> For help, type "help".
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from hexchat...
> (No debugging symbols found in hexchat)
> [New process 593923]
> [New process 578391]
> [New process 480615]
> [New process 123122]
> Core was generated by `hexchat'.
> Program terminated with signal SIGILL, Illegal instruction.
> #0  0x00000288f07bf992 in lj_BC_FUNCC () from 
> /usr/local/lib/libluajit-5.1.so.1.0

There is already a diff for luajit at 
https://marc.info/?l=openbsd-ports&m=168667722510843&w=2 (I included it below).

It was first reported with neovim, but I found later that neovim was using 
embedded version of luajit (so patching lang/luajit port was ineffective).

hexchat is using lang/luajit, so is it possible to test it ?

thanks.
-- 
Sebastien Marie

Index: patches/patch-dynasm_dasm_x86_lua
===================================================================
RCS file: patches/patch-dynasm_dasm_x86_lua
diff -N patches/patch-dynasm_dasm_x86_lua
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-dynasm_dasm_x86_lua   13 Jun 2023 13:36:00 -0000
@@ -0,0 +1,13 @@
+Teach luajit about endbr64 instruction (on amd64 only)
+
+Index: dynasm/dasm_x86.lua
+--- dynasm/dasm_x86.lua.orig
++++ dynasm/dasm_x86.lua
+@@ -960,6 +960,7 @@ local map_op = {
+   lea_2 =     "rx1dq:8DrM",
+   -- 8E: *mov seg,mdw
+   -- 8F: pop mdw
++  _CET_ENDBR_0 = (x64 and "F30F1EFA"),
+   nop_0 =     "90",
+   xchg_2 =    "Rrqdw:90R|rRqdw:90r|rm:87rM|mr:87Rm",
+   cbw_0 =     "6698",
Index: patches/patch-src_vm_x86_dasc
===================================================================
RCS file: patches/patch-src_vm_x86_dasc
diff -N patches/patch-src_vm_x86_dasc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_vm_x86_dasc       13 Jun 2023 13:36:00 -0000
@@ -0,0 +1,179 @@
+Index: src/vm_x86.dasc
+--- src/vm_x86.dasc.orig
++++ src/vm_x86.dasc
+@@ -4574,6 +4574,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+   /* -- Constant ops ------------------------------------------------------ */
+ 
+   case BC_KSTR:
++    |  _CET_ENDBR
+     |  ins_AND        // RA = dst, RD = str const (~)
+     |  mov RD, [KBASE+RD*4]
+     |  mov dword [BASE+RA*8+4], LJ_TSTR
+@@ -4582,6 +4583,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+   case BC_KCDATA:
+     |.if FFI
++    |  _CET_ENDBR
+     |  ins_AND        // RA = dst, RD = cdata const (~)
+     |  mov RD, [KBASE+RD*4]
+     |  mov dword [BASE+RA*8+4], LJ_TCDATA
+@@ -4590,6 +4592,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     |.endif
+     break;
+   case BC_KSHORT:
++    |  _CET_ENDBR
+     |  ins_AD // RA = dst, RD = signed int16 literal
+     |.if DUALNUM
+     |  movsx RD, RDW
+@@ -4606,6 +4609,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     |  ins_next
+     break;
+   case BC_KNUM:
++    |  _CET_ENDBR
+     |  ins_AD // RA = dst, RD = num const
+     |.if SSE
+     |  movsd xmm0, qword [KBASE+RD*8]
+@@ -4617,11 +4621,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     |  ins_next
+     break;
+   case BC_KPRI:
++    |  _CET_ENDBR
+     |  ins_AND        // RA = dst, RD = primitive type (~)
+     |  mov [BASE+RA*8+4], RD
+     |  ins_next
+     break;
+   case BC_KNIL:
++    |  _CET_ENDBR
+     |  ins_AD // RA = dst_start, RD = dst_end
+     |  lea RA, [BASE+RA*8+12]
+     |  lea RD, [BASE+RD*8+4]
+@@ -4859,6 +4865,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_GGET:
++    | _CET_ENDBR
+     |  ins_AND        // RA = dst, RD = str const (~)
+     |  mov LFUNC:RB, [BASE-8]
+     |  mov TAB:RB, LFUNC:RB->env
+@@ -4866,6 +4873,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     |  jmp ->BC_TGETS_Z
+     break;
+   case BC_GSET:
++    | _CET_ENDBR
+     |  ins_AND        // RA = src, RD = str const (~)
+     |  mov LFUNC:RB, [BASE-8]
+     |  mov TAB:RB, LFUNC:RB->env
+@@ -5281,6 +5289,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+   /* -- Calls and vararg handling ----------------------------------------- */
+ 
+   case BC_CALL: case BC_CALLM:
++    |  _CET_ENDBR
+     |  ins_A_C        // RA = base, (RB = nresults+1,) RC = nargs+1 | 
extra_nargs
+     if (op == BC_CALLM) {
+       |  add NARGS:RD, MULTRES
+@@ -5293,11 +5302,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_CALLMT:
++    |  _CET_ENDBR
+     |  ins_AD // RA = base, RD = extra_nargs
+     |  add NARGS:RD, MULTRES
+     |  // Fall through. Assumes BC_CALLT follows and ins_AD is a no-op.
+     break;
+   case BC_CALLT:
++    |  _CET_ENDBR
+     |  ins_AD // RA = base, RD = nargs+1
+     |  lea RA, [BASE+RA*8+8]
+     |  mov KBASE, BASE                        // Use KBASE for move + 
vmeta_call hint.
+@@ -5361,6 +5372,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_ITERC:
++    |  _CET_ENDBR
+     |  ins_A  // RA = base, (RB = nresults+1,) RC = nargs+1 (2+1)
+     |  lea RA, [BASE+RA*8+8]          // fb = base+1
+     |.if X64
+@@ -5390,6 +5402,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_ITERN:
++    |  _CET_ENDBR
+     |  ins_A  // RA = base, (RB = nresults+1, RC = nargs+1 (2+1))
+     |.if JIT
+     |  // NYI: add hotloop, record BC_ITERN.
+@@ -5480,6 +5493,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_ISNEXT:
++    |  _CET_ENDBR
+     |  ins_AD // RA = base, RD = target (points to ITERN)
+     |  cmp dword [BASE+RA*8-20], LJ_TFUNC; jne >5
+     |  mov CFUNC:RB, [BASE+RA*8-24]
+@@ -5499,6 +5513,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_VARG:
++    |  _CET_ENDBR
+     |  ins_ABC        // RA = base, RB = nresults+1, RC = numparams
+     |  mov TMP1, KBASE                        // Need one more free register.
+     |  lea KBASE, [BASE+RC*8+(8+FRAME_VARG)]
+@@ -5584,12 +5599,14 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+   /* -- Returns ----------------------------------------------------------- */
+ 
+   case BC_RETM:
++    |  _CET_ENDBR
+     |  ins_AD // RA = results, RD = extra_nresults
+     |  add RD, MULTRES                        // MULTRES >=1, so RD >=1.
+     |  // Fall through. Assumes BC_RET follows and ins_AD is a no-op.
+     break;
+ 
+   case BC_RET: case BC_RET0: case BC_RET1:
++    |  _CET_ENDBR
+     |  ins_AD // RA = results, RD = nresults+1
+     if (op != BC_RET0) {
+       |  shl RA, 3
+@@ -5939,6 +5956,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+    */
+ 
+   case BC_FUNCF:
++    |  _CET_ENDBR
+     |.if JIT
+     |  hotcall RB
+     |.endif
+@@ -5947,10 +5965,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_JFUNCF:
++    |  _CET_ENDBR
+ #if !LJ_HASJIT
+     break;
+ #endif
+   case BC_IFUNCF:
++    |  _CET_ENDBR
+     |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1
+     |  mov KBASE, [PC-4+PC2PROTO(k)]
+     |  mov L:RB, SAVE_L
+@@ -5977,6 +5997,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;
+ 
+   case BC_JFUNCV:
++    |  _CET_ENDBR
+ #if !LJ_HASJIT
+     break;
+ #endif
+@@ -5984,6 +6005,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+     break;  /* NYI: compiled vararg functions. */
+ 
+   case BC_IFUNCV:
++    |  _CET_ENDBR
+     |  ins_AD  // BASE = new base, RA = framesize, RD = nargs+1
+     |  lea RB, [NARGS:RD*8+FRAME_VARG]
+     |  lea RD, [BASE+NARGS:RD*8]
+@@ -6030,6 +6052,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defo
+ 
+   case BC_FUNCC:
+   case BC_FUNCCW:
++    |  _CET_ENDBR
+     |  ins_AD  // BASE = new base, RA = ins RA|RD (unused), RD = nargs+1
+     |  mov CFUNC:RB, [BASE-8]
+     |  mov KBASEa, CFUNC:RB->f

Reply via email to