Commit Graph
4 Commits
Author SHA1 Message Date
danielandClaude Fable 5 03d1a1bc2f feat: hosted libstdc++ for x86_64-montauk - full C++ on MontaukOS
The cross toolchain now builds real hosted C++: std::string, vector,
unique_ptr, iostreams and exceptions all work in a plain
x86_64-montauk-g++ invocation with no special flags. This is the
library that native cc1plus will link against for the GCC self-host.

crt1 now runs .preinit_array/.init_array before main and hooks
.fini_array through atexit (main returns via exit(), so destructors
run on both exit paths). Global constructors and libgcc's eh_frame
registration both ride this. GCC is reconfigured with
--enable-initfini-array (modern arrays instead of .ctors),
--with-newlib (satisfies libstdc++'s crossconfig for unknown hosts),
--disable-wchar_t and --disable-libstdcxx-pch; the montauk gcc patch
grows a hunk keeping os/generic ctype under --with-newlib (the
Montauk libc is not newlib).

libc additions harvested by the libstdc++ build: mbtowc/wctomb,
strxfrm, strtok/strtok_r, a real vfscanf/fscanf/scanf (character-
driven with widths and l/ll; also unblocks gprof later), fgetpos/
fsetpos/setbuf/fpos_t, modf plus the C99 float math variants
(acosf..tanhf, hypot/hypotf as wrappers), FP_* classification macros,
the full POSIX errno vocabulary, complete DT_* dirent types, and
mbstate_t.

The SDK ships the real libstdc++.a (was an empty stand-in), the C++
headers at 0:/sdk/include/c++, and cxx-test.elf (global ctor, string,
vector+sort, unique_ptr, throw/catch; exits 0 on 5/5). Ramdisk sits
at 1571 files, within the 2048 table.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-16 23:06:50 +02:00
danielandClaude Fable 5 eadc79708f refactor: drop the bfd TLS workaround, binutils uses real TLS now
With the TLS runtime landed (PT_TLS loading + per-thread FS base) and
tls-test.elf passing on the OS, the sysdep.h hunk that degraded BFD's
_Thread_local error state to plain globals is no longer needed.
Native binutils is rebuilt with genuine thread-locals: the shipped
tools now carry a PT_TLS segment and %fs-relative accesses, exercising
the new runtime in every invocation.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-16 18:51:30 +02:00
danielandClaude Fable 5 1f271b3ba8 fix: disable BFD thread-local storage on x86_64-montauk hosts
Every libbfd-based native tool (objdump, as, ld, ar, nm, ...) page
faulted at startup: binutils 2.43 keeps BFD's error state in
_Thread_local variables, and MontaukOS has no TLS runtime (no FS-base
setup, no PT_TLS handling), so the %fs:0 access in bfd_init trapped at
address 0. elfedit survived only because it does not link libbfd.

Patch bfd/sysdep.h to define the TLS storage macro to empty under
__montauk__ (binutils has no fallback of its own; ac_cv_tls=none does
not even compile). Single-threaded tools lose nothing.

Confirmed on the OS: objdump -S disassembles hello.elf in the
terminal. Real TLS support (FS base + PT_TLS in the ELF loader) stays
on the roadmap for the GCC/libstdc++ milestone.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-14 21:31:26 +02:00
danielandClaude Fable 5 778f897f1a 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]>
2026-07-14 10:19:35 +02:00