Repository navigation
Build: refuse, before any stage links, a macOS SDK this build's lld cannot read (#1826) - #1840
Merged
Merged
Conversation
Contributor
Author
|
Battery GREEN on the stack top |
ehartford
marked this pull request as ready for review
September 28, 2026 10:05
…annot read (#1826) Xcode 27's SDK lists `arm64e.x1-macos` (CPU_SUBTYPE_ARM64E_X1, 12) in the targets of every .tbd stub. Our ld64.lld 22.1.6 rejects the whole stub (llvm/lib/TextAPI/TextStub.cpp ScalarTraits<Target>::input, "unknown architecture": Architecture.def has no arm64e.x1), so with SDKROOT at that SDK libSystem, libc++ and libm were all unreadable and the build died at the stage2 lld link with hundreds of undefined symbols. comp_host_sdk_path returned SDKROOT unchecked. The llvm-link-metadata actions now ask the linker before writing the response files: an empty dylib linked with the build's own ld64.lld against -lSystem -lc++ -lm under -syslibroot <sdk>, the libraries the stage link reads. When it fails, the build stops there, before stage1, naming the SDK, whether SDKROOT or the default chose it, the linker and its LLVM version, and the stub entry TextAPI rejected: unreadable: .../MacOSX27.0.sdk/usr/lib/libSystem.tbd:4:20: unknown architecture 'arm64e.x1-macos' and a default SDK the linker does read (probed the same way), as the SDKROOT to set. Any other probe failure prints lld's error lines. The SDK is never swapped silently: SDKROOT is the programmer's choice. A missing SDK (SDKROOT unset, no CLT or Xcode SDK) is refused the same way instead of writing a response file with no -syslibroot. comp_host_sdk_path reads SDKROOT through the action's env_input, so the metadata actions that bake the path in name it as their own input rather than relying on sdk-llvm's graph-level read being inherited. The root fix is the linker: llvm/llvm-project#222721 (b8007a8e, main, 2026-09-11) adds arm64e.x1 to TextAPI; no LLVM release carries it yet (23.x backport: llvm/llvm-project#224185, open). Refs #1826.
ehartford
pushed a commit
that referenced
this pull request
Sep 29, 2026
…ir — #1840's SDK probe (merged after this layer was written) writes there
ehartford
pushed a commit
that referenced
this pull request
Sep 29, 2026
…e SDK, nightly and on request (#1826) `with build :sdk-host-link-check` runs the probe every compiler build runs before its stage links (#1840's comp_require_linkable_host_sdk) on its own, and sdk-canary.yml runs it on macos-latest and on GitHub's xcode-27 preview image with SDKROOT at the newest MacOSX<ver>.sdk under /Applications/Xcode*.app (or an SDK given at dispatch). A slice this LLVM's TextAPI cannot parse fails the lane naming the SDK, the linker and the rejected stub target, before that SDK is every developer's default SDKROOT. A canary, not a merge signal (D56).
ehartford
added a commit
that referenced
this pull request
Sep 29, 2026
…e links its own generation's runtime (#1810 #1587 #1815) (#1869) * Build/Link: a stage links and embeds only runtime objects its own compiler generation compiled, and a link checks the build's say-so instead of trusting it (D30, #761 class) stage2's code is stage1's codegen, but stage1 linked it against the seed-built out/bootstrap-lib (prepare-bootstrap-link-root empties out/lib and out/lib is compiled by stage2), and stage-embedded-objects gave stage2 and stage3 the same seed-built blobs. It never failed only because no runtime seam changed representation since the pinned seed; the &str view ABI (#1810) changes every `with_*`/`wl_*` &str parameter. The D30 check could not see it: WITH_OUT_DIR vouched for any root the build pointed at. - A generation is the tree a compiler is built from: sha256 over its src/ and rt/ sources (build/compiler.w compiler_generation, one owner; the .wo keys reuse the same compiler_tree_sha/compiler_sha256_text, moved out of build/wo.w). Every stamped compiler carries its generation and the generation of the runtime it embeds in two post-link slots beside the ABI stamp (compiler.AbiStamp; `with version --generation`, `--runtime-generation`). - Every runtime/bridge object set records its producer's generation in <dir>/.producer (`version --generation`, else `foreign:<sha256>` — the pinned seed predates the flag): out/bootstrap-lib (seed), NEW out/bootstrap/lib (stage1: runtime, bridges, link metadata), out/lib (stage2). - stage2 links out/bootstrap/lib and stage2/stage3 embed it; stage3 and the release link out/lib. Each stage link names its root (runtime-root= -> WITH_RUNTIME_ROOT) and its embedded set's producer (runtime-producer=). `:dev` builds out/bootstrap/lib. - Link.w: WITH_RUNTIME_ROOT is the only root and must be this generation, else a loud error and no fallback. WITH_OUT_DIR no longer vouches: a candidate is taken only when its .producer is this generation (or, with none recorded, byte-identical to an embedded runtime of this generation); the embedded runtime is taken only when it is this generation's, else "run `with build :dev`". stage1 run by hand links through out/bootstrap/lib (<compiler_dir>/../lib). An unstamped compiler keeps the old rule. - runtime-generation-regression (part of :test): the release is one generation with out/lib and its embedded runtime, links through out/lib by WITH_RUNTIME_ROOT, and refuses a root of another generation with the message and no output. Evidence (this worktree, seed cffa4a40): - .producer: out/bootstrap-lib foreign:cffa4a40…, out/bootstrap/lib and out/lib e4b881d8…; stage1 gen e4b881d8 rtgen foreign:cffa4a40; stage2, stage3 and release gen = rtgen = e4b881d8. - out/command/stage2/worker.effects: stage1 linked stage2 with WITH_RUNTIME_ROOT = sha256(<root>/out/bootstrap/lib) c593c2ed…; link-compiler and stage3 with sha256(<root>/out/lib) 20c31de1…. - The objdump marker of #1815 (rt_f64_fixed_digits' frame) cannot tell the sets apart here: this seed compiles rt_core.o byte-identical to stage1 (cmp out/bootstrap-lib/rt_core.o out/bootstrap/lib/rt_core.o), so the roots are shown by the recorded env and by the refusals below. - stage1 by hand: links test/hello.w (prints hello); with out/bootstrap/lib moved away: "error: no runtime objects of this compiler's generation (e4b881d8…) to link: its embedded runtime is generation foreign:cffa4a40… … run `with build :dev` …", no binary; WITH_RUNTIME_ROOT=<root>/out/bootstrap-lib: "… holds runtime objects of compiler generation foreign:cffa4a40…, but this compiler is generation e4b881d8…; linking them would mix compiler generations (D30, #1815)", no binary. - release by hand: hello in the checkout and outside it (embedded); WITH_RUNTIME_ROOT=<root>/out/bootstrap-lib refused as above. - src/main build: green; src/main build :fixpoint: stage2 == stage3 over all 16 units; :stage3, :runtime-generation-regression, :embedded-runtime-regression, :deep-debug-tool-tests --no-deps: green. `version --generation` and `--runtime-generation` are build plumbing, internal flags in the spec inventory like `--link-bundle`. The wo_bundles.md sentence this changes is proposed in the next commit. Fixes #1815 * PROPOSED (needs Eric's blessing): wo_bundles.md — stage2's and stage3's embedded runtime is the one stage1 compiled (#1815) docs/spec/toolchain/wo_bundles.md said the stage-embedded object "reuses the bootstrap runtime inputs" — the seed-built set. Since the previous commit it embeds out/bootstrap/lib, the runtime stage1 compiled, because stage2's code is stage1's codegen. Kept in its own commit so the exact words can go to Eric before they land. * rt/std/compiler: read a `&str`'s bytes through `s as *const str`, which means the same under either `&str` representation `unsafe **(&s as *const *const *const u8)` reached a `&str`'s data pointer by dereferencing the reference's own slot twice: right only while a `&str` is a pointer to a str header. #1810 makes a `&str` its own `{ptr, len}`, and on the way through the stage chain the runtime and the LLVM/Clang bridges are compiled by both representations — by the pinned seed for stage1 (pointer) and by stage1 for stage2 and its programs (view) — so every such read must mean one thing under both. `*(s as *const str as *const *const u8)` does: a `&str` cast to `*const str` names a str header either way (the seed passes the reference through, #747; a view is its own header — its storage, or a copy in the frame). 56 sites: rt_core (str_data, with_str_eq_ref/cmp_ref, with_parse_i64_ref, with_lines_out_ref), panic_runtime.str_data and each platform's rt_str_data/posix_str_to_c_buf/win_str_data/rt_net_str_data/wasm_str_data, LlvmBridge (to_cstr, path_to_cstr and 18 wl_* string parameters), ClangBridge (10), ClangDriver.cc_c_string, both intern pools, std.regex, std.internal.str_abi, std.collections.trie (the same idiom through `*const *mut u8`), and Sema.sema_str_has_data (which read the text's first eight bytes as a pointer under a view). Evidence: the seed compiles these sources into out/bootstrap-lib (pointer `&str`) and stage1 links and runs against them (`src/main build :dev`); stage1 compiles them into out/bootstrap/lib (view `&str`) and the #1810 matrix programs linked through it pass. `grep` for the idiom in rt/ src/ lib/ tools/ build/: none left. * PROPOSED (needs Eric's blessing): with-abi v7 — a shared `&str` is a view value with str's own `{ptr, len}` layout, passed like a slice docs/spec/abi/with-abi.md describes the ABI the compiler implements; this is the wording for the #1810 change that follows, kept in its own commit so the exact words can go to Eric before they land. - §1: a shared `&str` (or `&T` of a distinct type over str) is a view value `{ ptr: *const u8, len: i64 }`, not the address of a str header, so a range view `s[a..b]` exists without a header (spec §4.8a); `&mut str` stays a pointer. The fact's one owner is `TypeLayout.type_layout_is_str_view`. - §3: the layout row (16 bytes, align 8); `Option[&str]` is an ordinary tagged enum, not the D22 nullable pointer (its payload is not an address). - §4: `&str` views pass Fat, `{ptr, len}` by value, indirect under the existing Windows x86_64 rule, like `[]T`. - Header and status line: version 7 (they still said v4 after v5 and v6 were recorded); v7 history entry. The spec already rules the language question (§4.8a: a str range is a `&str` view of its bytes, with the origin of any view); this commit only describes its ABI consequence. * FnAbi/TypeLayout/Codegen/CCodegen: a shared `&str` is its own `{ptr, len}` view, passed by value like a slice, so a str range needs no header (D71 §4.8a, #1810) Spec §4.8a makes `s[a..b]` a `&str` view of its bytes, with the origin of any view. While `&str` was the address of a str header, a range view had no header to point at: #1587 built one in a hidden frame local and Sema refused every return of it. A `&str` is now the view itself. One owner: `Sema.type_layout_is_str_view` (TypeLayout.w) says a shared `&str` (or `&` of a distinct type over str) has str's layout, 16 bytes, align 8; `&mut str` stays a pointer. Everything else reads it: - FnAbi: a view classifies through its LLVM type (the str struct), so compute_fn_abi gives it PM_DIRECT by value (PM_INDIRECT under the windows-x86_64 rule), for With functions and every runtime `_ref` seam alike; `sig_param_is_explicit_ref` no longer calls it a reference. WITH_ABI_VERSION 6 -> 7; docs/with-abi.sha256 re-recorded. - LLVM codegen: `*view` is the view's own storage (no load); a shared borrow of a str place loads the header's bits; `*const str -> &str` loads, `&str -> *const T` names the view's storage. Every hand-built runtime declaration (str methods, fmt, concat, join, panic, cstr lend) now goes through `call_internal_runtime_fn`/the str type, so caller and callee read one FnAbi. `Option[&str]` is a tagged enum: slot lookups (Map.get, SlotMap.get, Vec element and iterator views, map traversal) read the view out of the slot (`mir_ref_from_slot_ptr`, `option_ref_from_slot_ptr`). - MirLower: a str range is the view itself, like `[]T`; the hidden header local is gone. - C backend: `&str` is `with_str` by value; `WITH_STR_REF` and every `const with_str *` for a `&str` parameter in runtime/with_runtime.h and build/package.w are gone; a str or view lent to `const char *` goes through `with_cstr_lend`/`with_cstr_release` as the LLVM backend lends it (D47; a range view is not NUL-terminated at its end), keyed on Sema's `sema_type_is_c_char_pointer` (Codegen's copy of that predicate is gone too). Evidence (compiler facts, `with analyze … matrix:`; the `&str` rows of the matrix programs, before -> after): m1 params: params pointer 84 -> 0, value 0 -> 84; args existing-pointer -> direct-value, all m2 consumers: params 84 ptr -> 84 value; args 107 existing-pointer + 100 direct-value -> 207 direct-value m3 Option: 84 -> 84 value; 105 + 97 -> 202 direct-value m6 c_import: 83 -> 83 value; 104 + 88 -> 192 direct-value m9 join/fmt: 83 -> 83 value; 103 + 91 -> 194 direct-value Behavior (build + run, before -> after; the programs that do not return a range view): params, consumers (compare, concat, match, hash, fmt, Display/Debug), Option lookups, places (iteration, closures, `&&str`, raw pointers), c_import lending: pass -> pass; `[&str; N]` element concat: codegen "wrong argument type actual=str expected=ptr" -> pass; `join(&str sep)` over a Vec: SIGBUS -> pass; `&dyn Display` over a str: the same phase BUG before and after (#1818, filed). New tests: behav_1810_str_view_{params,consumers,lookups,c_lend}.w. `src/main build` green; `src/main build :fixpoint`: stage2 == stage3 over all 16 units. `:emit-c-smoke` green (every test/emit_c fixture, run by both backends). `:deep-debug-tool-tests --no-deps` green; `:drop-audit` 213 cells, 0 non-PASS, 0 regressions; `:move-audit` 105 cells, 0 FAIL, 0 DIFF; `with analyze … audit:all` violations=0 on every matrix program and new test except the `mut fn` str receiver false positive (#1822, the same on the baseline; debug-alloc leak count 0). * Sema: a str range view carries only its base's origins, so `fn tail(s: &str) -> &str: s[1..]` returns a view of the caller's string (D71 §4.8a, §21.1 Rule 6) #1587 gave every str range view a second, frame-local origin (`syms.str_range_view`) because its header lived in a hidden local of the frame, and refused every return of one by name. Since the previous commit a `&str` is its own `{ptr, len}`: there is no header, so the sentinel described nothing. Check_slice now records only the base's origins, exactly as for `[]T`; a returned range view is checked by the same Rule 6 as every other returned view. Tests: - err_1587_str_range_returned.w becomes behav_1810_str_range_returned.w: `tail`, `tail_bound`, a range view through an inner function, in `Option`, and in a tuple, all read the caller's bytes. err_1587_…_via_binding.w is covered there and removed. - behav_1810_str_view_aggregates.w: range views in tuples, structs with a view field, and arrays, returned and printed with Debug. - test/emit_c/str_view_representation.w: the same in the C backend (range return, runtime seams, `const char *` lending, map lookups). - The origin rules still refuse what they must: err_1810_returned_view_of_consumed_param.w (a view of a consumed `str` parameter: "returned view may outlive its origin 's'") and err_1810_returned_view_invalidated.w (mutating a string under a live range view). - err_1810_global_view_across_mutating_callee.w: a view of a global str live across a callee that reassigns the global. §9.1c and §21.1 refuse it; the checker accepts it until #1819, which lands in the layer below this one, and under a `{ptr, len}` view the accepted program reads freed bytes. This test is red on this layer alone and green on the stack; it proves the order. Matrix (build + run, before this stack -> after): returned range view refused (#1587) -> "bc"; range views in a returned tuple / struct Debug refused -> pass; #1819 cell: accepted before and after this layer (refusal expected from #1819). Fixes #1810 Fixes #1587 * FnAbi: the &str view representation is ABI v8 — v7 is the variadic-definition convention that merged first (#1844) Both changes bumped WITH_ABI_VERSION to 7 in parallel; the variadic layer landed on main as v7, so the `&str` {ptr, len} view (its with-abi.md entry already renumbered v8 in the rebase) takes 8. docs/with-abi.sha256 is re-recorded on the stack top. * docs/with-abi.sha256: re-recorded for ABI v8 (the &str view; FnAbi.w and TypeLayout.w as stacked) * build.w: stage1-llvm-link-metadata declares its out/command capture dir — #1840's SDK probe (merged after this layer was written) writes there * test: behav_1810 returns the &str view its cast through &Name yields (§4.5, D75) Under D75 a cast through a reference borrows, so `n as str` with `n: &Name` is a `&str` view; returning it from `-> str` is refused (d95cd0c). The fixture predates D75; it now returns `&str`, keeping what it demonstrates (a view parameter's bytes reach the caller). --------- Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 29, 2026
) * sdk: backport arm64e.x1 (llvm/llvm-project b8007a8e) into the LLVM 22.1.6 source step (#1826) Xcode 27's SDK lists the arm64e.x1 slice (CPU_SUBTYPE_ARM64E_X1 = 12) in every .tbd stub, and TextAPI rejects a stub with a target it cannot parse, so ld64.lld 22.1.6 could not read libSystem, libc++ or libm. The upstream fix, "[ld64.lld, llvm-otool] Minimal arm64e.x1 support" (b8007a8e, main 2026-09-11), is in no release: 22.1.8 and 23.1.2 lack it and the 23.x backport (llvm/llvm-project#224185) is still open. The sdk-llvm-source step now inserts the two lines lld needs — the ARCHINFO(arm64e_x1, arm64e.x1, …) entry in TextAPI/Architecture.def and CPU_SUBTYPE_ARM64E_X1 = 12 in BinaryFormat/MachO.h — after their exact anchor lines, on a fresh extraction and on a tree extracted before the patch existed. A missing or duplicated anchor fails the step; a line already present is left alone. The patch is pinned to 22.1.6: any other COMPILER_LLVM_VERSION fails the step until the patch is deleted (an LLVM that carries b8007a8e) or re-anchored, so it cannot outlive its version. Refs #1826. * sdk: every SDK subprocess runs with the shell's toolchain-flag variables empty CMake folds LDFLAGS, CPPFLAGS, CFLAGS, CXXFLAGS and the *_PATH search variables from the environment into every compile and link line. On a shell carrying a package manager's LLVM (LDFLAGS=-L/opt/llvm-22.1.6/lib), the SDK's ninja linked that LLVM's libc++ ahead of the sysroot's and died with undefined std::length_error symbols (2026-09-28, while rebuilding the darwin SDK for #1826). The SDK is built by the tools the graph names and nothing else: sdk_run_capture now runs every subprocess through a ProcessSpec that sets those variables empty. * ci: SDK canary — the pre-stage SDK link check against the newest Xcode SDK, nightly and on request (#1826) `with build :sdk-host-link-check` runs the probe every compiler build runs before its stage links (#1840's comp_require_linkable_host_sdk) on its own, and sdk-canary.yml runs it on macos-latest and on GitHub's xcode-27 preview image with SDKROOT at the newest MacOSX<ver>.sdk under /Applications/Xcode*.app (or an SDK given at dispatch). A slice this LLVM's TextAPI cannot parse fails the lane naming the SDK, the linker and the rejected stub target, before that SDK is every developer's default SDKROOT. A canary, not a merge signal (D56). * nightly-release: darwin-aarch64 pins the republished SDK nightly-sdk-20260928-3ae5c9ec0b31 (#1826) with-llvm-sdk-22.1.6-darwin-aarch64.tar.gz built from source at 3ae5c9e with the arm64e.x1 backport; its ld64.lld links against Xcode 27's SDK. sha256 dd824534e89fe9570558036a69fcddfecb6075b0fcad1bfa7f502c67272de7a4. * sdk-host-link-check: the verdict is the output file; LLVM_PREFIX is the action's input Under the pinned seed a standalone action in a built tree evaluates at comptime, where print (generic over Display) does not resolve, so the check and the source-step backport no longer print; the check writes "<lld> (LLVM <ver>) reads <sdk>" to its output and the canary lane cats it. LLVM_PREFIX is now the action's env_input: the check is about one linker, and pointing at another SDK re-runs it instead of a cache hit (verified: the pre-backport lld against Xcode 27 fails naming arm64e.x1-macos; the republished lld passes). * sdk-canary: the seed pin follows seed.lock (nightly-20260929-local-1-2fa54a7197df) The canary workflow this layer adds was written before the seed moved; seed-driver refused its stale pin in the stack battery. --------- Co-authored-by: Eric Hartford <[email protected]>
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.
Stack created with GitHub Stacks CLI • Give Feedback 💬