Hi,

Could you test the following patch in ports/lang/luajit ?

I don't bump REVISION on purpose for testing.

The patches are enough to make the "testsuite" to pass, but as it is just 
running  luajit -e "print('hello world')"   I am unsure that it is enough.

Some real testing would be welcome.

To test:
$ cd /usr/ports/lang/luajit
$ patch -p0 < luajit.diff
$ make && make repackage
$ make reinstall

If SIGILL still occurs, please report the egdb backtrace.

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