Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/MachO/MachOFat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ abstract type MachOFatArchitecture end
end

@io struct MachOFatArch64 <: MachOFatArchitecture
cputype::UInt64
cpusubtype::UInt64
cputype::UInt32
cpusubtype::UInt32
offset::UInt64
size::UInt64
align::UInt32
Expand Down Expand Up @@ -59,15 +59,15 @@ function readmeta(io::IO,::Type{FatMachOHandle})

# Unpack the header
header = unpack(io, header_type, endianness)
return FatMachOHandle(io, start, header, path(io))
return FatMachOHandle(io, Int64(start), header, path(io))
end

# Iteration
keys(h::FatMachOHandle) = 1:length(h)
iterate(h::FatMachOHandle, idx=1) = idx > length(h) ? nothing : (h[idx], idx+1)
lastindex(h::FatMachOHandle) = lastindex(h.header.archs)
length(h::FatMachOHandle) = length(h.header.archs)
eltype(::Type{S}) where {S <: FatMachOHandle} = MachOLoadCmdRef
eltype(::Type{<:FatMachOHandle}) = MachOHandle
function getindex(h::FatMachOHandle, idx)
seek(h.io, h.start + h.header.archs[idx].offset)
only(readmeta(h.io, MachOHandle))
Expand Down
4 changes: 2 additions & 2 deletions src/MachO/MachOHeader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ Given the `magic` field from a Mach-O file header, return the endianness of the
Mach-O header.
"""
function macho_endianness(magic::UInt32)
if magic in (MH_CIGAM, MH_CIGAM_64, FAT_CIGAM, FAT_CIGAM_METAL)
if magic in (MH_CIGAM, MH_CIGAM_64, FAT_CIGAM, FAT_CIGAM_64, FAT_CIGAM_METAL)
return :BigEndian
elseif magic in (MH_MAGIC, MH_MAGIC_64, FAT_MAGIC, FAT_MAGIC_METAL, METALLIB_MAGIC)
elseif magic in (MH_MAGIC, MH_MAGIC_64, FAT_MAGIC, FAT_MAGIC_64, FAT_MAGIC_METAL, METALLIB_MAGIC)
return :LittleEndian
else
throw(MagicMismatch("Invalid Magic (0x$(string(magic, base=16, pad=8)))!"))
Expand Down
Binary file added test/mac64/libfoo_fat64.dylib
Binary file not shown.
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function test_libfoo_and_fooifier(fooifier_path, libfoo_path)
end

function test_fat_libfoo(file)
ohs = readmeta(open(file, "r"))
ohs = readmeta(file isa IO ? file : open(file, "r"))
@test isa(ohs, FatMachOHandle)
@test length(ohs) == 2
ntotal, n64 = 0, 0
Expand All @@ -217,6 +217,10 @@ function test_fat_libfoo(file)
end
@test ntotal == 2
@test n64 == 1

handles = collect(ohs)
@test handles isa Vector{<:MachOHandle}
@test length(handles) == 2
end

function test_metal(file)
Expand All @@ -241,6 +245,9 @@ test_libfoo_and_fooifier("./linux64/fooifier", "./linux64/libfoo.so")
# Run MachO tests
test_libfoo_and_fooifier("./mac64/fooifier", "./mac64/libfoo.dylib")
test_fat_libfoo("./mac64/libfoo_fat.dylib")
test_fat_libfoo(IOBuffer(read("./mac64/libfoo_fat.dylib")))
test_fat_libfoo("./mac64/libfoo_fat64.dylib")
test_fat_libfoo(IOBuffer(read("./mac64/libfoo_fat64.dylib")))
test_metal("./macmetal/dummy")

# Run COFF tests
Expand Down
Loading