--- title: Link sendfile with -lsendfile, read /proc with the proc tools, and treat libc as illumos libc area: api impact: HIGH tags: [sendfile, procfs, proc-tools, pthreads, libc, glibc, porting, linking] verified: 2026-11-04 --- # Link sendfile with -lsendfile, read /proc with the proc tools, and treat libc as illumos libc Four Linux habits break when porting to Solnix: `sendfile` is not in libc, `/proc` files are binary structs, thread priorities have other ranges, and libc is not glibc. The usual symptoms are an undefined symbol at link time, a parser that reads binary data as text, or a `pthread_create` that fails. **Antipattern** ```c #include n = sendfile(sock, fd, &off, len); /* built with no -lsendfile: sendfile is in libsendfile, not libc */ fp = fopen("/proc/self/status", "r"); /* /proc/self exists, but status is a binary pstatus struct */ readlink("/proc/self/exe", buf, sz); /* proc(5) lists no exe entry */ readlink("/proc/self/cwd", buf, sz); /* "A readlink(2) of /proc/pid/cwd yields a null string" */ p.sched_priority = 99; /* explicit priority outside the class range: pthread_create fails */ ``` **The Solnix way** ```sh # 1. sendfile(3EXT): , link -lsendfile # ssize_t sendfile(int out_fd, int in_fd, off_t *off, size_t len); # out_fd is a regular file or a connected AF_INET/AF_INET6 SOCK_STREAM socket; after a -1 with # some data written, *off still shows how far it got # sendfilev(fildes, vec, sfvcnt, &xferred): sfv_fd = SFV_FD_SELF sends a buffer; set sfv_flag to 0 # in a recipe overlay: NIX_LDFLAGS = (o.NIX_LDFLAGS or "") + " -lsendfile"; # 2. /proc/ files (status, psinfo, map, ...) are binary structs from ; # read them with the proc tools, or proc_get_psinfo(3PROC) (-lproc, Uncommitted) pargs -l PID; pargs -e PID # the command line; the environment pwdx PID; pcred PID; pmap -x PID # cwd; uids and gids; the address space pfiles PID; pldd PID; pstack PID # these stop the target while they run: ask before using them on a production process ps -o pid,rss,vsz,args -p PID # rss and vsz in kilobytes # the program's own path: /proc/self/path/a.out, or getexecname(3C) (not always absolute); its open files: the links in /proc/self/path # 3. POSIX threads are in libc: gcc -D_REENTRANT, nothing else; -lpthread is accepted and has no effect # explicit priorities: ask sched_get_priority_min/max (the TS class is -60..60; unprivileged, 1..60 fail with EPERM and values past the range with EINVAL: nspr handoff) # 4. illumos libc, not glibc: sockets are in libsocket (cc ... -lsocket -lnsl); libc hides POSIX/XPG # names depending on feature-test macros: with _XOPEN_SOURCE or _POSIX_C_SOURCE set, also define # __EXTENSIONS__ to see the illumos extensions (standards(7)) elfdump -d ./myprog | grep NEEDED # the libraries the binary needs ``` Solnix ships the gate's `libc.so.1` as `pkgs.solnix.libc`, so these are illumos facts. In Solnix builds, `ld: fatal: library -lsendfile: not found` meant the platform `-L/lib/amd64` was missing from the link line. Go binaries on illumos NEED `libsendfile.so` too. **The illumos way** (OpenIndiana, OmniOS, SmartOS) ```sh cc file.c -lsendfile # sendfile(3EXT) SYNOPSIS gcc -D_REENTRANT file.c # threads(7): "There are no other libraries or flags necessary." cc file.c -lsocket -lnsl # socket(3SOCKET) SYNOPSIS pargs PID; pfiles PID; pmap -x PID ``` Downstream distributions take libc from the gate. The man pages put the 64-bit libraries in `/lib/64` (libc(3LIB), libsendfile(3LIB) FILES). **The difference.** Same as illumos. Solnix changes where the fix goes: link flags and feature macros go in the package recipe (`NIX_LDFLAGS`, `NIX_CFLAGS_COMPILE`), and RUNPATH names store paths, not `crle`. The Solnix nspr port is an example of point 3: NSPR hardcoded priorities 1..127, `PR_CreateThread(PR_PRIORITY_HIGH)` got `EINVAL`, and the patch asks libc for the range. **Check.** `elfdump -d ./myprog | grep NEEDED` lists `libsendfile.so.1` for a binary that calls `sendfile`. `grep -rnE '/proc/(self|%d|[0-9]+)/(status|exe|maps|cmdline)' src/` shows no code that parses Linux /proc text (reading /proc//status as a pstatus struct, as proc(5) describes, is fine). **Unverified** - Whether the stdenv at solnix 5a8e5ce puts `-L/lib/amd64` on every link. The docs credit a tranche entry file that is not in the OS repo snapshot, so add `-lsendfile` and check the link yourself. - Which glibc-only functions are missing. No source here lists them; check each undefined symbol against libc(3LIB) INTERFACES. **Sources** - [standards(7)](https://solnix.io/docs/man/standards.7) (illumos, CDDL), feature test macros and __EXTENSIONS__ - [proc(1)](https://solnix.io/docs/man/proc.1) (illumos, CDDL), WARNINGS (stopping a process) - [sendfile(3EXT)](https://solnix.io/docs/man/sendfile.3ext) (illumos, CDDL), SYNOPSIS; DESCRIPTION (out_fd types, SFV_FD_SELF); RETURN VALUES (partial write) - [sendfilev(3EXT)](https://solnix.io/docs/man/sendfilev.3ext) (illumos, CDDL), SYNOPSIS; DESCRIPTION (sendfilevec, SFV_FD_SELF, sfv_flag) - [libsendfile(3LIB)](https://solnix.io/docs/man/libsendfile.3lib) and [libc(3LIB)](https://solnix.io/docs/man/libc.3lib) (illumos, CDDL), INTERFACES; FILES - [proc(5)](https://solnix.io/docs/man/proc.5) (illumos, CDDL), DESCRIPTION (entries are process-IDs; ``); STRUCTURE OF /proc/pid (/proc/self); status; psinfo; path; cwd; FILES - [proc(1)](https://solnix.io/docs/man/proc.1) (illumos, CDDL), SYNOPSIS; DESCRIPTION; WARNINGS (pfiles, pldd, pstack stop the target) - [pargs(1)](https://solnix.io/docs/man/pargs.1), [pmap(1)](https://solnix.io/docs/man/pmap.1), [ps(1)](https://solnix.io/docs/man/ps.1) (illumos, CDDL), OPTIONS -l, -e; -x; -o (rss, vsz, args) - [proc_get_psinfo(3PROC)](https://solnix.io/docs/man/proc_get_psinfo.3proc) and [getexecname(3C)](https://solnix.io/docs/man/getexecname.3c) (illumos, CDDL), LIBRARY; DESCRIPTION; INTERFACE STABILITY - [threads(7)](https://solnix.io/docs/man/threads.7) (illumos, CDDL), SYNOPSIS; DESCRIPTION (implementations in libc); USAGE (-mt; -D_REENTRANT) - [libpthread(3LIB)](https://solnix.io/docs/man/libpthread.3lib) (illumos, CDDL), DESCRIPTION (filter on libc.so.1; -lpthread has no effect) - [socket(3SOCKET)](https://solnix.io/docs/man/socket.3socket) (illumos, CDDL), SYNOPSIS - [elfdump(1)](https://solnix.io/docs/man/elfdump.1) (illumos, CDDL), -d - [.kiro/steering/illumos-domain.md](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/.kiro/steering/illumos-domain.md) (solnix 5a8e5ce), libc / linker / runtime (not glibc; libc, libsocket, libnsl, libresolv; RUNPATH, no crle) - [docs/design-pkgsrc-patches.md](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/docs/design-pkgsrc-patches.md) (solnix 5a8e5ce), §3 The recurring illumos-fix classes (feature-test macros; -lnsl/-lsocket/-lresolv) - [docs/cmake-on-illumos.md](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/docs/cmake-on-illumos.md) (solnix 5a8e5ce), Two premises that did not survive measurement (`-lsendfile: not found`, `/lib/amd64/libsendfile.so`, `elfdump -d` NEEDED) - [docs/aarch64-native-openssl-fix.md](https://codeberg.org/solnix/solnix/src/commit/5a8e5ce75a33086d7be4410149847bdf7501b8fc/docs/aarch64-native-openssl-fix.md) (solnix 5a8e5ce), the overrideAttrs `NIX_LDFLAGS` / `NIX_CFLAGS_COMPILE` pattern - [handoff: from-builder-20261028T231241-cache7-hm-rows-request](https://codeberg.org/solnix/solnix-infra/src/commit/c2ecf4535e0fc32261bbfb2414bc7961a73fa6ca/docs/handoff/from-builder-20261028T231241-cache7-hm-rows-request.md), Attachments (Go binaries NEED libsendfile.so) - [handoff: from-builder-20261104T035652-a64s-b4-aarch64-nspr-nss](https://codeberg.org/solnix/solnix-infra/src/commit/c2ecf4535e0fc32261bbfb2414bc7961a73fa6ca/docs/handoff/from-builder-20261104T035652-a64s-b4-aarch64-nspr-nss/README.md), The ports (nspr thread priority); The proof (priority 1..60 EPERM, 64+ EINVAL) - [Handbook: How Solnix is built](https://solnix.io/docs/handbook/how-solnix-is-built#pkgssolnix--the-fine-grained-world) (site 307b67f), The illumos gate; `pkgs.solnix.*` — the fine-grained world