Skip to content

macOS dylib cross-linked off a Mac gets an install name and a minimum; three glob-import fixes - #3874

Merged
paul-hammant merged 5 commits into
mainfrom
batch/cross-macos-triple
Nov 25, 2026
Merged

paul-hammant merged 5 commits into
mainfrom
batch/cross-macos-triple

Conversation

@paul-hammant

@paul-hammant paul-hammant commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Five fixes: one cross-build fix, three import m (*) compiler fixes, and a flaky std.tcp deadline test.

1. A macOS dylib cross-linked off a Mac gets an install name and a minimum (cb0301e)

zig spells the macOS targets aarch64-macos-none / x86_64-macos-none, and cross_target_is_apple() took only -apple- for an Apple target. So a macOS --emit=lib cross build linked on Linux or FreeBSD went through the ELF arm:

  • no -install_name, so zig recorded the -o build path as LC_ID_DYLIB (a release built on CI carried /home/runner/work/.../libfoo.so, and every program linked against it failed with "Library not loaded");
  • GNU strip flags under --size;
  • zig's default minimum, macOS 15.0.

A Mac host rewrote the id with install_name_tool after the link, which hid the first half there.

The fix splits the predicate, which was doing two jobs:

  • cross_target_uses_xcode() keeps the -apple- check, which picks the xcrun driver (the iOS clang triples).
  • cross_target_is_apple() recognises every Apple spelling: zig's -macos/-ios, clang's -apple-/-darwin, and the other Apple OS names. It decides the Mach-O link: -dynamiclib -install_name @rpath/<leaf> (the id the native macOS build sets) and Apple ld's -x -dead_strip.

A zig macOS triple now carries an explicit minimum: 13.0 by default, overridden with AETHER_MACOS_MIN the way AETHER_IOS_MIN works for iOS. This is documented in docs/build-system.md.

Linux and FreeBSD --emit=lib still set no DT_SONAME, which matches the native path. That is now documented and left as is.

Test: tests/integration/cross_macos_dylib_identity reads LC_ID_DYLIB and minos straight from the Mach-O load commands, so it needs no otool. It covers aarch64 at the default minimum, and x86_64 with --size and AETHER_MACOS_MIN=14.2. On a Mac it also links and runs a C consumer with -lgreet. CI runs it in the contrib.sqlite cross job, the Linux job that has zig.

  • On a Linux build of current main it fails with: LC_ID_DYLIB is '/tmp/tmp.U1th7PbCYf/build/out/arm64/libgreet.dylib', want '@rpath/libgreet.dylib'.
  • On a Mac build of current main it fails with: minos is '15.0', want '13.0'.

2. merge: a struct literal's field is not a module var's write (c1a95fc)

If a module has var size next to a struct field size, every Font { size: 2 } (in the module and through a glob import) used to be lowered to a field <module>_size that does not exist. Test: tests/integration/glob_import_struct_field_name.

3. merge, typechecker: a glob import binds what the module exports (98ccd97)

import m (*) no longer binds private names, vars included. docs/language-reference.md gets one sentence on this in its Glob Import section. Test: tests/integration/glob_import_private_var_hidden.

4. prune, typechecker: a local named like an imported function (78b967a)

button = 0; button = button(t) after import buttons (*) is now compile error E0301: "'button' is a local here, which hides the imported function 'buttons.button'". This matches the language reference and the check that already applies to a program's own functions. Test: tests/integration/glob_import_local_named_like_fn. Its E0301 fixture is listed in tests/ae_sweep_prune.txt.

5. tcp_deadline_cancel: each race round gets its deadline after the dial (895a934)

On the macOS x86_64 runner, the first run of this PR failed tests/integration/tcp_deadline_cancel with round 66: read ended with [connection closed or receive failed]. That failure was in the test, not the runtime. Each close-race round dialled with connect_until and a deadline 3 to 9 ms away. On macOS a non-blocking loopback connect is always EINPROGRESS, and the handshake completes on another kernel path, so a loaded runner can use up the whole deadline on the dial. When that happens, connect_until correctly refuses with "deadline exceeded". The round then went on with a null socket, and the read's error overwrote the dial's error. No deadline or cancel ever touched a descriptor.

