From f14ebe71015dd58d02dda740febfab851fbe4983 Mon Sep 17 00:00:00 2001 From: Datong Sun Date: Mon, 11 Sep 2023 16:05:12 +0800 Subject: [PATCH] chore(patches): apply the LuaJIT ARM64 LDP/STP fusion fix from LuaJIT (#11537) upstream https://github.com/LuaJIT/LuaJIT/commit/b8c6ccd50c61b7a2df5123ddc5a85ac7d089542b KAG-2473 (cherry picked from commit b0ca4241bb7a51089981c7b2ff90191f9b063740) --- .../kong/luajit_ldp_stp_fusion.yaml | 6 +++ ...uaJIT-2.1-20220411_06_ldp_stp_fusion.patch | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 CHANGELOG/unreleased/kong/luajit_ldp_stp_fusion.yaml create mode 100644 build/openresty/patches/LuaJIT-2.1-20220411_06_ldp_stp_fusion.patch diff --git a/CHANGELOG/unreleased/kong/luajit_ldp_stp_fusion.yaml b/CHANGELOG/unreleased/kong/luajit_ldp_stp_fusion.yaml new file mode 100644 index 000000000000..d613d1f1601a --- /dev/null +++ b/CHANGELOG/unreleased/kong/luajit_ldp_stp_fusion.yaml @@ -0,0 +1,6 @@ +message: "Fix incorrect LuaJIT LDP/STP fusion on ARM64 which may sometimes cause incorrect logic" +type: dependency +scope: Core +prs: +jiras: + - "KAG-2473" diff --git a/build/openresty/patches/LuaJIT-2.1-20220411_06_ldp_stp_fusion.patch b/build/openresty/patches/LuaJIT-2.1-20220411_06_ldp_stp_fusion.patch new file mode 100644 index 000000000000..ea36afd13382 --- /dev/null +++ b/build/openresty/patches/LuaJIT-2.1-20220411_06_ldp_stp_fusion.patch @@ -0,0 +1,46 @@ +From b8c6ccd50c61b7a2df5123ddc5a85ac7d089542b Mon Sep 17 00:00:00 2001 +From: Mike Pall +Date: Sat, 9 Sep 2023 18:01:37 +0200 +Subject: [PATCH] ARM64: Fix LDP/STP fusion (again). + +Reported and analyzed by Zhongwei Yao. Fix by Peter Cawley. #1075 +--- + src/lj_emit_arm64.h | 17 +++++++++++++---- + 1 file changed, 13 insertions(+), 4 deletions(-) + +diff --git a/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h b/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h +index d4c542557..9161c9582 100644 +--- a/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h ++++ b/bundle/LuaJIT-2.1-20220411/src/lj_emit_arm64.h +@@ -113,6 +113,17 @@ static int emit_checkofs(A64Ins ai, int64_t ofs) + } + } + ++static LJ_AINLINE uint32_t emit_lso_pair_candidate(A64Ins ai, int ofs, int sc) ++{ ++ if (ofs >= 0) { ++ return ai | A64F_U12(ofs>>sc); /* Subsequent lj_ror checks ofs. */ ++ } else if (ofs >= -256) { ++ return (ai^A64I_LS_U) | A64F_S9(ofs & 0x1ff); ++ } else { ++ return A64F_D(31); /* Will mismatch prev. */ ++ } ++} ++ + static void emit_lso(ASMState *as, A64Ins ai, Reg rd, Reg rn, int64_t ofs) + { + int ot = emit_checkofs(ai, ofs), sc = (ai >> 30) & 3; +@@ -124,11 +135,9 @@ static void emit_lso(ASMState *as, A64Ins ai, Reg rd, Reg rn, int64_t ofs) + uint32_t prev = *as->mcp & ~A64F_D(31); + int ofsm = ofs - (1<>sc)) || +- prev == ((ai^A64I_LS_U) | A64F_N(rn) | A64F_S9(ofsm&0x1ff))) { ++ if (prev == emit_lso_pair_candidate(ai | A64F_N(rn), ofsm, sc)) { + aip = (A64F_A(rd) | A64F_D(*as->mcp & 31)); +- } else if (prev == (ai | A64F_N(rn) | A64F_U12(ofsp>>sc)) || +- prev == ((ai^A64I_LS_U) | A64F_N(rn) | A64F_S9(ofsp&0x1ff))) { ++ } else if (prev == emit_lso_pair_candidate(ai | A64F_N(rn), ofsp, sc)) { + aip = (A64F_D(rd) | A64F_A(*as->mcp & 31)); + ofsm = ofs; + } else {