Skip to content

Fix Mach-O executables on macOS#30

Closed
badlogic wants to merge 1 commit into
vercel-labs:mainfrom
badlogic:badlogic/macho-lc-uuid
Closed

Fix Mach-O executables on macOS#30
badlogic wants to merge 1 commit into
vercel-labs:mainfrom
badlogic:badlogic/macho-lc-uuid

Conversation

@badlogic
Copy link
Copy Markdown
Contributor

Adds LC_UUID to direct Mach-O executables so dyld will actually run them.\n\nChecked with:\n\nsh\nmake -C native/zero-c\n.zero/bin/zero run examples/hello.0\n

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@badlogic is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@PeterXMR
Copy link
Copy Markdown

Confirmed this fixes the dyld error on macOS 26.4 / Darwin 25.4.0 arm64 — the salted hash + v4 bit-setting in macho_make_uuid are nice touches. Worth pairing the emit fix with a byte-level regression assertion so the bug can't silently come back. The assertMachOArm64Executable helper in conformance/run.mjs already runs for the direct exe test (around line 703) and doesn't currently scan load commands — adding a small walk catches missing LC_UUID even from a Linux sandbox where the binary can't be exec'd.
Suggested addition inside assertMachOArm64Executable, right after the existing asserts:
js // dyld rejects Mach-O executables without LC_UUID on recent macOS. const ncmds = bytes.readUInt32LE(16); let cursor = 32; let hasUuid = false; for (let i = 0; i < ncmds; i++) { const cmd = bytes.readUInt32LE(cursor); const cmdSize = bytes.readUInt32LE(cursor + 4); if (cmd === 0x1b) { hasUuid = true; break; } cursor += cmdSize; } assert(hasUuid, "Mach-O executable is missing LC_UUID load command"); ​
Verified locally: trips on a binary with LC_UUID surgically removed, passes on the binary this PR produces.

@ctate
Copy link
Copy Markdown
Collaborator

ctate commented May 17, 2026

Thanks for the PR @badlogic

Merged a fix in #55 - added you as a co-author

@ctate ctate closed this May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants