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 6ED3C6F3C4; Tue, 11 May 2021 01:31:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6ED3C6F3C4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1620685913; bh=1lYryjGTUXB17/Kqb2pnag+uGYoweVPgjpdaNXC3R80=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=rL6rlufso0dSEji5vE0nExAGivhgW/lfnSOjWqLvnJUzIl2o5QJ5ONaEBWrYE9Qbm rD4FYEe+U90gVM9gAHxXHzZ9TBwOkGkfmcXfeq+wInC/bNi4iPU8J6S4F0TPLzRmOP FDp4YVHd3EAxGLT88lSIwHX9YhlYEgq1WzNmfWU8= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 B76F46F814 for ; Tue, 11 May 2021 01:30:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B76F46F814 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lgEPt-0001ky-Qg; Tue, 11 May 2021 01:30:22 +0300 To: Sergey Ostanevich , Sergey Kaplun Date: Tue, 11 May 2021 01:09:07 +0300 Message-Id: <6753245c0309ed77250a6ac41fb7bfd3f82676c2.1620678384.git.imun@tarantool.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD95978C26455E69BE0ABDB394FB841241C41AA4B146174B5D1182A05F53808504044A2D9C161296DFB76D04AE7F18427D13FEFD090184D642956E05FE139A0D87E X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7E99F7FC786761FD8C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE709CF9AF650BAB6C1EA1F7E6F0F101C67CDEEF6D7F21E0D1D9295C2E9FA3191EE1B59CA4C82EFA6583CE8FE209BC9DC4134CAA235CEAD3585F6B57BC7E64490618DEB871D839B73339E8FC8737B5C2249957A4DEDD2346B42CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92176DF2183F8FC7C0A3E989B1926288338941B15DA834481F9449624AB7ADAF372E808ACE2090B5E14AD6D5ED66289B5259CC434672EE63711DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C30E7A8B1B1FD51AB935872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2AD77751E876CB595E8F7B195E1C978315B91A4E0F07C724B008EF5BE183B7CB3 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C08CF033E463A5088A1B308DBBB285C4BF3072138F3770A7A9C2B6934AE262D3EE7EAB7254005DCED114C52B35DBB74F4E7EAB7254005DCEDEC0BC6DB5D5D7B8B1E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0D18C7F408F36097E8E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A63B03BCD35E0C0A6B589E9E8DCA7A48A42C7C3F1D131F89E5E063166CCADF4E392845E52C2044371D7E09C32AA3244CFA29B0447CAC8672BAED0E6C1C362B737C0C08F7987826B9927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojW8rfvRc3+AoIQmGxKZrTBw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A0638222641E87556EFE8B466A9257C4C310194A7C8D0F45F857DBFE9F1EFEE2F478337FB559BB5D741EB964C8C2C849690F8E70A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit 3/3] FFI/ARM64/OSX: Fix vararg call handling. 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: Igor Munkin via Tarantool-patches Reply-To: Igor Munkin Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall Thanks to Igor Munkin. (cherry picked from commit 521b367567dc5d91d7f9ae29c257998953e24e53) This patch fixes the issue introduced by commit 2e2fb8f6b5118e1a7996b76600c6ee98bfd5f203 ('OSX/iOS: Handle iOS simulator and ARM64 Macs.'). Within the mentioned commit LJ_TARGET_IOS define is set via Apple system header to enable several features (e.g. JIT and external unwinder) on ARM64 Macs, but its usage was not adjusted source-wide. This is done for FFI machinery within this commit. Since all LJ_TARGET_IOS usage is done with LJ_TARGET_ARM64 define being set, we can simply replace all occurrences with LJ_TARGET_OSX. Igor Munkin: * added the description and the test for the problem Part of tarantool/tarantool#5629 Relates to tarantool/tarantool#5983 Reported-by: Nikita Pettik Signed-off-by: Igor Munkin --- src/lj_ccall.c | 8 ++++---- src/lj_ccallback.c | 2 +- .../lj-695-ffi-vararg-call.test.lua | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/tarantool-tests/lj-695-ffi-vararg-call.test.lua diff --git a/src/lj_ccall.c b/src/lj_ccall.c index 5c252e5b..06d1b3bd 100644 --- a/src/lj_ccall.c +++ b/src/lj_ccall.c @@ -334,7 +334,7 @@ isfp = sz == 2*sizeof(float) ? 2 : 1; #define CCALL_HANDLE_REGARG \ - if (LJ_TARGET_IOS && isva) { \ + if (LJ_TARGET_OSX && isva) { \ /* IOS: All variadic arguments are on the stack. */ \ } else if (isfp) { /* Try to pass argument in FPRs. */ \ int n2 = ctype_isvector(d->info) ? 1 : n*isfp; \ @@ -344,10 +344,10 @@ goto done; \ } else { \ nfpr = CCALL_NARG_FPR; /* Prevent reordering. */ \ - if (LJ_TARGET_IOS && d->size < 8) goto err_nyi; \ + if (LJ_TARGET_OSX && d->size < 8) goto err_nyi; \ } \ } else { /* Try to pass argument in GPRs. */ \ - if (!LJ_TARGET_IOS && (d->info & CTF_ALIGN) > CTALIGN_PTR) \ + if (!LJ_TARGET_OSX && (d->info & CTF_ALIGN) > CTALIGN_PTR) \ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ if (ngpr + n <= maxgpr) { \ dp = &cc->gpr[ngpr]; \ @@ -355,7 +355,7 @@ goto done; \ } else { \ ngpr = maxgpr; /* Prevent reordering. */ \ - if (LJ_TARGET_IOS && d->size < 8) goto err_nyi; \ + if (LJ_TARGET_OSX && d->size < 8) goto err_nyi; \ } \ } diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c index 846827b1..9158c2d3 100644 --- a/src/lj_ccallback.c +++ b/src/lj_ccallback.c @@ -406,7 +406,7 @@ void lj_ccallback_mcode_free(CTState *cts) nfpr = CCALL_NARG_FPR; /* Prevent reordering. */ \ } \ } else { \ - if (!LJ_TARGET_IOS && n > 1) \ + if (!LJ_TARGET_OSX && n > 1) \ ngpr = (ngpr + 1u) & ~1u; /* Align to regpair. */ \ if (ngpr + n <= maxgpr) { \ sp = &cts->cb.gpr[ngpr]; \ diff --git a/test/tarantool-tests/lj-695-ffi-vararg-call.test.lua b/test/tarantool-tests/lj-695-ffi-vararg-call.test.lua new file mode 100644 index 00000000..04be1998 --- /dev/null +++ b/test/tarantool-tests/lj-695-ffi-vararg-call.test.lua @@ -0,0 +1,16 @@ +local tap = require('tap') + +local test = tap.test('lj-695-ffi-vararg-call') +test:plan(2) + +local ffi = require('ffi') +local str = ffi.new('char[256]') +ffi.cdef('int sprintf(char *str, const char *format, ...)') +local strlen = ffi.C.sprintf(str, 'try vararg function: %s:%.2f(%d) - %llu', + 'imun', 9, 9LL, -1ULL) + +local result = ffi.string(str) +test:is(#result, strlen) +test:is(result, 'try vararg function: imun:9.00(9) - 18446744073709551615') + +os.exit(test:check() and 0 or 1) -- 2.25.0