feat(runtime/darwin): arm64 entry via LC_MAIN register convention#325
Conversation
darwin arm64 executables become PIE LC_MAIN images (briar-systems/mach#1718, #1722). dyld enters an LC_MAIN program like main(argc, argv, envp) with the arguments in registers, not on the stack, so the entry captures argc/argv/envp from x0/x1/x2 instead of reading them off [sp]. raw svc 0x80 is retained; the x86_64 darwin entry is unchanged. Closes #324
darwin mkdirat is 475 (464 is openat_nocancel), unlinkat is 472, and faccessat is 466 - the previous 464/466/468 were wrong. these only surfaced once arm64 darwin binaries actually run (briar-systems/mach#1722): the native self-host build failed to create its object directory because mkdirat hit the wrong trap. Refs #324.
|
Added a second commit to this branch: fix(os/darwin): correct mkdirat/unlinkat/faccessat syscall numbers.
These are latent darwin-runtime bugs that were never exercised before (darwin binaries couldn't run); folding them in here keeps all the "make arm64 darwin actually run" runtime work in one PR. Happy to split into a separate PR if preferred. |
Part of briar-systems/mach#1718 (the dynamic/PIE darwin epic). Pairs with the mach PIE-writer child (briar-systems/mach#1722).
What
mach is moving darwin arm64 executables to PIE
LC_MAINimages (required to exec on Apple Silicon — proven in mach#1718).LC_MAINhands control to a C-main-style entry with arguments in registers, not on the stack. This rewrites the darwin arm64_startto captureargc/argv/envpfromx0/x1/x2(theLC_MAINregister ABI dyld enters with) instead of reading them off[sp].Everything else is unchanged: still stores into
_rt_argc/_rt_argv/_rt_envp, calls_rt_initthenmain, exits via rawsvc 0x80(no libSystem). The x86_64 darwin entry is untouched (it keeps theLC_UNIXTHREADstack convention until the paired mach writer switches it too).Validation
The darwin runtime is cross-compile-only on the Linux CI host, so this is validated end-to-end on the mach side: the paired PIE writer (mach#1722) cross-builds an
aarch64-darwincompiler and execs it on amacos-14runner (noKilled: 9) where it self-hosts. mach-std CI stays green (the darwin arm64 file is$if-guarded off non-darwin builds).Closes #324
🤖 Generated with Claude Code