On 13.06.2024 18:40, Sergey Bronnikov via Tarantool-patches wrote:

Hi, Sergey


fixes applied and force-pushed

On 12.04.2024 14:27, Sergey Kaplun via Tarantool-patches wrote:
Hi, Sergey!
Thanks for the fixes!
LGTM, with a several minor nits below.

On 11.04.24, Sergey Bronnikov wrote:
From: Mike Pall <mike>

Thanks to Carlo Cabrera.

(cherry picked from commit b98b37231bd2dcb79e10b0f974cefd91eb0d7b3a)

Mach-O FAT object files generated by LuaJIT for ARM64 Had
Typo: s/Had/had/
Fixed, thanks!
an incorrect format due to the usage of the 32-bit version of
FFI structure. This patch adds the 64-bit structure definition
Typo: s/FFI structure/the FFI structure/
Fixed, thanks!
and uses it for ARM64.

Sergey Bronnikov:
* added the description and the test for the problem

Part of tarantool/tarantool#9595
---
 src/jit/bcsave.lua                            | 14 ++++-
 ...-865-cross-generation-mach-o-file.test.lua | 55 +++++++++++++++++--
 2 files changed, 63 insertions(+), 6 deletions(-)

<snipped>

 
   -- Mach-O FAT object header.
@@ -221,9 +263,11 @@ end
 --
 local SUM_CPUTYPE = {
   arm = 7 + 12,
+  arm64 = 0x01000007 + 0x0100000c,
Minor: The comment will be appreciated:
| x64 + arm64.
Added, thanks!
 }
 local SUM_CPUSUBTYPE = {
   arm = 3 + 9,
+  arm64 = 3 + 0,
Minor: The comment will be appreciated:
| x64 + arm64.

Added, thanks!


Iterative patch below


diff --git a/test/tarantool-tests/lj-865-fix_generation_of_mach-o_object_files.test.lua b/test/tarantool-tests/lj-865-fix_generation_of_mach-o_object_files.test.lua
index 661e148e..9c27e12d 100644
--- a/test/tarantool-tests/lj-865-fix_generation_of_mach-o_object_files.test.lua
+++ b/test/tarantool-tests/lj-865-fix_generation_of_mach-o_object_files.test.lua
@@ -173,7 +173,7 @@ local function read_mach_o(buf, is64)
   local mach_fat_arch_type = ffi.typeof('mach_fat_arch *')
   for i = 0, res.header.nfat_arch - 1 do
     local fat_arch = ffi.cast(mach_fat_arch_type, obj.fat_arch[i])
-    arch = {
+    local arch = {
       cputype = be32(fat_arch.cputype),
       cpusubtype = be32(fat_arch.cpusubtype),
     }
@@ -184,16 +184,18 @@ local function read_mach_o(buf, is64)
 end
 
 -- Defined in <src/jit/bcsave.lua:bcsave_machobj>.
-local sum_cputype = {
+local SUM_CPUTYPE = {
   x86 = 7,
   x64 = 0x01000007,
   arm = 7 + 12,
+  -- x64 + arm64.
   arm64 = 0x01000007 + 0x0100000c,
 }
-local sum_cpusubtype = {
+local SUM_CPUSUBTYPE = {
   x86 = 3,
   x64 = 3,
   arm = 3 + 9,
+  -- x64 + arm64.
   arm64 = 3 + 0,
 }
 
@@ -257,8 +259,8 @@ local function build_and_check_mach_o(is64)
     total_cputype = total_cputype + mach_o.fat_arch[i].cputype
     total_cpusubtype = total_cpusubtype + mach_o.fat_arch[i].cpusubtype
   end
-  test:is(total_cputype, sum_cputype[arch], 'cputype is correct in Mach-O, ' .. arch)
-  test:is(total_cpusubtype, sum_cpusubtype[arch], 'cpusubtype is correct in Mach-O, ' .. arch)
+  test:is(total_cputype, SUM_CPUTYPE[arch], 'cputype is correct in Mach-O, ' .. arch)
+  test:is(total_cpusubtype, SUM_CPUSUBTYPE[arch], 'cpusubtype is correct in Mach-O, ' .. arch)
 end
 
 -- ARM

This is a correct iterative patch:


--- a/test/tarantool-tests/lj-865-cross-generation-mach-o-file.test.lua
+++ b/test/tarantool-tests/lj-865-cross-generation-mach-o-file.test.lua
@@ -262,13 +262,15 @@ end
 -- 1. https://opensource.apple.com/source/xnu/xnu-4570.41.2/osfmk/mach/machine.h.auto.html
 --
 local SUM_CPUTYPE = {
-  -- x86 + arm
+  -- x86 + arm.
   arm = 7 + 12,
+  -- x64 + arm64.
   arm64 = 0x01000007 + 0x0100000c,
 }
 local SUM_CPUSUBTYPE = {
-  -- x86 + arm
+  -- x86 + arm.
   arm = 3 + 9,
+  -- x64 + arm64.
   arm64 = 3 + 0,
 }
 


 }
 
 -- The function builds Mach-O FAT object file and retrieves
<snipped>

-- 
2.34.1