fix(runtime/darwin): rewrite aarch64 _start in mach's inline-asm dialect#321
Merged
Conversation
the aarch64 darwin _start was written in standard ARM syntax that mach's inline-asm dialect rejects, so darwin-aarch64 could not link: '#'-prefixed immediates (mach treats '#' as the comment char, stripped at lower time, so 'add x1, sp, #8' became 'add x1, sp,'), a 4-operand shifted-register add 'add x2, x1, x2, lsl #3', and a bitmask-immediate 'and sp, sp, #-16'. mirror the CI-tested linux aarch64 _start instruction-form style — bare immediates, an explicit lsl+add for the envp scale, and no explicit stack realignment (sp is 16-byte aligned on arm64 kernel entry) — while preserving the darwin semantics: entry symbol 'start', the _rt_argc/_rt_argv/_rt_envp capture, _rt_init then main, and the darwin 'svc 0x80' exit. closes #320
This was referenced Jun 28, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #320.
The aarch64 darwin
_startwas written in standard ARM assembler syntax thatmach's inline-asm dialect rejects, so
mach build . --target darwin-aarch64couldnot link the runtime. Rewrites it in the dialect every other (working) runtime uses,
with zero behavior change.
Offending forms → fix
#-prefixed immediates (add x1, sp, #8,mov x16, #1,svc #0x80, ...) —#is mach's inline-asm comment character (stripped at lower time), so these became
malformed operands. → bare immediates (as the x86_64
_startalready uses).add x2, x1, x2, lsl #3— unsupported. → explicitlslthen 3-operandadd.and sp, sp, #-16— unsupported (and the register form can'ttarget SP). → dropped: sp is 16-byte aligned on arm64 kernel entry (an
architectural invariant the CI-tested linux aarch64
_startalready relies on).Mirrors the instruction-form style of the tested
src/runtime/linux/aarch64.mach_startwhile preserving the darwin semantics: entry symbolstart, the_rt_argc/_rt_argv/_rt_envpcapture,_rt_init→main, and the darwinsvc 0x80exit. The file header doc is updated to match.Validation
Built end-to-end with a mach compiler whose lock points at this commit:
mach build . --target darwin-aarch64 --profile releaselinks cleanly (nocset/undefined symbol/malformederrors) to a valid arm64 Mach-O executable —MH_NOUNDEFS, full segment set (__PAGEZERO/__TEXT/__DATA/__DATA_CONST/__LINKEDIT),LC_UNIXTHREADentry, and an ad-hocLC_CODE_SIGNATURE— verifiedwith llvm-otool. (Execution on macOS is gated on mach #1680's runners.)
Pairs with mach #1714 (the mach-side
csetinline-asm dispatch); both areprerequisites for the aarch64-darwin half of mach #1680.