From: Igor Munkin via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Sergey Ostanevich <sergos@tarantool.org>, Sergey Kaplun <skaplun@tarantool.org> Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH luajit 3/3] FFI/ARM64/OSX: Fix vararg call handling. Date: Tue, 11 May 2021 01:09:07 +0300 [thread overview] Message-ID: <6753245c0309ed77250a6ac41fb7bfd3f82676c2.1620678384.git.imun@tarantool.org> (raw) In-Reply-To: <cover.1620678384.git.imun@tarantool.org> From: Mike Pall <mike> 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 <korablev@tarantool.org> Signed-off-by: Igor Munkin <imun@tarantool.org> --- 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
next prev parent reply other threads:[~2021-05-10 22:31 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-05-10 22:09 [Tarantool-patches] [PATCH luajit 0/3] Basic fixes for LuaJIT on ARM64 Macs Igor Munkin via Tarantool-patches 2021-05-10 22:09 ` [Tarantool-patches] [PATCH luajit 1/3] build: pass sysroot to MacOS SDK Igor Munkin via Tarantool-patches 2021-05-11 9:49 ` Sergey Kaplun via Tarantool-patches 2021-05-12 21:55 ` Igor Munkin via Tarantool-patches 2021-05-14 16:07 ` Sergey Kaplun via Tarantool-patches 2021-05-17 17:21 ` Igor Munkin via Tarantool-patches 2021-05-18 5:50 ` Sergey Kaplun via Tarantool-patches 2021-05-18 18:47 ` Igor Munkin via Tarantool-patches 2021-05-19 11:38 ` Igor Munkin via Tarantool-patches 2021-05-19 12:40 ` Sergey Ostanevich via Tarantool-patches 2021-05-19 13:23 ` Igor Munkin via Tarantool-patches 2021-05-19 16:06 ` Sergey Kaplun via Tarantool-patches 2021-05-10 22:09 ` [Tarantool-patches] [PATCH luajit 2/3] OSX/iOS: Handle iOS simulator and ARM64 Macs Igor Munkin via Tarantool-patches 2021-05-11 11:02 ` Sergey Kaplun via Tarantool-patches 2021-05-11 11:03 ` Igor Munkin via Tarantool-patches 2021-05-14 11:36 ` Sergey Ostanevich via Tarantool-patches 2021-05-14 11:27 ` Igor Munkin via Tarantool-patches 2021-05-10 22:09 ` Igor Munkin via Tarantool-patches [this message] 2021-05-11 11:07 ` [Tarantool-patches] [PATCH luajit 3/3] FFI/ARM64/OSX: Fix vararg call handling Sergey Kaplun via Tarantool-patches 2021-05-11 11:31 ` Igor Munkin via Tarantool-patches 2021-05-12 16:11 ` Sergey Ostanevich via Tarantool-patches 2021-05-12 21:59 ` Igor Munkin via Tarantool-patches 2021-05-13 9:50 ` Sergey Ostanevich via Tarantool-patches 2021-05-13 10:44 ` Igor Munkin via Tarantool-patches 2021-05-14 10:10 ` Sergey Ostanevich via Tarantool-patches 2021-05-14 10:31 ` Igor Munkin via Tarantool-patches 2021-05-19 15:38 ` [Tarantool-patches] [PATCH luajit 0/3] Basic fixes for LuaJIT on ARM64 Macs Igor Munkin via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=6753245c0309ed77250a6ac41fb7bfd3f82676c2.1620678384.git.imun@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=imun@tarantool.org \ --cc=sergos@tarantool.org \ --cc=skaplun@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH luajit 3/3] FFI/ARM64/OSX: Fix vararg call handling.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox