libc-build: one recipe for glibc, musl and Eyra
cargo xtask libc-build --libc glibc|musl|eyra <crate dir> [--static] [--debug limited] [--panic abort] [--out dir] [--jobs n]
It builds the binary of the package in <crate dir> against the C library the one flag names and prints <sha256> <binary> on stdout. Everything runs in the toolchain container from Containerfile (podman); the xtask builds that image (tag = sha256 of the Containerfile and the patches), copies the workspace (without target and .git) to <out>/src, runs cargo there, then checks and hashes the ELF on the host. Default <out> is target/libc-build/<package>-<libc> in this repository; <out>/cargo-home is the cargo home.
--libc |
target | RUSTFLAGS | std | the result must be |
glibc |
x86_64-unknown-linux-gnu | none (--static: -C target-feature=+crt-static) |
prebuilt | dynamic: PT_INTERP + DT_NEEDED; --static: neither |
musl |
x86_64-unknown-linux-musl | none | prebuilt | no PT_INTERP, no DT_NEEDED, no glibc markers |
eyra |
x86_64-unknown-linux-gnu | -C relocation-model=static -C target-feature=+crt-static -C llvm-args=-enable-tail-merge=false -C llvm-args=-opt-disable=tailcallelim -Z merge-functions=disabled -Z plt=yes |
-Zbuild-std=std,core,alloc,panic_abort,test |
ET_EXEC (non-PIE), no PT_INTERP, no DT_NEEDED, no glibc markers (GLIBC_TUNABLES, __libc_start_main, GLIBC_2.) |
All three use the same compiler: nightly-2026-10-05 (the one Mímir's driver pins). --debug and --panic set CARGO_PROFILE_RELEASE_DEBUG / CARGO_PROFILE_RELEASE_PANIC; RUSTFLAGS stay as above. The code is xtask/src/libc_build.rs: a trait LibcBuild (toolchain, target, rustflags, build-std, Cargo patches, lock pins, features, check) with Glibc, Musl and Eyra.
Eyra disables tail merging so separate source calls retain separate call instructions. It disables tail-call elimination so final calls in compiled Rust code remain calls; rustc's allocator shims and assembly keep their jumps. Six direct tail jumps remain in the pinned program: four allocator shims and two assembly jumps. It disables function merging so distinct functions retain distinct addresses. -Z plt=yes avoids calls through GOT words in this static executable. A nightly update must check all four switches again.
On the pinned nightly, -opt-disable=tailcallelim (S2) also prints pass diagnostics: about 1.4 GB in the pinned program build. Every cargo xtask libc-build --libc eyra run inherits this output into the terminal or CI log; its size depends on the program.
These switches reach every target crate, including core and std, because the recipe rebuilds std from source with -Zbuild-std and an explicit --target. They do not apply to host build scripts or proc macros, or to C code compiled by a build script.
For a subsequent build, use the entire RUSTFLAGS line printed by the xtask. Cargo reads CARGO_ENCODED_RUSTFLAGS before RUSTFLAGS, and either environment setting takes precedence over rustflags in .cargo/config.toml. Clear CARGO_ENCODED_RUSTFLAGS when using the printed RUSTFLAGS; adding these switches only to config while RUSTFLAGS is set silently loses them.
Eyra: what the recipe fixes, so nobody finds it again
- Nightly drift:
VaList::argisnext_argon this nightly; c-scape 0.22.3 and printf-compat 0.3.1 are patched (01, 03) and given to cargo as--config patch.crates-io.<crate>.path="/opt/eyra/…". A workspace that patches one of them itself keeps its own copy (the xtask says so). - rustix: 1.1.5 renamed
rustix::runtime, which origin 0.26.2 calls. The lock is pinned withcargo update -p rustix@<v> --precise 1.1.4(and eyra to 0.22.0) aftercargo fetch. - Non-PIE: a static PIE crashes at start without origin's
experimental-relocate. - Panics (01): in non-PIE, c-scape's
dl_iterate_phdrgave__executable_startas the load bias, so the unwinder found no.eh_frame_hdrand every panic aborted ("failed to initiate panic"). - io_uring (01):
syscall(SYS_io_uring_*)is passed to the kernel (featuresyscall-io_uring). - Container runtimes (02, found on youki 0.7.0):
clone,mount,umount,umount2,unshare,setns,personality,setdomainnamewere missing (link errors);prctlpanicked on options it did not know (e.g. PR_SET_NO_NEW_PRIVS);syscall()panicked on capget/capset, setresuid/setresgid, setgroups, pivot_root, memfd_create, openat2, execveat, copy_file_range, close_range, ioprio_set, open_tree, move_mount, fsopen, fsconfig, fsmount, mount_setattr, pidfd_*, fcntl (featuresyscall-passthrough);recvmsgnever filledmsg_controllen, so SCM_RIGHTS parsing read stale bytes (youki aborted on a 140 TB allocation), andsendmsgstopped attodo!()on ancillary data: both are plain kernel calls now.cloneis x86-64 only; the rest is x86-64 and aarch64 since 05.clone3stays ENOSYS on purpose: callers fall back toclone/fork, which keep origin's thread record right. - Heimdall's own calls (04, found building Heimdall's container and broker):
rewinddirsat behind c-scape'stodofeature (link error; heimdall-container'ssys::dir_namesreads a directory again from its start), andprocess_vm_readvwas only atodo!()stub (heimdall-broker'ssys::read_cstrreads a job's memory with it).rewinddiris c-scape's own code, out of the gate;process_vm_readvis one plain kernel call (x86-64 only), and a kernel error is -1 witherrno, as glibc and musl give it.examples/eyra-libc-callschecks both (cargo test -p xtask --test eyra_libc_calls -- --ignored). c-scape'stodofeature must stay off: itstodo.rsstill holds aprocess_vm_readvstub, so withtodoon the symbol would be defined twice. - Raw calls of Holger's build (05, found when an Eyra build of Holger aborted in
syscall(444)at its Landlock start):syscall()hands on only the numbers it lists, and any other number panics. The crates linked into that build pass it 11 more:landlock_create_ruleset,landlock_add_rule,landlock_restrict_self(landlock, heimdall-confine),seccomp(heimdall-seccomp, heimdall-broker, libcontainer),setfsuid,setfsgid(heimdall-broker),getppid,faccessat2(heimdall-container),execve(heimdall-seccomp),sched_setattrandset_mempolicy(libcontainer). Each has its own arm, which reads that call's arguments and makes the call with its ownSYS_*number: never a number handed on, so a static graph sees one call per arm. The arms, 02's pass-through and plain wrappers and 04'sprocess_vm_readvreach the kernel on x86-64 (syscall) and aarch64 (svc 0,raw_wrappers::raw6), each call by itsSYS_*name and so by that arch's own number.examples/eyra-libc-callscalls each of the 11, in a child process of its own, with arguments the kernel refuses or that change nothing. - ioctl and fcntl of Holger's build (06, found when an Eyra build of Holger aborted in
ioctl(0xC0182101), SECCOMP_IOCTL_NOTIF_SEND, and infcntl(1033), F_ADD_SEALS): c-scape'sioctl()knows only TCGETS, FIONBIO, TIOCINQ, TIOCGWINSZ and FICLONE, and itsfcntl()only F_GETFL/SETFL, F_GETFD/SETFD, F_SETLK(W) and F_DUPFD_CLOEXEC; anything else panics. The crates linked into that build pass 15 more: SECCOMP_IOCTL_NOTIF_RECV, _SEND, _ID_VALID, _ADDFD (heimdall-seccomp's listener), TIOCSCTTY (libcontainer's console), PIDFD_GET_INFO (std's pidfd); F_DUPFD, F_GETLK, F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW, F_SETPIPE_SZ, F_GETPIPE_SZ (nix'sfcntl()), F_ADD_SEALS and F_GET_SEALS (heimdall-container's and heimdall-seccomp's sealed memfds). Each has its own arm: one plain kernel call (SYS_ioctlorSYS_fcntl) with its own request or command and the argument it takes (a pointer, an int, or none), on x86-64 and aarch64. 06 also gives each call of 02'ssyscall()pass-through list (capget … pidfd_getfd, 21 calls) and itsfcntlarm their own arm with their ownSYS_*number: 02 handed on any number of the list, so a static graph saw one call whose number it could not name.examples/eyra-libc-callschecks the 15 and the 22, each in a child process.
Open sites: a call whose number is not a constant at the call, so a static graph cannot name it:
| Site | Patch | Why it stays |
syscall(SYS_io_uring_setup/_register/_enter): raw_syscall_errno(number, a) |
01 | io_uring is opt-in (feature syscall-io_uring) and no crate of Holger's build calls it |
The real arm64 kernel's answers are open too: the aarch64 arms are compiled and linked, and checked only under qemu-user until there is an arm64 host.
Known arm64 gaps (x86-64 only after 06; their arm64 work is a later pair):
| Part | Patch | Call site | On aarch64 |
clone (its own x86-64 asm: the child's stack, fn(arg), SYS_exit) |
02 | libcontainer process/fork.rs, the fallback when clone3 gives ENOSYS: every container start |
not defined: a program that calls it does not link |
syscall(SYS_io_uring_setup/_register/_enter) (its own x86-64 asm, raw_syscall_errno) |
01 | heimdall-broker's heimdall-broker-selftest (not in Holger's build) |
not listed: the call panics |
The program must opt in to Eyra itself: either a cargo feature eyra (eyra = ["dep:eyra"], an optional eyra = { version = "0.22", features = ["extra-syscalls"] }, #[cfg(feature = "eyra")] extern crate eyra; in main.rs and a build.rs that prints cargo:rustc-link-arg=-nostartfiles when CARGO_FEATURE_EYRA is set), or a plain eyra dependency. The xtask turns the feature on for --libc eyra and refuses a package with neither.
Lane knobs: LIBC_BUILD_PODMAN_ARGS adds podman run flags (for example --cpu-shares 64); the build runs under nice -n 19 with --memory 32g --pids-limit=65536.