Skip to content

fix(runtime/darwin): rewrite aarch64 _start in mach's inline-asm dialect#321

Merged
octalide merged 1 commit into
devfrom
fix/320-darwin-aarch64-start
Jun 28, 2026
Merged

fix(runtime/darwin): rewrite aarch64 _start in mach's inline-asm dialect#321
octalide merged 1 commit into
devfrom
fix/320-darwin-aarch64-start

Conversation

@octalide

Copy link
Copy Markdown
Collaborator

Closes #320.

The aarch64 darwin _start was written in standard ARM assembler syntax that
mach's inline-asm dialect rejects, so mach build . --target darwin-aarch64 could
not 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 _start already uses).
  • 4-operand shifted-register add add x2, x1, x2, lsl #3 — unsupported. → explicit
    lsl then 3-operand add.
  • bitmask-immediate and sp, sp, #-16 — unsupported (and the register form can't
    target SP). → dropped: sp is 16-byte aligned on arm64 kernel entry (an
    architectural invariant the CI-tested linux aarch64 _start already relies on).

Mirrors the instruction-form style of the tested src/runtime/linux/aarch64.mach
_start while preserving the darwin semantics: entry symbol start, the
_rt_argc/_rt_argv/_rt_envp capture, _rt_initmain, and the darwin
svc 0x80 exit. 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 release links cleanly (no cset /
undefined symbol / malformed errors) to a valid arm64 Mach-O executable —
MH_NOUNDEFS, full segment set (__PAGEZERO/__TEXT/__DATA/__DATA_CONST/
__LINKEDIT), LC_UNIXTHREAD entry, and an ad-hoc LC_CODE_SIGNATURE — verified
with llvm-otool. (Execution on macOS is gated on mach #1680's runners.)

Pairs with mach #1714 (the mach-side cset inline-asm dispatch); both are
prerequisites for the aarch64-darwin half of mach #1680.

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
@octalide octalide marked this pull request as ready for review June 28, 2026 21:29
@octalide octalide merged commit bd3c034 into dev Jun 28, 2026
2 checks passed
@octalide octalide deleted the fix/320-darwin-aarch64-start branch June 28, 2026 21:33
This was referenced Jun 28, 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.

runtime(darwin/aarch64): _start uses inline-asm forms mach's dialect rejects — blocks aarch64-darwin link

1 participant