Each round now dials with the cancel bound and no deadline, and sets the few-ms deadline once it is connected. The deadline and the cancel still race the read and the close. A failed dial now reports its own error, and each round reports the first thing that went wrong in it.

  • Reproduced: a resolver stall preloaded into the test (12 ms in every 7th getaddrinfo, to stand in for a lost CPU) gives the CI message on every run of the old test: Mac 30/30, ae-x64 20/20, ghostbsd 20/20. Under the same stall the new test fails 0 of 30, 0 of 20 and 0 of 20 runs. On the Mac under real load (background QoS, 16 busy loops), an instrumented copy of the old test logged dial: deadline exceeded 6 times in about 3,000 rounds.
  • Without the stall, the new test passed 40/40 runs on the Mac, 20/20 on ae-x64 and 19/20 on ghostbsd. The one ghostbsd failure was an earlier case: the 192.0.2.1 stall address failed at once with "connection failed" in the lab network. That is unrelated to this change, and the old test passed 20/20 there. Under the same background-QoS load, the new test ran 2,000 race rounds with no failures. That load also starves the trickle case below its 4-byte floor, in both the old and the new test.
  • With 895a934: ae-x64 CC=gcc make ci gave 2380 passed, 0 failed, 31 skipped (CI PASSED). On macOS arm64, make test-ae gave 2355 passed, 0 failed, 56 skipped.
  • The broken-canceller demonstration (BROKEN_CANCELLER=1) still reports "a decoy was disturbed".

Verification

  • ae-x64 (Ubuntu 22.04 x86_64), CC=gcc make ci: 2380 passed, 0 failed, 31 skipped; CI PASSED.
  • ae-x64 with the pinned zig 0.16.0, zig cross tests run one at a time (cross_macos_dylib_identity, cross_emit_lib, cross_linux_musl, cross_riscv64_loongarch64, emit_csrc_cross, c_include_directive, lzf_offsets_portable): all pass. When the whole sweep ran with zig on PATH, these tests hit the 420 s per-test limit on the 4-core VM, because they were all cross-compiling the runtime cold at the same time.
  • cachyos (Linux, zig 0.17.0): the new test fails on main and passes on the branch. Dylibs it built for aarch64-macos and x86_64-macos were copied to a Mac:
    • otool -D gives @rpath/libgreet.dylib;
    • LC_BUILD_VERSION minos is 13.0;
    • codesign -v is OK;
    • a C consumer linked -lgreet loads the arm64 dylib and runs.
  • macOS arm64:
    • make test: green.
    • make test-ae: 2355 passed, 0 failed, 56 skipped. This includes the sweep with both new prune entries.
    • The cross subset passes: cross_ios, cross_emit_lib, cross_staticlib_sources, when_cross_target and others.
  • The three glob-import commits also passed make ci on ae-x64 in their author's own run (2380 passed, 0 failed).

🤖 Generated with Claude Code

paul-hammant and others added 5 commits November 24, 2026 20:55
A struct literal's field initialiser (`Font { size: 2 }`) and a struct
pattern's field are AST_ASSIGNMENT nodes whose value is the field name.
rename_intra_module_refs renames the target of a write to a module-level
`var` (#937), so with a module `var size` beside `struct Font { size }`
the field became `<ns>_size`, in the module's own functions and, through
`import m (*)`, in the importer. Only the initialiser (or sub-pattern) of
such a field is renamed now.

Regression: tests/integration/glob_import_struct_field_name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`import m (*)` bound every `m_<name>` in the symbol table and renamed
every constant of m in the importer, a private module-level `var`
included. An importer's loop variable or local `text` then became m's
`var text` (`m_text = <string>` on a string[]). A glob now binds only
what m's `exports (...)` list names (module_glob_binds: everything when
there is no list, never a leading underscore), in the checker's alias
table, in the importer's rename pass, and in a module's own glob of
another module (apply_inherited_selective_imports).

