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 34CE36E0C4; Tue, 24 Nov 2026 18:49:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 34CE36E0C4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1795535353; bh=76/EvurTrKkXecfainQvm5HWPUr6PY/EZWaBxqy7mgs=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=mK0civLT9Y0xqo7GxgxBSQpKKSj/vqVjPysOovKWymySqmY30TvP4BWpNQJ5aYW6N fqOFN7wvUNuCOv51XazneIt8aaAhHDdLCb8V9qorNUdPx4WbK/O7WgD261+N/YRS0T a68EjH657X4sr4tj/odTLlv6Pe4xlrTe8dr4WOIE= Received: from send149.i.mail.ru (send149.i.mail.ru [89.221.237.244]) (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 BB5586E0C4 for ; Tue, 24 Nov 2026 18:49:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BB5586E0C4 Received: by exim-smtp-canary-10-7cf57c478c-rwcs4 with esmtpa (envelope-from ) id 1xVsla-00000000MJ4-2Ng1; Tue, 24 Nov 2026 18:49:10 +0300 To: Evgeniy Temirgaleev , Sergey Bronnikov Date: Tue, 24 Nov 2026 18:51:25 +0300 Message-ID: <20261124155125.1713061-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.56.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD977B76FDA87AFA8B97B9B6F0E16AC57D3BBA1E96A3BE64445182A05F5380850406395AF0F3D2A844C3DE06ABAFEAF6705B73589B50238DFCEDD8E9C3A7639EBFB21809EC83B530B45 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79A02CDD1178524C2EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB5533756603DA5D6BE41EFC0DAC9117DB95975183C95CADEF28ED2A78934B2DF10E9CA21D389733CBF5DBD5E9D5E8D9A59859A8B6E5E764EB5D94DBD4CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB86D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE70BB89B22BF4660DC731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5DB338522633A3F7E5002B1117B3ED69624271E39A5024C77F09842853758E9E5823CB91A9FED034534781492E4B8EEAD13926AAAFEFA6645C79554A2A72441328621D336A7BC284946AD531847A6065A535571D14F44ED41 X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34C77DD89D51EBB774225B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659C7454204A3B2740660DE0494F94ADB8F86166B4E1838D19E261E13D1D3114993AC183E5F77A070A4B8341EE9D5BE9A0A1FDC945A0707E91FF5A16A87C941AECE2AAA204FA968222CC7CEAA0681F5848F4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXOcIETfglQORZ0zpDET4Zrk3igikrdHlWA+E1RsG2kB9sl0Q2O/NArY= X-Mailru-Sender: 689FA8AB762F73937C9FA53A4753B313ACE254384A2021FDC7EFEF61D83745CD612C7F4598571DD5E49D44BB4BD9522A059A1ED8796F048DB274557F927329BE89D5A3BC2B10C37545BD1C3CC395C826B4A721A3011E896F X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit] FFI: Adjust J->maxslot after ffi.offsetof. 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" From: Mike Pall Reported by Elias Hogstvedt. (cherry picked from commit 3000f7cdb1123f2a4d8b690d4292c541359c670c) The `recff_ffi_xof()` for `ffi.offsetof()` records 3 slots returned to the Lua stack unconditionally, while the VM returns this much only for bitfields. This leads to the maximum slot assertion failure in the `rec_check_slots()`. This patch fixes this by adjusting the `maxslot` before the recording of the next instruction in the `LJ_POST_FIXCONST` fixup step by the correct slots delta. Sergey Kaplun: * added the description and the test for the problem Part of tarantool/tarantool#13442 --- Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1514-ffi-offsetof-maxslot Related issues: * https://github.com/LuaJIT/LuaJIT/issues/1514 * https://github.com/tarantool/tarantool/issues/13442 src/lj_record.c | 2 ++ .../lj-1514-ffi-offsetof-maxslot.test.lua | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua diff --git a/src/lj_record.c b/src/lj_record.c index dbfc7f47..ffc07b52 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -2118,6 +2118,8 @@ void lj_record_ins(jit_State *J) { BCReg s; TValue *tv = J->L->base; + ptrdiff_t delta = J->L->top - tv; + if (J->maxslot > (BCReg)delta) J->maxslot = (BCReg)delta; for (s = 0; s < J->maxslot; s++) /* Constify stack slots (if any). */ if (J->base[s] == TREF_NIL && !tvisnil(&tv[s])) J->base[s] = lj_record_constify(J, &tv[s]); diff --git a/test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua b/test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua new file mode 100644 index 00000000..dd6cc50f --- /dev/null +++ b/test/tarantool-tests/lj-1514-ffi-offsetof-maxslot.test.lua @@ -0,0 +1,34 @@ +local tap = require('tap') + +-- The test file to demonstrate an incorrect JIT slots recording +-- for the `ffi.offsetof()` fast function. +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1514. +local test = tap.test('lj-1514-ffi-offsetof-maxslot'):skipcond({ + ['Test requires JIT enabled'] = not jit.status(), +}) + +test:plan(1) + +local ffi = require('ffi') + +ffi.cdef[[ + struct test {int a;} +]] + +jit.opt.start('hotloop=1') + +local ct = ffi.typeof('struct test') + +local res +for _ = 1, 4 do + -- Need to use CALLM for the `ffi.offsetof()` call to adjust + -- JIT slots to occupy extra slots above the top of the Lua + -- stack. Use `tonumber()` as an external function as the + -- simplest proxy. `ffi.offsetof()` returns 1 value for regular + -- fields. + res = tonumber(ffi.offsetof(ct, 'a')) +end + +test:is(res, 0, 'correct offset value') + +test:done(true) -- 2.56.0