boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

run-gcc-libc-flat-tcc.sh (4663B)


      1 #!/bin/sh
      2 ## run-gcc-libc-flat-tcc.sh — tcc-gcc baseline runner.
      3 ##
      4 ## Builds the tcc.flat.c-built tcc-gcc against mes-libc's mem* sources
      5 ## into a runtime archive, then walks tests/cc/<name>.c through tcc-gcc
      6 ## linking against that archive. The control reference for the
      7 ## tcc/cc/tcc-libc suites — if a fixture passes here but fails through
      8 ## cc.scm + tcc-boot2 / tcc-tcc, the bug lives in our pipeline rather
      9 ## than in tcc-0.9.26 itself.
     10 ##
     11 ## Env: ARCH=aarch64 (default) | amd64
     12 ##      TCC=<path> overrides the per-arch tcc-gcc binary
     13 ## Usage: tcc/scripts/run-gcc-libc-flat-tcc.sh [<test-name>...]
     14 
     15 set -eu
     16 
     17 ROOT=$(cd "$(dirname "$0")/.." && pwd)
     18 cd "$ROOT"
     19 
     20 ARCH=${ARCH:-aarch64}
     21 
     22 case "$ARCH" in
     23     aarch64) TCC_TARGET=ARM64;  RUNTIME_TARGET_DEFINES="-D TCC_TARGET_ARM64=1 -D TCC_TARGET_ARM=1"; LIB_HELPER_SRC=lib/lib-arm64.c; LIB_HELPER_NAME=lib-arm64.o ;;
     24     amd64)   TCC_TARGET=X86_64; RUNTIME_TARGET_DEFINES="-D TCC_TARGET_X86_64=1";                    LIB_HELPER_SRC=;               LIB_HELPER_NAME= ;;
     25     *) echo "$0: unsupported ARCH '$ARCH' (aarch64|amd64)" >&2; exit 2 ;;
     26 esac
     27 
     28 TCC=${TCC:-build/$ARCH/tcc/gcc/tcc-gcc}
     29 START=build/$ARCH/tcc/cc/start.o
     30 OUT_ROOT=build/$ARCH/tests/gcc-libc-flat-tcc
     31 WORK_ROOT=build/$ARCH/.work/tests/gcc-libc-flat-tcc
     32 TCC_SRC=build/$ARCH/vendor/tcc/tcc-0.9.26-1147-gee75a10c
     33 MES_INC=vendor/mes-libc/include
     34 case "$ARCH" in
     35     aarch64) MES_LINUX_INC=vendor/mes-libc/include/linux/riscv64 ;;
     36     amd64)   MES_LINUX_INC=vendor/mes-libc/include/linux/x86_64  ;;
     37 esac
     38 RUNTIME=$WORK_ROOT/runtime.a
     39 
     40 [ -x "$TCC" ] || {
     41     echo "missing $TCC; build it with tcc/scripts/build-tcc-gcc.sh and $TCC_SRC/../tcc.flat.c" >&2
     42     exit 2
     43 }
     44 [ -r "$START" ] || { echo "missing $START" >&2; exit 2; }
     45 
     46 mkdir -p "$OUT_ROOT" "$WORK_ROOT"
     47 
     48 "$TCC" -v
     49 
     50 build_runtime() {
     51     rm -rf "$WORK_ROOT/runtime-objs"
     52     mkdir -p "$WORK_ROOT/runtime-objs"
     53 
     54     # shellcheck disable=SC2086 # RUNTIME_TARGET_DEFINES is intentionally word-split.
     55     "$TCC" -c -D HAVE_CONFIG_H=1 -D HAVE_LONG_LONG=1 -D HAVE_FLOAT=1 \
     56         $RUNTIME_TARGET_DEFINES \
     57         -I "$TCC_SRC" -I "$TCC_SRC/include" \
     58         -o "$WORK_ROOT/runtime-objs/libtcc1.o" "$TCC_SRC/lib/libtcc1.c"
     59     if [ -n "$LIB_HELPER_SRC" ]; then
     60         # shellcheck disable=SC2086 # RUNTIME_TARGET_DEFINES is intentionally word-split.
     61         "$TCC" -c -D HAVE_CONFIG_H=1 -D HAVE_LONG_LONG=1 -D HAVE_FLOAT=1 \
     62             $RUNTIME_TARGET_DEFINES \
     63             -I "$TCC_SRC" -I "$TCC_SRC/include" \
     64             -o "$WORK_ROOT/runtime-objs/$LIB_HELPER_NAME" "$TCC_SRC/$LIB_HELPER_SRC"
     65     fi
     66 
     67     for src in string/memcpy.c string/memmove.c string/memset.c string/memcmp.c; do
     68         obj=$WORK_ROOT/runtime-objs/$(basename "$src" .c).o
     69         "$TCC" -c -D HAVE_CONFIG_H=1 -I "$MES_INC" -I "$MES_LINUX_INC" \
     70             -o "$obj" "vendor/mes-libc/$src"
     71     done
     72 
     73     "$TCC" -ar cr "$RUNTIME" "$WORK_ROOT"/runtime-objs/*.o
     74 }
     75 
     76 build_runtime
     77 
     78 if [ "$#" -gt 0 ]; then
     79     NAMES="$*"
     80 else
     81     NAMES=$(
     82         ls tests/cc 2>/dev/null \
     83             | sed -n 's/^\([^_][^.]*\)\.c$/\1/p' \
     84             | sort -u
     85     )
     86 fi
     87 
     88 pass=0
     89 fail=0
     90 
     91 check_one() {
     92     name=$1
     93     src=tests/cc/$name.c
     94     exe=$OUT_ROOT/$name
     95     work=$WORK_ROOT/$name
     96     tcc_log=$work/tcc.log
     97     out=$work/stdout
     98     mkdir -p "$work"
     99 
    100     if [ -e tests/cc/$name.expected ]; then
    101         expout=$(cat tests/cc/$name.expected)
    102     else
    103         expout=
    104     fi
    105     if [ -e tests/cc/$name.expected-exit ]; then
    106         expexit=$(cat tests/cc/$name.expected-exit)
    107     else
    108         expexit=0
    109     fi
    110 
    111     if ! "$TCC" -nostdlib -I "$TCC_SRC/include" \
    112             "$START" "$src" "$RUNTIME" -o "$exe" >"$tcc_log" 2>&1; then
    113         echo "  FAIL gcc-libc-flat-tcc/$name"
    114         echo "    tcc compile/link failed:"
    115         sed 's/^/    /' "$tcc_log"
    116         fail=$((fail + 1))
    117         return
    118     fi
    119 
    120     if "$exe" >"$out" 2>&1; then
    121         actexit=0
    122     else
    123         actexit=$?
    124     fi
    125     actout=$(cat "$out")
    126 
    127     if [ "$actexit" != "$expexit" ]; then
    128         echo "  FAIL gcc-libc-flat-tcc/$name"
    129         echo "    exit: expected $expexit, got $actexit"
    130         fail=$((fail + 1))
    131         return
    132     fi
    133 
    134     if [ "$actout" != "$expout" ]; then
    135         echo "  FAIL gcc-libc-flat-tcc/$name"
    136         echo "    --- expected ---"
    137         printf '%s\n' "$expout" | sed 's/^/    /'
    138         echo "    --- actual ---"
    139         printf '%s\n' "$actout" | sed 's/^/    /'
    140         fail=$((fail + 1))
    141         return
    142     fi
    143 
    144     echo "  PASS gcc-libc-flat-tcc/$name"
    145     pass=$((pass + 1))
    146 }
    147 
    148 for name in $NAMES; do
    149     [ -e tests/cc/$name.c ] || continue
    150     check_one "$name"
    151 done
    152 
    153 echo "$pass passed, $fail failed"
    154 [ "$fail" -eq 0 ]