Skip to content

Link on any Linux layout: host libraries from the loader, runtime beside the compiler, and four fixes found running WIPE on a Steam Deck - #2361

Merged
ehartford merged 9 commits into
mainfrom
linux-host-layouts
Oct 15, 2026
Merged

ehartford merged 9 commits into
mainfrom
linux-host-layouts

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

On SteamOS (Arch), with run in a raylib project (~/with/spiral) failed to link with unable to find library -lGL / -lX11. The library search knew Debian's multiarch layout and nothing else, so other distributions failed one by one. This PR makes the link ask the host where its libraries are, so it works on any glibc Linux layout without a list of distributions. Four more fixes came up on the way to building and running WIPE on a Steam Deck.

Commits

  1. Host libraries on any Linux layout (src/compiler/HostLibs.w, new). One resolver for the link and for with get.
    • Search directories: LIBRARY_PATH, the dynamic loader's trusted directories, and every directory /etc/ld.so.conf names (includes and globs read as ldconfig reads them).
    • What -l<name> resolves to: lib<name>.so, then .a, else the highest lib<name>.so.N. A runtime package installs only the soname; -l:<file> is also honored.
    • Other architectures are skipped: each candidate's ELF e_machine (or an archive's first member) is checked against the target. SteamOS lists /usr/lib32, and lld refuses an incompatible library where GNU ld skips it.
    • Removed: the hardcoded z/zstd/xml2 path list and the Conan client's own host-library lookup. The CRT and gcc directory scans now accept any triple.
    • Test: test/internals/host_libs_test.w, renamed from conan_host_lib_test.w.
  2. Runtime directory beside the compiler. It resolves through the running executable (with_self_exe), not argv[0]. So a with found through PATH (~/.local/bin/with) finds its runtime.
  3. Build cache. An executable's binary is its output, so a missing binary makes the target stale. Before, a deleted binary left the target "fresh", and with run said run target 'spiral' did not produce executable output. Test: test/behavior/behav_build_cache_executable_output.w fails at the old HEAD and passes here.
  4. c_import lays out C's long as 64 bits on Windows: the C type aliases are hardcoded to arm64 macOS #2176: long double. It maps to c_longdouble only where clang sizes it at 8 bytes. On x86_64 Linux it is 16 bytes, and an extern, an inline function, a pointer slot or an L float macro that needs it is omitted and recorded, never mistyped. Test: test/behavior/behav_2176_long_double_omitted.w.
  5. D107 evidence: nothing under sizeof runs, so nothing under it is evidence.
    • The bug: glibc's assert(e) wraps e in (void) sizeof ((e) ? 1 : 0). The migrator read that ?: as a NULL test whose NULL branch continues, so c-migrator-basic-tests was red on Linux (contract param 0: Option). The same hole made sizeof(f(NULL)) count as a NULL caller.
    • Not this PR's regression: main's nightly-20261011 binary gives the same wrong verdict.
    • The test: the fixture's new sized case fails on every host before the fix, not only on glibc.

Evidence

  • Gate: src/main build :gate is green on eric-5090 (linux-x86_64), driven by the pinned seed nightly-20261011-local-2-e4861e1d6997. It ran at this branch's head (8e449af), based on c97a008. A fresh worktree has no battery measurements, so the gate ran the fixed list only.
  • Real use: with run in the spiral project links and runs on a Steam Deck. WIPE (raylib + SDL3 + Steam) builds and runs there too.
  • Not yet run: the battery. This PR stays a draft until a battery is green and posted here.

Filed along the way

#2353 (LLVM_PREFIX worktree), #2354 (one-liners adopt the enclosing project), #2360 (a stale seed cannot fetch the pinned seed).

Eric Hartford added 5 commits October 12, 2026 00:37
…s the machine

`with run` on SteamOS failed to link raylib's -lGL/-lX11 though both were
installed: the native link searched only Debian's multiarch directories,
and Arch keeps them in /usr/lib (Fedora in /usr/lib64). Three places each
guessed a Debian layout: the own-sysroot link's -L dirs, the gcc path's
-L dirs with its hand-listed z/zstd/xml2 sonames and Debian-only crt/gcc
lookup, and `with get`'s system-package resolution.

