The devkit target in programs/GNUmakefile stages the native binutils (as, ld, ar, nm, objcopy, objdump, readelf, ranlib, strip, size, strings, addr2line, c++filt, elfedit as *.elf) into the image at 0:/usr/bin, plus a target-side sysroot: libc headers, montauk/ and Api/ SDK headers and the freestanding C++ set at 0:/usr/include, and libc.a + crt1/crti/crtn objects (with empty libm/libstdc++ stand-ins) at 0:/usr/lib. ld's ldscripts ship under 0:/usr/x86_64-montauk. The /usr prefix matches the binutils configure prefix, and the kernel already resolves driveless absolute paths against the cwd drive, so compiled-in /usr/lib search paths work natively on drive 0. The shell resolves commands from 0:/usr/bin (after 0:/os) and tab completion lists it. When toolchain/native/ has not been built, the devkit step skips cleanly and the image builds as before. Co-Authored-By: Claude Fable 5 <[email protected]>
102 lines
4.4 KiB
Markdown
102 lines
4.4 KiB
Markdown
# 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)
|
|
```
|
|
|
|
## 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 `devkit` target in programs/GNUmakefile ships the staged tools
|
|
into the OS image at 0:/usr/bin (as.elf, ld.elf, ar.elf, ...) with a
|
|
target-side sysroot at 0:/usr/include + 0:/usr/lib (libc.a, crt
|
|
objects, empty libm/libstdc++). The kernel resolves driveless
|
|
absolute paths ("/usr/lib") against the cwd drive, so the binutils
|
|
--prefix=/usr layout works natively. The shell searches 0:/usr/bin
|
|
and tab-completes it. If toolchain/native/ has not been built the
|
|
devkit step is skipped and the image builds without it.
|