fix: guard load-shared-object so static builds don't abort at init
ober
d95d774c6854cf1b9a5234beb5738fea8677f5ba
--- a/lib/chez/fuse.sls +++ b/lib/chez/fuse.sls @@ -63,15 +63,18 @@ ;; FFI: low-level read/write on the /dev/fuse fd ;; ====================================================================== + ;; Guarded: in fully-static jsh-ta6le builds there's no libc.so to dlopen; + ;; symbols come from Sforeign_symbol registrations in the embedding C main. (define libc-loaded - (begin - (load-shared-object - (case (machine-type) - [(a6le ta6le i3le ti3le arm64le tarm64le) "libc.so.6"] - [(a6fb ta6fb i3fb ti3fb arm64fb tarm64fb) "libc.so.7"] - [(a6osx ta6osx arm64osx tarm64osx) "libSystem.B.dylib"] - [else "libc.so"])) - #t)) + (or (guard (e [#t #f]) + (load-shared-object + (case (machine-type) + [(a6le ta6le i3le ti3le arm64le tarm64le) "libc.so.6"] + [(a6fb ta6fb i3fb ti3fb arm64fb tarm64fb) "libc.so.7"] + [(a6osx ta6osx arm64osx tarm64osx) "libSystem.B.dylib"] + [else "libc.so"])) + #t) + #f)) (define c-read (foreign-procedure "read" (int u8* size_t) ssize_t)) --- a/lib/chez/fuse/mount.sls +++ b/lib/chez/fuse/mount.sls @@ -18,7 +18,9 @@ load-shared-object foreign-procedure format)) - ;; Load the C mount helper shared library. + ;; Load the C mount helper shared library. In a fully-static jsh-ta6le + ;; build there is no shared lib; we silently skip rather than raise so + ;; modules importing chez-fuse don't fail to instantiate. (define mount-lib-loaded? (let ([loaded #f]) (lambda () @@ -26,12 +28,14 @@ (guard (exn [else (guard (exn2 [else (guard (exn3 [else - (error 'chez-fuse - "cannot load libchez_fuse_mount.so — run 'make' first")]) + ;; Static binary: no .so to load. Mark loaded; calls into + ;; foreign-procedures from chez-fuse will fail at use time. + (set! loaded 'static-no-op)]) (load-shared-object "libchez_fuse_mount.so"))]) (load-shared-object "./src/libchez_fuse_mount.so"))]) (load-shared-object "./libchez_fuse_mount.so")) - (set! loaded #t))))) + (unless (eq? loaded 'static-no-op) + (set! loaded #t)))))) ;; Public: ensure the shared lib is loaded (called by secmem, access modules) (define (ensure-mount-lib!) --- a/lib/chez/vault/blockstore.sls +++ b/lib/chez/vault/blockstore.sls @@ -23,14 +23,16 @@ ;; ---- OS file I/O FFI ---- ;; Load libc for pread, pwrite, open, close, fsync. + ;; Guarded: static binaries (JERBOA_STATIC) have no libc.so to dlopen. (define _libc-loaded - (begin - (load-shared-object - (case (machine-type) - [(a6fb ta6fb i3fb ti3fb arm64fb tarm64fb) "libc.so.7"] - [(a6le ta6le i3le ti3le arm64le tarm64le) "libc.so.6"] - [else "libc.so"])) - #t)) + (or (guard (e [#t #f]) + (load-shared-object + (case (machine-type) + [(a6fb ta6fb i3fb ti3fb arm64fb tarm64fb) "libc.so.7"] + [(a6le ta6le i3le ti3le arm64le tarm64le) "libc.so.6"] + [else "libc.so"])) + #t) + #f)) (define c-open (foreign-procedure "open" (string int int) int))