compiler.HostLibs now owns the answer. The directories are the host's:
LIBRARY_PATH, the loader's trusted directories that exist, and everything
/etc/ld.so.conf names (includes followed). ld.so.conf names other
machines' libraries too (SteamOS lists /usr/lib32), and lld refuses an
incompatible library rather than skipping it as GNU ld does, so each
candidate's ELF header (an archive's first object) is checked against the
target. A runtime-only soname still links by path when the dev symlink is
absent. A library in a directory the link names (a package's own, the
sysroot's) keeps -l<name>: a package's archive never gives way to a
same-named host library. `with get` records names only; the link resolves
them on the machine that links.

test/internals/host_libs_test.w replaces conan_host_lib_test.w: sonames,
other-machine .so and .a, linker scripts, -l:file, ld.so.conf parsing.
… PATH

link_stage_compiler_runtime_dir and link_stage_resolve_runtime_root took
dirname(argv[0]) as the compiler's directory. Run from PATH, argv[0] is a
bare `with`, whose dirname is the cwd, so a compiler whose runtime sits
beside it (a stage1 copied with its lib/) looked in ./runtime and ./../lib
and refused every link ("no runtime objects of this compiler's
generation"). Both now read with_self_exe(), which the Linux link already
uses to run its own linker.
…s stale

`.executable("spiral", "src/main.w")` declares no output and makes
out/bin/spiral. The cache collected only target.output, so it tracked no
output for any executable: a deleted binary stayed "fresh", `with build`
did nothing, and `with run` reported the target "did not produce
executable output".

build_graph_target_output_path (BuildGraphSupport) is now the one answer
for a target's file by kind; the output-ownership check and the cache read
it, as `with run` reads build_graph_output_path.
behav_build_cache_executable_output.w fails at e4861e1 ("fresh" after
the binary is removed) and passes here.
On x86-64 and AArch64 Linux, `long double` is x87 extended or binary128,
c_longdouble is not defined (ci_c_type_aliases), and a declaration that
needs it is to be omitted. ClangBridge translated it to c_longdouble
unconditionally, so `use c_import("SDL3/SDL.h", ...)` failed with
"unknown type 'c_longdouble'" on glibc's wcstold.

- ClangBridge: long double is c_longdouble where clang sizes it as a
  double (8 bytes: Apple arm64, Windows), else __UNSUPPORTED with the
  reason, which omits an extern as any untranslatable type does.
- CImport: an inline function's signature is checked for __UNSUPPORTED as
  an extern's is; before, the reason text was printed as a type.
- CImport: an `L` float macro is omitted on such a target.

behav_2176_long_double_omitted.w covers an extern, an inline function, a
pointer return, an `L` literal and a cast macro.
…ence

glibc's assert(e) is `((void) sizeof ((e) ? 1 : 0), ({ if (e) ; else
__assert_fail (...); }))`. The NULL-test walk read the `?:` under the
sizeof as a test whose NULL branch continues (its `0`), so on Linux
`assert(cb != NULL)` made `cb` Option and c-migrator-basic-tests failed:
"contract param 0: Option: body tests it for NULL and continues". The
call-evidence walk had the same hole: `sizeof(f(NULL))` read as a NULL
caller. Both walks, and the aborts check, stop at CXK_UNARY_EXPR (sizeof,
_Alignof), whose operand is a type's, never a value.

The fixture's `sized` fails on every host before this, not only on glibc.
Eric Hartford added 2 commits October 12, 2026 11:26
Four compiler sites each derived it (TMPDIR or /tmp; TMP, then TEMP, on
Windows in two of them; a trailing slash trimmed in one), and five
internals tests used `runtime_getenv("TMPDIR") ++ "/with-…"` with no
fallback. TMPDIR is set by a macOS login, not by a Linux one: under ssh on
eric-5090 the battery's internals-tests failed in archive_formats_test,
tar_extract_test and link_elf_undefined_symbols_test with "could not
create /with-archive-formats-93916/pkg-1.0.tar.xz", at the filesystem
root. compiler.Runtime's runtime_temp_dir is the one derivation; every site
and test reads it.
…ver's

build-w-workspace-message-complete appends a flag to the PreLink command
in that linker's syntax, and chose `-Wl,--gc-sections` on Linux, a C
driver's spelling. Every native Linux link has been the compiler's own
ELF lld since #1915 (D81), which refused it on eric-5090: "ld.lld: error:
unknown argument '-Wl,--gc-sections'". The flag is `--gc-sections`.
Eric Hartford added 2 commits October 12, 2026 14:26
pcre2test prints a freed block's size only when the block's address is in
its malloc list. check_match_limit (pcre2test_inc.h:3070) frees the cached
heap frames on every find_limits retry while show_memory is off, so the
list keeps a stale entry, and a later free prints its size only if malloc
returned that same address again. Upstream's RunTest says this test's output
"may vary in different environments" and runs it only on request.

Evidence on eric-5090 (glibc 2.43):
- the C pcre2test built by gcc fails upstream's testoutputheap-8 too
  (pattern 2: "free unremembered block" where we expected "free 20480");
- under gdb, the C pcre2test and the migrated one make the same 146
  my_malloc/my_free calls, with the same sizes, in the same order; only
  the addresses glibc returns differ.

The normalizer had rewritten upstream's expected output into the Mac's
address reuse (pattern 2 "free 20480"), so Linux was red. The heap test
now runs on its own and compares every free as "free": allocation sizes,
frame sizes, heapframes sizes and the order and count of frees still
compare. The match-data size (128 -> 152) stays a plain size rewrite.
…ot walked

check_live_views_for_origin runs for every binding leaving scope and asks
every live binding in the function about it. It computed
type_owns_user_drop(view_ty), an uncached recursive walk over the type's
fields, variants and arguments, before asking whether that binding depends
on the departing origin at all, and almost none do. The dependency
predicates are read-only, so asking them first decides the same programs.

perf on eric-5090, release `with check src/main.w` (109 s, 106 s user):
pop_scope 49% inclusive, check_live_views_for_origin 42.5%,
type_owns_user_drop 37%, half of it SipHash in hm_find_slot. With the
change, type_owns_user_drop drops out of the profile. issue61-regression
runs this check under a 180 s limit and timed out at 182.6 s in the
battery (#2362).

test/compile_errors under the fixed stage1 fails the same 22 files as the
release compiler without the change.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN at 2b4a12e on linux-x86_64 (eric-5090), driven by the pinned seed: gate rc=0 (734 s), uat rc=0 (34 s), battery-checks rc=0 (1443 s).

The two reds from the previous run are fixed:

Follow-ups: #2370, #2371, #2372, #2373.

@ehartford
ehartford marked this pull request as ready for review October 12, 2026 23:36
@ehartford
ehartford merged commit 9bf91a2 into main Oct 15, 2026
@ehartford
ehartford deleted the linux-host-layouts branch October 15, 2026 15:57
ehartford added a commit that referenced this pull request Oct 15, 2026
…ded go (D111: a str is a value, a push copies it; a consuming List parameter never needs a call-site `move`). Main's ceremony census was red after #2361 merged under #2422: clone-call in src 537 -> 543, move-arg 847 -> 854; this brings both under the bar. (#2423)

Co-authored-by: Eric Hartford <[email protected]>
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