#+TITLE: Chapter 2: Toolchain Setup: Modern GCC 14 & The Hybrid Pipeline #+AUTHOR: Hermes & Claude #+DATE: 2026-10-07 #+PARENT: [[file:index.org][Index]] #+INCLUDE: goback.org * The Toolchain Problem Historically, compiling for Palm OS required GCC 2.95.3 (~prc-tools-2.3~), released in 2001. GCC 2.95.3 suffers from severe limitations: - Limited to ANSI C89 and ancient C++ (pre-C++98 / early draft). - Mandatory declaration placement at the top of code blocks. - No support for modern C++ standards (C++11, C++17, C++20, C++23). - Old autotools build scripts fail on 64-bit modern Linux hosts (~x86_64~ architecture not recognized by 2001-era ~config.sub~). However, Debian continues to maintain a modern m68k cross-compiler: ~gcc-14-m68k-linux-gnu~ (GCC 14.4.0) in the Debian Sid (unstable) ports repository. This chapter demonstrates how to build a rock-solid, reproducible hybrid toolchain that leverages modern GCC 14 for compiling modern C++ while utilizing Palm OS binutils for final linking and packaging. * The Modern-Legacy Toolchain Split Why do we need a hybrid pipeline rather than using GCC 14 for the entire build? | Toolchain Stage | Modern Tool (GCC 14) | Palm OS Legacy Tool (prc-tools binutils) | Reason | |-----------------+----------------------+------------------------------------------+--------| | C++ Compiler | ~m68k-linux-gnu-g++-14~ | ❌ Ancient (2.95.3) | GCC 14 provides full C++20/C++23 features | | Assembler | ❌ Lacks m68k Palm COFF | ~m68k-palmos-as~ (binutils 2.14) | Palm OS linker strictly requires COFF format | | Linker | ❌ LLD/GNU ld lack ~--embedded-relocs~ | ~m68k-palmos-ld~ | Produces Palm OS runtime relocation tables | | PRC Packager | N/A | ~/usr/bin/build-prc~ | Constructs the multi-resource ~.prc~ file | The workflow is: #+BEGIN_SRC text [Source: .cpp] │ ▼ (GCC 14 g++ via sid-libc wrapper: -S -m68000 -fno-pic -nostdlib -ffreestanding) [Assembly: .s] │ ▼ (Directive filter: grep -v modern ELF annotations) [Clean Assembly: .clean.s] │ ▼ (Palm OS Assembler: m68k-palmos-as -m68000) [COFF Object: .o] │ ▼ (Palm OS Linker: m68k-palmos-ld --embedded-relocs -T palmres.ld) [Linked Executable: .elf] │ ▼ (Packager: build-prc -t appl -c GP14 -n "Gpp14Modern") [Raw Database: .prc] │ ▼ (Header Flag Fix: byte 0x20 |= 0x0008) [Launchable Palm OS PRC: .prc] #+END_SRC * Overcoming the Host GLIBC Gap Modern GCC 14 cross-binaries from Debian Sid are linked against GLIBC 2.38+. Many production or LTS distributions (like Debian 12 Bookworm, which uses GLIBC 2.36) reject the binary with: #+BEGIN_EXAMPLE m68k-linux-gnu-g++-14: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.38' not found #+END_EXAMPLE ** The Trap: Why ~patchelf~ Fails Attempting to patch the interpreter and RPATH using ~patchelf --set-interpreter~ corrupts internal GCC sub-binaries (~cc1~, ~cc1plus~, ~lto1~). While simple ~--version~ checks might pass, the compiler segfaults during actual code generation due to symbol version collisions! ** The Solution: Dynamic Linker Shell Wrappers The reliable, battle-tested solution is to extract Sid's ~libc6~ into an isolated prefix (~/tmp/sid-libc~) and route the compiler drivers and sub-tools directly through Sid's ~ld-linux-x86-64.so.2~. * Step-by-Step Installation Recipe Run these commands in your Linux environment to configure the complete toolchain: ** Step 1: Install Palm OS Binutils and Base Dependencies #+BEGIN_SRC bash # Install build prerequisites and prc-tools-remix binutils sudo apt update sudo apt install -y build-essential curl wget binutils-multiarch # prc-tools-remix provides /usr/bin/build-prc, m68k-palmos-as, m68k-palmos-ld # If not already present via deb, download prc-tools-remix release deb #+END_SRC ** Step 2: Download and Force-Install GCC 14 Cross-Packages #+BEGIN_SRC bash mkdir -p /tmp/gcc14-install && cd /tmp/gcc14-install BASE="http://ftp.us.debian.org/debian/pool/main/g/gcc-14-cross-ports" for pkg in gcc-14-m68k-linux-gnu cpp-14-m68k-linux-gnu gcc-14-m68k-linux-gnu-base \ libgcc-14-dev-m68k-cross g++-14-m68k-linux-gnu libstdc++-14-dev-m68k-cross; do curl -sLO "$BASE/${pkg}_14.4.0-1cross2_amd64.deb" || \ curl -sLO "$BASE/${pkg}_14.4.0-1cross2_all.deb" done # Install ignoring host libc dependency constraints sudo dpkg --force-depends -i *.deb #+END_SRC ** Step 3: Extract Sid GLIBC #+BEGIN_SRC bash mkdir -p /tmp/sid-libc curl -sLO "http://ftp.us.debian.org/debian/pool/main/g/glibc/libc6_2.42-17_amd64.deb" dpkg-deb -x libc6_*.deb /tmp/sid-libc/ #+END_SRC ** Step 4: Create the Compiler Wrapper Hierarchy GCC invokes sub-binaries (~cc1~ for C, ~cc1plus~ for C++) during compilation. We construct a clean ~-B~ prefix layout: #+BEGIN_SRC bash mkdir -p /tmp/gcc14-root/bin mkdir -p /tmp/gcc14-root/m68k-linux-gnu/14 # Sub-tool wrapper for cc1 (C frontend) cat > /tmp/gcc14-root/m68k-linux-gnu/14/cc1 << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/libexec/gcc-cross/m68k-linux-gnu/14/cc1 "$@" EOF # Sub-tool wrapper for cc1plus (C++ frontend) cat > /tmp/gcc14-root/m68k-linux-gnu/14/cc1plus << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/libexec/gcc-cross/m68k-linux-gnu/14/cc1plus "$@" EOF # Sub-tool wrappers for lto1 and collect2 for sub in lto1 collect2; do cat > "/tmp/gcc14-root/m68k-linux-gnu/14/$sub" << EOF #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \\ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \\ /usr/libexec/gcc-cross/m68k-linux-gnu/14/$sub "\$@" EOF done chmod +x /tmp/gcc14-root/m68k-linux-gnu/14/* #+END_SRC ** Step 5: Create Master Driver Scripts Create executable wrappers ~/tmp/gcc14-palmos~ and ~/tmp/g++14-palmos~: #+BEGIN_SRC bash cat > /tmp/g++14-palmos << 'EOF' #!/bin/bash exec /tmp/sid-libc/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \ --library-path /tmp/sid-libc/usr/lib/x86_64-linux-gnu \ /usr/bin/m68k-linux-gnu-g++-14 "-B/tmp/gcc14-root/m68k-linux-gnu/14" "$@" EOF chmod +x /tmp/g++14-palmos #+END_SRC ** Verification Test the C++ compiler: #+BEGIN_SRC bash /tmp/g++14-palmos --version # Expected output: # m68k-linux-gnu-g++-14 (Debian 14.4.0-1cross2) 14.4.0 #+END_SRC * The Linker Script: ~palmres.ld~ The 6-line linker script below is the universal anchor for linking modern m68k code into Palm OS binaries: #+BEGIN_SRC ld OUTPUT_FORMAT("coff-m68k") MEMORY { coderes : ORIGIN = 0x0, LENGTH = 32770 } SECTIONS { .text : { *(.text) } > coderes /DISCARD/ : { *(.note.GN) *(.comment) *(.ident) } } #+END_SRC - ~OUTPUT_FORMAT("coff-m68k")~: Sets the binary output format to m68k Common Object File Format (COFF). - ~MEMORY~: Allocates the primary code resource window up to 32 KB. - ~/DISCARD/~: Purges compiler metadata sections (~.note.GN~, ~.comment~, ~.ident~) emitted by modern GCC that cause the Palm OS packager to reject the output. #+LF * Further Reading & Reference Resources - **GCC & Binutils Documentation:** - Free Software Foundation. /Using the GNU Compiler Collection (GCC 14)/: https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/ - GNU Binutils Documentation (as, ld, objcopy): https://sourceware.org/binutils/docs/ - **Debian Cross-Compilation Infrastructure:** - Debian Cross-Toolchains Portal: https://wiki.debian.org/CrossToolchains - Debian Ports m68k Archive: https://www.debian.org/ports/m68k/ - Debian Sid cross-ports pool index: http://ftp.us.debian.org/debian/pool/main/g/gcc-14-cross-ports/ - **Palm OS Toolchain Projects:** - prc-tools-remix on GitHub (jichu4n): https://github.com/jichu4n/prc-tools-remix - Original PRC-Tools SourceForge Archive: https://prc-tools.sourceforge.net - PilRC Modern Releases & Source Archive: https://github.com/jichu4n/pilrc