From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 9099A6ECE3; Mon, 27 Jun 2022 19:04:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9099A6ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1656345864; bh=gD+4izVgQkY0sFqdjFD7N46ztA9tEJ8KHF1j3FJXRfU=; h=In-Reply-To:Date:References:To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=U/sxQx+3T7fxHCF7FBhpqHn4n/K+7d438EuYLCYeuQlZSy3BOOSatsdeGdu6YF3Pw CVI07Lj7Y9zMIqg2qai6WdvB7/J6u+WpxAGsQva17vti7o9ay1+B8A3v7APKzV4NY9 j3VnTa0rZia6YoT51p+Y5O5PjptdAruMQzCuQuDU= Received: from smtp29.i.mail.ru (smtp29.i.mail.ru [94.100.177.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id AF7AE6ECE3 for ; Mon, 27 Jun 2022 19:04:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org AF7AE6ECE3 Received: by smtp29.i.mail.ru with esmtpa (envelope-from ) id 1o5rDr-0005KT-5d; Mon, 27 Jun 2022 19:04:23 +0300 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) In-Reply-To: <20220127115346.22800-1-skaplun@tarantool.org> Date: Mon, 27 Jun 2022 19:04:22 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <60369E65-251D-4C39-B8BB-0EE3E291DC16@tarantool.org> References: <20220127115346.22800-1-skaplun@tarantool.org> To: Sergey Kaplun X-Mailer: Apple Mail (2.3696.100.31) X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD921FF253C2DCA6432B19C84BDF7B311F5398DDA30710E2DF100894C459B0CD1B90508466942BA2B5C2A81FA72ADD0F6BFB8A39A109BFDF921A7427CD01E6BCEC9 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 0D63561A33F958A5E0C6BFA28A04D07D931B617FC52BF4C61512755ABDCEBA31D59269BC5F550898D99A6476B3ADF6B4886A5961035A09600383DAD389E261318FB05168BE4CE3AF X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34DFB7A809FB5370870E7E9DE3ED90AF86B567D5A0F97694B2FB8F41191D701F35F1DC148740E099DE1D7E09C32AA3244C5548A6F1FC7318B3AA0A11425BAC315ED9ADFF0C0BDB8D1FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj8L65zF8kk4cBrj0i0pwekw== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE40767057A73D2DC12432FE5F2268511FA5DD87BDD711256813D19381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: OK Subject: Re: [Tarantool-patches] [PATCH luajit] Fix bytecode dump unpatching. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for the patch! Just some nits in changelog, LGTM Sergos > On 27 Jan 2022, at 14:53, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > Reported by Christopher Oliver. >=20 > (cherry picked from commit 20ac817a747cf8cab044ae81b09c08d23e34342b) >=20 > When a compiled function with up-recursion RET bytecodes are patched = to > JLOOP bytecode. If I got it right?=20 =E2=80=9CRET bytecodes are patched to JLOOP bytecode in a function with = up-recursion." > During dump of those bytecodes they should be unpatched ^^^ ^^^^^ remove 2 words > to the original one. > It is done by restoring the opcode by subtraction > the diff between JLOOP and ILOOP bytecodes. That gives the LOOP > bytecodes instead RET as expected. The restore was done by the erroneous opcode subtraction, that led to a = LOOP bytecode in place of the RET one. > This patch fixes the bytecode unpatching via copy the original start of ???? > instruction, that was patched. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#6548 > --- >=20 > Branch: = https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-wrong-bc-ret > Tarantool branch: = https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-wrong-bc-r= et-full-ci > Related issue: https://github.com/tarantool/tarantool/issues/6548 >=20 > src/lj_bcwrite.c | 5 +---- > .../bc-jit-unpatching.test.lua | 22 +++++++++++++++++++ > 2 files changed, 23 insertions(+), 4 deletions(-) > create mode 100644 test/tarantool-tests/bc-jit-unpatching.test.lua >=20 > diff --git a/src/lj_bcwrite.c b/src/lj_bcwrite.c > index 5e05caea..a86d6d00 100644 > --- a/src/lj_bcwrite.c > +++ b/src/lj_bcwrite.c > @@ -219,10 +219,7 @@ static char *bcwrite_bytecode(BCWriteCtx *ctx, = char *p, GCproto *pt) > q[LJ_ENDIAN_SELECT(0, 3)] =3D (uint8_t)(op-BC_IFORL+BC_FORL); > } else if (op =3D=3D BC_JFORL || op =3D=3D BC_JITERL || op =3D=3D = BC_JLOOP) { > BCReg rd =3D q[LJ_ENDIAN_SELECT(2, 1)] + (q[LJ_ENDIAN_SELECT(3, = 0)] << 8); > - BCIns ins =3D traceref(J, rd)->startins; > - q[LJ_ENDIAN_SELECT(0, 3)] =3D (uint8_t)(op-BC_JFORL+BC_FORL); > - q[LJ_ENDIAN_SELECT(2, 1)] =3D bc_c(ins); > - q[LJ_ENDIAN_SELECT(3, 0)] =3D bc_b(ins); > + memcpy(q, &traceref(J, rd)->startins, 4); > } > } > } > diff --git a/test/tarantool-tests/bc-jit-unpatching.test.lua = b/test/tarantool-tests/bc-jit-unpatching.test.lua > new file mode 100644 > index 00000000..9f9cb390 > --- /dev/null > +++ b/test/tarantool-tests/bc-jit-unpatching.test.lua > @@ -0,0 +1,22 @@ > +local tap =3D require('tap') > +local utils =3D require('utils') > + > +local test =3D tap.test('bc-jit-unpatching') > +test:plan(1) > + > +-- Function with up-recursion. > +local function f(n) > + return n < 2 and n or f(n - 1) + f(n - 2) > +end > + > +local ret1bc =3D 'RET1%s*1%s*2' > +-- Check that this bytecode still persists. > +assert(utils.hasbc(loadstring(string.dump(f)), ret1bc)) > + > +-- Compile function to get JLOOP bytecode in recursion. Do you need any jit.opt.start(=E2=80=98hotloop=3D1=E2=80=99) here? > +f(10) > + > +test:ok(utils.hasbc(loadstring(string.dump(f)), ret1bc), > + 'bytecode unpached correctly') > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.34.1 >=20