The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(k1): check every staged Linux sidecar module, not 4 of them
purple85a86983cfc4
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex ea8ec484..52919862 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -544,6 +544,45 @@ jobs:[ "$missing" -eq 0 ] || exit 1echo "OK: every staged sidecar companion is present inside the built AppImage ($extracted_llama_dir)"+ # SKEPTIKER-LINUX-WEB-K1.md: the AppImage check above proves nothing+ # about the .deb, a completely different bundler (dpkg-deb, not+ # linuxdeploy) with its own independent failure mode for the exact+ # same reason K1-18 exists -- a bundler that packages the exe but+ # silently drops (or never even looks at) the resources directory.+ # bundle.targets is "all" (src-tauri/tauri.conf.json), so this+ # workflow already builds and publishes a .deb every release; nothing+ # before this step ever inspected what actually landed inside it.+ - name: Verify built .deb carries every sidecar companion (K1-18)+ if: matrix.platform == 'ubuntu-22.04'+ shell: bash+ timeout-minutes: 5+ run: |+ set -euo pipefail+ deb_rel="$(find src-tauri/target -type f -iname '*.deb' -print -quit)"+ [ -n "$deb_rel" ] || { echo "FAIL: no .deb found under src-tauri/target after the build (K1-18)" >&2; exit 1; }+ deb="$(realpath "$deb_rel")"+ workdir="$RUNNER_TEMP/deb-extract"+ rm -rf "$workdir"+ mkdir -p "$workdir"+ # dpkg-deb -x extracts only the data archive (no root needed, no+ # install), ships on every Ubuntu image including bare runners.+ dpkg-deb -x "$deb" "$workdir"+ extracted_llama_dir="$(find "$workdir/usr/lib" -mindepth 1 -maxdepth 3 -type d -iname 'llama' -print -quit)"+ if [ -z "$extracted_llama_dir" ]; then+ echo "FAIL: no .../usr/lib/.../llama directory inside the extracted .deb at all; the deb bundler dropped the whole sidecar companions directory (K1-18)" >&2+ exit 1+ fi+ missing=0+ for f in "src-tauri/resources/llama/${{ matrix.sidecar_triple }}"/*; do+ base="$(basename "$f")"+ if [ ! -e "$extracted_llama_dir/$base" ]; then+ echo "FAIL: $base is staged in src-tauri/resources/llama/${{ matrix.sidecar_triple }} but MISSING from the built .deb ($extracted_llama_dir); a bundler can drop a companion silently and still exit 0 (K1-18)" >&2+ missing=$((missing + 1))+ fi+ done+ [ "$missing" -eq 0 ] || exit 1+ echo "OK: every staged sidecar companion is present inside the built .deb ($extracted_llama_dir)"+# The promise above, made real for every trigger. Runs after the binaries are# attached, so a release published as a full release is put back before# anyone is offered it, and never touches the release that is already Latest.diff --git a/scripts/__fixtures__/linux-isa/avx-hit-baseline.disasm.txt b/scripts/__fixtures__/linux-isa/avx-hit-baseline.disasm.txtnew file mode 100644index 00000000..15df3c02--- /dev/null+++ b/scripts/__fixtures__/linux-isa/avx-hit-baseline.disasm.txt@@ -0,0 +1,6 @@+0000000000401040 <regressed_baseline_fn>:+ 401040: 55 push %rbp+ 401041: 48 89 e5 mov %rsp,%rbp+ 401044: c5 f8 28 c1 vmovaps %xmm1,%xmm0+ 401048: c5 fc 77 vzeroupper+ 40104b: c3 retdiff --git a/scripts/__fixtures__/linux-isa/avx2-leak-in-avx-only.disasm.txt b/scripts/__fixtures__/linux-isa/avx2-leak-in-avx-only.disasm.txtnew file mode 100644index 00000000..2d803432--- /dev/null+++ b/scripts/__fixtures__/linux-isa/avx2-leak-in-avx-only.disasm.txt@@ -0,0 +1,7 @@+0000000000401080 <piledriver_style_fn_with_avx2_leak>:+ 401080: 55 push %rbp+ 401081: 48 89 e5 mov %rsp,%rbp+ 401084: c5 fc 58 c1 vaddps %ymm1,%ymm0,%ymm0+ 401088: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0+ 40108d: c5 fc 77 vzeroupper+ 401090: c3 retdiff --git a/scripts/__fixtures__/linux-isa/avx512-leak-in-avx2.disasm.txt b/scripts/__fixtures__/linux-isa/avx512-leak-in-avx2.disasm.txtnew file mode 100644index 00000000..245d1161--- /dev/null+++ b/scripts/__fixtures__/linux-isa/avx512-leak-in-avx2.disasm.txt@@ -0,0 +1,7 @@+00000000004010c0 <alderlake_style_fn_with_avx512_leak>:+ 4010c0: 55 push %rbp+ 4010c1: 48 89 e5 mov %rsp,%rbp+ 4010c4: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0+ 4010c9: 62 f1 7c 48 58 c1 vaddps %zmm1,%zmm0,%zmm0+ 4010cf: c5 fc 77 vzeroupper+ 4010d2: c3 retdiff --git a/scripts/__fixtures__/linux-isa/clean-avx-only.disasm.txt b/scripts/__fixtures__/linux-isa/clean-avx-only.disasm.txtnew file mode 100644index 00000000..b94e21ff--- /dev/null+++ b/scripts/__fixtures__/linux-isa/clean-avx-only.disasm.txt@@ -0,0 +1,7 @@+0000000000401060 <sandybridge_style_fn>:+ 401060: 55 push %rbp+ 401061: 48 89 e5 mov %rsp,%rbp+ 401064: c5 fc 58 c1 vaddps %ymm1,%ymm0,%ymm0+ 401068: c4 e2 7d 18 05 00 00 00 00 vbroadcastss 0x0(%rip),%ymm0+ 401071: c5 fc 77 vzeroupper+ 401074: c3 retdiff --git a/scripts/__fixtures__/linux-isa/clean-avx2.disasm.txt b/scripts/__fixtures__/linux-isa/clean-avx2.disasm.txtnew file mode 100644index 00000000..96935aad--- /dev/null+++ b/scripts/__fixtures__/linux-isa/clean-avx2.disasm.txt@@ -0,0 +1,7 @@+00000000004010a0 <haswell_style_fn>:+ 4010a0: 55 push %rbp+ 4010a1: 48 89 e5 mov %rsp,%rbp+ 4010a4: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0+ 4010a9: c4 e2 ed b8 c1 vfmadd231ps %ymm1,%ymm2,%ymm0+ 4010ae: c5 fc 77 vzeroupper+ 4010b1: c3 retdiff --git a/scripts/__fixtures__/linux-isa/clean-avx512.disasm.txt b/scripts/__fixtures__/linux-isa/clean-avx512.disasm.txtnew file mode 100644index 00000000..4f247042--- /dev/null+++ b/scripts/__fixtures__/linux-isa/clean-avx512.disasm.txt@@ -0,0 +1,6 @@+00000000004010f0 <skylakex_style_fn>:+ 4010f0: 55 push %rbp+ 4010f1: 48 89 e5 mov %rsp,%rbp+ 4010f4: 62 f1 7c 48 58 c1 vaddps %zmm1,%zmm0,%zmm0+ 4010fa: c5 fc 77 vzeroupper+ 4010fd: c3 retdiff --git a/scripts/__fixtures__/linux-isa/clean-baseline.disasm.txt b/scripts/__fixtures__/linux-isa/clean-baseline.disasm.txtnew file mode 100644index 00000000..080085f1--- /dev/null+++ b/scripts/__fixtures__/linux-isa/clean-baseline.disasm.txt@@ -0,0 +1,8 @@+0000000000401020 <clean_baseline_fn>:+ 401020: 55 push %rbp+ 401021: 48 89 e5 mov %rsp,%rbp+ 401024: 0f 10 45 f0 movups -0x10(%rbp),%xmm0+ 401028: 66 0f 6f c1 movdqa %xmm1,%xmm0+ 40102c: f3 0f b8 c0 popcnt %eax,%eax+ 401030: 66 0f 3a 44 c1 00 pclmulqdq $0x0,%xmm1,%xmm0+ 401036: c3 retdiff --git a/scripts/__fixtures__/linux-isa/haswell-positive-control.disasm.txt b/scripts/__fixtures__/linux-isa/haswell-positive-control.disasm.txtnew file mode 100644index 00000000..b33d89fe--- /dev/null+++ b/scripts/__fixtures__/linux-isa/haswell-positive-control.disasm.txt@@ -0,0 +1,6 @@+00000000004010e0 <haswell_kernel_fn>:+ 4010e0: 55 push %rbp+ 4010e1: 48 89 e5 mov %rsp,%rbp+ 4010e4: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0+ 4010e9: c5 fc 77 vzeroupper+ 4010ec: c3 retdiff --git a/scripts/lib/isa-guard-linux-rules.sh b/scripts/lib/isa-guard-linux-rules.shnew file mode 100644index 00000000..de813e72--- /dev/null+++ b/scripts/lib/isa-guard-linux-rules.sh@@ -0,0 +1,246 @@+#!/usr/bin/env bash+#+# isa-guard-linux-rules.sh: the pure decision logic for the Linux half of+# scripts/verify-sidecar-isa.sh (K1, 3.0.1), factored out of that script so+# it can be exercised by scripts/verify-sidecar-isa.selftest.sh against+# small checked-in disassembly-text fixtures, on any platform. This file+# touches no ELF file, no objdump, no companions directory: the real run+# (verify-sidecar-isa.sh) sources it and feeds it real objdump output, the+# selftest sources it and feeds it fixture text. Same functions, same+# verdicts, either way.+#+# FUND this responds to (SKEPTIKER-LINUX-WEB-K1.md, Abschnitt zum+# Linux-Waechter): the Linux guard checked 4 of the modules+# build-llama.sh stages (x64, sse42, ggml-base, the exe) and silently+# skipped every other base module (ggml, llama, llama-common,+# llama-server-impl, mtmd, ggml-vulkan) and every CPU-tier variant's own+# ISA ceiling entirely, exactly the modules that carried 24-98 VEX hits on+# the Windows side of the same regression.+#+# SCOPE, stated honestly (same spirit as scripts/win-isa-guard.mjs's own+# SCOPE comment): this file is a MNEMONIC/register-text classifier over+# objdump AT&T-syntax output, not an opcode-byte disassembler like the+# Windows guard. It answers two yes/no questions exactly, because both have+# an unambiguous textual signature:+# - "does this file contain ANY VEX/EVEX-coded instruction at all"+# (has_avx_or_above, unchanged from the pre-existing baseline rule: a+# %ymm/%zmm register or a mnemonic beginning with 'v').+# - "does this file contain an AVX-512 instruction specifically"+# (has_avx512_or_above: a %zmm register, or an opmask operand like+# "{%k1}" -- AVX-512 is the only x86 extension that defines 512-bit+# registers or opmask registers at all, so this is exact, not a guess).+# The one boundary this file cannot draw exactly from mnemonic text alone+# is "AVX-only vs. AVX2": many AVX2 integer mnemonics (vpaddd, vpand, ...)+# are spelled identically whether they operate on a 128-bit %xmm (legal+# under plain AVX, which promoted the SSE integer set to VEX encoding at+# 128 bits only) or a 256-bit %ymm (which requires AVX2 -- plain AVX never+# defined a 256-bit integer op). Telling those apart from mnemonic+register+# text alone needs per-instruction operand-width parsing this file does not+# do. Instead has_avx2_marker checks a curated list of mnemonics AVX2+# introduced that have NO pre-AVX2 meaning at any width (broadcast-from-GPR,+# gather, variable-shift, the 128<->256 lane insert/extract/permute forms):+# every HIT is unambiguously AVX2-or-later, but a miss is not proof of+# absence (a 256-bit vpaddd smuggled into an AVX-only-tier build would slip+# past has_avx2_marker). Not silently assumed complete: the ceiling checks+# below always pair this with has_avx512_or_above, which alone already+# catches the reportable K1 shape (a "dynamic" build secretly compiled at a+# fixed high ISA level) as either an AVX-512 hit in a sub-AVX-512 tier, or+# an AVX-or-above hit in a baseline module -- both of which this file DOES+# catch exactly, not heuristically.+set -euo pipefail++has_avx_or_above() {+ grep -qE '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$1"+}++has_avx512_or_above() {+ grep -qE '%zmm[0-9]+|\{%k[1-7]\}' <<<"$1"+}++# Mnemonics AVX2 introduced that have no pre-AVX2 (plain-AVX or SSE) meaning+# at ANY operand width: broadcast-from-GPR/128-bit-lane forms, the 128<->256+# lane insert/extract/permute forms, variable-count shifts, masked+# load/store, and gather. A hit here is unambiguous; see the SCOPE comment+# above for why a miss is not proof of absence.+AVX2_ONLY_MNEMONICS='vpbroadcastb|vpbroadcastw|vpbroadcastd|vpbroadcastq|vbroadcasti128|vbroadcasti32x4|vinserti128|vextracti128|vperm2i128|vpermd|vpermps|vpermq|vpermpd|vpsllvd|vpsllvq|vpsrlvd|vpsrlvq|vpsravd|vpblendd|vpmaskmovd|vpmaskmovq|vpgatherdd|vpgatherqd|vpgatherdq|vpgatherqq|vgatherdps|vgatherqps|vgatherdpd|vgatherqpd'++has_avx2_marker() {+ grep -qE "[[:space:]]($AVX2_ONLY_MNEMONICS)([[:space:]]|\$)" <<<"$1"+}++# --- tier table: llama.cpp GGML_CPU_ALL_VARIANTS, x86, non-MSVC branch -----+# Read at LLAMA_COMMIT (ggml/src/CMakeLists.txt, ggml_add_cpu_backend_variant+# calls; the "if (NOT MSVC)" branches only exist on Linux/GCC, not on+# Windows/MSVC, matching the four extra names verify-sidecar-isa.sh's own+# EXPECTED_VARIANTS comment already calls out):+# x64 (ISA-neutral baseline)+# sse42 SSE42 (ISA-neutral baseline)+# sandybridge SSE42 AVX+# ivybridge SSE42 AVX F16C+# piledriver SSE42 AVX F16C FMA+# haswell SSE42 AVX F16C FMA AVX2 BMI2+# alderlake SSE42 AVX F16C FMA AVX2 BMI2 AVX_VNNI (no AVX512)+# skylakex + AVX512+# cannonlake + AVX512_VBMI+# cascadelake + AVX512_VNNI+# icelake + AVX512_VBMI AVX512_VNNI+# cooperlake + AVX512_BF16+# zen4 + AVX512_VBMI AVX512_VNNI AVX512_BF16+# sapphirerapids + AVX512_VBMI AVX512_VNNI AVX512_BF16 AMX_TILE AMX_INT8+# A future pin bump that changes this list is expected to update these+# arrays in the same commit, the same discipline EXPECTED_VARIANTS in+# verify-sidecar-isa.sh already holds itself to. sapphirerapids' AMX+# instructions are not VEX/EVEX-coded (a different encoding entirely) and+# are not detected by this file at all; that is fine here because+# sapphirerapids is already the top tier with no ceiling to enforce above+# AVX-512, the same residual gap win-isa-guard.mjs documents for BMI/POPCNT.+TIER_BASELINE_VARIANTS=(x64 sse42)+TIER_AVX_ONLY_VARIANTS=(sandybridge ivybridge piledriver)+TIER_AVX2_VARIANTS=(haswell alderlake)+TIER_AVX512_VARIANTS=(skylakex cannonlake cascadelake icelake cooperlake zen4 sapphirerapids)++# Derived, not a second hand-written copy (review-waechter-windows.md N5's+# lesson applied here too): the full Linux CPU-variant name list is exactly+# the union of the four tier arrays above, in one place, so it cannot drift+# from verify-sidecar-isa.sh's own EXPECTED_VARIANTS without the two being+# compared (verify-sidecar-isa.sh asserts the sets match at startup).+LINUX_CPU_VARIANTS=(+ "${TIER_BASELINE_VARIANTS[@]}"+ "${TIER_AVX_ONLY_VARIANTS[@]}"+ "${TIER_AVX2_VARIANTS[@]}"+ "${TIER_AVX512_VARIANTS[@]}"+)++# Every non-CPU-tier-variant module this pinned llama.cpp checkout produces+# for x86_64-unknown-linux-gnu: ggml/src/CMakeLists.txt add_library(ggml-base+# ...) and add_library(ggml ...), src/CMakeLists.txt add_library(llama ...),+# common/CMakeLists.txt (llama-common), tools/mtmd/CMakeLists.txt (mtmd),+# tools/server/CMakeLists.txt (llama-server-impl), plus the Vulkan backend+# module (ggml_add_backend_library(ggml-vulkan ...)). The same nine names+# (eight here plus the exe) EXPECTED_BASE_WINDOWS_MODULES in+# verify-sidecar-isa.sh already lists for MSVC -- one llama.cpp source tree,+# two platforms, the same target names (ggml.dll <-> libggml.so, etc.).+EXPECTED_BASE_LINUX_MODULES=(+ ggml ggml-base ggml-vulkan llama llama-common llama-server-impl mtmd+)++# Returns (on stdout) the ISA-ceiling role of a CPU-tier variant name:+# baseline|avx-only|avx2|avx512, or "unknown" (with a non-zero exit) for a+# name none of the four tier arrays list -- fail closed rather than guess.+tier_of_variant() {+ local variant="$1" v+ for v in "${TIER_BASELINE_VARIANTS[@]}"; do [ "$v" = "$variant" ] && { printf 'baseline\n'; return 0; }; done+ for v in "${TIER_AVX_ONLY_VARIANTS[@]}"; do [ "$v" = "$variant" ] && { printf 'avx-only\n'; return 0; }; done+ for v in "${TIER_AVX2_VARIANTS[@]}"; do [ "$v" = "$variant" ] && { printf 'avx2\n'; return 0; }; done+ for v in "${TIER_AVX512_VARIANTS[@]}"; do [ "$v" = "$variant" ] && { printf 'avx512\n'; return 0; }; done+ printf 'unknown\n'+ return 1+}++# Classify one staged filename against the known Linux module set (fail+# closed on anything not recognised, K1 SKEPTIKER-LINUX-WEB-K1.md).+# $1: basename as found in the companions directory+# (e.g. "libggml-base.so", "libggml-base.so.1", "libggml-cpu-haswell.so")+# $2: lib prefix ("lib" on Linux, see LIB_PREFIX in verify-sidecar-isa.sh)+# $3: lib ext ("so")+# stdout, exactly one of:+# base:<name> -- exact match, one of EXPECTED_BASE_LINUX_MODULES+# variant:<name>:<tier> -- exact match, one of LINUX_CPU_VARIANTS+# sibling:<canonical> -- a SONAME-versioned copy of one of the above+# ("<canonical-filename>.<digits>[.<digits>...]").+# cp without -P/-d (stage_dynamic_isa_companions+# in build-llama.sh) turns every hop of a+# libFoo.so -> libFoo.so.N -> libFoo.so.N.n.n+# symlink chain into its own real file with+# identical bytes here (see the "extension .0"+# comment in verify-sidecar-isa.sh's+# find_variant_file) -- not independently+# disassembled, already checked under its+# canonical name.+# unknown -- neither of the above; the caller must fail+# closed on this, never skip it silently.+classify_linux_module() {+ local base="$1" prefix="$2" ext="$3" name tier v exact+ for name in "${EXPECTED_BASE_LINUX_MODULES[@]}"; do+ if [ "$base" = "${prefix}${name}.${ext}" ]; then+ printf 'base:%s\n' "$name"+ return 0+ fi+ done+ for v in "${LINUX_CPU_VARIANTS[@]}"; do+ if [ "$base" = "${prefix}ggml-cpu-${v}.${ext}" ]; then+ tier="$(tier_of_variant "$v")"+ printf 'variant:%s:%s\n' "$v" "$tier"+ return 0+ fi+ done+ for name in "${EXPECTED_BASE_LINUX_MODULES[@]}"; do+ exact="${prefix}${name}.${ext}"+ case "$base" in+ "$exact".[0-9]*)+ printf 'sibling:%s\n' "$exact"+ return 0+ ;;+ esac+ done+ for v in "${LINUX_CPU_VARIANTS[@]}"; do+ exact="${prefix}ggml-cpu-${v}.${ext}"+ case "$base" in+ "$exact".[0-9]*)+ printf 'sibling:%s\n' "$exact"+ return 0+ ;;+ esac+ done+ printf 'unknown\n'+ return 1+}++# Evaluate one module's disassembly text against its ISA role and print a+# one-line verdict to stdout ("OK: ..." or "FAIL: ..."); returns 0 for a+# pass, 1 for a fail. An unrecognised role also fails (fail closed): never+# silently treat an unclassified role as "nothing to check".+# $1: role -- baseline | avx-only | avx2 | avx512+# $2: disassembly text+# $3: label for the message (module name plus path, caller's choice)+evaluate_module_asm() {+ local role="$1" asm="$2" label="${3:-module}"+ case "$role" in+ baseline)+ if has_avx_or_above "$asm"; then+ printf 'FAIL: %s contains an AVX-or-above instruction, this is supposed to be ISA-neutral baseline code (loaded by every CPU regardless of age)\n' "$label"+ return 1+ fi+ printf 'OK: %s carries no AVX-or-above instruction, as expected for a baseline module\n' "$label"+ return 0+ ;;+ avx-only)+ if has_avx512_or_above "$asm"; then+ printf 'FAIL: %s contains an AVX-512 instruction; this tier (SSE42 AVX F16C FMA at most) must never reach AVX-512\n' "$label"+ return 1+ fi+ if has_avx2_marker "$asm"; then+ printf 'FAIL: %s contains an AVX2-only instruction; this tier (SSE42 AVX F16C FMA at most) must never reach AVX2\n' "$label"+ return 1+ fi+ printf 'OK: %s stays at or below its AVX-only ceiling (no AVX-512, no AVX2-only mnemonic found)\n' "$label"+ return 0+ ;;+ avx2)+ if has_avx512_or_above "$asm"; then+ printf 'FAIL: %s contains an AVX-512 instruction; this tier (AVX2 at most) must never reach AVX-512\n' "$label"+ return 1+ fi+ printf 'OK: %s stays at or below its AVX2 ceiling (no AVX-512 found)\n' "$label"+ return 0+ ;;+ avx512)+ printf 'OK: %s is the top CPU tier (AVX-512 and above allowed by design), nothing to cap\n' "$label"+ return 0+ ;;+ *)+ printf 'FAIL: %s has an unrecognised ISA role "%s", refusing to guess a ceiling (fail closed)\n' "$label" "$role"+ return 1+ ;;+ esac+}diff --git a/scripts/verify-sidecar-isa.selftest.sh b/scripts/verify-sidecar-isa.selftest.shnew file mode 100755index 00000000..09c4335b--- /dev/null+++ b/scripts/verify-sidecar-isa.selftest.sh@@ -0,0 +1,185 @@+#!/usr/bin/env bash+#+# verify-sidecar-isa.selftest.sh: proves the DECISION LOGIC of the Linux+# half of verify-sidecar-isa.sh (scripts/lib/isa-guard-linux-rules.sh)+# against small checked-in disassembly-text fixtures+# (scripts/__fixtures__/linux-isa/), with no objdump, no real ELF file and+# no COMPANIONS_DIR needed. Runs the same on the Linux CI runner and on a+# Mac dev box (arm64), the same reasoning win-isa-guard.test.mjs already+# uses for the Windows half of this guard: the real Linux run always needs+# a real x86_64 build to disassemble (see the "real run" command at the+# bottom of this file's usage comment), but the CLASSIFICATION and CEILING+# rules that decide pass/fail from that disassembly text are pure functions+# and can be proven everywhere, every commit.+#+# FUND this answers (SKEPTIKER-LINUX-WEB-K1.md): the pre-existing Linux+# guard checked 4 of the staged modules and never exercised a tier-ceiling+# rule at all, so nothing in this repo's test suite could have caught a+# regression there before a real Linux build ran. This selftest is that+# missing coverage, runnable on every commit regardless of platform.+#+# Usage: scripts/verify-sidecar-isa.selftest.sh+# Real Linux run (after a real build, by the tester assigned to it):+# scripts/build-llama.sh x86_64-unknown-linux-gnu+# scripts/verify-sidecar-isa.sh x86_64-unknown-linux-gnu+set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+FIXTURES_DIR="$SCRIPT_DIR/__fixtures__/linux-isa"+# shellcheck disable=SC1091+source "$SCRIPT_DIR/lib/isa-guard-linux-rules.sh"++pass_count=0+fail_count=0++# Every assertion goes through this so a wrong verdict AND a wrong exit+# code are both caught, the same "exact expected outcome, not just any+# failure" discipline verify-sidecar-isa.sh's own Windows controls already+# hold themselves to (review-waechter-windows.md BLOCKER B2).+assert_eq() {+ local desc="$1" expected="$2" actual="$3"+ if [ "$expected" = "$actual" ]; then+ printf ' ok %s\n' "$desc"+ pass_count=$((pass_count + 1))+ else+ printf ' FAIL %s: expected [%s], got [%s]\n' "$desc" "$expected" "$actual" >&2+ fail_count=$((fail_count + 1))+ fi+}++fixture() {+ local name="$1"+ [ -f "$FIXTURES_DIR/$name" ] || { printf ' FAIL missing fixture %s\n' "$name" >&2; fail_count=$((fail_count + 1)); return; }+ cat "$FIXTURES_DIR/$name"+}++echo "== tier table consistency (derived list vs. the hand-typed set) =="+# Same 14 names verify-sidecar-isa.sh's own EXPECTED_VARIANTS lists for a+# non-Windows triple, order-independent. Catches the two lists drifting+# apart the way review-waechter-windows.md N5 warned about for the Windows+# side of this same guard.+expected_variant_set='alderlake cannonlake cascadelake cooperlake haswell icelake ivybridge piledriver sandybridge sapphirerapids skylakex sse42 x64 zen4'+actual_variant_set="$(printf '%s\n' "${LINUX_CPU_VARIANTS[@]}" | sort | tr '\n' ' ' | sed 's/ $//')"+assert_eq "LINUX_CPU_VARIANTS matches the 14-name pin (14 entries, one place)" \+ "$(printf '%s' "$expected_variant_set" | tr ' ' '\n' | sort | tr '\n' ' ' | sed 's/ $//')" \+ "$actual_variant_set"++echo "== tier_of_variant =="+assert_eq "x64 is baseline" "baseline" "$(tier_of_variant x64)"+assert_eq "sse42 is baseline" "baseline" "$(tier_of_variant sse42)"+assert_eq "sandybridge is avx-only" "avx-only" "$(tier_of_variant sandybridge)"+assert_eq "piledriver is avx-only" "avx-only" "$(tier_of_variant piledriver)"+assert_eq "haswell is avx2" "avx2" "$(tier_of_variant haswell)"+assert_eq "alderlake is avx2" "avx2" "$(tier_of_variant alderlake)"+assert_eq "skylakex is avx512" "avx512" "$(tier_of_variant skylakex)"+assert_eq "sapphirerapids is avx512" "avx512" "$(tier_of_variant sapphirerapids)"+assert_eq "made-up name is unknown" "unknown" "$(tier_of_variant not-a-real-tier || true)"++echo "== classify_linux_module (fail-closed module accounting) =="+assert_eq "libggml-base.so is a known base module" "base:ggml-base" \+ "$(classify_linux_module libggml-base.so lib so)"+assert_eq "libggml-cpu-haswell.so is a known variant (avx2 tier)" "variant:haswell:avx2" \+ "$(classify_linux_module libggml-cpu-haswell.so lib so)"+assert_eq "libggml-cpu-sandybridge.so is a known variant (avx-only tier)" "variant:sandybridge:avx-only" \+ "$(classify_linux_module libggml-cpu-sandybridge.so lib so)"+assert_eq "libggml-base.so.1 is a SONAME sibling of libggml-base.so" "sibling:libggml-base.so" \+ "$(classify_linux_module libggml-base.so.1 lib so)"+assert_eq "libggml-cpu-x64.so.1.2.3 is a SONAME sibling of libggml-cpu-x64.so" "sibling:libggml-cpu-x64.so" \+ "$(classify_linux_module libggml-cpu-x64.so.1.2.3 lib so)"+assert_eq "an unrelated new .so is unknown (fail closed, the skeptic's actual finding)" "unknown" \+ "$(classify_linux_module libggml-cpu-zen5.so lib so || true)"+assert_eq "a plain typo/near-miss name is unknown, not fuzzy-matched" "unknown" \+ "$(classify_linux_module libggml-cpu-haswel.so lib so || true)"++echo "== has_avx_or_above / has_avx512_or_above / has_avx2_marker =="+clean_baseline="$(fixture clean-baseline.disasm.txt)"+avx_hit_baseline="$(fixture avx-hit-baseline.disasm.txt)"+clean_avx_only="$(fixture clean-avx-only.disasm.txt)"+avx2_leak="$(fixture avx2-leak-in-avx-only.disasm.txt)"+clean_avx2="$(fixture clean-avx2.disasm.txt)"+avx512_leak="$(fixture avx512-leak-in-avx2.disasm.txt)"+haswell_positive="$(fixture haswell-positive-control.disasm.txt)"+clean_avx512="$(fixture clean-avx512.disasm.txt)"++if has_avx_or_above "$clean_baseline"; then+ printf ' FAIL clean-baseline fixture should have NO AVX-or-above hit\n' >&2; fail_count=$((fail_count + 1))+else+ printf ' ok clean-baseline fixture has no AVX-or-above hit\n'; pass_count=$((pass_count + 1))+fi+if has_avx_or_above "$avx_hit_baseline"; then+ printf ' ok avx-hit-baseline fixture IS caught by has_avx_or_above\n'; pass_count=$((pass_count + 1))+else+ printf ' FAIL avx-hit-baseline fixture should have an AVX-or-above hit\n' >&2; fail_count=$((fail_count + 1))+fi+if has_avx2_marker "$avx2_leak"; then+ printf ' ok avx2-leak-in-avx-only fixture IS caught by has_avx2_marker\n'; pass_count=$((pass_count + 1))+else+ printf ' FAIL avx2-leak-in-avx-only fixture should trip has_avx2_marker\n' >&2; fail_count=$((fail_count + 1))+fi+if has_avx2_marker "$clean_avx_only"; then+ printf ' FAIL clean-avx-only fixture must NOT trip has_avx2_marker\n' >&2; fail_count=$((fail_count + 1))+else+ printf ' ok clean-avx-only fixture does not trip has_avx2_marker\n'; pass_count=$((pass_count + 1))+fi+if has_avx512_or_above "$avx512_leak"; then+ printf ' ok avx512-leak-in-avx2 fixture IS caught by has_avx512_or_above\n'; pass_count=$((pass_count + 1))+else+ printf ' FAIL avx512-leak-in-avx2 fixture should trip has_avx512_or_above\n' >&2; fail_count=$((fail_count + 1))+fi+if has_avx512_or_above "$clean_avx2"; then+ printf ' FAIL clean-avx2 fixture must NOT trip has_avx512_or_above\n' >&2; fail_count=$((fail_count + 1))+else+ printf ' ok clean-avx2 fixture does not trip has_avx512_or_above\n'; pass_count=$((pass_count + 1))+fi+# Positive control on the detector itself: without this, a broken grep+# pattern that never matches anything would make every "no AVX found"+# result above unproven (the exact reasoning verify-sidecar-isa.sh's own+# POSITIVE_CONTROL section already uses on a real haswell build).+if has_avx_or_above "$haswell_positive"; then+ printf ' ok positive control: haswell-style fixture shows an AVX hit, the detector itself works\n'; pass_count=$((pass_count + 1))+else+ printf ' FAIL positive control: haswell-style fixture shows NO AVX hit, has_avx_or_above is broken\n' >&2; fail_count=$((fail_count + 1))+fi++echo "== evaluate_module_asm (the actual per-tier ceiling decision) =="+out="$(evaluate_module_asm baseline "$clean_baseline" "clean-baseline")"; status=$?+assert_eq "baseline/clean exits 0" "0" "$status"+assert_eq "baseline/clean verdict text" "OK: clean-baseline carries no AVX-or-above instruction, as expected for a baseline module" "$out"++set +e+out="$(evaluate_module_asm baseline "$avx_hit_baseline" "avx-hit-baseline")"; status=$?+set -e+assert_eq "baseline/regressed exits 1 (RED PROBE)" "1" "$status"+assert_eq "baseline/regressed verdict text (RED PROBE)" "FAIL: avx-hit-baseline contains an AVX-or-above instruction, this is supposed to be ISA-neutral baseline code (loaded by every CPU regardless of age)" "$out"++out="$(evaluate_module_asm avx-only "$clean_avx_only" "clean-avx-only")"; status=$?+assert_eq "avx-only/clean exits 0" "0" "$status"++set +e+out="$(evaluate_module_asm avx-only "$avx2_leak" "avx2-leak")"; status=$?+set -e+assert_eq "avx-only/avx2-leak exits 1 (RED PROBE)" "1" "$status"+assert_eq "avx-only/avx2-leak verdict text (RED PROBE)" "FAIL: avx2-leak contains an AVX2-only instruction; this tier (SSE42 AVX F16C FMA at most) must never reach AVX2" "$out"++out="$(evaluate_module_asm avx2 "$clean_avx2" "clean-avx2")"; status=$?+assert_eq "avx2/clean exits 0 (negative control: a real haswell-shaped body is not flagged)" "0" "$status"++set +e+out="$(evaluate_module_asm avx2 "$avx512_leak" "avx512-leak")"; status=$?+set -e+assert_eq "avx2/avx512-leak exits 1 (RED PROBE)" "1" "$status"+assert_eq "avx2/avx512-leak verdict text (RED PROBE)" "FAIL: avx512-leak contains an AVX-512 instruction; this tier (AVX2 at most) must never reach AVX-512" "$out"++out="$(evaluate_module_asm avx512 "$clean_avx512" "clean-avx512")"; status=$?+assert_eq "avx512/top-tier always exits 0 (nothing to cap above AVX-512)" "0" "$status"++set +e+out="$(evaluate_module_asm made-up-role "$clean_baseline" "some-module")"; status=$?+set -e+assert_eq "unrecognised role fails closed (RED PROBE)" "1" "$status"+assert_eq "unrecognised role verdict text (RED PROBE)" 'FAIL: some-module has an unrecognised ISA role "made-up-role", refusing to guess a ceiling (fail closed)' "$out"++echo+echo "$pass_count passed, $fail_count failed"+[ "$fail_count" -eq 0 ] || exit 1+echo "OK: isa-guard-linux-rules.sh decision logic proven against fixtures (module classification, all four tier ceilings, positive/negative controls, red probes), no ELF file or objdump needed"diff --git a/scripts/verify-sidecar-isa.sh b/scripts/verify-sidecar-isa.shindex a0980ccb..f9018482 100755--- a/scripts/verify-sidecar-isa.sh+++ b/scripts/verify-sidecar-isa.sh@@ -9,20 +9,38 @@# build cache, or a future llama.cpp release changing its own defaults could# all make the command line lie):#-# 1. The BASELINE files (the "x64" and "sse42" CPU variants, ggml-base,-# and the llama-server exe itself) must contain NO AVX-or-above-# instruction. These are the files every CPU loads no matter how old,-# so an AVX instruction inside one of them is exactly the K1 bug: a-# "dynamic" build that is secretly still a fixed x86-64-v3 (or higher)-# binary. Checked by disassembling and searching for ymm/zmm registers-# and VEX/EVEX-coded mnemonics (they are the ones objdump prints with a-# leading "v", e.g. vmovaps, vzeroupper, vfmadd231ps; no plain SSE-# mnemonic is spelled that way).-# 2. The HASWELL variant (the first AVX2 tier) MUST contain at least one-# such instruction. Without this positive control, a disassembler that-# silently failed, or a grep pattern that never matches anything, would-# make check 1 pass on every input, including a build that produced no-# real code at all. Two files, two opposite expectations, in one script.+# 1. The BASELINE modules (the "x64" and "sse42" CPU variants, every named+# base module -- ggml, ggml-base, ggml-vulkan, llama, llama-common,+# llama-server-impl, mtmd -- and the llama-server exe itself) must+# contain NO AVX-or-above instruction. These are the files every CPU+# loads no matter how old, so an AVX instruction inside one of them is+# exactly the K1 bug: a "dynamic" build that is secretly still a fixed+# x86-64-v3 (or higher) binary. Checked by disassembling and searching+# for ymm/zmm registers and VEX/EVEX-coded mnemonics (they are the ones+# objdump prints with a leading "v", e.g. vmovaps, vzeroupper,+# vfmadd231ps; no plain SSE mnemonic is spelled that way).+# 2. Every CPU-tier VARIANT module must stay at or below the ISA ceiling+# its own tier is supposed to have (sandybridge/ivybridge/piledriver:+# AVX at most, no AVX2, no AVX-512; haswell/alderlake: AVX2 at most, no+# AVX-512; skylakex and above: AVX-512 is the top tier, nothing to+# cap). The rules and the tier table live in+# scripts/lib/isa-guard-linux-rules.sh (shared with+# scripts/verify-sidecar-isa.selftest.sh, which proves this logic+# against checked-in fixtures with no ELF file or objdump needed,+# runnable on any platform). SKEPTIKER-LINUX-WEB-K1.md found the+# earlier version of this script checked 4 of the staged modules+# (x64, sse42, ggml-base, exe) and skipped every other base module and+# every variant's own ceiling outright.+# 3. Every file actually staged in the companions directory must be a+# recognised module (a known base module, a known CPU-tier variant, or+# a SONAME-versioned sibling of one of those) -- an unrecognised module+# turns this guard RED rather than being silently skipped (fail+# closed).+# 4. The HASWELL variant (the first AVX2 tier) MUST contain at least one+# AVX-or-above instruction. Without this positive control, a+# disassembler that silently failed, or a grep pattern that never+# matches anything, would make check 1 pass on every input, including+# a build that produced no real code at all.## Also fails RED when an expected CPU variant is simply missing from the# companions directory (a partial build, or a future cmake refactor that@@ -650,52 +668,100 @@ disassemble() {fi}-# True when the disassembly contains an AVX-or-above register or a-# VEX/EVEX-coded mnemonic. ymm*/zmm* registers cover AVX and AVX-512 data;-# the mnemonic pattern catches the handful of VEX instructions that touch no-# wide register at all (vzeroupper is the standing example: it clears the-# upper bits of every ymm register and takes no operand). A mnemonic is the-# first word after the opcode-byte column, so anchoring on tab/space-# boundaries avoids matching inside a byte string or a symbol name.-has_avx_or_above() {- grep -qE '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$1"-}--BASELINE_TARGETS=("x64" "sse42")-POSITIVE_CONTROL="haswell"+# has_avx_or_above and the tier-ceiling rules live in one shared file+# (scripts/lib/isa-guard-linux-rules.sh) so scripts/verify-sidecar-isa.selftest.sh+# can prove the same decision logic against checked-in fixtures on any+# platform, with no ELF file or objdump needed. See that file's own header+# for the SCOPE of what a mnemonic/register-text classifier can and cannot+# tell apart (exact for "any VEX/EVEX at all" and for AVX-512 specifically,+# a documented heuristic for AVX-only-vs-AVX2).+# shellcheck disable=SC1091+source "$SCRIPT_DIR/lib/isa-guard-linux-rules.sh"++# Belt and suspenders (review-waechter-windows.md N5's lesson, applied to+# this list too): the 14-name Linux CPU-variant pin exists in exactly two+# places by necessity (EXPECTED_VARIANTS above decides what MUST exist on+# disk; LINUX_CPU_VARIANTS in the sourced lib decides each name's ISA+# ceiling) and the two must never silently drift apart -- a name added to+# one and not the other would leave that variant either unchecked for its+# ceiling or wrongly rejected as unrecognised. Compared as sets, not order.+linux_pin_a="$(printf '%s\n' "${EXPECTED_VARIANTS[@]}" | sort)"+linux_pin_b="$(printf '%s\n' "${LINUX_CPU_VARIANTS[@]}" | sort)"+[ "$linux_pin_a" = "$linux_pin_b" ] \+ || vdie "EXPECTED_VARIANTS (verify-sidecar-isa.sh) and LINUX_CPU_VARIANTS (scripts/lib/isa-guard-linux-rules.sh) have drifted apart. EXPECTED_VARIANTS: ${EXPECTED_VARIANTS[*]}. LINUX_CPU_VARIANTS: ${LINUX_CPU_VARIANTS[*]}. Update both together when the llama.cpp pin changes its variant list"++# --- SKEPTIKER-LINUX-WEB-K1.md: every staged module checked, not 4 of them --+#+# Every file actually staged in COMPANIONS_DIR must be accounted for: a+# known base module (EXPECTED_BASE_LINUX_MODULES), a known CPU-tier variant+# (LINUX_CPU_VARIANTS, with its own tier's ceiling), or a SONAME-versioned+# sibling of one of those (cp without -P/-d in stage_dynamic_isa_companions+# turns every hop of a libFoo.so -> libFoo.so.N -> libFoo.so.N.n.n symlink+# chain into its own real file with identical bytes, see the "extension .0"+# comment above find_variant_file). Anything else is an unclassified module+# and turns this guard RED instead of being silently skipped -- the exact+# gap the skeptic found (4 of 16 modules checked, and the 12 unchecked ones+# carried 24-98 VEX hits on the Windows side of this same regression).+staged_files=()+while IFS= read -r f; do+ [ -n "$f" ] || continue+ staged_files+=("$(basename "$f")")+done < <(find "$COMPANIONS_DIR" -maxdepth 1 -type f -iname '*.so*' | sort)++declare -A module_role=() # full path -> baseline|avx-only|avx2|avx512+declare -A module_label=() # full path -> human label for messages+unclassified=()+for base in "${staged_files[@]}"; do+ cls="$(classify_linux_module "$base" "$LIB_PREFIX" "$LIB_EXT" || true)"+ case "$cls" in+ base:*)+ name="${cls#base:}"+ module_role["$COMPANIONS_DIR/$base"]="baseline"+ module_label["$COMPANIONS_DIR/$base"]="$name"+ ;;+ variant:*)+ rest="${cls#variant:}"+ name="${rest%%:*}"+ tier="${rest#*:}"+ module_role["$COMPANIONS_DIR/$base"]="$tier"+ module_label["$COMPANIONS_DIR/$base"]="ggml-cpu-$name"+ ;;+ sibling:*)+ vlog "$base: SONAME sibling of ${cls#sibling:}, identical bytes already checked under that name, not disassembled again"+ ;;+ *)+ unclassified+=("$base")+ ;;+ esac+done+if [ "${#unclassified[@]}" -gt 0 ]; then+ vdie "unrecognised module(s) staged in $COMPANIONS_DIR: ${unclassified[*]}. Neither a known base module (EXPECTED_BASE_LINUX_MODULES in scripts/lib/isa-guard-linux-rules.sh) nor a known CPU-tier variant (EXPECTED_VARIANTS) nor a SONAME-versioned sibling of one. Classify it before this guard can trust it: add it to EXPECTED_BASE_LINUX_MODULES if it is a new base module that must stay ISA-neutral like the rest of own code, or to the appropriate tier array if it is a new CPU-tier variant"+fifail_count=0-for variant in "${BASELINE_TARGETS[@]}"; do- f="$(find_variant_file "$variant")"- asm="$(disassemble "$f")"- if has_avx_or_above "$asm"; then- printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s contains an AVX-or-above instruction, this is supposed to be the no-AVX baseline:\n' "$f" >&2+for path in "${!module_role[@]}"; do+ role="${module_role[$path]}"+ label="${module_label[$path]} ($path)"+ asm="$(disassemble "$path")"+ if verdict="$(evaluate_module_asm "$role" "$asm" "$label")"; then+ vlog "$verdict"+ else+ printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s\n' "$verdict" >&2grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || truefail_count=$((fail_count + 1))- else- vlog "$variant ($f): no AVX-or-above instruction found, as expected"fidone-asm="$(disassemble "$GGML_BASE_FILE")"-if has_avx_or_above "$asm"; then- printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s (ggml-base, loaded by every CPU variant) contains an AVX-or-above instruction, this is supposed to be ISA-neutral:\n' "$GGML_BASE_FILE" >&2- grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || true- fail_count=$((fail_count + 1))-else- vlog "ggml-base ($GGML_BASE_FILE): no AVX-or-above instruction found, as expected"-fi-exe_name="$(out_name_for "$TRIPLE")"exe_path="$BIN_DIR/$exe_name"if [ -f "$exe_path" ]; thenasm="$(disassemble "$exe_path")"- if has_avx_or_above "$asm"; then- printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s (the exe itself) contains an AVX-or-above instruction, it must be ISA-neutral, all CPU-specific code belongs in the ggml-cpu-* variants:\n' "$exe_path" >&2+ if verdict="$(evaluate_module_asm baseline "$asm" "$exe_name ($exe_path)")"; then+ vlog "$verdict"+ else+ printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s\n' "$verdict" >&2grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || truefail_count=$((fail_count + 1))- else- vlog "$exe_name: no AVX-or-above instruction found, as expected"fielsevlog "no exe found at $exe_path, skipping the exe-itself check (build first for the full check)"@@ -704,13 +770,13 @@ fi# Positive control: without this, a broken disassembler invocation (a typo'd# flag, a tool that silently prints nothing) would make every check above# pass vacuously. haswell is the first tier with AVX2, so it MUST show up.-f="$(find_variant_file "$POSITIVE_CONTROL")"+f="$(find_variant_file haswell)"asm="$(disassemble "$f")"if ! has_avx_or_above "$asm"; then- vdie "$f (the $POSITIVE_CONTROL variant, which IS supposed to use AVX2) shows no AVX instruction at all, the disassembler step itself is not working, every 'no AVX found' result above is unproven"+ vdie "$f (the haswell variant, which IS supposed to use AVX2) shows no AVX instruction at all, the disassembler step itself is not working, every 'no AVX found'/'ceiling respected' result above is unproven"fi-vlog "$POSITIVE_CONTROL ($f): AVX-or-above instruction found, confirming the disassembler actually sees the ISA it is looking for"+vlog "haswell ($f): AVX-or-above instruction found, confirming the disassembler actually sees the ISA it is looking for"-[ "$fail_count" -eq 0 ] || vdie "$fail_count file(s) failed the no-AVX-in-the-baseline check"+[ "$fail_count" -eq 0 ] || vdie "$fail_count module(s) failed their ISA ceiling check"vlog "OK: $TRIPLE sidecar, dynamic ISA layout intact, baseline files carry no AVX, disassembler proven working"