ARM64: Add support for saving bytecode as object files.

This commit is contained in:
Mike Pall 2015-08-25 10:16:39 +02:00
parent ba617df6f8
commit 0a3cd94631

View File

@ -63,7 +63,7 @@ local map_type = {
} }
local map_arch = { local map_arch = {
x86 = true, x64 = true, arm = true, ppc = true, x86 = true, x64 = true, arm = true, arm64 = true, ppc = true,
mips = true, mipsel = true, mips = true, mipsel = true,
} }
@ -237,7 +237,7 @@ typedef struct {
hdr.eendian = isbe and 2 or 1 hdr.eendian = isbe and 2 or 1
hdr.eversion = 1 hdr.eversion = 1
hdr.type = f16(1) hdr.type = f16(1)
hdr.machine = f16(({ x86=3, x64=62, arm=40, ppc=20, mips=8, mipsel=8 })[ctx.arch]) hdr.machine = f16(({ x86=3, x64=62, arm=40, arm64=183, ppc=20, mips=8, mipsel=8 })[ctx.arch])
if ctx.arch == "mips" or ctx.arch == "mipsel" then if ctx.arch == "mips" or ctx.arch == "mipsel" then
hdr.flags = 0x50001006 hdr.flags = 0x50001006
end end
@ -477,13 +477,13 @@ typedef struct {
} mach_obj_64; } mach_obj_64;
typedef struct { typedef struct {
mach_fat_header fat; mach_fat_header fat;
mach_fat_arch fat_arch[4]; mach_fat_arch fat_arch[2];
struct { struct {
mach_header hdr; mach_header hdr;
mach_segment_command seg; mach_segment_command seg;
mach_section sec; mach_section sec;
mach_symtab_command sym; mach_symtab_command sym;
} arch[4]; } arch[2];
mach_nlist sym_entry; mach_nlist sym_entry;
uint8_t space[4096]; uint8_t space[4096];
} mach_fat_obj; } mach_fat_obj;
@ -494,6 +494,8 @@ typedef struct {
is64, align, mobj = true, 8, "mach_obj_64" is64, align, mobj = true, 8, "mach_obj_64"
elseif ctx.arch == "arm" then elseif ctx.arch == "arm" then
isfat, mobj = true, "mach_fat_obj" isfat, mobj = true, "mach_fat_obj"
elseif ctx.arch == "arm64" then
is64, align, isfat, mobj = true, 8, true, "mach_fat_obj"
else else
check(ctx.arch == "x86", "unsupported architecture for OSX") check(ctx.arch == "x86", "unsupported architecture for OSX")
end end
@ -503,8 +505,8 @@ typedef struct {
-- Create Mach-O object and fill in header. -- Create Mach-O object and fill in header.
local o = ffi.new(mobj) local o = ffi.new(mobj)
local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align) local mach_size = aligned(ffi.offsetof(o, "space")+#symname+2, align)
local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12,12,12} })[ctx.arch] local cputype = ({ x86={7}, x64={0x01000007}, arm={7,12}, arm64={0x01000007,0x0100000c} })[ctx.arch]
local cpusubtype = ({ x86={3}, x64={3}, arm={3,6,9,11} })[ctx.arch] local cpusubtype = ({ x86={3}, x64={3}, arm={3,9}, arm64={3,0} })[ctx.arch]
if isfat then if isfat then
o.fat.magic = be32(0xcafebabe) o.fat.magic = be32(0xcafebabe)
o.fat.nfat_arch = be32(#cpusubtype) o.fat.nfat_arch = be32(#cpusubtype)