From 1f271b3ba8be6321e9a78523a205af4b982967d0 Mon Sep 17 00:00:00 2001 From: Daniel Hammer Date: Tue, 14 Jul 2026 21:31:26 +0200 Subject: [PATCH] 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 --- .../patches/binutils-2.43.1-montauk.patch | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/toolchain/patches/binutils-2.43.1-montauk.patch b/toolchain/patches/binutils-2.43.1-montauk.patch index 31bf02d..99a00b8 100644 --- a/toolchain/patches/binutils-2.43.1-montauk.patch +++ b/toolchain/patches/binutils-2.43.1-montauk.patch @@ -45,3 +45,21 @@ x86_64-*-elf* | x86_64-*-rtems* | x86_64-*-fuchsia* | x86_64-*-genode*) targ_emul=elf_x86_64 targ_extra_emuls="elf_i386 elf_iamcu elf32_x86_64" +--- a/bfd/sysdep.h ++++ b/bfd/sysdep.h +@@ -27,6 +27,15 @@ + #endif + + #include "config.h" ++ ++/* MontaukOS provides no runtime TLS yet (no FS-base setup, no PT_TLS ++ handling in the ELF loader), so a _Thread_local access traps at ++ %fs:0. Degrade BFD's thread-local error state to plain globals; ++ the native tools are single-threaded. */ ++#ifdef __montauk__ ++#undef TLS ++#define TLS ++#endif + #include + + #ifdef HAVE_SYS_TYPES_H