rename_intra_module_refs also took any name spelt like one of the
prefix module's vars for that var (write targets, receivers, and the
locals it drops from shadowing), whatever the import bound; it now does
so only for a var among the `consts` it renames (bound_module_var):
all of them in the module's own bodies, as before, only the imported
ones in an importer's.

Regression: tests/integration/glob_import_private_var_hidden.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`button = button(t)` after `import buttons (*)` built C calling an
undeclared `buttons_button`. The checker resolved the right-hand call to
the import (the local is bound after its initializer), but the dead-code
prune skipped every call spelt like a local of the enclosing function
(#2218) and dropped the function.

The prune now also tracks, per function, which locals are bound so far
in walk order (PruneScope: a binding counts from after its initializer
to the end of its block; anything it cannot place counts as unbound,
which only seeds more), and seeds a call spelt like a local that is not
bound yet.

The checker's #3086 alias step took a bare call for the import even over
a local of that name, so a call AFTER the binding (`button = 0` then
`button = button(t)`) called the function too, against the language
reference, and the prune had dropped it. It now leaves a local or
parameter alone, and the call fails E0301 as for a program's own
function (#2683), naming the import: "'button' is a local here, which
hides the imported function 'buttons.button'".

Regression: tests/integration/glob_import_local_named_like_fn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zig spells the macOS targets aarch64-macos-none / x86_64-macos-none, and
cross_target_is_apple() took only "-apple-" for an Apple target, so a
macOS --emit=lib cross build linked on Linux or FreeBSD went through the
ELF arm: no -install_name, so zig recorded the -o build path as the
dylib's LC_ID_DYLIB and every program linked against it failed with
"Library not loaded"; GNU strip flags under --size; and zig's default
minimum, macOS 15.0. A Mac host rewrote the id with install_name_tool
after the link, which hid the first half there.

The one predicate did two jobs. cross_target_uses_xcode() now keeps the
"-apple-" check for choosing the xcrun driver (the iOS clang triples
only); cross_target_is_apple() recognises every Apple spelling (zig's
-macos/-ios, clang's -apple-/-darwin, and the other Apple OS names) and
decides the Mach-O link: -dynamiclib -install_name @rpath/<leaf>, as the
native macOS build sets it, and Apple ld's -x -dead_strip. A zig macOS
triple carries an explicit minimum, 13.0 by default, AETHER_MACOS_MIN to
override (as AETHER_IOS_MIN does for iOS); documented in build-system.md.

tests/integration/cross_macos_dylib_identity reads LC_ID_DYLIB and the
minos from the load commands, so it runs on the Linux runner; CI runs it
in the contrib.sqlite cross job, which has zig.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The close-race rounds dialled with connect_until and a deadline 3 to 9 ms
away. A loopback connect is non-blocking there, and on macOS it is always
EINPROGRESS: the handshake completes on another kernel path, so a loaded
runner can spend the whole deadline on the dial. connect_until then
rightly refuses with "deadline exceeded", the round goes on with a null
socket, and the read's "connection closed or receive failed" overwrote
the dial's error: the failure seen on the macOS x86_64 runner, which read
like a deadline or cancel disturbing a connection.

Each round now dials with the cancel bound and no deadline, then sets the
few-ms deadline once connected, so the deadline and the cancel still race
the read and the close as before. A failed dial ends the loop with its own
error, and the first thing wrong in a round is the one reported: decoy
dial errors no longer give way to "a decoy was disturbed".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant
paul-hammant merged commit 58b87a8 into main Nov 25, 2026
54 checks passed
@paul-hammant
paul-hammant deleted the batch/cross-macos-triple branch November 25, 2026 05:32
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.

1 participant