From e32875322d5537c25684b5b2363fb5a8b69621bf Mon Sep 17 00:00:00 2001 From: japabu Date: Wed, 30 Sep 2026 23:28:55 +0200 Subject: [PATCH 1/3] issues: what stops the hosted rustc from carrying LLVM, measured The scout for M3's rustc half of issues/build/toyos-builds-itself.md. Nothing but issues/ changes: the first blocker is outside this brief (the C library), and the exit is further blocked on M2's LLD and on the tooling. How each number was taken, at main 649ea51d4, with #637's C sysroot de0de8ee7862147a (libc++ in it, clang and LLVM at 849da7d62), APFS-cloned into scratch so nothing of another worktree's was written: - LLVM for a ToyOS host. CMake cross-configure of src/llvm-project/llvm (849da7d62, a private detached worktree of the fork clone) with that clone's clang for x86_64-unknown-toyos, CMAKE_SYSTEM_NAME=ToyOS and UNIX=ON as src/libcxx.rs names the system, the store LLVM's llvm-tblgen, targets AArch64;X86 as clang::LLVM_CONFIG, every host library off. Configure exit 1 at CheckAtomic.cmake:59 with 18 "unable to find library -lm"; with empty libm/libpthread/libdl/librt archives in the scratch sysroot, exit 0. - `ninja -k 0 llvm-libraries`, with only a scratch machine/endian.h: 20 objects failed, 12 of them in the 71 libraries rustc links (llvm-config --libnames of rustc_llvm's required components plus x86 and aarch64): 9 in LLVMSupport, Host.cpp in LLVMTargetParser, two MachO files in LLVMObjectYAML. Scratch headers and forced declarations were added for each missing name, in three layers, until `ninja -k 0` of those 71 targets exited 0. The issue lists every name a layer added. - The link. compiler/rustc_llvm/llvm-wrapper from the pinned fork, compiled for the target with the same defines rustc_llvm's build script gives, archived and linked --whole-archive with the 71 archives, libc++.a and the Rust sysroot's archives (libtoyos_c.a among them) by ld.lld -shared -z defs: 17 duplicate _Unwind_* (libc++.a's libunwind against std's `unwinding`), 2 R_X86_64_TPOFF32 "cannot be used with -shared" against libc++abi's eh_globals; with --allow-multiple-definition, 36 undefined symbols, 29 of them C functions (the other 7: std's allocator shim, LLVMRustStringWriteImpl, main). With --noinhibit-exec -z undefs it wrote a 55,071,992-byte object, 41,131,639 bytes of text. - The linker. A host build of toyos-ld (cargo build -p toyos-ld --release) as -C linker for a std hello.rs compiled for x86_64-unknown-toyos: exit 1, "an executable with thread-local storage: toyos-ld is frozen"; through rust-lld, exit 0. What is read from code and not run is said so in the track: bootstrap's Generic fallback for CMAKE_SYSTEM_NAME, its clang-tblgen panic with an external host LLVM, rustc_llvm's stdc++/C-library/triple-replacement arms, and the two LLVM sites with no ToyOS arm. libc's mmap dropping fd and offset is read from userland/libc/src/posix_io.rs. Filed: the track and five issues it points at. toyos-builds-itself.md gains one pointer paragraph at its end, clear of the lines #637 rewrites. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016t9wjdQkB8SH7bmfUoiy6L --- ...-std-binary-cannot-link-the-cxx-runtime.md | 27 ++++++++++ ...-cannot-build-a-hosted-rustc-of-its-own.md | 24 +++++++++ ...map-ignores-the-file-it-is-asked-to-map.md | 18 +++++++ ...ot-has-no-libm-so-llvms-configure-fails.md | 23 +++++++++ ...t-because-llvm-does-not-build-for-toyos.md | 51 +++++++++++++++++++ issues/build/toyos-builds-itself.md | 3 ++ ...the-posix-surface-llvm-compiles-against.md | 49 ++++++++++++++++++ 7 files changed, 195 insertions(+) create mode 100644 issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md create mode 100644 issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md create mode 100644 issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md create mode 100644 issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md create mode 100644 issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md create mode 100644 issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md diff --git a/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md b/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md new file mode 100644 index 00000000000..e586514d080 --- /dev/null +++ b/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md @@ -0,0 +1,27 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# A Rust std binary cannot link the C++ runtime + +LLVM is C++, so a rustc that carries it links the C++ runtime into +`librustc_driver.so` beside std. The runtime #637 builds into the C sysroot, +`lib/libc++.a` (sysroot `de0de8ee7862147a`), does not link there. Linking +rustc's LLVM wrapper (`compiler/rustc_llvm/llvm-wrapper`, whole), the 71 LLVM +archives rustc links, `libc++.a` and the Rust sysroot's archives with `ld.lld +-shared` gives: + +- **Two unwinders.** `libc++.a` carries LLVM's libunwind + (`LIBCXXABI_ENABLE_STATIC_UNWINDER`) and std carries the `unwinding` crate, + and both define the Itanium `_Unwind_*` interface: 17 duplicate symbols, + `_Unwind_Resume` among them, at libunwind's `UnwindLevel1.c` and at + `unwinding`'s `src/unwinder/mod.rs:346`. +- **Local-exec thread-locals.** libc++abi's `eh_globals` is reached through + `R_X86_64_TPOFF32`, twice `cannot be used with -shared`: the runtime is + compiled as position-independent executable code, not for a shared object. + +**Exit**: a Rust std shared object and a Rust std executable each link the C++ +runtime with one unwinder and no relocation error, and a guest case runs a Rust +std program in which C++ code throws and catches an exception. diff --git a/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md b/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md new file mode 100644 index 00000000000..66e40946967 --- /dev/null +++ b/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md @@ -0,0 +1,24 @@ +--- +status: open +kind: tooling +opened: 2026-09-30 +--- + +# A worktree cannot build a hosted rustc of its own + +The ToyOS-hosted rustc is built by the primary checkout alone +(`src/toolchain.rs`'s `ensure`, under `Owner::Us`), from the primary's `rust/` +under the primary's `write_config`. A worktree's image with `hosted-rustc = +true` carries that one: refused by name when the worktree builds a compiler of +its own (`src/build.rs`, `env.primary_compiler`), and taken without a word when +only the worktree's `write_config` differs, so the image then carries a rustc +another tree's recipe built. + +So no branch can put the hosted rustc it changes into a guest before it lands. +Carrying LLVM instead of Cranelift changes `write_config`'s hosted target and +the fork's `compiler/rustc_llvm` and `src/bootstrap`, and its guest test could +run only after the merge. + +**Exit**: a worktree whose `write_config`, or whose fork's `compiler/` or +`src/bootstrap`, differs from the primary's builds a hosted rustc of its own, +keyed as `src/compiler.rs` keys a compiler, and its image carries that one. diff --git a/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md b/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md new file mode 100644 index 00000000000..12c1ea497a0 --- /dev/null +++ b/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md @@ -0,0 +1,18 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# libc's mmap ignores the file it is asked to map + +`mmap` (`userland/libc/src/posix_io.rs`) never reads its `fd` or `offset`, and +maps anonymous memory: a file mapping succeeds and reads zeros. LLVM maps a +file it reads when it is at least four pages and needs no terminator past the +mapping's end (`llvm/lib/Support/MemoryBuffer.cpp`'s `shouldUseMmap`, with +libc's `sysconf(_SC_PAGESIZE)` answering 4096), so an LLVM on ToyOS reads such +a file as zeros and reports no error. + +**Exit**: `mmap` with a file descriptor maps that file's bytes from `offset`, or +fails with `errno` set, and a guest case maps a file of at least 16 KiB and +reads its bytes back. diff --git a/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md b/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md new file mode 100644 index 00000000000..2a0558a0342 --- /dev/null +++ b/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md @@ -0,0 +1,23 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# The C sysroot has no libm, so LLVM's configure fails + +LLVM's configure adds `m` to every link probe on a `UNIX` system that is not +Apple, BeOS or Haiku (`llvm/cmake/config-ix.cmake`), and probes `pthread`, +`dl` and `rt` as libraries. The C sysroot's `lib/` holds `libtoyos_c.a` and no +archive under any of those names, so every probe that links fails. + +Configuring `src/llvm-project/llvm` at `849da7d62` for `x86_64-unknown-toyos`, +with CMake's system `ToyOS` and `UNIX=ON`, against #637's C sysroot +(`de0de8ee7862147a`): `unable to find library -lm` 18 times, `sysconf`, +`isatty` and `setenv` reported absent though `libtoyos_c.a` defines them, and a +stop at `cmake/modules/CheckAtomic.cmake:59`, exit 1. With empty `libm.a`, +`libpthread.a`, `libdl.a` and `librt.a` beside `libtoyos_c.a`, the same +configure exits 0. + +**Exit**: that configure exits 0 against the C sysroot as `src/libc.rs` lays it +out, and finds every function `libtoyos_c.a` defines. diff --git a/issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md b/issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md new file mode 100644 index 00000000000..6db5e3f274c --- /dev/null +++ b/issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md @@ -0,0 +1,51 @@ +--- +status: open +kind: track +opened: 2026-09-30 +--- + +# The hosted rustc carries Cranelift because LLVM does not build for ToyOS + +M3's rustc half of `issues/build/toyos-builds-itself.md`: the ToyOS-hosted +rustc links LLVM, as the host's does, instead of `rustc_codegen_cranelift` +(`src/toolchain.rs`'s `write_config`). *Exit*: a Rust program compiled and run +inside ToyOS by that rustc. + +**Blocked on**, each measured against main `649ea51d4` with #637's C sysroot +(`de0de8ee7862147a`, LLVM `849da7d62`): +- The C++ runtime (#637), and linking it beside std: + `issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md`. +- The C library: `issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`, + `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md` and + `issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md`. +- A linker in the guest (M2). toyos-ld refuses every executable with + thread-local storage, so every std program: `hello.rs`, compiled for + `x86_64-unknown-toyos` by the host's rustc and linked by a host build of + toyos-ld, stops at `an executable with thread-local storage: toyos-ld is + frozen, and places it where the loader does not`, exit 1; the same program + through `rust-lld`, exit 0. Whatever its backend, the hosted rustc links no + std program inside ToyOS before LLD runs there + (`issues/build/the-hosted-rustc-names-a-linker-toyos-does-not-have.md`). +- Testing it before it lands: + `issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md`. + +Threads, memory and `dlopen` at run time are unmeasured: nothing links to run. +rustc's LLVM wrapper, the 71 LLVM archives it links, `libc++.a` and std, +linked `-shared`, carry 41,131,639 bytes of text (`llvm-size`). + +**What the build must also do, read from the fork and not yet run:** +- Bootstrap names no CMake system for a ToyOS target, and its fallback is + `Generic` (`src/bootstrap/src/core/build_steps/llvm.rs`, `configure_cmake`), + under which LLVM sets `LLVM_ON_UNIX` to 0 + (`llvm/cmake/modules/HandleLLVMOptions.cmake`) and compiles no `Unix/` + implementation of `Support`. +- With `clang = true`, bootstrap's LLVM step for a target that is not the host + panics without `clang-tblgen` in the host's own LLVM build directory, and + every compiler here links the store's LLVM (`src/llvm.rs`), which bootstrap + did not build. +- `compiler/rustc_llvm/build.rs` links `stdc++` for a target it does not list, + links no C library, and finds a cross target's LLVM by replacing the host + triple in the host `llvm-config`'s paths, which the store's paths do not + contain. +- LLVM's `llvm/include/llvm/ADT/bit.h` takes `machine/endian.h` on ToyOS, and + `llvm/lib/Support/Unix/Path.inc`'s `is_local_impl` has no ToyOS arm. diff --git a/issues/build/toyos-builds-itself.md b/issues/build/toyos-builds-itself.md index 8267404b85e..0748152354a 100644 --- a/issues/build/toyos-builds-itself.md +++ b/issues/build/toyos-builds-itself.md @@ -61,3 +61,6 @@ by the ToyOS-hosted rustc (`issues/build/the-hosted-rustc-names-a-linker-toyos-does-not-have.md`). It goes when lld runs in the guest: the row, the crate and its host tests go together, the hosted rustc names `rust-lld`, and the published crates.io crate is yanked. + +**What M3's rustc half is blocked on** is measured in +`issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md`. diff --git a/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md b/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md new file mode 100644 index 00000000000..b8b971af2b8 --- /dev/null +++ b/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md @@ -0,0 +1,49 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# ToyOS's libc lacks the POSIX surface LLVM compiles against + +LLVM does not build for a ToyOS host. The 71 libraries rustc links +(`llvm-config --libnames` of `compiler/rustc_llvm/build.rs`'s required +components, with `x86` and `aarch64`) stop in `LLVMSupport`, +`LLVMTargetParser` and `LLVMObjectYAML`, on names the C library does not +declare or define. Measured by configuring `src/llvm-project/llvm` at +`849da7d62` for `x86_64-unknown-toyos`, with CMake's system `ToyOS` and +`UNIX=ON` as `src/libcxx.rs` names it, against #637's C sysroot +(`de0de8ee7862147a`), compiling with `ninja -k 0`, and declaring each missing +name in a scratch header until all 71 archives built, exit 0. + +**Headers the C sysroot does not have:** `dirent.h` (its functions are in +`libtoyos_c.a`), `sys/resource.h`, `sys/utsname.h`, `sys/statvfs.h`, +`sys/un.h`, `pwd.h`, `sysexits.h` and `endian.h`. + +**Names its headers do not declare:** +- `signal.h`: `sigemptyset`, `sigfillset`, `sigaddset`, `pthread_sigmask`, + `SIGUSR1`, `SIGUSR2`, `SA_ONSTACK`, `SA_RESETHAND`, `SA_NODEFER`. +- `unistd.h`: `alarm`, `gethostname`, `getsid`, `setsid`, `execv`, `execve`, + `readlink`, `symlink`, `link`, `ftruncate`, `fchown`, `_SC_ARG_MAX`, + `_SC_PAGE_SIZE`, `_SC_GETPW_R_SIZE_MAX`. +- `string.h` and `stdlib.h`: `strnlen`, `strsignal`, `realpath`. +- `sys/stat.h`: `fchmod`. `sys/wait.h`: `wait4`. `limits.h`: `_POSIX_ARG_MAX`. +- `sys/mman.h`: `msync`, `MS_SYNC`, `madvise`, `MADV_WILLNEED`, + `MADV_DONTNEED`. +- `fcntl.h`: `struct flock`, `F_SETLK`, `F_SETLKW`, `F_RDLCK`, `F_WRLCK`, + `F_UNLCK`. +- `sys/socket.h`: `AF_UNIX`. `dlfcn.h`: `Dl_info`, `dladdr`. + +**Functions no archive defines**, once those compile. rustc's LLVM wrapper +(`compiler/rustc_llvm/llvm-wrapper`, whole), the 71 archives, `libc++.a` and +the Rust sysroot's archives, `libtoyos_c.a` among them, linked by `ld.lld +-shared -z defs`, leave 29 C functions undefined: `alarm aligned_alloc dladdr +execv execve fchown fstatvfs getpwnam_r getpwuid_r getrlimit link logb madvise +modf msync pthread_sigmask readlink realpath setrlimit setsid sigaddset +sigemptyset sigfillset statvfs strsignal symlink uname wait wait4`. +`aligned_alloc` is the C allocator's, which in a std program is std's: it +defines `malloc`, `calloc`, `realloc` and `free`, and not `aligned_alloc`. + +**Exit**: those 71 libraries compile for `x86_64-unknown-toyos` against the C +sysroot with nothing declared beside it, and that link leaves no C function +undefined. From a606e5d0d9ba3274df9d65b23d302646e7470402 Mon Sep 17 00:00:00 2001 From: japabu Date: Thu, 1 Oct 2026 00:06:38 +0200 Subject: [PATCH 2/3] issues: what stops LLVM building for a ToyOS host, ordered, with exits a build or a test can fail Round 2 of the scout, answering the review of e32875322. The track goes. Its exit was M3's rustc exit word for word, which the Cranelift rustc meets the day a linker runs in the guest, so it could not fail on its own title. toyos-builds-itself.md now orders what stops LLVM building for a ToyOS host, configure, compile, link, run, test, then the linker, and says which of it blocks M2's clang and lld before M3's rustc; toyos-has-no-c-compiler-inside-it.md cites the same issues. Both edits sit clear of the lines #637 and #568 rewrite. The track's "what the build must also do" becomes llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md, whose exit is bootstrap building rustc_llvm for x86_64-unknown-toyos and the guest's `rustc -vV` printing `LLVM version:`: the Cranelift backend's print_version prints `Cranelift version:` (rust/compiler/rustc_codegen_cranelift/src/lib.rs), so today's hosted rustc fails it. The bit.h and Path.inc fixes are said to be upstream-shaped LLVM arms, and clang-tblgen and the cross target's paths to be fixed in ToyOS's build or carried as the LLD precedent is. The POSIX-surface issue gives stage 3 of the child-process track wait, wait4 and the signal-set calls, and the header-drift issue SIGUSR1 and the names libc defines and declares nowhere (dirent.h, ftruncate, fchmod). Its exit now asks each name to do what POSIX says or refuse as POSIX reports an error, ENOSYS for setsid, getsid, execv and execve, with a guest C case per function and a host test that compiles and links one probe per name against the C sysroot. alarm leaves it for libc-has-no-alarm.md: POSIX gives alarm no refusal, and its SIGALRM reaches a handler only through stage 3's imitated signals. aligned_alloc leaves it for a-rust-std-program-defines-no-aligned-alloc.md: link-shared3.log has libc++.a's stdlib_new_delete.cpp and fallback_malloc.cpp reference it, and in a std program the C allocator is std's (rust/library/std/src/sys/pal/toyos/mod.rs), not libc's. Filed: fcntl's and fchmod's answer-0 stubs; pread and pwrite's seek-read-seek, which LLVM reads every file slice through once a header declares pread; and readdir answering DT_REG for a directory, which LLVM trusts once dirent.h defines DTTOIF. mmap's exit is the refusal: a file mapping, shared or private, answers ENODEV. The kernel maps no file, and LLVM falls back to read (MemoryBuffer) and to a buffer in memory (FileOutputBuffer) when a map fails. The shared case is in that exit: FileOutputBuffer maps lld's output MAP_SHARED and writable, which libc maps private, so lld inside ToyOS would write zeros and report success. Read from llvm/lib/Support/FileOutputBuffer.cpp at 849da7d62, not run. The configure's exit-1 arm now has a log. Rerun at 849da7d62 (git archive of llvm/, cmake/, third-party/ into scratch) against APFS clones of #637's C sysroot de0de8ee7862147a's c/, with the sysroot's own clang and the store LLVM 1425e623e612b348's llvm-tblgen, no scratch headers: - as laid out: CONFIGURE_EXIT=1 at CheckAtomic.cmake:59; CMakeConfigureLog.yaml holds `unable to find library -lm` 18 times and -lpthread, -lc, -ldl, -lrt and -latomic once each; - with empty libm.a, libpthread.a, libdl.a and librt.a: CONFIGURE_EXIT=0; eleven probes flip from failed to passed between the two logs, and the libm exit names exactly those. pread is not found in either. The rust-lld control and the byte sizes had no log and go with the track. The worktree issue says #629's the-hosted-rustc-is-not-built.md covers it and whichever lands second folds it. The C++ runtime issue loses the line citations into libunwind and unwinding, and says #637's follow-up closes it; #637 now carries a copy, and main's copy replaces this one once #637 lands. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016t9wjdQkB8SH7bmfUoiy6L --- ...-std-binary-cannot-link-the-cxx-runtime.md | 5 +- ...st-std-program-defines-no-aligned-alloc.md | 21 +++++ ...-cannot-build-a-hosted-rustc-of-its-own.md | 5 ++ ...cntl-and-fchmod-answer-0-and-do-nothing.md | 24 ++++++ issues/build/libc-has-no-alarm.md | 21 +++++ ...map-ignores-the-file-it-is-asked-to-map.md | 26 ++++-- ...e-move-the-offset-another-thread-shares.md | 22 +++++ ...eaddir-calls-every-entry-a-regular-file.md | 18 +++++ ...stcs-build-have-no-arm-for-a-toyos-host.md | 43 ++++++++++ ...ot-has-no-libm-so-llvms-configure-fails.md | 25 ++++-- ...t-because-llvm-does-not-build-for-toyos.md | 51 ------------ issues/build/toyos-builds-itself.md | 26 +++++- .../toyos-has-no-c-compiler-inside-it.md | 12 +++ ...the-posix-surface-llvm-compiles-against.md | 80 ++++++++++++------- 14 files changed, 281 insertions(+), 98 deletions(-) create mode 100644 issues/build/a-rust-std-program-defines-no-aligned-alloc.md create mode 100644 issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md create mode 100644 issues/build/libc-has-no-alarm.md create mode 100644 issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md create mode 100644 issues/build/libc-readdir-calls-every-entry-a-regular-file.md create mode 100644 issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md delete mode 100644 issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md diff --git a/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md b/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md index e586514d080..112095ae1f7 100644 --- a/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md +++ b/issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md @@ -16,12 +16,13 @@ archives rustc links, `libc++.a` and the Rust sysroot's archives with `ld.lld - **Two unwinders.** `libc++.a` carries LLVM's libunwind (`LIBCXXABI_ENABLE_STATIC_UNWINDER`) and std carries the `unwinding` crate, and both define the Itanium `_Unwind_*` interface: 17 duplicate symbols, - `_Unwind_Resume` among them, at libunwind's `UnwindLevel1.c` and at - `unwinding`'s `src/unwinder/mod.rs:346`. + `_Unwind_Resume` among them. - **Local-exec thread-locals.** libc++abi's `eh_globals` is reached through `R_X86_64_TPOFF32`, twice `cannot be used with -shared`: the runtime is compiled as position-independent executable code, not for a shared object. +Both are in #637's artifact, and #637's follow-up closes this. + **Exit**: a Rust std shared object and a Rust std executable each link the C++ runtime with one unwinder and no relocation error, and a guest case runs a Rust std program in which C++ code throws and catches an exception. diff --git a/issues/build/a-rust-std-program-defines-no-aligned-alloc.md b/issues/build/a-rust-std-program-defines-no-aligned-alloc.md new file mode 100644 index 00000000000..b6e62547d0a --- /dev/null +++ b/issues/build/a-rust-std-program-defines-no-aligned-alloc.md @@ -0,0 +1,21 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# A Rust std program defines no aligned_alloc + +In a Rust std program the C allocator is std's: +`rust/library/std/src/sys/pal/toyos/mod.rs` defines `malloc`, `calloc`, +`realloc` and `free`, and libc's allocator is not built beside std +(`userland/libc/src/memory.rs`, `feature = "std-runtime"`). Nothing defines +C11's `aligned_alloc`, which libc++abi calls for an over-aligned `operator new` +and in its fallback allocator: the link +`issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md` describes +leaves it undefined, referenced from `libc++.a`'s `stdlib_new_delete.cpp` and +`fallback_malloc.cpp`. + +**Exit**: a Rust std program's C code allocates through `aligned_alloc` from +std's allocator and frees through `free`, and a guest case does it at an +alignment above 16. diff --git a/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md b/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md index 66e40946967..8df3211f8b8 100644 --- a/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md +++ b/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md @@ -19,6 +19,11 @@ Carrying LLVM instead of Cranelift changes `write_config`'s hosted target and the fork's `compiler/rustc_llvm` and `src/bootstrap`, and its guest test could run only after the merge. +#629 deletes this build and files `the-hosted-rustc-is-not-built.md`, whose +exit, a store product keyed on a compiler building the hosted rustc and an +image carrying it, covers this one: whichever of the two lands second folds +this issue into that one. + **Exit**: a worktree whose `write_config`, or whose fork's `compiler/` or `src/bootstrap`, differs from the primary's builds a hosted rustc of its own, keyed as `src/compiler.rs` keys a compiler, and its image carries that one. diff --git a/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md b/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md new file mode 100644 index 00000000000..c3b791388ff --- /dev/null +++ b/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md @@ -0,0 +1,24 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# libc's fcntl and fchmod answer 0 and do nothing + +`fcntl` (`userland/libc/src/posix_io.rs`) answers 0 to every command on every +descriptor: `F_DUPFD` names descriptor 0 as the duplicate, `F_GETFL` reads +every descriptor as read-only and blocking, `F_SETFL` sets nothing, and a +command it does not know is answered as done. `fchmod` answers 0 and changes +nothing. Once `fcntl.h` declares the record locks +(`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`), +LLVM's `sys::fs::tryLockFile` and `lockFile` +(`llvm/lib/Support/Unix/Path.inc`) take a lock nothing holds. Close-on-exec, +`F_GETFD` and `F_SETFD`, is the descriptor table's of stage 3 of +`issues/kernel/a-childs-end-is-an-event-and-a-parent-takes-its-children-down.md`. + +**Exit**: every other command POSIX defines for `fcntl` does what POSIX says or +answers -1 with `errno` set — a record lock `EINVAL`, as POSIX has a file that +supports no locking answer — and a command POSIX does not define answers +`EINVAL`; `fchmod` changes the mode `fstat` reads back, or answers -1 with +`errno` set. A guest C case asserts each command's answer and `fchmod`'s. diff --git a/issues/build/libc-has-no-alarm.md b/issues/build/libc-has-no-alarm.md new file mode 100644 index 00000000000..ec53f4312c5 --- /dev/null +++ b/issues/build/libc-has-no-alarm.md @@ -0,0 +1,21 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# libc has no alarm + +libc neither declares nor defines `alarm`, and LLVM bounds its wait on a child +with one: a `SIGALRM` handler makes `wait4` answer `EINTR` +(`llvm/lib/Support/Unix/Program.inc`, `Wait`), so an LLVM built for ToyOS does +not link without it +(`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md` +measures that link). POSIX gives `alarm` no refusal, and its `SIGALRM` reaches +a handler only through the signals libc imitates from stage 3 of +`issues/kernel/a-childs-end-is-an-event-and-a-parent-takes-its-children-down.md` +on; this waits on that stage. + +**Exit**: `alarm` arms `SIGALRM` as POSIX says, which a guest C case shows: a +handler installed without `SA_RESTART` runs, and a `wait4` on a child that has +not ended answers `EINTR`. diff --git a/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md b/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md index 12c1ea497a0..c3dc5d39be8 100644 --- a/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md +++ b/issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md @@ -7,12 +7,22 @@ opened: 2026-09-30 # libc's mmap ignores the file it is asked to map `mmap` (`userland/libc/src/posix_io.rs`) never reads its `fd` or `offset`, and -maps anonymous memory: a file mapping succeeds and reads zeros. LLVM maps a -file it reads when it is at least four pages and needs no terminator past the -mapping's end (`llvm/lib/Support/MemoryBuffer.cpp`'s `shouldUseMmap`, with -libc's `sysconf(_SC_PAGESIZE)` answering 4096), so an LLVM on ToyOS reads such -a file as zeros and reports no error. +maps anonymous memory, `MAP_SHARED` as `MAP_PRIVATE`: a file mapping succeeds +and reads zeros, and what is written through a shared one never reaches the +file. The kernel maps no file (`kernel/src/syscall/vm.rs`). Read from LLVM at +`849da7d62`, not run: -**Exit**: `mmap` with a file descriptor maps that file's bytes from `offset`, or -fails with `errno` set, and a guest case maps a file of at least 16 KiB and -reads its bytes back. +- `MemoryBuffer` maps a file it reads, private and read-only, when the file is + at least four pages and needs no terminator past the mapping's end + (`llvm/lib/Support/MemoryBuffer.cpp`'s `shouldUseMmap`, with libc's + `sysconf(_SC_PAGESIZE)` answering 4096), so it reads such a file as zeros + and reports no error. +- `FileOutputBuffer`, through which lld writes its output, maps the output file + shared and writable (`llvm/lib/Support/FileOutputBuffer.cpp`), so lld writes + an output of zeros and reports success. + +Each falls back, to `read` and to a buffer in memory, when the map fails. + +**Exit**: `mmap` of a file, shared or private, at offset 0 or at a later page, +answers `MAP_FAILED` with `errno` `ENODEV`, and a guest C case asserts each and +that an anonymous mapping still maps. diff --git a/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md b/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md new file mode 100644 index 00000000000..f9daf14dd5d --- /dev/null +++ b/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md @@ -0,0 +1,22 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# libc's pread and pwrite move the offset another thread shares + +`pread` and `pwrite` (`userland/libc/src/posix_io.rs`) seek the descriptor to +their offset, read or write, and seek it back: three calls, nothing held +between them. POSIX has them leave the file offset alone. Here a `read`, +`write`, `lseek`, `pread` or `pwrite` of the same descriptor on another thread, +landing between those calls, reads or writes at the wrong offset, or has its +own moved. The ABI has no positional read or write (`toyos-abi/src/syscall.rs` +has `seek`). No header declares `pread` +(`issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`), +so LLVM's configure finds none; once it does, LLVM reads every file slice +through it (`llvm/lib/Support/Unix/Path.inc`, `readNativeFileSlice`). + +**Exit**: `pread` and `pwrite` never move the descriptor's offset, which a +guest C case shows: while one thread `read`s a file through, another `pread`s +it at one offset, and each reads only the bytes at its own offset. diff --git a/issues/build/libc-readdir-calls-every-entry-a-regular-file.md b/issues/build/libc-readdir-calls-every-entry-a-regular-file.md new file mode 100644 index 00000000000..d38c4c96d5b --- /dev/null +++ b/issues/build/libc-readdir-calls-every-entry-a-regular-file.md @@ -0,0 +1,18 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# libc's readdir calls every entry a regular file + +`readdir` (`userland/libc/src/posix_io.rs`) answers `d_type` `DT_REG` for every +entry, a directory's too. libc ships no `dirent.h` yet +(`issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`); +once one defines `DTTOIF`, LLVM takes an entry's type from `d_type` +(`llvm/lib/Support/Unix/Path.inc`, `direntType`) and reads a directory as a +file. + +**Exit**: `readdir` answers each entry's type, or `DT_UNKNOWN` where it does +not know it, and a guest C case reads a directory holding a file and a +directory. diff --git a/issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md b/issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md new file mode 100644 index 00000000000..00e63ed3549 --- /dev/null +++ b/issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md @@ -0,0 +1,43 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# LLVM and rustc's build have no arm for a ToyOS host + +Read from the fork at `rust/` and from `src/llvm-project` at `849da7d62`, not +run. The first two stop any LLVM built for a ToyOS host, so M2's clang and lld +(`issues/build/toyos-builds-itself.md`) before M3's rustc; the last two are +rustc's alone. + +- **Configure.** Bootstrap names no CMake system for a ToyOS target and falls + back to `Generic` (`src/bootstrap/src/core/build_steps/llvm.rs`, + `configure_cmake`), under which LLVM sets `LLVM_ON_UNIX` to 0 + (`llvm/cmake/modules/HandleLLVMOptions.cmake`) and compiles no `Unix/` + implementation of `Support`. +- **Compile.** `llvm/include/llvm/ADT/bit.h` includes `` on the + systems it lists and `` on any other, ToyOS among them, and + `llvm/lib/Support/Unix/Path.inc`'s `is_local_impl` reads the BSDs' + `MNT_LOCAL` on a system it does not list. +- **Build.** With `clang = true`, bootstrap's LLVM step for a target that is + not the host panics without `clang-tblgen` in the host's own LLVM build + directory, and every compiler here links the store's LLVM (`src/llvm.rs`), + which bootstrap did not build. +- **`rustc_llvm`.** `compiler/rustc_llvm/build.rs` links `stdc++` for a target + it does not list, links no C library, and finds a cross target's LLVM by + replacing the host triple in the host `llvm-config`'s paths, which the + store's paths do not contain. + +The fixes to `bit.h`, `is_local_impl`, bootstrap's CMake system and +`rustc_llvm`'s C++ runtime and C library are ToyOS arms at existing dispatch +sites, written as upstream would take them: ToyOS joins `bit.h`'s `` +list, so libc carries POSIX's `endian.h` and no BSD name +(`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`). +`clang-tblgen` and the cross target's paths are not arms: each is fixed in +ToyOS's build, or written as upstream would take it and carried as +`issues/build/lld-beside-an-external-llvm-config-is-carried-without-an-upstream-pr.md` +carries LLD's. + +**Exit**: bootstrap builds `rustc_llvm` for `x86_64-unknown-toyos`, and the +guest's `rustc -vV` prints `LLVM version:`. diff --git a/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md b/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md index 2a0558a0342..ee6bd39730e 100644 --- a/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md +++ b/issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md @@ -7,17 +7,28 @@ opened: 2026-09-30 # The C sysroot has no libm, so LLVM's configure fails LLVM's configure adds `m` to every link probe on a `UNIX` system that is not -Apple, BeOS or Haiku (`llvm/cmake/config-ix.cmake`), and probes `pthread`, +Apple, BeOS or Haiku (`llvm/cmake/config-ix.cmake`), and probes `pthread`, `c`, `dl` and `rt` as libraries. The C sysroot's `lib/` holds `libtoyos_c.a` and no archive under any of those names, so every probe that links fails. Configuring `src/llvm-project/llvm` at `849da7d62` for `x86_64-unknown-toyos`, with CMake's system `ToyOS` and `UNIX=ON`, against #637's C sysroot -(`de0de8ee7862147a`): `unable to find library -lm` 18 times, `sysconf`, -`isatty` and `setenv` reported absent though `libtoyos_c.a` defines them, and a -stop at `cmake/modules/CheckAtomic.cmake:59`, exit 1. With empty `libm.a`, -`libpthread.a`, `libdl.a` and `librt.a` beside `libtoyos_c.a`, the same -configure exits 0. +(`de0de8ee7862147a`): `unable to find library -lm` 18 times, and exit 1 at +`cmake/modules/CheckAtomic.cmake:59`, "Host compiler appears to require +libatomic, but cannot find it". With empty `libm.a`, `libpthread.a`, `libdl.a` +and `librt.a` beside `libtoyos_c.a`, the same configure exits 0, and these +probes pass that failed: `HAVE_CXX_ATOMICS_WITHOUT_LIB`, +`HAVE_BUILTIN_THREAD_POINTER`, `HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC`, +`C_SUPPORTS_WERROR_UNGUARDED_AVAILABILITY_NEW`, `sysconf`, `isatty`, +`strerror_r`, `setenv`, `dlopen`, `dlopen` in `dl` and `pthread_create` in +`pthread`. + +`pread` is not found in either: no header declares it +(`issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`), +and once one does, LLVM reads through +`issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md`. **Exit**: that configure exits 0 against the C sysroot as `src/libc.rs` lays it -out, and finds every function `libtoyos_c.a` defines. +out, with those eleven probes passing, and a host test links a C probe with +each of `-lm`, `-lpthread`, `-lc`, `-ldl` and `-lrt` against that sysroot with +the toolchain's clang. diff --git a/issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md b/issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md deleted file mode 100644 index 6db5e3f274c..00000000000 --- a/issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md +++ /dev/null @@ -1,51 +0,0 @@ ---- -status: open -kind: track -opened: 2026-09-30 ---- - -# The hosted rustc carries Cranelift because LLVM does not build for ToyOS - -M3's rustc half of `issues/build/toyos-builds-itself.md`: the ToyOS-hosted -rustc links LLVM, as the host's does, instead of `rustc_codegen_cranelift` -(`src/toolchain.rs`'s `write_config`). *Exit*: a Rust program compiled and run -inside ToyOS by that rustc. - -**Blocked on**, each measured against main `649ea51d4` with #637's C sysroot -(`de0de8ee7862147a`, LLVM `849da7d62`): -- The C++ runtime (#637), and linking it beside std: - `issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md`. -- The C library: `issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`, - `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md` and - `issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md`. -- A linker in the guest (M2). toyos-ld refuses every executable with - thread-local storage, so every std program: `hello.rs`, compiled for - `x86_64-unknown-toyos` by the host's rustc and linked by a host build of - toyos-ld, stops at `an executable with thread-local storage: toyos-ld is - frozen, and places it where the loader does not`, exit 1; the same program - through `rust-lld`, exit 0. Whatever its backend, the hosted rustc links no - std program inside ToyOS before LLD runs there - (`issues/build/the-hosted-rustc-names-a-linker-toyos-does-not-have.md`). -- Testing it before it lands: - `issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md`. - -Threads, memory and `dlopen` at run time are unmeasured: nothing links to run. -rustc's LLVM wrapper, the 71 LLVM archives it links, `libc++.a` and std, -linked `-shared`, carry 41,131,639 bytes of text (`llvm-size`). - -**What the build must also do, read from the fork and not yet run:** -- Bootstrap names no CMake system for a ToyOS target, and its fallback is - `Generic` (`src/bootstrap/src/core/build_steps/llvm.rs`, `configure_cmake`), - under which LLVM sets `LLVM_ON_UNIX` to 0 - (`llvm/cmake/modules/HandleLLVMOptions.cmake`) and compiles no `Unix/` - implementation of `Support`. -- With `clang = true`, bootstrap's LLVM step for a target that is not the host - panics without `clang-tblgen` in the host's own LLVM build directory, and - every compiler here links the store's LLVM (`src/llvm.rs`), which bootstrap - did not build. -- `compiler/rustc_llvm/build.rs` links `stdc++` for a target it does not list, - links no C library, and finds a cross target's LLVM by replacing the host - triple in the host `llvm-config`'s paths, which the store's paths do not - contain. -- LLVM's `llvm/include/llvm/ADT/bit.h` takes `machine/endian.h` on ToyOS, and - `llvm/lib/Support/Unix/Path.inc`'s `is_local_impl` has no ToyOS arm. diff --git a/issues/build/toyos-builds-itself.md b/issues/build/toyos-builds-itself.md index 0748152354a..b45062a1f5f 100644 --- a/issues/build/toyos-builds-itself.md +++ b/issues/build/toyos-builds-itself.md @@ -62,5 +62,27 @@ by the ToyOS-hosted rustc goes when lld runs in the guest: the row, the crate and its host tests go together, the hosted rustc names `rust-lld`, and the published crates.io crate is yanked. -**What M3's rustc half is blocked on** is measured in -`issues/build/the-hosted-rustc-carries-cranelift-because-llvm-does-not-build-for-toyos.md`. +**What stops LLVM building for a ToyOS host**, in the order each blocks the +next. M2's clang and lld wait on it first, and M3's rustc after them. +- Configure: `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md`, + and bootstrap's CMake system in + `issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md`. +- Compile: `issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`, + with the names it leaves to + `issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`, + and the LLVM arms of the build issue. +- Link: the POSIX issue's functions, with those it leaves to the child-process + track's stage 3 and to `issues/build/libc-has-no-alarm.md`. M3's rustc + alone: `issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md`, + `issues/build/a-rust-std-program-defines-no-aligned-alloc.md`, and the build + issue's `clang-tblgen` and `rustc_llvm`. +- Run: `issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md`, + `issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md`, + `issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md` + and `issues/build/libc-readdir-calls-every-entry-a-regular-file.md`. +- Test, for M3: `issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md`. + +M3's exit then waits on a linker in the guest +(`issues/build/the-hosted-rustc-names-a-linker-toyos-does-not-have.md`), which +toyos-ld is not: it refuses every executable with thread-local storage, so +every std program. diff --git a/issues/build/toyos-has-no-c-compiler-inside-it.md b/issues/build/toyos-has-no-c-compiler-inside-it.md index e33bb0ed56e..196600654bc 100644 --- a/issues/build/toyos-has-no-c-compiler-inside-it.md +++ b/issues/build/toyos-has-no-c-compiler-inside-it.md @@ -15,6 +15,18 @@ compiler, so no test went with it. `toyos-ld` is still in the image, frozen, and links objects a ToyOS process already has; nothing in the image makes one from C. +Before any package, LLVM does not build for a ToyOS host, and so neither do +clang and lld: `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md`, +`issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md`, +`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md` and +`issues/build/libc-has-no-alarm.md`; and one that built would read and write +files wrongly through +`issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md`, +`issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md`, +`issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md` +and `issues/build/libc-readdir-calls-every-entry-a-regular-file.md`. The +self-hosting track orders them. + **Exit**: the self-hosting track's M2 (`issues/build/toyos-builds-itself.md`) — clang and lld installed as a package, and a guest test that compiles `hello.c` inside ToyOS and runs what it built. diff --git a/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md b/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md index b8b971af2b8..916a699f7b5 100644 --- a/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md +++ b/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md @@ -6,44 +6,68 @@ opened: 2026-09-30 # ToyOS's libc lacks the POSIX surface LLVM compiles against -LLVM does not build for a ToyOS host. The 71 libraries rustc links -(`llvm-config --libnames` of `compiler/rustc_llvm/build.rs`'s required -components, with `x86` and `aarch64`) stop in `LLVMSupport`, -`LLVMTargetParser` and `LLVMObjectYAML`, on names the C library does not -declare or define. Measured by configuring `src/llvm-project/llvm` at -`849da7d62` for `x86_64-unknown-toyos`, with CMake's system `ToyOS` and -`UNIX=ON` as `src/libcxx.rs` names it, against #637's C sysroot -(`de0de8ee7862147a`), compiling with `ninja -k 0`, and declaring each missing -name in a scratch header until all 71 archives built, exit 0. +LLVM does not build for a ToyOS host, so neither do clang and lld (M2 of +`issues/build/toyos-builds-itself.md`) nor a rustc that carries it (M3). The 71 +libraries rustc links (`llvm-config --libnames` of +`compiler/rustc_llvm/build.rs`'s required components, with `x86` and +`aarch64`) stop in `LLVMSupport`, `LLVMTargetParser` and `LLVMObjectYAML`, on +names the C library does not declare or define. Measured by configuring +`src/llvm-project/llvm` at `849da7d62` for `x86_64-unknown-toyos`, with CMake's +system `ToyOS` and `UNIX=ON` as `src/libcxx.rs` names it, against #637's C +sysroot (`de0de8ee7862147a`), compiling with `ninja -k 0`, and declaring each +missing name in a scratch header until all 71 archives built, exit 0. Eight +objects outside those 71 also failed (ORC, the interpreter, `llvm-objcopy`'s +Mach-O, `llvm-exegesis`) and were not chased, and clang's and lld's own +libraries were not built. -**Headers the C sysroot does not have:** `dirent.h` (its functions are in -`libtoyos_c.a`), `sys/resource.h`, `sys/utsname.h`, `sys/statvfs.h`, -`sys/un.h`, `pwd.h`, `sysexits.h` and `endian.h`. +**Headers the C sysroot does not have:** `sys/resource.h`, `sys/utsname.h`, +`sys/statvfs.h`, `sys/un.h`, `pwd.h`, `sysexits.h`, and `endian.h`, which +`bit.h` includes once ToyOS joins its list +(`issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md`). The +scratch headers carried `machine/endian.h` and `MNT_LOCAL`, BSD names LLVM +reads only on a system it does not list; that issue's two LLVM arms answer +them, not libc. **Names its headers do not declare:** -- `signal.h`: `sigemptyset`, `sigfillset`, `sigaddset`, `pthread_sigmask`, - `SIGUSR1`, `SIGUSR2`, `SA_ONSTACK`, `SA_RESETHAND`, `SA_NODEFER`. -- `unistd.h`: `alarm`, `gethostname`, `getsid`, `setsid`, `execv`, `execve`, - `readlink`, `symlink`, `link`, `ftruncate`, `fchown`, `_SC_ARG_MAX`, - `_SC_PAGE_SIZE`, `_SC_GETPW_R_SIZE_MAX`. +- `signal.h`: `pthread_sigmask`, `SIGUSR2`, `SA_ONSTACK`, `SA_RESETHAND`, + `SA_NODEFER`. +- `unistd.h`: `gethostname`, `getsid`, `setsid`, `execv`, `execve`, + `readlink`, `symlink`, `link`, `fchown`, `_SC_ARG_MAX`, `_SC_PAGE_SIZE`, + `_SC_GETPW_R_SIZE_MAX`. - `string.h` and `stdlib.h`: `strnlen`, `strsignal`, `realpath`. -- `sys/stat.h`: `fchmod`. `sys/wait.h`: `wait4`. `limits.h`: `_POSIX_ARG_MAX`. +- `limits.h`: `_POSIX_ARG_MAX`. - `sys/mman.h`: `msync`, `MS_SYNC`, `madvise`, `MADV_WILLNEED`, `MADV_DONTNEED`. - `fcntl.h`: `struct flock`, `F_SETLK`, `F_SETLKW`, `F_RDLCK`, `F_WRLCK`, - `F_UNLCK`. + `F_UNLCK`, which `fcntl` answers as + `issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md` says. - `sys/socket.h`: `AF_UNIX`. `dlfcn.h`: `Dl_info`, `dladdr`. **Functions no archive defines**, once those compile. rustc's LLVM wrapper (`compiler/rustc_llvm/llvm-wrapper`, whole), the 71 archives, `libc++.a` and the Rust sysroot's archives, `libtoyos_c.a` among them, linked by `ld.lld --shared -z defs`, leave 29 C functions undefined: `alarm aligned_alloc dladdr -execv execve fchown fstatvfs getpwnam_r getpwuid_r getrlimit link logb madvise -modf msync pthread_sigmask readlink realpath setrlimit setsid sigaddset -sigemptyset sigfillset statvfs strsignal symlink uname wait wait4`. -`aligned_alloc` is the C allocator's, which in a std program is std's: it -defines `malloc`, `calloc`, `realloc` and `free`, and not `aligned_alloc`. +-shared -z defs`, leave 29 C functions undefined. 22 are this issue's: +`dladdr execv execve fchown fstatvfs getpwnam_r getpwuid_r getrlimit link logb +madvise modf msync pthread_sigmask readlink realpath setrlimit setsid statvfs +strsignal symlink uname`. LLVM reaches `execv`, `execve` and `setsid` only +after libc's `fork`, which answers `ENOSYS` +(`llvm/lib/Support/Unix/Program.inc`, `Execute`). -**Exit**: those 71 libraries compile for `x86_64-unknown-toyos` against the C -sysroot with nothing declared beside it, and that link leaves no C function -undefined. +**Left to other issues.** `wait`, `wait4`, `sigemptyset`, `sigfillset` and +`sigaddset` are stage 3 of +`issues/kernel/a-childs-end-is-an-event-and-a-parent-takes-its-children-down.md`, +with the `posix_spawn` LLVM starts a child through once libc has one. +`SIGUSR1`, and `dirent.h`, `ftruncate` and `fchmod`, which libc defines and +declares nowhere, are +`issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`'s. +`alarm` is `issues/build/libc-has-no-alarm.md`'s, and `aligned_alloc` +`issues/build/a-rust-std-program-defines-no-aligned-alloc.md`'s. + +**Exit**: every name listed above is declared by the header POSIX puts it in, +and each function among them is defined and does what POSIX specifies — a name +POSIX does not specify, what its Linux manual page does — or refuses as POSIX +has it report an error, with `ENOSYS` where ToyOS has no such call: `setsid` +and `getsid`, the child-process track ruling out a POSIX session, and `execv` +and `execve`, no call replacing a process's image. A guest C case per function +asserts its answer, each refusal among them, and a host test compiles and +links, with the toolchain's clang against the C sysroot, one C probe per name. From 94139d9e46c0f777f1081248f04d67bfce2140b3 Mon Sep 17 00:00:00 2001 From: japabu Date: Thu, 1 Oct 2026 00:47:11 +0200 Subject: [PATCH 3/3] issues: bootstrap's LLVM is M2's and rustc_llvm M3's; each libc exit reads its effect back The LLVM and rustc build issue is two. Bootstrap reads CLANG_TABLEGEN only when it builds clang (src/bootstrap/src/core/build_steps/llvm.rs, builder.config.llvm_clang), so clang-tblgen, the Generic CMake fallback, bit.h and is_local_impl stand between M2 and clang and lld for a ToyOS host: bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md, whose exit is bootstrap installing a clang and an ld.lld for x86_64-unknown-toyos. rustc_llvm's C++ runtime, C library and cross paths are M3's alone: rustc-llvm-cannot-build-for-a-toyos-host.md keeps the rustc -vV exit. The track lists each under its milestone. Neither LLVM nor Rust changes for a ToyOS tool. The platform arms stay arms; clang-tblgen and the cross paths name what ToyOS's own build must do instead. Bootstrap finds clang-tblgen only in the CMake build directory of a host LLVM it built itself, and rustc_llvm swaps the host triple in the host llvm-config's paths, both of which hold for a bootstrap build directory and neither for the store's. Bootstrap's ToyOS arm is refused by LLVM's configure ("Unable to determine platform", HandleLLVMOptions.cmake at 849da7d62) until CMake sets UNIX, which only a platform module does (Platform/UnixPaths.cmake), so the issue cites the CMake-platform one. aligned_alloc's exit asks for the address to be a multiple of the requested alignment, at 64 and 4096, and for free and realloc to release each block at the layout it was allocated with. dlmalloc 0.2.14 checks a freed size and ignores the alignment, so no case sees the second half; std's realloc releases at alignment 16 as its free does. The libc cases each read their effect back: F_GETFL on an O_RDWR | O_APPEND descriptor, F_DUPFD at least its argument, chmod beside fchmod (LLVM's setPermissions calls both); the old mask of a second pthread_sigmask or sigprocmask, getrlimit after setrlimit, readlink of symlink, the file through link's name. sigprocmask, an answer-0 stub LLVM calls from Unix/Signals.inc, joins the POSIX issue, and SIGUSR1 returns to its signal.h line, since the header-drift exit checks prototypes only. alarm(0) answers 1 to 5 after alarm(5) and 0 after that, since LLVM's Wait disarms with it before restoring the old SIGALRM action. The pread race runs over a file whose every 8-byte word holds its offset, today's pread and pwrite its negative control, and a pwrite arm joins it. readdir never answers DT_REG for a directory. Removed: the LLD-precedent clause, the paragraph naming an open PR and a file main does not have, and toyos-has-no-c-compiler-inside-it.md's copy of the track's list, which returns to main's. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016t9wjdQkB8SH7bmfUoiy6L --- ...st-std-program-defines-no-aligned-alloc.md | 15 +++++-- ...-cannot-build-a-hosted-rustc-of-its-own.md | 9 +--- ...ild-llvm-clang-and-lld-for-a-toyos-host.md | 43 +++++++++++++++++++ ...cntl-and-fchmod-answer-0-and-do-nothing.md | 20 +++++---- issues/build/libc-has-no-alarm.md | 11 +++-- ...e-move-the-offset-another-thread-shares.md | 8 +++- ...eaddir-calls-every-entry-a-regular-file.md | 5 ++- ...stcs-build-have-no-arm-for-a-toyos-host.md | 43 ------------------- ...ustc-llvm-cannot-build-for-a-toyos-host.md | 28 ++++++++++++ issues/build/toyos-builds-itself.md | 24 ++++++----- .../toyos-has-no-c-compiler-inside-it.md | 12 ------ ...the-posix-surface-llvm-compiles-against.md | 21 ++++++--- 12 files changed, 141 insertions(+), 98 deletions(-) create mode 100644 issues/build/bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md delete mode 100644 issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md create mode 100644 issues/build/rustc-llvm-cannot-build-for-a-toyos-host.md diff --git a/issues/build/a-rust-std-program-defines-no-aligned-alloc.md b/issues/build/a-rust-std-program-defines-no-aligned-alloc.md index b6e62547d0a..04d6fe8009a 100644 --- a/issues/build/a-rust-std-program-defines-no-aligned-alloc.md +++ b/issues/build/a-rust-std-program-defines-no-aligned-alloc.md @@ -16,6 +16,15 @@ and in its fallback allocator: the link leaves it undefined, referenced from `libc++.a`'s `stdlib_new_delete.cpp` and `fallback_malloc.cpp`. -**Exit**: a Rust std program's C code allocates through `aligned_alloc` from -std's allocator and frees through `free`, and a guest case does it at an -alignment above 16. +Std's `free` and `realloc` release every block at alignment 16, the one its +`malloc` allocates at. The allocator under them, dlmalloc +(`rust/library/std/src/sys/alloc/toyos.rs`), checks a released block's size and +ignores its alignment, so a block allocated at a larger one and released at 16 +is a layout mismatch nothing reports. + +**Exit**: std's C allocator defines `aligned_alloc`, whose block's address is a +multiple of the requested alignment, and `free` and `realloc` release each +block at the layout it was allocated with, the block's header carrying its +alignment as libc's own allocator's does. A guest case in a Rust std program +allocates through `aligned_alloc` at alignments 64 and 4096, asserts each +address a multiple of its alignment, and frees each. diff --git a/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md b/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md index 8df3211f8b8..a1938ad124f 100644 --- a/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md +++ b/issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md @@ -16,13 +16,8 @@ another tree's recipe built. So no branch can put the hosted rustc it changes into a guest before it lands. Carrying LLVM instead of Cranelift changes `write_config`'s hosted target and -the fork's `compiler/rustc_llvm` and `src/bootstrap`, and its guest test could -run only after the merge. - -#629 deletes this build and files `the-hosted-rustc-is-not-built.md`, whose -exit, a store product keyed on a compiler building the hosted rustc and an -image carrying it, covers this one: whichever of the two lands second folds -this issue into that one. +the fork's `compiler/rustc_llvm`, and its guest test could run only after the +merge. **Exit**: a worktree whose `write_config`, or whose fork's `compiler/` or `src/bootstrap`, differs from the primary's builds a hosted rustc of its own, diff --git a/issues/build/bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md b/issues/build/bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md new file mode 100644 index 00000000000..2539f8f9796 --- /dev/null +++ b/issues/build/bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md @@ -0,0 +1,43 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# Bootstrap cannot build LLVM, clang and lld for a ToyOS host + +M2's clang and lld (`issues/build/toyos-builds-itself.md`) are LLVM built for +`x86_64-unknown-toyos`. Read from the fork at `rust/` and from +`src/llvm-project` at `849da7d62`, not run, four things stop bootstrap's LLVM +step for that target: + +- **`clang-tblgen`.** With `clang = true`, the step for a target that is not + the host panics unless `clang-tblgen` is in the CMake build directory of a + host LLVM bootstrap built itself + (`src/bootstrap/src/core/build_steps/llvm.rs`, `CLANG_TABLEGEN`). Every + compiler build here names the store's LLVM (`src/llvm.rs`) as the host's + `llvm-config`, so bootstrap builds no host LLVM and the file is never there. +- **Its CMake system.** `configure_cmake` names no system for a ToyOS target and + falls back to `Generic`, under which LLVM sets `LLVM_ON_UNIX` to 0 + (`llvm/cmake/modules/HandleLLVMOptions.cmake`) and compiles no `Unix/` + implementation of `Support`. +- **`bit.h`.** `llvm/include/llvm/ADT/bit.h` includes `` on the + systems it lists and `` on any other, ToyOS among them. +- **`is_local_impl`.** `llvm/lib/Support/Unix/Path.inc` reads the BSDs' + `MNT_LOCAL` on a system it does not list. + +The last three are ToyOS arms at existing dispatch sites, written as upstream +would take them. ToyOS joins `bit.h`'s `` list, so libc carries +POSIX's `endian.h` and no BSD name +(`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`). +Bootstrap's arm names the system `ToyOS`, which LLVM's configure refuses, +`Unable to determine platform`, until CMake knows ToyOS and sets `UNIX` +(`issues/build/the-cxx-runtime-names-toyos-to-cmake-as-unix.md`). + +`clang-tblgen` is no arm, and neither bootstrap nor LLVM changes for it: ToyOS's +build builds the LLVM for a ToyOS host in a bootstrap build that built the +host's LLVM itself, as `src/llvm.rs` builds the store's, never in a compiler +build that names the store's. + +**Exit**: bootstrap, with `clang = true`, installs a clang and an `ld.lld` for +`x86_64-unknown-toyos`. diff --git a/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md b/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md index c3b791388ff..b0a290e3433 100644 --- a/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md +++ b/issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md @@ -4,21 +4,25 @@ kind: defect opened: 2026-09-30 --- -# libc's fcntl and fchmod answer 0 and do nothing +# libc's fcntl, chmod and fchmod answer 0 and do nothing `fcntl` (`userland/libc/src/posix_io.rs`) answers 0 to every command on every descriptor: `F_DUPFD` names descriptor 0 as the duplicate, `F_GETFL` reads every descriptor as read-only and blocking, `F_SETFL` sets nothing, and a -command it does not know is answered as done. `fchmod` answers 0 and changes -nothing. Once `fcntl.h` declares the record locks +command it does not know is answered as done. `chmod` and `fchmod` answer 0 and +change nothing, and LLVM's `sys::fs::setPermissions` calls each +(`llvm/lib/Support/Unix/Path.inc`). Once `fcntl.h` declares the record locks (`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`), -LLVM's `sys::fs::tryLockFile` and `lockFile` -(`llvm/lib/Support/Unix/Path.inc`) take a lock nothing holds. Close-on-exec, -`F_GETFD` and `F_SETFD`, is the descriptor table's of stage 3 of +LLVM's `sys::fs::tryLockFile` and `lockFile`, in the same file, take a lock +nothing holds. Close-on-exec, `F_GETFD` and `F_SETFD`, is the descriptor +table's of stage 3 of `issues/kernel/a-childs-end-is-an-event-and-a-parent-takes-its-children-down.md`. **Exit**: every other command POSIX defines for `fcntl` does what POSIX says or answers -1 with `errno` set — a record lock `EINVAL`, as POSIX has a file that supports no locking answer — and a command POSIX does not define answers -`EINVAL`; `fchmod` changes the mode `fstat` reads back, or answers -1 with -`errno` set. A guest C case asserts each command's answer and `fchmod`'s. +`EINVAL`; `chmod` and `fchmod` each change the mode `stat` and `fstat` read +back, or answer -1 with `errno` set. A guest C case asserts each command's +answer: `F_GETFL` on a descriptor opened `O_RDWR | O_APPEND` answers both, and +`F_DUPFD` a descriptor no lower than its argument. It asserts what `chmod` and +`fchmod` answer, and the mode `stat` and `fstat` then read. diff --git a/issues/build/libc-has-no-alarm.md b/issues/build/libc-has-no-alarm.md index ec53f4312c5..3e9df88a5eb 100644 --- a/issues/build/libc-has-no-alarm.md +++ b/issues/build/libc-has-no-alarm.md @@ -16,6 +16,11 @@ a handler only through the signals libc imitates from stage 3 of `issues/kernel/a-childs-end-is-an-event-and-a-parent-takes-its-children-down.md` on; this waits on that stage. -**Exit**: `alarm` arms `SIGALRM` as POSIX says, which a guest C case shows: a -handler installed without `SA_RESTART` runs, and a `wait4` on a child that has -not ended answers `EINTR`. +LLVM's `Wait` disarms it with `alarm(0)` and then restores the old `SIGALRM` +action (`llvm/lib/Support/Unix/Program.inc`), so an `alarm(0)` that disarms +nothing ends the process when the alarm fires under the default action. + +**Exit**: `alarm` arms and disarms `SIGALRM` as POSIX says, which a guest C +case shows: a handler installed without `SA_RESTART` runs, and a `wait4` on a +child that has not ended answers `EINTR`; and after `alarm(5)`, `alarm(0)` +answers from 1 to 5 and a second `alarm(0)` answers 0. diff --git a/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md b/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md index f9daf14dd5d..5f1e906ec4b 100644 --- a/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md +++ b/issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md @@ -18,5 +18,9 @@ so LLVM's configure finds none; once it does, LLVM reads every file slice through it (`llvm/lib/Support/Unix/Path.inc`, `readNativeFileSlice`). **Exit**: `pread` and `pwrite` never move the descriptor's offset, which a -guest C case shows: while one thread `read`s a file through, another `pread`s -it at one offset, and each reads only the bytes at its own offset. +guest C case shows over a file whose every 8-byte word holds its own offset. +While one thread `read`s the file through, another `pread`s it at one offset, +and every word either reads holds the offset it was read from. While one +thread `write`s such words through a second file, another `pwrite`s one at its +offset, and every word of that file then holds its own offset. Today's `pread` +and `pwrite` are the negative control: the case is measured red against them. diff --git a/issues/build/libc-readdir-calls-every-entry-a-regular-file.md b/issues/build/libc-readdir-calls-every-entry-a-regular-file.md index d38c4c96d5b..006bd500da8 100644 --- a/issues/build/libc-readdir-calls-every-entry-a-regular-file.md +++ b/issues/build/libc-readdir-calls-every-entry-a-regular-file.md @@ -14,5 +14,6 @@ once one defines `DTTOIF`, LLVM takes an entry's type from `d_type` file. **Exit**: `readdir` answers each entry's type, or `DT_UNKNOWN` where it does -not know it, and a guest C case reads a directory holding a file and a -directory. +not know it, which a guest C case shows over a directory holding a file and a +directory: the directory's entry answers `DT_DIR` or `DT_UNKNOWN`, never +`DT_REG`, and the file's `DT_REG` or `DT_UNKNOWN`. diff --git a/issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md b/issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md deleted file mode 100644 index 00e63ed3549..00000000000 --- a/issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -status: open -kind: defect -opened: 2026-09-30 ---- - -# LLVM and rustc's build have no arm for a ToyOS host - -Read from the fork at `rust/` and from `src/llvm-project` at `849da7d62`, not -run. The first two stop any LLVM built for a ToyOS host, so M2's clang and lld -(`issues/build/toyos-builds-itself.md`) before M3's rustc; the last two are -rustc's alone. - -- **Configure.** Bootstrap names no CMake system for a ToyOS target and falls - back to `Generic` (`src/bootstrap/src/core/build_steps/llvm.rs`, - `configure_cmake`), under which LLVM sets `LLVM_ON_UNIX` to 0 - (`llvm/cmake/modules/HandleLLVMOptions.cmake`) and compiles no `Unix/` - implementation of `Support`. -- **Compile.** `llvm/include/llvm/ADT/bit.h` includes `` on the - systems it lists and `` on any other, ToyOS among them, and - `llvm/lib/Support/Unix/Path.inc`'s `is_local_impl` reads the BSDs' - `MNT_LOCAL` on a system it does not list. -- **Build.** With `clang = true`, bootstrap's LLVM step for a target that is - not the host panics without `clang-tblgen` in the host's own LLVM build - directory, and every compiler here links the store's LLVM (`src/llvm.rs`), - which bootstrap did not build. -- **`rustc_llvm`.** `compiler/rustc_llvm/build.rs` links `stdc++` for a target - it does not list, links no C library, and finds a cross target's LLVM by - replacing the host triple in the host `llvm-config`'s paths, which the - store's paths do not contain. - -The fixes to `bit.h`, `is_local_impl`, bootstrap's CMake system and -`rustc_llvm`'s C++ runtime and C library are ToyOS arms at existing dispatch -sites, written as upstream would take them: ToyOS joins `bit.h`'s `` -list, so libc carries POSIX's `endian.h` and no BSD name -(`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`). -`clang-tblgen` and the cross target's paths are not arms: each is fixed in -ToyOS's build, or written as upstream would take it and carried as -`issues/build/lld-beside-an-external-llvm-config-is-carried-without-an-upstream-pr.md` -carries LLD's. - -**Exit**: bootstrap builds `rustc_llvm` for `x86_64-unknown-toyos`, and the -guest's `rustc -vV` prints `LLVM version:`. diff --git a/issues/build/rustc-llvm-cannot-build-for-a-toyos-host.md b/issues/build/rustc-llvm-cannot-build-for-a-toyos-host.md new file mode 100644 index 00000000000..f42cdcc6617 --- /dev/null +++ b/issues/build/rustc-llvm-cannot-build-for-a-toyos-host.md @@ -0,0 +1,28 @@ +--- +status: open +kind: defect +opened: 2026-09-30 +--- + +# rustc_llvm cannot build for a ToyOS host + +M3's rustc (`issues/build/toyos-builds-itself.md`) carries LLVM through +`compiler/rustc_llvm`, whose `build.rs`, read from the fork at `rust/`, not +run, builds it for `x86_64-unknown-toyos` wrongly three ways: + +- It links `stdc++` for a target it does not list unless bootstrap's + `use-libcxx` asks for `c++`, and ToyOS's one C++ runtime is `libc++`. +- It links no C library: a cross build asks `llvm-config` for no system + libraries. +- It finds a cross target's LLVM by replacing the host triple in the host + `llvm-config`'s paths, and the store's paths (`src/llvm.rs`) do not contain + it, so the replacement names the host's LLVM. + +The C++ runtime and the C library are ToyOS arms at existing dispatch sites, +written as upstream would take them. The paths are no arm, and rustc does not +change for them: ToyOS's build hands the hosted rustc's build a host LLVM whose +paths hold the host triple where the ToyOS host's LLVM's hold +`x86_64-unknown-toyos`, as bootstrap's own build directory lays the two out. + +**Exit**: bootstrap builds `rustc_llvm` for `x86_64-unknown-toyos`, and the +guest's `rustc -vV` prints `LLVM version:`. diff --git a/issues/build/toyos-builds-itself.md b/issues/build/toyos-builds-itself.md index dc58f8764c4..4947b541ca8 100644 --- a/issues/build/toyos-builds-itself.md +++ b/issues/build/toyos-builds-itself.md @@ -53,25 +53,27 @@ by the ToyOS-hosted rustc goes when lld runs in the guest: the row, the crate and its host tests go together, the hosted rustc names `rust-lld`, and the published crates.io crate is yanked. -**What stops LLVM building for a ToyOS host**, in the order each blocks the -next. M2's clang and lld wait on it first, and M3's rustc after them. -- Configure: `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md`, - and bootstrap's CMake system in - `issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md`. +**What stops M2: LLVM, clang and lld built for a ToyOS host**, in the order +each blocks the next. +- Configure: the `clang-tblgen` and the CMake system of + `issues/build/bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md`, + and `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md`. - Compile: `issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md`, with the names it leaves to `issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`, - and the LLVM arms of the build issue. + and the bootstrap issue's `bit.h` and `is_local_impl`. - Link: the POSIX issue's functions, with those it leaves to the child-process - track's stage 3 and to `issues/build/libc-has-no-alarm.md`. M3's rustc - alone: `issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md`, - `issues/build/a-rust-std-program-defines-no-aligned-alloc.md`, and the build - issue's `clang-tblgen` and `rustc_llvm`. + track's stage 3 and to `issues/build/libc-has-no-alarm.md`. - Run: `issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md`, `issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md`, `issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md` and `issues/build/libc-readdir-calls-every-entry-a-regular-file.md`. -- Test, for M3: `issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md`. + +**What M3 adds: a rustc that carries that LLVM**, after all of M2's. +- Build: `issues/build/rustc-llvm-cannot-build-for-a-toyos-host.md`. +- Link: `issues/build/a-rust-std-binary-cannot-link-the-cxx-runtime.md` and + `issues/build/a-rust-std-program-defines-no-aligned-alloc.md`. +- Test: `issues/build/a-worktree-cannot-build-a-hosted-rustc-of-its-own.md`. M3's exit then waits on a linker in the guest (`issues/build/the-hosted-rustc-names-a-linker-toyos-does-not-have.md`), which diff --git a/issues/build/toyos-has-no-c-compiler-inside-it.md b/issues/build/toyos-has-no-c-compiler-inside-it.md index 196600654bc..e33bb0ed56e 100644 --- a/issues/build/toyos-has-no-c-compiler-inside-it.md +++ b/issues/build/toyos-has-no-c-compiler-inside-it.md @@ -15,18 +15,6 @@ compiler, so no test went with it. `toyos-ld` is still in the image, frozen, and links objects a ToyOS process already has; nothing in the image makes one from C. -Before any package, LLVM does not build for a ToyOS host, and so neither do -clang and lld: `issues/build/the-c-sysroot-has-no-libm-so-llvms-configure-fails.md`, -`issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md`, -`issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md` and -`issues/build/libc-has-no-alarm.md`; and one that built would read and write -files wrongly through -`issues/build/libc-mmap-ignores-the-file-it-is-asked-to-map.md`, -`issues/build/libc-fcntl-and-fchmod-answer-0-and-do-nothing.md`, -`issues/build/libc-pread-and-pwrite-move-the-offset-another-thread-shares.md` -and `issues/build/libc-readdir-calls-every-entry-a-regular-file.md`. The -self-hosting track orders them. - **Exit**: the self-hosting track's M2 (`issues/build/toyos-builds-itself.md`) — clang and lld installed as a package, and a guest test that compiles `hello.c` inside ToyOS and runs what it built. diff --git a/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md b/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md index 916a699f7b5..6a6c5a92968 100644 --- a/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md +++ b/issues/build/toyos-libc-lacks-the-posix-surface-llvm-compiles-against.md @@ -23,14 +23,14 @@ libraries were not built. **Headers the C sysroot does not have:** `sys/resource.h`, `sys/utsname.h`, `sys/statvfs.h`, `sys/un.h`, `pwd.h`, `sysexits.h`, and `endian.h`, which `bit.h` includes once ToyOS joins its list -(`issues/build/llvm-and-rustcs-build-have-no-arm-for-a-toyos-host.md`). The +(`issues/build/bootstrap-cannot-build-llvm-clang-and-lld-for-a-toyos-host.md`). The scratch headers carried `machine/endian.h` and `MNT_LOCAL`, BSD names LLVM reads only on a system it does not list; that issue's two LLVM arms answer them, not libc. **Names its headers do not declare:** -- `signal.h`: `pthread_sigmask`, `SIGUSR2`, `SA_ONSTACK`, `SA_RESETHAND`, - `SA_NODEFER`. +- `signal.h`: `pthread_sigmask`, `SIGUSR1`, `SIGUSR2`, `SA_ONSTACK`, + `SA_RESETHAND`, `SA_NODEFER`. - `unistd.h`: `gethostname`, `getsid`, `setsid`, `execv`, `execve`, `readlink`, `symlink`, `link`, `fchown`, `_SC_ARG_MAX`, `_SC_PAGE_SIZE`, `_SC_GETPW_R_SIZE_MAX`. @@ -53,12 +53,16 @@ strsignal symlink uname`. LLVM reaches `execv`, `execve` and `setsid` only after libc's `fork`, which answers `ENOSYS` (`llvm/lib/Support/Unix/Program.inc`, `Execute`). +**A function it has and does not do.** `sigprocmask` +(`userland/libc/src/misc.rs`), which LLVM calls +(`llvm/lib/Support/Unix/Signals.inc`), answers 0 and neither sets nor reports +a mask. + **Left to other issues.** `wait`, `wait4`, `sigemptyset`, `sigfillset` and `sigaddset` are stage 3 of `issues/kernel/a-childs-end-is-an-event-and-a-parent-takes-its-children-down.md`, with the `posix_spawn` LLVM starts a child through once libc has one. -`SIGUSR1`, and `dirent.h`, `ftruncate` and `fchmod`, which libc defines and -declares nowhere, are +`dirent.h`, `ftruncate` and `fchmod`, which libc defines and declares nowhere, are `issues/build/libc-headers-are-written-by-hand-and-drift-from-its-definitions.md`'s. `alarm` is `issues/build/libc-has-no-alarm.md`'s, and `aligned_alloc` `issues/build/a-rust-std-program-defines-no-aligned-alloc.md`'s. @@ -69,5 +73,8 @@ POSIX does not specify, what its Linux manual page does — or refuses as POSIX has it report an error, with `ENOSYS` where ToyOS has no such call: `setsid` and `getsid`, the child-process track ruling out a POSIX session, and `execv` and `execve`, no call replacing a process's image. A guest C case per function -asserts its answer, each refusal among them, and a host test compiles and -links, with the toolchain's clang against the C sysroot, one C probe per name. +asserts its answer, each refusal among them, and reads back the effect of each +that has one: the old set a second `pthread_sigmask` or `sigprocmask` answers, +`getrlimit` after `setrlimit`, `readlink` of what `symlink` made, and the file +read through the name `link` made. A host test compiles and links, with the +toolchain's clang against the C sysroot, one C probe per name.