From 2d46e99fdf512ed6d18b6fe123edad3cc20dd710 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 30 Jan 2023 17:33:39 -0800 Subject: [PATCH 1/2] Segmentation fault while running test-suite and iter.lua Test case failuer on pcc64le --- src/vm_ppc.dasc | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc index 14a7f8216..13fc7fd82 100644 --- a/src/vm_ppc.dasc +++ b/src/vm_ppc.dasc @@ -977,8 +977,11 @@ static void build_subroutines(BuildCtx *ctx) |.if FFI | cmplwi TMP0, 1 |.endif - | lwz PC, -16(RB) // Restore PC from [cont|PC]. - | subi TMP2, RD, 8 + |// PC value corrected to avoid segfault + | lwz PC, FRAME_CONTPC(RB) // Restore PC from [cont|PC]. + | addi BASEP4, BASE, 4 + | addi TMP2, RD, WORD_HI-8 + | lwz TMP1, LFUNC:TMP1->pc | stwx TISNIL, RA, TMP2 // Ensure one valid arg. |.if P64 | ld TMP3, 0(DISPATCH) @@ -986,7 +989,9 @@ static void build_subroutines(BuildCtx *ctx) |.if FFI | ble >1 |.endif - | lwz TMP1, LFUNC:TMP1->pc + |.if P64 + | add TMP0, TMP0, TMP3 + |.endif | lwz KBASE, PC2PROTO(k)(TMP1) | // BASE = base, RA = resultptr, RB = meta base | mtctr TMP0 @@ -1715,24 +1720,33 @@ static void build_subroutines(BuildCtx *ctx) | |//-- Base library: iterators ------------------------------------------- | - |.ffunc_1 next - | stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. - | checktab CARG3 + |.ffunc next + | cmplwi NARGS8:RC, 8 + | lwz TAB:CARG1, WORD_LO(BASE) + | blt ->fff_fallback + |.if ENDIAN_LE + | add TMP1, BASE, NARGS8:RC + | stw TISNIL, WORD_HI(TMP1) // Set missing 2nd arg to nil. + |.else + | stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. + |.endif | lwz PC, FRAME_PC(BASE) - | bne ->fff_fallback + | stp BASE, L->base // Add frame since C call can throw. + | stp BASE, L->top // Dummy frame length is ok. | la CARG2, 8(BASE) | la CARG3, -8(BASE) - | bl extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o) + | stw PC, SAVE_PC + | bl extern lj_tab_next // (GCtab *t, cTValue *key,TValue *o) | // Returns 1=found, 0=end, -1=error. | cmpwi CRET1, 0 | la RA, -8(BASE) | li RD, (2+1)*8 - | bgt ->fff_res // Found key/value. + | bgt ->fff_res // Found key/value. | li CARG3, LJ_TNIL - | beq ->fff_restv // End of traversal: return nil. + | beq ->fff_restv // End of traversal: return nil. | lwz CFUNC:RB, FRAME_FUNC(BASE) | li NARGS8:RC, 2*8 - | b ->fff_fallback // Invalid key. + | b ->fff_fallback // Invalid key. | |.ffunc_1 pairs | checktab CARG3 @@ -5667,10 +5681,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq | add TMP3, PC, TMP0 | bne cr0, >5 - | lus TMP1, (LJ_KEYINDEX >> 16) - | ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff) - | stw ZERO, -4(RA) // Initialize control var. - | stw TMP1, -8(RA) + | lus TMP1, 0xfffe + | ori TMP1, TMP1, 0x7fff + | stw ZERO, WORD_LO-8(RA) // Initialize control var. + | stw TMP1, WORD_HI-8(RA) | addis PC, TMP3, -(BCBIAS_J*4 >> 16) |1: | ins_next From a94adaf862c7481e3f97a2f2b0c653982cf4e0e7 Mon Sep 17 00:00:00 2001 From: vikasgupta8 Date: Thu, 5 Oct 2023 09:43:34 +0000 Subject: [PATCH 2/2] Added code to support PPC64LE --- src/vm_ppc.dasc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc index 13fc7fd82..6e5775d36 100644 --- a/src/vm_ppc.dasc +++ b/src/vm_ppc.dasc @@ -977,11 +977,16 @@ static void build_subroutines(BuildCtx *ctx) |.if FFI | cmplwi TMP0, 1 |.endif + |.if P64 |// PC value corrected to avoid segfault | lwz PC, FRAME_CONTPC(RB) // Restore PC from [cont|PC]. | addi BASEP4, BASE, 4 | addi TMP2, RD, WORD_HI-8 | lwz TMP1, LFUNC:TMP1->pc + |.else + | lwz PC, -16(RB) // Restore PC from [cont|PC]. + | subi TMP2, RD, 8 + |.endif | stwx TISNIL, RA, TMP2 // Ensure one valid arg. |.if P64 | ld TMP3, 0(DISPATCH) @@ -991,6 +996,8 @@ static void build_subroutines(BuildCtx *ctx) |.endif |.if P64 | add TMP0, TMP0, TMP3 + |.else + | lwz TMP1, LFUNC:TMP1->pc |.endif | lwz KBASE, PC2PROTO(k)(TMP1) | // BASE = base, RA = resultptr, RB = meta base @@ -1720,6 +1727,7 @@ static void build_subroutines(BuildCtx *ctx) | |//-- Base library: iterators ------------------------------------------- | + |.if P64 |.ffunc next | cmplwi NARGS8:RC, 8 | lwz TAB:CARG1, WORD_LO(BASE) @@ -1737,6 +1745,16 @@ static void build_subroutines(BuildCtx *ctx) | la CARG3, -8(BASE) | stw PC, SAVE_PC | bl extern lj_tab_next // (GCtab *t, cTValue *key,TValue *o) + |.else + |.ffunc_1 next + | stwx TISNIL, BASE, NARGS8:RC // Set missing 2nd arg to nil. + | checktab CARG3 + | lwz PC, FRAME_PC(BASE) + | bne ->fff_fallback + | la CARG2, 8(BASE) + | la CARG3, -8(BASE) + | bl extern lj_tab_next // (GCtab *t, cTValue *key, TValue *o) + |.endif | // Returns 1=found, 0=end, -1=error. | cmpwi CRET1, 0 | la RA, -8(BASE) @@ -5681,10 +5699,17 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop) | crand 4*cr0+eq, 4*cr0+eq, 4*cr7+eq | add TMP3, PC, TMP0 | bne cr0, >5 + |.if P64 | lus TMP1, 0xfffe | ori TMP1, TMP1, 0x7fff | stw ZERO, WORD_LO-8(RA) // Initialize control var. | stw TMP1, WORD_HI-8(RA) + |.else + | lus TMP1, (LJ_KEYINDEX >> 16) + | ori TMP1, TMP1, (LJ_KEYINDEX & 0xffff) + | stw ZERO, -4(RA) // Initialize control var. + | stw TMP1, -8(RA) + |.endif | addis PC, TMP3, -(BCBIAS_J*4 >> 16) |1: | ins_next