Files
BFM-decomp/tools/psyq_build_libs.sh
T
Drew T 26b71c5b2d feat(phase-7): PsyQ library-linking proven byte-exact + rodata-island mechanism — session C checkpoint
- rodata-island mechanism PROVEN: migration (dotted .rodata sibling named "800")
  + tools/ld_interleave.py (.data->.rodata->.data linker placement) + data-in-text
  carve; rodata/data sizes come out byte-exact. +24 residual root-caused to the
  .align-3 jumptable file-split padding (6 sites; spim suggests 8 splits)
- PsyQ 4.0 library linking PROVEN end-to-end: libcd SYS.o (483 instrs, full TU + 21
  externals + internal .rdata/.data relocs) links BYTE-IDENTICAL to BFM
  - tools/psyq_lib_split.py: split Sony LIB\x01 archive -> member .OBJ
  - tools/psyq_build_libs.sh: .LIB -> psyq-obj-parser -> ELF .a (14 BFM libs)
  - tools/psyq_identify.py: relocation-masked search -> object link addresses
    (libcd 18/25 used, contiguous from 0x80043088)
  - external symbols recovered from the EXE's own resolved relocations
  - section-alignment 8->4 fix (psyq-obj-parser over-aligns; the +4 mismatch is the tell)
- cookbook §8 (rodata island) + §9 (PsyQ library-linking recipe); CURRENT_PHASE full
  diagnosis, asset inventory, and resume plan
- 3rd consecutive green session (143dbb89 BYTE-IDENTICAL) -> Gen1 >=3-session bar MET
- SDK assets (PsyQ 4.0 USA DTL-S2002 libs + psyq-obj-parser) staged gitignored under
  tools/psyq/; no function matches added (architectural session)
2026-06-14 21:24:10 -06:00

34 lines
1.6 KiB
Bash

#!/usr/bin/env bash
# Build ELF .a archives from the PsyQ 4.0 .LIB files (Phase 7 — PsyQ-library linking).
# Pipeline per lib: psyq_lib_split.py (.LIB -> .OBJ members) -> psyq-obj-parser (each
# .OBJ -> ELF .o) -> ar (-> <lib>.a). Output (gitignored, SDK-derived):
# tools/psyq/lib40_elf/<LIB>.a + .run/obj40/<lib>/*.{obj,o} scratch
# The .a are then linked into the build for the functions identified as PsyQ SDK code.
# Requires: tools/psyq/lib40/*.LIB (extracted from the DTL-S2002 redump), tools/psyq/
# psyq-obj-parser, mipsel-linux-gnu-ar. SDK assets stay out of git (.gitignore /tools/psyq/).
set -euo pipefail
cd "$(dirname "$0")/.."
LIBDIR=tools/psyq/lib40
OUTDIR=tools/psyq/lib40_elf
SCRATCH=.run/obj40
PARSER=tools/psyq/psyq-obj-parser
AR=mipsel-linux-gnu-ar
mkdir -p "$OUTDIR"
# BFM-relevant libraries (the SDK footprint in the EXE); pass args to override.
LIBS=("${@:-LIBCD LIBGS LIBSPU LIBSND LIBMCRD LIBSN LIBAPI LIBETC LIBGTE LIBGPU LIBMATH LIBCARD LIBC LIBC2}")
for L in ${LIBS[@]}; do
lib="$LIBDIR/$L.LIB"
[ -f "$lib" ] || { echo " skip $L (no $lib)"; continue; }
od="$SCRATCH/$(echo "$L" | tr A-Z a-z)"
rm -rf "$od"; mkdir -p "$od"
n=$(python3 tools/psyq_lib_split.py "$lib" "$od" | head -1 | grep -oE '[0-9]+ objects' | grep -oE '[0-9]+')
ok=0
for o in "$od"/*.obj; do
if "$PARSER" "$o" -o "${o%.obj}.o" >/dev/null 2>&1; then ok=$((ok+1)); fi
done
rm -f "$OUTDIR/$L.a"
$AR rcs "$OUTDIR/$L.a" "$od"/*.o 2>/dev/null || true
printf " %-10s %3s objs -> %3d .o -> %s.a\n" "$L" "${n:-?}" "$ok" "$L"
done
echo "done -> $OUTDIR/"