cp
authorThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Mon, 5 May 2025 07:37:35 +0000 (00:37 -0700)
committerThomas Walker Lynch <eknp9n@reasoningtechnology.com>
Mon, 5 May 2025 07:37:35 +0000 (00:37 -0700)
scriptπŸ–‰/audit_glibc_headers.sh [new file with mode: 0755]
scriptπŸ–‰/build_Linux_requisites.sh [changed mode: 0644->0755]
scriptπŸ–‰/build_all.sh
scriptπŸ–‰/build_glibc_bootstrap.sh [new file with mode: 0755]
scriptπŸ–‰/build_glibc_bootstrap_requisites.sh [new file with mode: 0755]
scriptπŸ–‰/build_glibc_headers.sh
scriptπŸ–‰/build_glibc_headers_requisites.sh [new file with mode: 0755]
scriptπŸ–‰/clean_build.sh

diff --git a/scriptπŸ–‰/audit_glibc_headers.sh b/scriptπŸ–‰/audit_glibc_headers.sh
new file mode 100755 (executable)
index 0000000..64ddd57
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "πŸ”Ž Auditing glibc build state..."
+
+declare -a missing
+declare -a present
+
+# GLIBC_BUILD sanity
+[[ -d "$GLIBC_BUILD" ]] && present+=("GLIBC_BUILD exists: $GLIBC_BUILD") || missing+=("GLIBC_BUILD missing")
+
+# Check for Makefile
+if [[ -s "$GLIBC_BUILD/Makefile" ]]; then
+  present+=("Makefile exists and non-empty")
+else
+  missing+=("Makefile missing or empty in $GLIBC_BUILD")
+fi
+
+# Check bits/stdio_lim.h
+if [[ -f "$GLIBC_BUILD/bits/stdio_lim.h" ]]; then
+  present+=("bits/stdio_lim.h exists (post-header install marker)")
+else
+  missing+=("bits/stdio_lim.h missing β€” make install-headers likely incomplete")
+fi
+
+# Check csu/Makefile
+if [[ -f "$GLIBC_BUILD/csu/Makefile" ]]; then
+  present+=("csu/Makefile exists")
+  grep -q 'crt1\.o' "$GLIBC_BUILD/csu/Makefile" \
+    && present+=("csu/Makefile defines crt1.o") \
+    || missing+=("csu/Makefile missing rule for crt1.o")
+else
+  missing+=("csu/Makefile missing")
+fi
+
+# Show report
+echo "βœ… Present:"
+for p in "${present[@]}"; do echo "  $p"; done
+
+echo
+if (( ${#missing[@]} )); then
+  echo "❌ Missing:"
+  for m in "${missing[@]}"; do echo "  $m"; done
+  exit 1
+else
+  echo "πŸŽ‰ All bootstrap prerequisites are in place"
+  exit 0
+fi
old mode 100644 (file)
new mode 100755 (executable)
index 920a8f7..201e76f 100755 (executable)
@@ -21,8 +21,8 @@ cd "$SCRIPT_DIR"
 ./build_linux_requisites.sh
 ./build_linux.sh
 
-./prepare_glibc_sources.sh
-./build_glibc_headers.sh
+#./build_glibc_bootstrap_requisites.sh
+./build_glibc_bootstrap.sh
 
 ./build_gcc_stage1_requisites.sh
 ./build_gcc_stage1.sh
diff --git a/scriptπŸ–‰/build_glibc_bootstrap.sh b/scriptπŸ–‰/build_glibc_bootstrap.sh
new file mode 100755 (executable)
index 0000000..b1c5c73
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "πŸ“¦ Building glibc startup files (crt*.o)..."
+
+pushd "$GLIBC_BUILD"
+
+  # Confirm that required build artifacts are present
+  if [[ ! -f bits/stdio_lim.h ]]; then
+    echo "❌ Missing bits/stdio_lim.h β€” did you run build_glibc_headers.sh?"
+    exit 1
+  fi
+
+  if [[ ! -f csu/Makefile ]]; then
+    echo "❌ Missing csu/Makefile β€” glibc configure phase may have failed"
+    exit 1
+  fi
+
+  # Attempt to build the crt startup object files
+  make csu/crt1.o csu/crti.o csu/crtn.o -j"$MAKE_JOBS"
+
+  # Install them to the sysroot
+  install -m 644 csu/crt1.o csu/crti.o csu/crtn.o "$SYSROOT/usr/lib"
+
+  # Create a dummy libc.so to satisfy linker if needed
+  touch "$SYSROOT/usr/lib/libc.so"
+
+  # βœ… Verify installation
+  for f in crt1.o crti.o crtn.o; do
+    if [[ ! -f "$SYSROOT/usr/lib/$f" ]]; then
+      echo "❌ Missing startup file after install: $f"
+      exit 1
+    fi
+  done
+
+popd
+
+echo "βœ… glibc startup files installed to $SYSROOT/usr/lib"
diff --git a/scriptπŸ–‰/build_glibc_bootstrap_requisites.sh b/scriptπŸ–‰/build_glibc_bootstrap_requisites.sh
new file mode 100755 (executable)
index 0000000..e10ea96
--- /dev/null
@@ -0,0 +1,138 @@
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "πŸ“¦ Checking requisites for glibc startup file build (crt1.o, crti.o, crtn.o)."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 1. Required tools
+#
+  required_tools=(
+    "gcc"
+    "g++"
+    "make"
+    "ld"
+    "as"
+  )
+
+  for tool in "${required_tools[@]}"; do
+    if location=$(command -v "$tool"); then
+      found_requisite_list+=("$location")
+    else
+      missing_requisite_list+=("$tool")
+    fi
+  done
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 2. Required directories and sources
+#
+  if [ -d "$GLIBC_SRC" ] && [ "$(ls -A "$GLIBC_SRC")" ]; then
+    found_requisite_list+=("$GLIBC_SRC")
+  else
+    missing_requisite_list+=("$GLIBC_SRC (empty or missing)")
+  fi
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 3. Required sysroot include path with Linux headers
+#
+  linux_headers=(
+    "$SYSROOT/usr/include/linux/version.h"
+    "$SYSROOT/usr/include/asm/unistd.h"
+    "$SYSROOT/usr/include/bits/types.h"
+  )
+
+  for header in "${linux_headers[@]}"; do
+    if [[ -f "$header" ]]; then
+      found_requisite_list+=("$header")
+    else
+      missing_requisite_list+=("$header")
+    fi
+  done
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 4. Confirm SYSROOT write access
+#
+  if [[ -w "$SYSROOT/usr/include" ]]; then
+    found_requisite_list+=("SYSROOT writable: $SYSROOT/usr/include")
+  else
+    missing_requisite_list+=("SYSROOT not writable: $SYSROOT/usr/include")
+  fi
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# Additional sanity checks before header & crt build
+#
+
+  # 1. Check that the C preprocessor works and headers can be found
+  echo '#include <stddef.h>' | gcc -E - > /dev/null 2>&1
+  if [[ $? -eq 0 ]]; then
+    found_requisite_list+=("C preprocessor operational: gcc -E works")
+  else
+    missing_requisite_list+=("C preprocessor failed: gcc -E on <stddef.h> failed")
+  fi
+
+  # 2. Check that bits/stdio_lim.h exists after headers install (glibc marker)
+  if [[ -f "$GLIBC_BUILD/bits/stdio_lim.h" ]]; then
+    found_requisite_list+=("$GLIBC_BUILD/bits/stdio_lim.h (glibc headers marker found)")
+  else
+    missing_requisite_list+=("$GLIBC_BUILD/bits/stdio_lim.h missing β€” headers may not be fully installed")
+  fi
+
+  # 3. Check for crt objects already present (optional)
+  for f in crt1.o crti.o crtn.o; do
+    if [[ -f "$GLIBC_BUILD/csu/$f" ]]; then
+      found_requisite_list+=("$GLIBC_BUILD/csu/$f (already built)")
+    fi
+  done
+
+  # 4. Check that Makefile exists and is non-empty
+  if [[ -f "$GLIBC_BUILD/Makefile" ]]; then
+    if [[ -s "$GLIBC_BUILD/Makefile" ]]; then
+      found_requisite_list+=("$GLIBC_BUILD/Makefile exists and is populated")
+    else
+      missing_requisite_list+=("$GLIBC_BUILD/Makefile exists but is empty β€” incomplete configure?")
+    fi
+  else
+    missing_requisite_list+=("$GLIBC_BUILD/Makefile missing β€” did configure run?")
+  fi
+
+  # 5. Check that csu Makefile has rules for crt1.o
+  if [[ -f "$GLIBC_BUILD/csu/Makefile" ]]; then
+    if grep -q 'crt1\.o' "$GLIBC_BUILD/csu/Makefile"; then
+      found_requisite_list+=("csu/Makefile defines crt1.o")
+    else
+      missing_requisite_list+=("csu/Makefile does not define crt1.o β€” possible misconfigure")
+    fi
+  else
+    missing_requisite_list+=("csu/Makefile missing β€” subdir config likely failed")
+  fi
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# Print results
+#
+  if (( ${#found_requisite_list[@]} > 0 )); then
+    echo "found:"
+    for item in "${found_requisite_list[@]}"; do
+      echo "  $item"
+    done
+  fi
+
+  if (( ${#missing_requisite_list[@]} > 0 )); then
+    echo "missing:"
+    for item in "${missing_requisite_list[@]}"; do
+      echo "  $item"
+    done
+  fi
+
+  # Final verdict
+  #
+  if (( ${#missing_requisite_list[@]} > 0 )); then
+    echo "❌ Missing requisites for glibc bootstrap"
+    exit 1
+  else
+    echo "βœ… All specified requisites found"
+    exit 0
+  fi
index 67e6b59..abcb5a4 100755 (executable)
@@ -3,75 +3,44 @@ set -euo pipefail
 
 source "$(dirname "$0")/environment.sh"
 
-echo "Γ°\9f\93\9a Building glibc headers..."
+echo "Γ°\9f\93Β¦ Building and installing glibc headers..."
 
-# πŸ§Ή Clean previous build artifacts to ensure idempotence
-echo "🧼 Cleaning glibc build directory: $GLIBC_BUILD"
-rm -rf "$GLIBC_BUILD"
 mkdir -p "$GLIBC_BUILD"
-
 pushd "$GLIBC_BUILD"
 
-# πŸ—️ Configure glibc for headers-only installation
-echo "βš™οΈ  Configuring glibc headers install..."
-"$GLIBC_SRC/configure" \
-  --prefix=/usr \
-  --with-headers="$SYSROOT/usr/include" \
-  --disable-multilib \
-  --enable-static \
-  --disable-shared \
-  libc_cv_slibdir="/usr/lib"
-
-# πŸ“₯ Install headers only
-echo "πŸ› οΈ  Installing glibc headers to sysroot..."
-make install-headers -j"$(nproc)" DESTDIR="$SYSROOT"
-
-# πŸ“Ž Verify critical header files and directories were installed
-echo "πŸ“¦ Verifying installed files..."
-
-required_headers=(
-  "$SYSROOT/usr/include/gnu/libc-version.h"
-  "$SYSROOT/usr/include/stdio.h"
-  "$SYSROOT/usr/include/unistd.h"
-)
-
-missing_files=()
-for header in "${required_headers[@]}"; do
-  if [[ ! -f "$header" ]]; then
-    missing_files+=("$header")
-  fi
-done
-
-if (( ${#missing_files[@]} > 0 )); then
-  echo "❌ Missing required glibc headers:"
-  printf '   %s\n' "${missing_files[@]}"
-  exit 1
-fi
-
-# πŸ“¦ Verify the expected directory structure
-if [[ ! -d "$SYSROOT/usr/include" ]]; then
-  echo "❌ Expected include directory not found: $SYSROOT/usr/include"
-  exit 1
-fi
-
-if [[ ! -d "$SYSROOT/usr/lib" ]]; then
-  echo "❌ Expected lib directory not found: $SYSROOT/usr/lib"
-  exit 1
-fi
-
-# πŸ“š Additional verification: check for key startup files
-startup_files=(
-  "$SYSROOT/usr/lib/crt1.o"
-  "$SYSROOT/usr/lib/crti.o"
-  "$SYSROOT/usr/lib/crtn.o"
-)
-
-for file in "${startup_files[@]}"; do
-  if [[ ! -f "$file" ]]; then
-    echo "❌ Missing startup file: $file"
+  # Configure glibc with minimal bootstrap options
+  "$GLIBC_SRC/configure" \
+    --prefix=/usr \
+    --build="$HOST" \
+    --host="$HOST" \
+    --with-headers="$SYSROOT/usr/include" \
+    --disable-multilib \
+    --enable-static \
+    --disable-shared \
+    --enable-kernel=4.4.0 \
+    libc_cv_slibdir="/usr/lib"
+
+
+  # Install headers into sysroot
+  make install-headers -j"$MAKE_JOBS" DESTDIR="$SYSROOT"
+
+  # βœ… Verify headers were installed
+  required_headers=(
+    "$SYSROOT/usr/include/gnu/libc-version.h"
+    "$SYSROOT/usr/include/stdio.h"
+    "$SYSROOT/usr/include/unistd.h"
+  )
+
+  missing=()
+  for h in "${required_headers[@]}"; do
+    [[ -f "$h" ]] || missing+=("$h")
+  done
+
+  if (( ${#missing[@]} > 0 )); then
+    echo "❌ Missing required glibc headers:"
+    printf '   %s\n' "${missing[@]}"
     exit 1
   fi
-done
 
 popd
 
diff --git a/scriptπŸ–‰/build_glibc_headers_requisites.sh b/scriptπŸ–‰/build_glibc_headers_requisites.sh
new file mode 100755 (executable)
index 0000000..0264c81
--- /dev/null
@@ -0,0 +1,99 @@
+#!/bin/bash
+set -euo pipefail
+
+source "$(dirname "$0")/environment.sh"
+
+echo "πŸ“¦ Checking requisites for glibc headers installation."
+
+missing_requisite_list=()
+found_requisite_list=()
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 1. Required tools for headers phase
+#
+required_tools=(
+  "gcc"
+  "g++"
+  "make"
+  "ld"
+  "as"
+)
+
+for tool in "${required_tools[@]}"; do
+  if location=$(command -v "$tool"); then
+    found_requisite_list+=("$location")
+  else
+    missing_requisite_list+=("$tool")
+  fi
+done
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 2. glibc source directory check
+#
+if [ -d "$GLIBC_SRC" ] && [ "$(ls -A "$GLIBC_SRC")" ]; then
+  found_requisite_list+=("$GLIBC_SRC")
+else
+  missing_requisite_list+=("$GLIBC_SRC (empty or missing)")
+fi
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 3. Kernel headers required for bootstrap glibc
+#
+linux_headers=(
+  "$SYSROOT/usr/include/linux/version.h"
+  "$SYSROOT/usr/include/asm/unistd.h"
+  "$SYSROOT/usr/include/bits/types.h"
+)
+
+for header in "${linux_headers[@]}"; do
+  if [[ -f "$header" ]]; then
+    found_requisite_list+=("$header")
+  else
+    missing_requisite_list+=("$header")
+  fi
+done
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 4. Confirm SYSROOT write access for header install
+#
+if [[ -w "$SYSROOT/usr/include" ]]; then
+  found_requisite_list+=("SYSROOT writable: $SYSROOT/usr/include")
+else
+  missing_requisite_list+=("SYSROOT not writable: $SYSROOT/usr/include")
+fi
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# 5. Check C preprocessor is operational
+#
+echo '#include <stddef.h>' | gcc -E - > /dev/null 2>&1
+if [[ $? -eq 0 ]]; then
+  found_requisite_list+=("C preprocessor operational: gcc -E works")
+else
+  missing_requisite_list+=("C preprocessor failed: gcc -E on <stddef.h> failed")
+fi
+
+# β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
+# Print results
+#
+if (( ${#found_requisite_list[@]} > 0 )); then
+  echo "found:"
+  for item in "${found_requisite_list[@]}"; do
+    echo "  $item"
+  done
+fi
+
+if (( ${#missing_requisite_list[@]} > 0 )); then
+  echo "missing:"
+  for item in "${missing_requisite_list[@]}"; do
+    echo "  $item"
+  done
+fi
+
+# Final verdict
+if (( ${#missing_requisite_list[@]} > 0 )); then
+  echo "❌ Missing requisites for glibc header install"
+  exit 1
+else
+  echo "βœ… All specified requisites found for glibc headers"
+  exit 0
+fi
index d239cef..7c9bca3 100755 (executable)
@@ -3,7 +3,6 @@ set -euo pipefail
 
 source "$(dirname "$0")/environment.sh"
 
-# Clean the build directories listed in BUILD_DIR_LISTECTORY_LIST
 echo "🧹 Cleaning build directories..."
 
 for dir in "${BUILD_DIR_LIST[@]}"; do