Skip to content
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

Support reading metallib v1.2.8 files from macOS 15. #367

Merged
merged 1 commit into from
Jun 17, 2024
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
41 changes: 38 additions & 3 deletions src/compiler/library.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,44 @@ tag_value_io["SARC"] = (
id = String(readuntil(io, UInt8(0)))
compressed = read(io, nb - sizeof(id) - 1)

# unpad and decompress the archive
i = findlast(!iszero, compressed)
archive = transcode(Bzip2Decompressor, compressed[1:i])
# Bzip2Decompressor doesn't support padding (JuliaIO/CodecBzip2.jl#31),
# so find the end marker and truncate the archive (in a naive way,
# but these source code archives are expected to be small)
compressed[1:2] == [0x42, 0x5a] || error("Not a BZip2 archive")
trailing_bytes = 10 # end marker + checksum
end_marker = 0x177245385090
i = 1
while i < length(compressed) - trailing_bytes
# aligned match
current_value = UInt64(compressed[i]) << 40 |
UInt64(compressed[i+1]) << 32 |
UInt64(compressed[i+2]) << 24 |
UInt64(compressed[i+3]) << 16 |
UInt64(compressed[i+4]) << 8 |
UInt64(compressed[i+5])
if current_value == end_marker
break
end

# misaligned match
current_value = UInt64(current_value) << 8 | compressed[i+6]
if end_marker in ((current_value >> 1) & 0xffffffffffff,
(current_value >> 2) & 0xffffffffffff,
(current_value >> 3) & 0xffffffffffff,
(current_value >> 4) & 0xffffffffffff,
(current_value >> 5) & 0xffffffffffff,
(current_value >> 6) & 0xffffffffffff,
(current_value >> 7) & 0xffffffffffff)
i += 1
break
end

i += 1
end
compressed = compressed[1:i+trailing_bytes-1]

# decompress the archive
archive = transcode(Bzip2Decompressor, compressed)

(; id, archive)
end,
Expand Down
2 changes: 1 addition & 1 deletion test/metallib/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
METAL := xcrun -sdk macosx metal
MACOSX_VERSIONS := 11 12 13 14
MACOSX_VERSIONS := 11 12 13 14 15

SOURCES := $(wildcard *.metal)
METALLIBS := $(foreach ver,$(MACOSX_VERSIONS),$(SOURCES:.metal=.$(ver).metallib))
Expand Down
Binary file added test/metallib/constants.15.metallib
Binary file not shown.
Binary file added test/metallib/debuginfo.15.metallib
Binary file not shown.
Binary file added test/metallib/kernel.15.metallib
Binary file not shown.
Binary file added test/metallib/kernels.15.metallib
Binary file not shown.
Binary file added test/metallib/sources.15.metallib
Binary file not shown.