kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

riscv-flags.sh (3954B)


      1 #!/bin/sh
      2 # RISC-V psABI ELF e_flags merge/oracle coverage (KIT-P1-004).
      3 
      4 set -u
      5 
      6 script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
      7 repo_root=$(CDPATH= cd -- "$script_dir/../.." && pwd)
      8 KIT=${KIT:-$repo_root/build/kit}
      9 KIT_KIT_DIR=$repo_root/test/lib
     10 . "$repo_root/test/lib/kit_sh_kit.sh"
     11 
     12 kit_require_kit riscv-flags
     13 kit_report_init
     14 kit_workdir riscv-flags
     15 work=$KIT_WORK
     16 
     17 READELF=$(command -v llvm-readelf 2>/dev/null || command -v readelf 2>/dev/null || true)
     18 if [ -z "$READELF" ]; then
     19   skip_test riscv-flags "llvm-readelf/readelf is required as the independent oracle"
     20   kit_summary riscv-flags
     21   kit_exit
     22 fi
     23 
     24 main_src=$repo_root/test/tier1/kitchen/cross/shared_main.c
     25 dep_src=$repo_root/test/tier1/kitchen/cross/shared_dep.c
     26 
     27 check_flags() {
     28   label=$1
     29   file=$2
     30   want=$3
     31   if "$READELF" -h "$file" > "$work/$label.readelf" \
     32        2> "$work/$label.readelf.err" &&
     33      grep -E "Flags:[[:space:]]*$want([,[:space:]]|$)" \
     34        "$work/$label.readelf" >/dev/null 2>&1; then
     35     ok "$label"
     36   else
     37     {
     38       printf 'expected ELF flags %s\n' "$want"
     39       sed 's/^/readelf: /' "$work/$label.readelf" 2>/dev/null
     40       sed 's/^/err: /' "$work/$label.readelf.err" 2>/dev/null
     41     } > "$work/$label.diag"
     42     not_ok "$label" "$work/$label.diag"
     43   fi
     44 }
     45 
     46 build_variant() {
     47   tag=$1
     48   triple=$2
     49   march=$3
     50   mabi=$4
     51   want=$5
     52 
     53   run_ok "$tag-main" "$KIT" cc -target "$triple" -march="$march" \
     54     -mabi="$mabi" -ffreestanding -c "$main_src" -o "$work/$tag-main.o"
     55   run_ok "$tag-dep" "$KIT" cc -target "$triple" -march="$march" \
     56     -mabi="$mabi" -ffreestanding -c "$dep_src" -o "$work/$tag-dep.o"
     57   run_ok "$tag-relocatable" "$KIT" ld -r -o "$work/$tag-merged.o" \
     58     "$work/$tag-main.o" "$work/$tag-dep.o"
     59   check_flags "$tag-relocatable-flags" "$work/$tag-merged.o" "$want"
     60   run_ok "$tag-final" "$KIT" cc -target "$triple" -march="$march" \
     61     -mabi="$mabi" -nostdlib -Wl,-e,main "$work/$tag-main.o" \
     62     "$work/$tag-dep.o" -o "$work/$tag.elf"
     63   check_flags "$tag-final-flags" "$work/$tag.elf" "$want"
     64 }
     65 
     66 build_variant rv32-soft riscv32-none-elf \
     67   rv32imac_zicsr_zifencei ilp32 0x1
     68 build_variant rv32-single riscv32-none-elf \
     69   rv32imafc_zicsr_zifencei ilp32f 0x3
     70 build_variant rv64-soft riscv64-none-elf \
     71   rv64imac_zicsr_zifencei lp64 0x1
     72 build_variant rv64-double riscv64-none-elf \
     73   rv64imafdc_zicsr_zifencei lp64d 0x5
     74 
     75 run_fail rv32-mixed-float "$KIT" ld -r -o "$work/rv32-mixed.o" \
     76   "$work/rv32-soft-main.o" "$work/rv32-single-dep.o"
     77 contains rv32-mixed-names-first "$work/rv32-mixed-float.err" \
     78   "rv32-soft-main.o"
     79 contains rv32-mixed-float-diagnostic "$work/rv32-mixed-float.err" \
     80   "float ABI mismatch"
     81 
     82 run_fail rv64-mixed-float "$KIT" ld -r -o "$work/rv64-mixed.o" \
     83   "$work/rv64-soft-main.o" "$work/rv64-double-dep.o"
     84 contains rv64-mixed-names-first "$work/rv64-mixed-float.err" \
     85   "rv64-soft-main.o"
     86 contains rv64-mixed-float-diagnostic "$work/rv64-mixed-float.err" \
     87   "float ABI mismatch"
     88 
     89 # RVC is a mergeable presence bit. A non-C object remains unmarked on its own,
     90 # then combining it with a C-enabled peer retains RVC in partial and final
     91 # links while preserving the agreed double-float ABI.
     92 run_ok rv64-double-noc-main "$KIT" cc -target riscv64-none-elf \
     93   -march=rv64imafd_zicsr_zifencei -mabi=lp64d -ffreestanding \
     94   -c "$main_src" -o "$work/rv64-double-noc-main.o"
     95 check_flags rv64-double-noc-object-flags \
     96   "$work/rv64-double-noc-main.o" 0x4
     97 run_ok rv64-rvc-merge-relocatable "$KIT" ld -r \
     98   -o "$work/rv64-rvc-merged.o" "$work/rv64-double-noc-main.o" \
     99   "$work/rv64-double-dep.o"
    100 check_flags rv64-rvc-merge-relocatable-flags \
    101   "$work/rv64-rvc-merged.o" 0x5
    102 run_ok rv64-rvc-merge-final "$KIT" cc -target riscv64-none-elf \
    103   -march=rv64imafdc_zicsr_zifencei -mabi=lp64d -nostdlib -Wl,-e,main \
    104   "$work/rv64-double-noc-main.o" "$work/rv64-double-dep.o" \
    105   -o "$work/rv64-rvc-merged.elf"
    106 check_flags rv64-rvc-merge-final-flags "$work/rv64-rvc-merged.elf" 0x5
    107 
    108 kit_summary riscv-flags
    109 kit_exit