Files
metal2vulkan/crates/metal2vulkan-devtools
Anees Iqbal 4bcb58dbb1 Container: read a metallib of format 2.2, whose entries carry no MDSZ and which has no extended header
What: MDSZ is no longer a required function-entry tag. An entry without it
holds its module from its start (OFFT) to the next module's start, the
nearest larger bitcode start of any entry, or to the bitcode section's end
for the last. And where a section holding bytes starts at the last entry's
end, the library has no extended header and no extended tags. The entries'
bitcode ranges are resolved once every entry's start is known (a new
Entry, read from the tags, then with_bitcode). NAME, TYPE, HASH, OFFT and
VERS stay required. The overlap, section-bounds and HASH checks are as
before, and HASH is verified over the resolved range.

Why: a guest's library, an app's precompiled metallib of format 2.2 from
an older toolchain, was refused as Container(MissingTag) at its first
entry, and every pipeline made from it was dropped. Its seven entries are
NAME, TYPE, HASH, OFFT, VERS. The length rule comes from what the file
itself states and is exact. In Apple's output every module is a bitcode
wrapper padded to a multiple of 16 bytes, written right after the one
before it, and MDSZ is the distance to the next module's start, not the
wrapper's offset plus size (probe m3-max-73748, 4 of 4 modules). In the
guest's file, read for structure only on its lab host (m3-max-73749), each
HASH is the SHA-256 of the bytes up to the next module's start for 7 of 7
functions. The wrapper's own size gives that range for only 4 of 7, so
reading it would have refused 3 with HashMismatch. Since HASH is checked
over the range, a module of any other length is still refused. Behind the
MDSZ refusal the same file met a second one: its public metadata starts
right at the end of its function list (939), so there is no extended
header, and the reader would have parsed the metadata as tags (BadTag).
Metal takes such a library and runs it: m3-max-73748 made a library from
our own MSL with MDSZ removed from every entry, at header 2.9 and 2.2,
made all its functions, and ran both kernels and the render pipeline as
expected, with MTL_DEBUG_LAYER on and off. Without any of the other five
tags Metal makes no function that runs as written, so they stay required.

Docs: mtlb.rs's module docs (the 2.2 layout, the length rule and why it is
exact, Metal's answers); ContainerError::MissingTag's doc. No refusal
kind, public type or cached artifact changes: a library that parsed before
parses to the same functions.

Fixture: metal2vulkan-devtools' metallib_2_2 writes the 2.2 layout (header
2.2 with os and os version 0, no MDSZ, no extended header) around the
modules a test supplies.

Tests: container::tests::format_2_2_entries_hold_their_module_to_the_next_start
(padded and unpadded modules, the table equal to the MDSZ layout's, one
entry without MDSZ among entries with it, a HASH of the unpadded wrapper
refused as HashMismatch); malformed_function_tags no longer lists MDSZ;
tests::format_2_2_libraries (three owned fixtures padded to 16 bytes, one
past its wrapper's end, in metallib_2_2: same content keys, compile keys
and SPIR-V words as in today's layout). Both new tests fail without the
reader change (MissingTag).
2026-11-25 12:25:48 -08:00
..