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 738914124A9; Mon, 15 Jan 2024 18:43:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 738914124A9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1705333433; bh=kORdR5EIEg8ixNTwmFRsRzDG3grnxlE+J2PbE3//q/o=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wqcbYxxu0pkFertrzEGhHFI5JksyAu5knNLqkp9rsu+uxkAtOL4I3JdfTNDL+P8In Kipg9zE1XiYkZrn6UHHy2tinfcRZsg1s4ZU7lG+lHqsm5/vvhXOw2lMTDrGEfY5hST VpJja0PDvvJfNH/QduBpdbZQfK59kAao4qeD3RcU= Received: from smtp44.i.mail.ru (smtp44.i.mail.ru [95.163.41.82]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5CB714124A9 for ; Mon, 15 Jan 2024 18:43:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5CB714124A9 Received: by smtp44.i.mail.ru with esmtpa (envelope-from ) id 1rPP7v-00DNvL-1B; Mon, 15 Jan 2024 18:43:51 +0300 Date: Mon, 15 Jan 2024 18:39:38 +0300 To: Maxim Kokryashkin Message-ID: References: <20240115142914.22527-1-m.kokryashkin@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240115142914.22527-1-m.kokryashkin@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD950579510D3C71096099F67255A28B1AE58695AF48E8B7AA500894C459B0CD1B9C1EC0167953E2A3B0975076A5D446B96EA6B95E0524EC278978AC9872AA98EF9 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78E88BD1CA827EF00C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE72407438AC6002944EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B73AB1701401CD8713DCFC255B3FF11C42ED2DC3FE295B2F7CC7F00164DA146DAFE8445B8C89999728AA50765F790063793270F7220657A0A389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8A9FF340AA05FB58CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE33AC447995A7AD181150BA43C84913FC3A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735438480C876D879DDC4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A564A599667ED405BA532DDABA8889290AE882F8738B50D074F87CCE6106E1FC07E67D4AC08A07B9B0A816C540FC8EEC30CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF122E0490BAC06978B846E09D47A7F94E3FC79AF348CAEB23E051E23EDEB9FAD6ABDA6BB679979B95151C858F58AF3247C128B044413F47E1915DA6C895B62D58E48CAC7CA610320002C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioji89z+8RvaBMfb9nhKRfblw== X-DA7885C5: AE0253C22462F60A32DC58E6D3486BE11610E44C27A855C2ABB253C41C319266262E2D401490A4A0DB037EFA58388B346E8BC1A9835FDE71 X-Mailru-Sender: 689FA8AB762F7393590D8C940224AE33B7E3A2C7E5D3695F0047379F6141CE8E0FBE9A32752B8C9C2AA642CC12EC09F1FB559BB5D741EB962F61BD320559CF1EFD657A8799238ED55FEEDEB644C299C0ED14614B50AE0675 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix recording of __concat metamethod. 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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim! Thanks for the patch! LGTM, after adding a comment about the magic sequence of values for the concatenation (see the comment below). On 15.01.24, Maxim Kokryashkin wrote: > From: Mike Pall > > Reported by Elias Oelschner. Analyzed by XmiliaH. > > (cherry-picked from commit 3ee3c9cfa988339f1bf3068530515e2a6fb179d2) > > During the recording of `__concat` methametod, the `rec_mm_arith` > function overrides stack slots that are not restored for GC64 > mode later after the call. This leads to a segmentation fault > later on. This patch fixes the issue by accounting for those > additional slots in the array that is used to restore stack Minor: "slots in the array that is used to restore" sounds a little cumbersome. I suggest to say "slots in the array used for restoring" Feel free to ignore. > values. > > Maxim Kokryashkin: > * added the description and the test for the problem > > Part of tarantool/tarantool#9145 > --- > Branch: https://github.com/tarantool/luajit/tree/fckxorg/lj-839-concat-recording > PR: https://github.com/tarantool/tarantool/pull/9597 > Issues: https://github.com/tarantool/tarantool/issues/9145 > https://github.com/luajit/luajit/issues/839 > > src/lj_record.c | 2 +- > .../lj-839-concat-recording.test.lua | 27 +++++++++++++++++++ > 2 files changed, 28 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/lj-839-concat-recording.test.lua > > diff --git a/src/lj_record.c b/src/lj_record.c > index a929b8aa..59549b03 100644 > --- a/src/lj_record.c > +++ b/src/lj_record.c > @@ -1932,7 +1932,7 @@ static TRef rec_tnew(jit_State *J, uint32_t ah) > static TRef rec_cat(jit_State *J, BCReg baseslot, BCReg topslot) > { > TRef *top = &J->base[topslot]; > - TValue savetv[5]; > + TValue savetv[5+LJ_FR2]; > BCReg s; > RecordIndex ix; > lj_assertJ(baseslot < topslot, "bad CAT arg"); > diff --git a/test/tarantool-tests/lj-839-concat-recording.test.lua b/test/tarantool-tests/lj-839-concat-recording.test.lua > new file mode 100644 > index 00000000..9ec0ed96 > --- /dev/null > +++ b/test/tarantool-tests/lj-839-concat-recording.test.lua > @@ -0,0 +1,27 @@ > +local tap = require('tap') > +local test = tap.test('lj-839-concat-recording'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > +test:plan(1) > + > +-- Test file to demonstrate LuaJIT overriding stack slots without > +-- restoration during the recording of the concat metamethod. > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/839. > + > +-- Setup value with the `__concat` metamethod. > +local v1 = setmetatable({}, { > + __concat = function() return "" end, Typo: s/""/''/, according to the codestyle. Nit: 2 extra whitespaces at the beginning. > +}); > + > +jit.opt.start('hotloop=1') > +local result > +for _ = 1, 4 do > + result = v1 .. "" .. v1 .. "" Typo: s/""/''/g, according to the codestyle. Why do we need exactly this sequence? Please add a comment. > +end > + > +-- There should be an empty string in case of success. Typo: s/case/the case/ > +-- Failure results in a segmentation fault. > +-- The issue is GC64-specific, yet it is still being tested for > +-- other builds. > +test:is(result, '', 'correct stack restoration') > +test:done(true) > -- > 2.43.0 > -- Best regards, Sergey Kaplun