fix: dont register jsh coreutils weak stubs with Sforeign_symbol on FreeBSD #85

Merged
ober merged 1 commit from fix/freebsd-coreutils-weak-stubs into master 2026-09-16 19:38:14 -04:00
Owner

Problem

On FreeBSD, every coreutils command (ls, cat, cp, hostname, etc.) fails with:

[freebsd-main-weak] jsh_ls

This happens both when running jsh -c "ls" on the FreeBSD host directly and when connecting via ssh biggus.

Root Cause

The (jsh coreutils) module registers ~90 coreutils commands as shell builtins via register-coreutils!, which guards each registration with (when (cdr entry) ...) — checking whether the FFI function binding is non-#f. The define-coreutil-ffi macro binds to (and (foreign-entry? symbol) (foreign-procedure symbol ...)), so if foreign-entry? returns true, the binding is valid.

On FreeBSD, the Rust uutils library (libjsh_coreutils.a) is not linked. The jsh_* symbols (jsh_ls, jsh_cat, etc.) are emitted as attribute((weak)) C stubs that print [freebsd-main-weak] jsh_ls and return 0. But they are also registered with Sforeign_symbol in all three FreeBSD build files, causing foreign-entry? to return true. The builtin handler then calls the stub instead of falling through to the system /bin/ls.

Fix

Move the jsh_* coreutils symbols out of the Sforeign_symbol-registered symbol lists into a separate coreutils-weak-symbols list. The weak C stubs remain (required for linker resolution), but they are not registered with Chez's Sforeign_symbol, so foreign-entry? returns false. register-coreutils! skips them, and commands fall through to the normal PATH-based execution via which()/execute-external().

Files changed

  • support/gen-jsh-freebsd-main.ss: Split jsh_* into coreutils-weak-symbols, emit stubs without Sforeign_symbol
  • build-jsh-freebsd.ss: Wrap jsh-coreutils-commands Sforeign_symbol registration in (when has-rust-coreutils? ...)
  • build-jsh-freebsd-cross.ss: Same split as gen-jsh-freebsd-main.ss
  • VERSION: 0.10.52 to 0.10.53

Verification

  • make binary (macOS native with all features): builds successfully
  • make pre-pr-macos-linux-amd64-all (cross-compile Linux amd64 with all features from macOS): 35MB static ELF builds successfully
## Problem On FreeBSD, every coreutils command (ls, cat, cp, hostname, etc.) fails with: ``` [freebsd-main-weak] jsh_ls ``` This happens both when running `jsh -c "ls"` on the FreeBSD host directly and when connecting via `ssh biggus`. ## Root Cause The (jsh coreutils) module registers ~90 coreutils commands as shell builtins via register-coreutils!, which guards each registration with (when (cdr entry) ...) — checking whether the FFI function binding is non-#f. The define-coreutil-ffi macro binds to (and (foreign-entry? symbol) (foreign-procedure symbol ...)), so if foreign-entry? returns true, the binding is valid. On FreeBSD, the Rust uutils library (libjsh_coreutils.a) is not linked. The jsh_* symbols (jsh_ls, jsh_cat, etc.) are emitted as __attribute__((weak)) C stubs that print [freebsd-main-weak] jsh_ls and return 0. But they are also registered with Sforeign_symbol in all three FreeBSD build files, causing foreign-entry? to return true. The builtin handler then calls the stub instead of falling through to the system /bin/ls. ## Fix Move the jsh_* coreutils symbols out of the Sforeign_symbol-registered symbol lists into a separate coreutils-weak-symbols list. The weak C stubs remain (required for linker resolution), but they are not registered with Chez's Sforeign_symbol, so foreign-entry? returns false. register-coreutils! skips them, and commands fall through to the normal PATH-based execution via which()/execute-external(). ### Files changed - support/gen-jsh-freebsd-main.ss: Split jsh_* into coreutils-weak-symbols, emit stubs without Sforeign_symbol - build-jsh-freebsd.ss: Wrap jsh-coreutils-commands Sforeign_symbol registration in (when has-rust-coreutils? ...) - build-jsh-freebsd-cross.ss: Same split as gen-jsh-freebsd-main.ss - VERSION: 0.10.52 to 0.10.53 ## Verification - make binary (macOS native with all features): builds successfully - make pre-pr-macos-linux-amd64-all (cross-compile Linux amd64 with all features from macOS): 35MB static ELF builds successfully
fix: dont register jsh coreutils weak stubs with Sforeign_symbol on FreeBSD
Some checks failed
version-policy / required (pull_request) Successful in 3m56s
required-ci / required (pull_request) Failing after 25m18s
2c62d411b0
ober scheduled this pull request to auto merge when all checks succeed 2026-09-16 19:38:03 -04:00
ober merged commit 81272a6a35 into master 2026-09-16 19:38:14 -04:00
ober referenced this pull request from a commit 2026-09-16 19:38:16 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ober/jerboa-shell!85
No description provided.