FreeBSD jsh coreutils commands fail: [freebsd-main-weak] jsh_ls / jsh_hostname on every coreutil #86
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
On FreeBSD, every coreutils command (ls, cat, cp, mv, hostname, etc.) fails when run through the jsh-built-in path. Instead of executing the command, jsh prints a message of the form
[freebsd-main-weak] jsh_ls(or the relevantjsh_<util>name) and returns success (exit 0) without doing anything.This affects:
./jsh-freebsd -c 'ls'./jsh-freebsd -c 'hostname'ls,hostname, and every other coreutil interactively inside the FreeBSD jsh binaryssh biggusand running the shell locally on the hostEnvironment
biggus)jsh-freebsdbuilt viagmake jsh-freebsdwithJSH_FEATURES=alllibjsh_coreutils.a) — coreutils are provided as weak C stubs.Symptom / Reproduction
command -V lsinside the broken build reports the command as a jsh builtin rather than/bin/ls.Root Cause
The
(jsh coreutils)module (vendor/jerboa-shell-extras/jerboa-src/src/jsh/coreutils.ss) registers ~90 coreutils commands as shell builtins viaregister-coreutils!. Each registration is guarded by(when (cdr entry) ...), which checks whether the FFI binding for the command is non-#f.Each binding is produced by
define-coreutil-ffiso the binding is truthy whenever Chez's
(foreign-entry? symbol)returns true for that symbol (e.g."jsh_ls").On FreeBSD the Rust uutils library is not linked. The build scripts instead emit
__attribute__((weak)) long jsh_ls() { fprintf(stderr, "[freebsd-main-weak] jsh_ls\n"); ... return 0; }stubs AND register those stub addresses withSforeign_symbol(...)in the generated C main:support/gen-jsh-freebsd-main.ss—jsh_*symbols were inweak-stub-symbols, which is registered viaSforeign_symbol.build-jsh-freebsd.ss— emitted stub functions returning 127 and unconditionally registered them viaSforeign_symbol.build-jsh-freebsd-cross.ss— same as gen-jsh-freebsd-main.Result:
(foreign-entry? "jsh_ls")returns true, soregister-coreutils!installs every coreutil as a jsh builtin pointing at the stub. Once registered, the executor's builtin lookup (builtin-lookup) wins and the normal external-command resolution viawhich()/ffi-fork-exec(which would find/bin/lson PATH) is never reached.Fix (merged as PR #85)
PR: #85 (merged into master)
Changes:
jsh_*coreutils command symbols into a dedicatedcoreutils-weak-symbolslist in the FreeBSD build-C generators.Sforeign_symbol.Sforeign_symbolregistration,(foreign-entry? "jsh_ls")returns false →register-coreutils!skips those commands → the executor falls through to PATH-based external execution (which→ffi-fork-exec→/bin/ls).build-jsh-freebsd.ssnow only registersjsh-coreutils-commandswithSforeign_symbolwhenhas-rust-coreutils?is true (i.e. a real uutils archive is present).Files changed:
support/gen-jsh-freebsd-main.ssbuild-jsh-freebsd.ssbuild-jsh-freebsd-cross.ssVERSIONVerification (on the FreeBSD host)
Rebuilt from the fix branch on
biggus:lsnow lists the directory,hostnameprints the host name, and both are resolved to the system binaries on PATH.Related / Follow-up
fix/all-features-followup, "fix: make all-features extras bootstrap and cross builds reliable") originally built on top of the same area and had merge conflicts against master after #85 landed (conflicts inVERSION,support/extras-recorder-raw-control.patch,support/patch-extras-build.sh,test/test-meta-commands.sh). The conflict insupport/extras-recorder-raw-control.patchinvolved master's sigaction-basedrecorder_relay_job_signals_ignoredversus the branch's mutex-locked version; the resolved patch keeps the thread-safe mutex version and applies cleanly to the vendored extrasffi-shim.c. As of writing, that PR was being rebased/updated to resolve the conflicts and pass CI; therequired-cigate additionally runs a full pristinefeatures-allbootstrap +binarybuild + smoke checks on a FreeBSD runner, which takes a long time.Sforeign_symbolregistration for symbols that Scheme probes withforeign-entry?for capability detection.foreign-entry?is a "does an entry exist" probe, not a "is this entry functional" probe — stub registration defeats the(when (cdr entry) ...)guard.