Files
parallel-ps2/tests/stackframe/build.sh
T
LibretroAdmin 5335635718 Stack frames stay within 4 KiB, and 2 KiB in libretro-common
Buffers of a path's size or more that sat in a function's frame - or in
a callee's, once inlined - live elsewhere:

- on the heap: the gzip index builder's input and window, the gzip
  extractor's (kept with its state), the CHD reader's feed buffer (made
  on first use), the gzip index name and its template, the M3U reader's
  paths, a cue's directory, the PGS log line past 512 bytes, and in
  libretro-common the copy's destination directory, the dirent stat's
  joined path, the abbreviated-or-relative working paths and the CPU
  class values;
- static, where one thread uses them one call at a time: the default
  and runtime Pcsx2Config (25 KB each), the IOP HLE host-file paths, and
  the VU flag pass's visited set, one per VU since VU0 and VU1 may
  compile at once;
- shared: the NVRAM and MEC file paths take turns in one buffer, and an
  extra ROM's name is built in a std::string.

The runtime config LoadSettings carries over is moved rather than
copied.

tests/stackframe compiles every first-party source the Makefile builds,
with its flags, under -Werror=frame-larger-than=4096 (2048 for
libretro-common).
2026-10-09 04:48:31 +02:00

56 lines
2.1 KiB
Bash

#!/bin/sh
# No function in the core's own code has a stack frame over 4 KiB, or over
# 2 KiB in libretro-common, which also builds for platforms whose threads
# have small stacks. Every source the core's Makefile builds is compiled
# with its own flags plus -Werror=frame-larger-than; third-party sources
# (3rdparty/, and parallel-gs's Granite and gs) are left out.
#
# The frame sizes are those of this machine's compiler at the Makefile's
# optimisation level: inlining folds a callee's buffers into its caller's
# frame, so a release build is the one to check.
#
# Usage: sh tests/stackframe/build.sh (MAKE, JOBS optional)
set -e
DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
ROOT=$(CDPATH= cd -- "$DIR/../.." && pwd)
MAKE=${MAKE:-make}
JOBS=${JOBS:-$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)}
WORK="$DIR/.work"
rm -rf "$WORK" && mkdir -p "$WORK"
trap 'rm -rf "$WORK"' EXIT
# Each compile command, one script per source, its object sent to WORK.
"$MAKE" --no-print-directory -s -n -B -C "$ROOT" > "$WORK/all.txt"
n=0
grep -E '^[^ ]+ -c -o[^ ]+ [^ ]+\.(c|cc|cpp) ' "$WORK/all.txt" \
| grep -v -E ' (3rdparty|pcsx2/GS/parallel-gs/Granite|pcsx2/GS/parallel-gs/gs)/' \
> "$WORK/cmds.txt" || true
while IFS= read -r cmd; do
n=$((n + 1))
case "$cmd" in
*" libretro/libretro-common/"*) limit=2048 ;;
*) limit=4096 ;;
esac
obj=$(printf '%s\n' "$cmd" | sed -E 's/^[^ ]+ -c -o([^ ]+) .*/\1/')
body=$(printf '%s\n' "$cmd" | sed -E "s|^([^ ]+ -c) -o[^ ]+ |\1 -o\"$WORK/$n.o\" |")
{
printf 'cd "%s" || exit 1\n' "$ROOT"
printf '%s -Werror=frame-larger-than=%s 2> "%s/%s.log" || { echo " FAIL: %s"; grep -h -E "frame size|error" "%s/%s.log" | sed "s/^/ /"; exit 1; }\n' \
"$body" "$limit" "$WORK" "$n" "$obj" "$WORK" "$n"
} > "$WORK/$n.sh"
done < "$WORK/cmds.txt"
if [ "$n" -eq 0 ]; then
echo " FAIL: no compile commands from the Makefile"
exit 1
fi
echo "== stack frames: $n sources, $JOBS at a time =="
failed=0
ls "$WORK"/*.sh | xargs -n 1 -P "$JOBS" sh > "$WORK/out.txt" 2>&1 || failed=1
cat "$WORK/out.txt"
if [ "$failed" -ne 0 ]; then
echo "stack frames: FAILED"
exit 1
fi
echo "stack frames: ok"