diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 20922c5..924d0c2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,29 @@ --- +## V43 2026-03-21 01:15:00 + +**Add zlib build to chroot phase — ld needs libz.so.1 at runtime** + +### Changes: +- Added `024a-zlib.sh`: Builds zlib as the first package in the chroot. The linker + (`ld`) from binutils pass 2 was compiled with zlib support and dynamically links + against `libz.so.1`. Without it, every link attempt fails with "error while loading + shared libraries: libz.so.1: cannot open shared object file". This was the actual + root cause of "C compiler cannot create executables" — not a missing ld symlink + (though that was also needed and fixed in V42). +- Updated `023a-chroot-build-all.sh`: Added `024a-zlib.sh` between 024 and 025. +- Simplified `024-chroot-essentials.sh`: Replaced verbose gcc diagnostic with a + simple presence check + note that zlib must be built first. + +### Plan deviation/changes: +- None + +### What is missing/needs polish: +- None + +--- + ## V42 2026-03-21 01:00:00 **Fix chroot gcc linker failure — create cross-prefix symlinks for ld** diff --git a/toolchain/scripts/023a-chroot-build-all.sh b/toolchain/scripts/023a-chroot-build-all.sh index 5104b01..792bca1 100644 --- a/toolchain/scripts/023a-chroot-build-all.sh +++ b/toolchain/scripts/023a-chroot-build-all.sh @@ -75,6 +75,7 @@ echo "=== Chapter 7: Chroot Build Scripts ===" echo "" run_script "${SCRIPTS}/024-chroot-essentials.sh" +run_script "${SCRIPTS}/024a-zlib.sh" run_script "${SCRIPTS}/025-gettext.sh" run_script "${SCRIPTS}/026-bison.sh" run_script "${SCRIPTS}/027-perl.sh" diff --git a/toolchain/scripts/024-chroot-essentials.sh b/toolchain/scripts/024-chroot-essentials.sh index 306588a..6ceb0e1 100755 --- a/toolchain/scripts/024-chroot-essentials.sh +++ b/toolchain/scripts/024-chroot-essentials.sh @@ -83,53 +83,13 @@ install -o root -g utmp -m 664 /dev/null /var/log/wtmp echo "=== Essential files and symlinks created ===" echo "" - -# --- Verify compiler works inside chroot -------------------------------------- -echo ">>> Verifying gcc works inside chroot..." +echo ">>> Checking gcc and ld are present..." +echo " gcc: $(ls /usr/bin/gcc 2>/dev/null && echo 'OK' || echo 'MISSING')" +echo " ld: $(ls /usr/bin/ld 2>/dev/null && echo 'OK' || echo 'MISSING')" +echo " ld-linux-x86-64.so.2: $(ls /lib64/ld-linux-x86-64.so.2 2>/dev/null && echo 'OK' || echo 'MISSING')" +echo " crt1.o: $(ls /usr/lib/crt1.o 2>/dev/null && echo 'OK' || echo 'MISSING')" echo "" - -# Show where gcc is -echo " which gcc: $(which gcc 2>&1 || echo 'NOT FOUND')" -echo " which cc: $(which cc 2>&1 || echo 'NOT FOUND')" -echo " which ld: $(which ld 2>&1 || echo 'NOT FOUND')" +echo " NOTE: gcc won't link until zlib is built (ld needs libz.so.1)." +echo " 024a-zlib.sh runs next to fix this." echo "" - -# Check for the dynamic linker -if [ -e /lib64/ld-linux-x86-64.so.2 ]; then - echo " /lib64/ld-linux-x86-64.so.2: EXISTS" - ls -la /lib64/ld-linux-x86-64.so.2 -else - echo " WARNING: /lib64/ld-linux-x86-64.so.2 NOT FOUND" - echo " Checking /usr/lib..." - ls -la /usr/lib/ld-linux-x86-64.so.2 2>/dev/null || echo " /usr/lib/ld-linux-x86-64.so.2 NOT FOUND" - echo " Contents of /lib64/:" - ls -la /lib64/ 2>/dev/null || echo " /lib64 does not exist" -fi -echo "" - -# Check for crt files -echo " crt1.o: $(find /usr/lib -name crt1.o 2>/dev/null || echo 'NOT FOUND')" -echo " crti.o: $(find /usr/lib -name crti.o 2>/dev/null || echo 'NOT FOUND')" -echo "" - -# Try to compile a test program -echo " Testing: echo 'int main(){}' | gcc -x c - -o /tmp/test-gcc" -if echo 'int main(){}' | gcc -x c - -o /tmp/test-gcc 2>/tmp/gcc-test-error.log; then - echo " PASS: gcc can create executables" - rm -f /tmp/test-gcc -else - echo " FAIL: gcc cannot create executables!" - echo " Error output:" - cat /tmp/gcc-test-error.log - echo "" - echo " Trying with verbose output:" - echo 'int main(){}' | gcc -v -x c - -o /tmp/test-gcc 2>&1 | tail -30 - echo "" - echo " gcc search dirs:" - gcc -print-search-dirs 2>&1 | head -10 - exit 1 -fi -rm -f /tmp/gcc-test-error.log - -echo "" -echo "Next: Run the chroot build scripts (025-xxx) to build additional tools." +echo "Next: Build zlib, then the remaining chroot tools." diff --git a/toolchain/scripts/024a-zlib.sh b/toolchain/scripts/024a-zlib.sh new file mode 100644 index 0000000..5ba7e52 --- /dev/null +++ b/toolchain/scripts/024a-zlib.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# ============================================================================ +# DarkForge Linux — Phase 0, Chapter 7: Zlib (Chroot) +# ============================================================================ +# Purpose: Build zlib inside the chroot. The binutils linker (ld) from pass 2 +# was built with zlib support and dynamically links against libz.so.1. +# Without zlib installed, ld fails with: +# "error while loading shared libraries: libz.so.1" +# This must be the FIRST thing built in the chroot, before any +# package that needs to link (i.e., everything). +# Inputs: /sources/zlib-1.3.2.tar.xz +# Outputs: /usr/lib/libz.so.1 +# Assumes: Running inside chroot +# ============================================================================ + +set -euo pipefail + +PACKAGE="zlib" +VERSION="1.3.2" + +echo "=== Building ${PACKAGE}-${VERSION} (Chroot — ld dependency) ===" + +cd /sources +tar -xf "${PACKAGE}-${VERSION}.tar.xz" +cd "${PACKAGE}-${VERSION}" + +./configure --prefix=/usr + +make +make install + +# Verify libz.so.1 exists +if [ -f /usr/lib/libz.so.1 ]; then + echo " PASS: /usr/lib/libz.so.1 exists" +else + echo " FAIL: /usr/lib/libz.so.1 NOT FOUND after install!" + exit 1 +fi + +cd /sources +rm -rf "${PACKAGE}-${VERSION}" +echo "=== ${PACKAGE}-${VERSION} complete ==="