Skip to content

One tree, one compiler binary, in any worktree: WITH_FILE_PREFIX_MAP (D50) - #1226

Merged
ehartford merged 2 commits into
mainfrom
debug-paths-are-checkout-independent
Sep 20, 2026
Merged

ehartford merged 2 commits into
mainfrom
debug-paths-are-checkout-independent

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Third item of the build-redo survey (D50, recorded here with the survey, the reference comparison, what landed and what remains).

The problem. The compiler named its checkout in three places, so one commit built in two worktrees gave two different compilers, and nothing built in one worktree could be shared with another (test verdicts, artifacts, a warm start for a new worktree):

Where What it cost
DWARF compile unit: /Users/eric/with/rt (16×), …/out/gen (2×) the path in the binary
module link names: __with_mod_<hash>__name hashed the module's absolute path rt_core's alloc_* and channel_runtime's chan_* had a different name per checkout: 176 bytes of __const, shifting 36 MB
the linker's debug map: 23 N_OSO stabs naming each object by absolute path 48 bytes of string table

What the others do (checked in .reference/): Go passes -trimpath always and normalizes the work dir; Rust has remap-debuginfo (/rustc/<sha>); Zig's manifests store prefix-relative paths; Scala 3 has -sourceroot. We already did this for bundle objects (#949).

The change. WITH_FILE_PREFIX_MAP=<from>=<to>, after clang's -ffile-prefix-map. The mapped root is what codegen_canonical_module_path returns, so the link-name hash and the compile unit both use it; the darwin lld link passes -oso_prefix <from>/; dsymutil gets -oso-prepend-path <from>. The build passes <project root>=/with-src to the compiler's own compiles.

Evidence. One commit built at the same time in two worktrees (path-free, path-free-b):

out/release/bin/with.unstamped   56f47bd93c2ab7bc   in both
out/release/bin/with             7de3cf4dad34c38e   in both
both unit-digest lists identical
.dSYM whole: 22 MB, 8496 subprograms

Debugging: lldb -o "settings set target.source-map /with-src $PWD" -- <binary> sets rt_core.w:1500 and lists the source; without the map it lists nothing, so the LLDB recipe in CLAUDE.md/AGENTS.md now carries the line.

behav_file_prefix_map_objects_match: a two-module program compiled in two directories gives identical objects under the map and different ones without it.

ABI hash. abi-hash-check went red on the first battery because src/FnAbi.w changed. The convention did not: the mapping changes a link-name hash only when the option is set and only for a module outside the stdlib tree, and a .wo bundle's modules are named <embedded-std>/…, which the mapping never sees. Re-recorded as the gate prescribes, no WITH_ABI_VERSION bump; every .wo rebuilds once.

Until the next seed. with-stage2 still differs between worktrees (136 symbols, all rt_core's alloc_*): it links the bootstrap runtime objects, which the pinned seed compiles, and the seed does not know the option. The release binary is unaffected.

Battery (pinned seed, head 1b744b4):

build rc=0   fixpoint rc=0   test rc=0   move-audit rc=0   drop-audit rc=0
test-green rc=0   last-green rc=0

Eric Hartford added 2 commits September 20, 2026 07:49
…(D50)

The compiler named its checkout in three places, so the same commit built in
two worktrees gave two different compilers and nothing built in one could be
shared with another (test verdicts, artifacts, a warm start for a new
worktree):

- the DWARF compile unit: /Users/eric/with/rt (16x) and .../out/gen (2x);
- module link names: `__with_mod_<hash>__name` hashed the module's absolute
  path, so rt_core's alloc_* and channel_runtime's chan_* had a different
  name per checkout (176 bytes of __const, shifting 36 MB of the binary);
- the linker's debug map: 23 N_OSO stabs naming each linked object by
  absolute path (48 bytes of the string table between `path-free` and
  `path-free-b`).

WITH_FILE_PREFIX_MAP=<from>=<to>, after clang's -ffile-prefix-map and Rust's
remap-debuginfo, beside #949's canonical stdlib paths: the mapped root is what
codegen_canonical_module_path returns (so both the link-name hash and the
compile unit use it), the darwin lld link passes -oso_prefix <from>/, and
dsymutil gets -oso-prepend-path <from> to find the objects again. The build
passes <project root>=/with-src to the compiler's own compiles.

Evidence, one commit built at the same time in two worktrees
(path-free, path-free-b): out/release/bin/with.unstamped 56f47bd93c2ab7bc in
both, out/release/bin/with 7de3cf4dad34c38e in both, both unit-digest lists
identical. The .dSYM is whole (22 MB, 8496 subprograms). lldb with
`settings set target.source-map /with-src $PWD` sets rt_core.w:1500 and lists
the source; without the map it lists nothing, so CLAUDE.md's LLDB recipe
carries it. with-stage2 still differs between worktrees (136 symbols, all
rt_core's alloc_*): it links the bootstrap runtime objects, which the pinned
seed compiles and the seed does not know the option; that ends at the next
seed.

behav_file_prefix_map_objects_match: a two-module program compiled in two
directories gives identical objects under the map and different ones
without it.

D50 records the survey, what Go, Zig, Rust, Scala 3, Bazel and Vale do, the
three decisions landed so far (#1224, #1225, this) and what remains.
…e convention is unchanged

abi-hash-check asks for a conscious decision when an ABI-defining source
changes. src/FnAbi.w changed (fn_abi_file_prefix_mapped, and
codegen_canonical_module_path applying it); the calling convention did not.
The mapping changes a module's link-name hash only when WITH_FILE_PREFIX_MAP
is set and only for a module outside the stdlib tree; a .wo bundle's modules
are named <embedded-std>/..., which the mapping never sees. No
WITH_ABI_VERSION bump; every .wo rebuilds once, as the gate says.
@ehartford
ehartford merged commit 8cdb5c2 into main Sep 20, 2026
5 checks passed
@ehartford
ehartford deleted the debug-paths-are-checkout-independent branch September 20, 2026 13:26
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