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
+56 -4
View File
@@ -22,6 +22,7 @@
#include <sys/stat.h>
#include <utime.h>
#include <spawn.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <unistd.h>
@@ -2286,7 +2287,7 @@ int stat(const char *path, struct stat *buf) {
int h = (int)_zos_syscall1(SYS_OPEN, (long)path);
if (h >= 0) {
buf->st_mode = S_IFREG;
buf->st_size = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)h);
buf->st_size = (off_t)_zos_syscall1(SYS_GETSIZE, (long)h);
_zos_syscall1(SYS_CLOSE, (long)h);
/* No inodes in the VFS API: derive a stable id from the path
so that distinct paths compare as distinct files. */
@@ -2297,7 +2298,7 @@ int stat(const char *path, struct stat *buf) {
buf->st_ino = ino | 1;
buf->st_nlink = 1;
buf->st_blksize = 4096;
buf->st_blocks = (buf->st_size + 511) / 512;
buf->st_blocks = (blkcnt_t)((buf->st_size + 511) / 512);
return 0;
}
@@ -2318,13 +2319,13 @@ int fstat(int fd, struct stat *buf) {
}
memset(buf, 0, sizeof(*buf));
buf->st_mode = S_IFREG;
buf->st_size = (unsigned long)_zos_syscall1(SYS_GETSIZE, (long)fd);
buf->st_size = (off_t)_zos_syscall1(SYS_GETSIZE, (long)fd);
/* Handles do not map back to paths, so fake a per-handle inode in a
range disjoint from the path hashes used by stat(). */
buf->st_ino = 0x4000000000000000UL + (unsigned long)fd;
buf->st_nlink = 1;
buf->st_blksize = 4096;
buf->st_blocks = (buf->st_size + 511) / 512;
buf->st_blocks = (blkcnt_t)((buf->st_size + 511) / 512);
return 0;
}
@@ -3711,6 +3712,57 @@ int kill(pid_t pid, int sig) {
return 0;
}
int getpagesize(void) {
return 4096;
}
long sysconf(int name) {
switch (name) {
case 4: /* _SC_OPEN_MAX */
return 64;
case 30: /* _SC_PAGESIZE */
return 4096;
case 84: /* _SC_NPROCESSORS_ONLN */
return 1;
default:
errno = EINVAL;
return -1;
}
}
/* Anonymous mappings only: SYS_ALLOC hands back zeroed page-aligned
memory and SYS_FREE releases it. Length is remembered by the kernel
per allocation, so munmap ignores its length argument. */
void *mmap(void *addr, size_t length, int prot, int flags, int fd,
long offset) {
(void)addr; (void)prot; (void)offset;
if (length == 0 || fd != -1 || !(flags & MAP_ANONYMOUS)) {
errno = ENODEV;
return MAP_FAILED;
}
void *p = (void *)_zos_syscall1(SYS_ALLOC, (long)length);
if (p == NULL) {
errno = ENOMEM;
return MAP_FAILED;
}
return p;
}
int munmap(void *addr, size_t length) {
(void)length;
if (addr == NULL || addr == MAP_FAILED) {
errno = EINVAL;
return -1;
}
_zos_syscall1(SYS_FREE, (long)addr);
return 0;
}
int mprotect(void *addr, size_t length, int prot) {
(void)addr; (void)length; (void)prot;
return 0; /* page protections are not adjustable from userspace */
}
long pathconf(const char *path, int name) {
(void)path;
switch (name) {