kit

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

compat-driver.sh (2812B)


      1 #!/bin/sh
      2 # Driver-side target selection checks for the public link-session
      3 # compatibility boundary (KIT-P0-004).  The C unit covers raw bytes,
      4 # in-memory builders, archives, and DSO inputs for ELF/Mach-O/COFF; this
      5 # focused shell layer pins explicit -target authority and implicit first-input
      6 # inference in `kit ld`.
      7 
      8 set -u
      9 
     10 script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
     11 repo_root=$(CDPATH= cd -- "$script_dir/../.." && pwd)
     12 KIT=${KIT:-$repo_root/build/kit}
     13 KIT_KIT_DIR=$repo_root/test/lib
     14 . "$repo_root/test/lib/kit_sh_kit.sh"
     15 
     16 kit_require_kit link-compat-driver
     17 kit_report_init
     18 kit_workdir link-compat-driver
     19 work=$KIT_WORK
     20 
     21 fixture=$repo_root/test/cross/cases/exit.c
     22 
     23 run_ok x64-object "$KIT" cc -target x86_64-none-elf -ffreestanding \
     24   -c "$fixture" -o "$KIT_WORK/x64.o"
     25 run_ok aa64-object "$KIT" cc -target aarch64-none-elf -ffreestanding \
     26   -c "$fixture" -o "$KIT_WORK/aa64.o"
     27 
     28 # An explicit target is authoritative.  This used to be overwritten by the
     29 # first object immediately before the public link session was created.
     30 run_fail explicit-target-authoritative "$KIT" ld \
     31   -target aarch64-none-elf -r -o "$KIT_WORK/explicit-mismatch.o" \
     32   "$KIT_WORK/x64.o"
     33 contains explicit-target-names-input \
     34   "$KIT_WORK/explicit-target-authoritative.err" "$KIT_WORK/x64.o"
     35 contains explicit-target-expected-arch \
     36   "$KIT_WORK/explicit-target-authoritative.err" "expected arch=aarch64"
     37 contains explicit-target-actual-arch \
     38   "$KIT_WORK/explicit-target-authoritative.err" "got arch=x86_64"
     39 
     40 run_ok explicit-target-match "$KIT" ld -target aarch64-none-elf -r \
     41   -o "$KIT_WORK/explicit-match.o" "$KIT_WORK/aa64.o"
     42 
     43 # Without -target, the first target-bearing object selects the effective
     44 # target and the same public boundary rejects a later disagreement.
     45 run_fail inferred-first-target "$KIT" ld -r \
     46   -o "$KIT_WORK/inferred-mismatch.o" "$KIT_WORK/x64.o" "$KIT_WORK/aa64.o"
     47 contains inferred-first-names-input "$KIT_WORK/inferred-first-target.err" \
     48   "$KIT_WORK/aa64.o"
     49 contains inferred-first-expected-arch "$KIT_WORK/inferred-first-target.err" \
     50   "expected arch=x86_64"
     51 contains inferred-first-actual-arch "$KIT_WORK/inferred-first-target.err" \
     52   "got arch=aarch64"
     53 
     54 # Archive validation must inspect every member before symbol selection, so a
     55 # foreign second member cannot hide behind an unreferenced archive entry.
     56 run_ok mixed-archive "$KIT" ar rcs "$KIT_WORK/libmixed.a" \
     57   "$KIT_WORK/x64.o" "$KIT_WORK/aa64.o"
     58 run_fail archive-foreign-member "$KIT" ld -target x86_64-none-elf -r \
     59   --whole-archive "$KIT_WORK/libmixed.a" \
     60   -o "$KIT_WORK/archive-mismatch.o"
     61 contains archive-names-container "$KIT_WORK/archive-foreign-member.err" \
     62   "$KIT_WORK/libmixed.a"
     63 contains archive-names-member "$KIT_WORK/archive-foreign-member.err" \
     64   "aa64.o"
     65 
     66 kit_summary link-compat-driver
     67 kit_exit