-
Notifications
You must be signed in to change notification settings - Fork 11
Add support for Metal-produced universal binaries #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7b8fce7
Add rudimentary support for fat MachO files
maleadt d12fac6
Add search methods for Symbols.
maleadt f6ed8d8
Make findfirst return nothing instead of erroring.
maleadt 5076fba
Fix MachO section handling.
maleadt 05a2e5c
Don't assume every IO comes from a file.
maleadt f998f4d
Support parsing fat MachO objects produced by Metal.
maleadt 5c68d75
Add rudimentary support for parsing Metal libraries.
maleadt 2d4bdbc
Add Metal tests.
maleadt 77f8fa9
Bump version.
maleadt a24dd83
Rework readmeta to always return a collection of handles.
maleadt 86ffe10
Bump Julia requirement.
maleadt cd96517
position(io) always return an Int64.
maleadt a639d84
Add missing reserved field.
maleadt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "ObjectFile" | ||
uuid = "d8793406-e978-5875-9003-1fc021f44a92" | ||
authors = ["Elliot Saba <[email protected]>"] | ||
version = "0.3.7" | ||
version = "0.4.0" | ||
|
||
[deps] | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
|
@@ -11,7 +11,7 @@ StructIO = "53d494c1-5632-5724-8f4c-31dff12d585f" | |
[compat] | ||
Reexport = "0.2, 1.0" | ||
StructIO = "0.3" | ||
julia = "1.0" | ||
julia = "1.6" | ||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,78 @@ | ||
# Eventually, we will hopefully support multiarch MachO files | ||
@io struct MachOFatArch | ||
export MachOFatArch, MachOFatHeader, FatMachOHandle | ||
|
||
abstract type MachOFatArchitecture end | ||
|
||
@io struct MachOFatArch32 <: MachOFatArchitecture | ||
cputype::UInt32 | ||
cpusubtype::UInt32 | ||
offset::UInt32 | ||
size::UInt32 | ||
align::UInt32 | ||
end | ||
|
||
@io struct MachOFatArch64 <: MachOFatArchitecture | ||
cputype::UInt64 | ||
cpusubtype::UInt64 | ||
offset::UInt64 | ||
size::UInt64 | ||
align::UInt32 | ||
reserved::UInt32 | ||
end | ||
|
||
struct MachOFatHeader{H <: ObjectHandle} <: MachOHeader{H} | ||
archs::Vector{MachOFatArch} | ||
end | ||
magic::UInt32 | ||
archs::Vector{MachOFatArchitecture} | ||
end | ||
|
||
function StructIO.unpack(io::IO, T::Type{<:MachOFatHeader}, endian::Symbol) | ||
magic = read(io, UInt32) | ||
nfats = unpack(io, UInt32, endian) | ||
archtyp = macho_is64bit(magic) ? MachOFatArch64 : MachOFatArch32 | ||
archs = Vector{archtyp}(undef, nfats) | ||
for i = 1:nfats | ||
archs[i] = unpack(io, archtyp, endian) | ||
end | ||
T(magic, archs) | ||
end | ||
|
||
function show(io::IO, header::MachOFatHeader) | ||
println(io, "MachOFatHeader Header") | ||
println(io, " architectures: $(length(header.archs))") | ||
end | ||
|
||
struct FatMachOHandle{T <: IO} <: AbstractMachOHandle{T} | ||
# Backing IO and start point within the IOStream of this MachO object | ||
io::T | ||
start::Int64 | ||
|
||
# The parsed-out header of the MachO object | ||
header::MachOFatHeader | ||
|
||
# The path of the file this was created with, if it exists | ||
path::String | ||
end | ||
|
||
function readmeta(io::IO,::Type{FatMachOHandle}) | ||
start = position(io) | ||
header_type, endianness = readmeta(io, AbstractMachOHandle) | ||
(header_type <: MachOFatHeader) || throw(MagicMismatch("Binary is not fat")) | ||
|
||
# Unpack the header | ||
header = unpack(io, header_type, endianness) | ||
return FatMachOHandle(io, 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 | ||
function getindex(h::FatMachOHandle, idx) | ||
seek(h.io, h.start + h.header.archs[idx].offset) | ||
only(readmeta(h.io, MachOHandle)) | ||
end | ||
|
||
function show(io::IO, oh::FatMachOHandle) | ||
print(io, "$(format_string(typeof(oh))) Fat Handle") | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.