feat: x86_64-montauk userspace cross toolchain
Add build-montauk-toolchain.sh: builds an OS-aware cross GCC/binutils (same versions and prefix as the bare-metal x86_64-elf toolchain) whose x86_64-montauk target links static ET_EXEC binaries against the Montauk libc sysroot with no special flags: 4 KiB max page size for the kernel ELF loader, -mno-red-zone by default, crt1/crti/crtn + -lc from the sysroot, __montauk__ defined. Target patches are checked into toolchain/patches/, the GCC target header into toolchain/files/. sys/types.h now includes <stdint.h> so hosted code (libgcov and friends) sees intptr_t via the stdio include chain. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# MontaukOS Toolchains
|
||||
|
||||
Two cross toolchains live here, both installed to `toolchain/local/`:
|
||||
|
||||
| Script | Triple | Purpose |
|
||||
|--------|--------|---------|
|
||||
| `build-toolchain.sh` | `x86_64-elf` | Bare-metal compiler for the kernel |
|
||||
| `build-montauk-toolchain.sh` | `x86_64-montauk` | OS-aware compiler for userspace programs |
|
||||
|
||||
Both use Binutils 2.43.1 + GCC 14.2.0 and share the source trees in
|
||||
`src/`. The Montauk target is added by the patches in `patches/` plus
|
||||
the target header `files/montauk.h` (installed as
|
||||
`gcc/config/montauk.h` in the GCC tree).
|
||||
|
||||
## The x86_64-montauk target
|
||||
|
||||
`x86_64-montauk-gcc` knows the Montauk userspace ABI, so a hosted
|
||||
program builds with no special flags:
|
||||
|
||||
```bash
|
||||
toolchain/local/bin/x86_64-montauk-gcc hello.c -o hello.elf
|
||||
```
|
||||
|
||||
What the target does by default:
|
||||
|
||||
- Links static, non-PIE `ET_EXEC` binaries (what the kernel ELF loader
|
||||
in `kernel/src/Sched/ElfLoader.cpp` accepts), text at 0x400000.
|
||||
- `-z max-page-size=0x1000` — the loader maps 4 KiB pages; the x86-64
|
||||
default of 2 MiB segment alignment would bloat every binary.
|
||||
- Startup/link line: `crt1.o crti.o crtbegin.o ... -lc crtend.o crtn.o`
|
||||
taken from the sysroot (`toolchain/sysroot/usr/lib`), which is
|
||||
assembled from `programs/lib/libc` by the build script.
|
||||
- Headers resolve against the sysroot (`toolchain/sysroot/usr/include`),
|
||||
assembled from `programs/include/libc` plus the `montauk/` SDK
|
||||
headers. `#include <stdio.h>` just works; no `-nostdinc` needed.
|
||||
- `-mno-red-zone` (the project-wide userspace convention). Standard
|
||||
hard-float SysV ABI otherwise; pass `-mno-sse` etc. per program if
|
||||
wanted.
|
||||
- Defines `__montauk__` / `__MONTAUK__`.
|
||||
|
||||
C++ works with `-fno-exceptions -fno-rtti` (the project convention).
|
||||
There is no libstdc++ yet — only libgcc is built. A hosted libstdc++
|
||||
needs a more complete libc and is the next step toward self-hosting.
|
||||
|
||||
## Refreshing the sysroot
|
||||
|
||||
The sysroot is rebuilt every time `build-montauk-toolchain.sh` runs
|
||||
(the compiler build steps are skipped once installed). After changing
|
||||
libc headers or the libc itself, re-run the script to refresh it.
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
toolchain/
|
||||
build-toolchain.sh # bare-metal x86_64-elf (kernel)
|
||||
build-montauk-toolchain.sh # x86_64-montauk (userspace)
|
||||
patches/ # Montauk target patches (checked in)
|
||||
files/montauk.h # GCC target header (checked in)
|
||||
src/ # downloaded + patched sources (ignored)
|
||||
build/ # build trees (ignored)
|
||||
local/ # install prefix (ignored)
|
||||
sysroot/ # generated target sysroot (ignored)
|
||||
```
|
||||
Reference in New Issue
Block a user