Extract the Mach-O shim with LLVM objcopy
The hypervisor needs the shim's raw AArch64 instructions. Some objcopy -O binary implementations leave them in a Mach-O container. When elfuse detects that format in the output, it extracts __TEXT,__text and checks the result against the section metadata from Apple's developer tools.
The check permits debug records, zero-fill sections and alignment padding. A second section with file-backed data stops the build and identifies the need to extend extraction. A completed conversion replaces the output atomically. The macOS analysis job compares LLVM's output against GNU objcopy for release and debug builds of the same object.
Verification
- GNU binutils 2.47 and LLVM 22.1.8 both produced the same 7,516-byte release and debug shims. Built and signed elfuse with each tool, passed the host checks, and ran an x86-64 BusyBox guest with each binary.
- Exercised 30 builds covering Mach-O and ELF input, wrapped and renamed tools, debug sections, zero-fill, alignment padding, extra initialized data, truncated output and failed conversions.
- Interrupted a rebuild and checked that the previous shim remained usable. Six concurrent GNU and LLVM extractions of the same target also produced the complete reference bytes.
- With the Rosetta loader change in #555, the AArch64 matrix recorded 327 passes, 11 failures and 10 skips. All 11 failures also occurred on the unchanged base with the same Mac and fixtures.
Summary by cubic
Fixes shim extraction when an objcopy implementation (including LLVM's fallback) preserves the Mach-O container in -O binary output, which previously made the hypervisor reject the shim.
- Detects Mach-O magic in the produced bytes and extracts
__TEXT,__textvia--dump-sectionwhen present. - Compares the extracted byte count against the section metadata from
otool, allowing debug records, zero-fill, and empty aligned sections that add no bytes to the flat image. - Fails the build if any other file-backed section contains data, and replaces the shim only after a successful conversion so failed builds keep the last good output.
- Adds a macOS CI check that compares GNU and LLVM output for release and debug shims.