feat: native GCC - cc1, cc1plus and the gcc driver run on MontaukOS

Cross-build GCC 14.2.0 with --host=x86_64-montauk: the driver, cc1,
cc1plus and collect2 now link as static Montauk ET_EXEC binaries
against the hosted libstdc++, and ship in the SDK. Together with the
native binutils, TCC and the target sysroot, MontaukOS carries a
complete self-contained C and C++ toolchain at 0:/sdk.

libc: anonymous mmap/munmap over SYS_ALLOC (GCC's page allocator
wants mmap; SYS_ALLOC memory is page-aligned by construction),
getpagesize, minimal sysconf, MB_CUR_MAX, isascii/toascii, POSIX id
typedefs (ino_t, dev_t, nlink_t, ...), struct stat fields switched to
proper POSIX types (st_size is a signed off_t now), and a
conventional _STDIO_H guard marker so GMP's FILE detection works.

Build recipe and the five host-build gotchas (bundled config.subs,
gettext removal, stdio guard sniffing, endianness cache preset,
sysroot sdk symlink) are documented in toolchain/README.md. The
devkit stages the driver as gcc.elf/g++.elf/cpp.elf, the backends in
the libexec layout the driver expects, a copy of ld where collect2
searches, and a 0:/tmp scratch dir. Ramdisk: 1604 files, 368 MB.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-07-16 23:51:30 +02:00
co-authored by Claude Fable 5
parent 03d1a1bc2f
commit f234c67a2b
13 changed files with 195 additions and 17 deletions
+38
View File
@@ -80,6 +80,44 @@ make install-strip-gas install-strip-ld install-strip-binutils \
DESTDIR=$PWD/../../native
```
## Native GCC (runs on MontaukOS)
GCC itself cross-builds for the montauk host (build dir
toolchain/build/gcc-native, install DESTDIR toolchain/native-gcc):
```bash
../../src/gcc-14.2.0/configure \
--build=x86_64-pc-linux-gnu --host=x86_64-montauk \
--target=x86_64-montauk --prefix=/sdk \
--with-native-system-header-dir=/sdk/include \
--with-build-sysroot=$PWD/../../sysroot \
--enable-languages=c,c++ --disable-nls --disable-shared \
--disable-multilib --disable-gcov --disable-lto --disable-plugin \
--disable-bootstrap --disable-fixincludes --with-newlib \
--enable-initfini-array --disable-wchar_t --disable-libstdcxx-pch \
--with-gnu-as --with-gnu-ld
ac_cv_c_bigendian=no make -j$(nproc) all-gcc
make install-gcc DESTDIR=$PWD/../../native-gcc
```
Host-build gotchas, in the order they bite:
- The bundled gmp/mpfr/mpc/isl/gettext carry their own config.sub
copies; overwrite each with the patched top-level one.
- Remove the src tree's gettext symlink (--disable-nls does not skip
it, and its gnulib needs more locale surface than the libc has).
- gmp.h sniffs the libc's stdio include-guard name to detect FILE;
the Montauk stdio.h defines the conventional _STDIO_H marker.
- The gcc subdir configure cannot run host binaries to probe
endianness; preset ac_cv_c_bigendian=no.
- The build sysroot needs an sdk -> usr symlink so
--with-native-system-header-dir=/sdk/include resolves at build time.
The devkit target ships gcc/g++/cpp as .elf in 0:/sdk/bin, cc1 +
cc1plus + collect2 (and a copy of ld for collect2's search) under
0:/sdk/libexec/gcc/x86_64-montauk/14.2.0, libgcc.a + crtbegin/crtend
under 0:/sdk/lib/gcc/x86_64-montauk/14.2.0, and a 0:/tmp scratch dir
for driver intermediates.
Notes:
- Build only `all-gas all-ld all-binutils`. gprof needs fscanf with
%[] scansets (not in the Montauk libc); gold and gprofng are