feat: POSIX libc surface, native binutils (as/ld/ar run on MontaukOS)

Grow the Montauk libc enough to cross-build binutils 2.43.1 with
--host=x86_64-montauk. gas, ld, ar, nm, objcopy, objdump, readelf,
ranlib, strip and friends now link as native ET_EXEC Montauk binaries
(staged stripped in toolchain/native/, not yet shipped in the image).

New libc surface: full Linux errno and signal sets, O_* flags with
real O_EXCL/O_APPEND semantics, unlink/rmdir/dup/dup2/getpid/_exit,
kill (SYS_KILL), fcntl, fileno/fdopen, putc/getchar/rewind,
ctime/asctime, strtoll/strtoull/atoll, bsearch, mkstemp/mktemp,
realpath (lexical, drive-prefix aware), mbstowcs/mblen, chmod/fchmod/
umask/utime no-ops (VFS has no modes or settable times), full struct
stat with fake inodes, sscanf field widths (bounded conversions),
SCN*/PRI* completions, wait/waitpid over SYS_WAITPID, and new headers
sys/wait.h, sys/param.h, utime.h, wchar.h, memory.h.

fork/exec/pipe are declared but fail with ENOSYS: binutils never
spawns, and real process plumbing is the posix_spawn milestone, which
needs kernel support (exit status reporting, fd redirection).

TCC's montauk_compat.h shims (unlink, chmod, execvp, realpath, fdopen,
strtoll, strtoull) are retired in favor of the libc versions.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-07-14 10:55:39 +02:00
co-authored by Claude Fable 5
parent 648f7111c0
commit bd9158fdcc
24 changed files with 875 additions and 136 deletions
+33
View File
@@ -61,3 +61,36 @@ toolchain/
local/ # install prefix (ignored)
sysroot/ # generated target sysroot (ignored)
```
## Native binutils (runs on MontaukOS)
Binutils can be cross-compiled to run *on* MontaukOS itself
(`--host=x86_64-montauk`), the first step toward a self-hosted GCC:
```bash
mkdir -p toolchain/build/binutils-native && cd toolchain/build/binutils-native
export PATH=$PWD/../../local/bin:$PATH
../../src/binutils-2.43.1/configure \
--build=x86_64-pc-linux-gnu --host=x86_64-montauk \
--target=x86_64-montauk --prefix=/usr \
--disable-nls --disable-werror --disable-gprofng --disable-gold \
--disable-plugins --disable-shared --enable-static
make -j$(nproc) all-gas all-ld all-binutils
make install-strip-gas install-strip-ld install-strip-binutils \
DESTDIR=$PWD/../../native
```
Notes:
- Build only `all-gas all-ld all-binutils`. gprof needs fscanf with
%[] scansets (not in the Montauk libc); gold and gprofng are
disabled outright.
- The libc gained a large POSIX surface for this port (fd functions,
full errno/signal sets, struct stat, sys/wait.h, utime.h, wchar.h,
sys/param.h, memory.h, bsearch, sscanf field widths, ...). pex-style
process spawning (fork/exec/pipe) is stubbed to fail with ENOSYS:
the tools themselves never spawn, and real process plumbing is the
posix_spawn milestone that needs kernel support (exit codes in
SYS_WAITPID, fd redirection wiring).
- The staged tree in toolchain/native/ is not yet integrated into the
OS image; that needs a target-side sysroot layout decision (where
headers, libc.a and crt objects live on 0:/).