Skip to content

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.

fix(k1): close both Linux ISA-guard blockers from review-isalinux.md Runde 2

purple59b29c6f2d04
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f7dfae7f..c9d2f498 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -77,6 +77,17 @@ jobs:
- name: Import cycles
run: npm run cycles
+ # AUFLAGE a (review-isalinux.md Runde 2): the K1 ISA guard's own
+ # decision logic (scripts/lib/isa-guard-linux-rules.sh) had zero CI
+ # coverage -- it only ever ran once, by hand, on the Bauer's Mac. This
+ # needs no build, no ELF file and no objdump (it proves the pure
+ # classification/ceiling functions against checked-in fixture text,
+ # scripts/__fixtures__/linux-isa/*.disasm.txt), so it runs here on
+ # every commit, on the plain ubuntu-22.04 runner this job already
+ # has, well before the real per-platform run in release.yml.
+ - name: K1 ISA guard selftest (Linux decision logic)
+ run: bash scripts/verify-sidecar-isa.selftest.sh
+
- name: Unit tests
run: npx vitest run
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 52919862..bd3bbfb4 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -257,6 +257,16 @@ jobs:
with:
arch: x64
+ # AUFLAGE a (review-isalinux.md Runde 2): prove the Linux half's pure
+ # decision logic (scripts/lib/isa-guard-linux-rules.sh) against
+ # checked-in text fixtures before trusting it against a real build on
+ # this runner. Needs no ELF file or objdump, runs identically on every
+ # matrix platform (ci.yml already runs it on every commit too; kept
+ # here as well so a release build is never gated on a real run alone).
+ - name: K1 ISA guard selftest (Linux decision logic)
+ shell: bash
+ run: bash scripts/verify-sidecar-isa.selftest.sh
+
# K1 (3.0.1): the guard against shipping a fixed x86-64-v3 binary again.
# Runs on the real build this lane just produced, on the real runner
# architecture (not emulated), so a regression here is the same failure
diff --git a/scripts/__fixtures__/linux-isa/avx2-integer-ymm-leak-in-avx-only.disasm.txt b/scripts/__fixtures__/linux-isa/avx2-integer-ymm-leak-in-avx-only.disasm.txt
new file mode 100644
index 00000000..7e3ccedc
--- /dev/null
+++ b/scripts/__fixtures__/linux-isa/avx2-integer-ymm-leak-in-avx-only.disasm.txt
@@ -0,0 +1,7 @@
+0000000000401160 <piledriver_style_fn_with_plain_vp_ymm_leak>:
+ 401160: 55 push %rbp
+ 401161: 48 89 e5 mov %rsp,%rbp
+ 401164: c5 fc 58 c1 vaddps %ymm1,%ymm0,%ymm0
+ 401168: c5 fd fe c1 vpaddd %ymm1,%ymm0,%ymm0
+ 40116e: c5 fc 77 vzeroupper
+ 401171: c3 ret
diff --git a/scripts/__fixtures__/linux-isa/avx512-extended-register-leak-in-avx2.disasm.txt b/scripts/__fixtures__/linux-isa/avx512-extended-register-leak-in-avx2.disasm.txt
new file mode 100644
index 00000000..179bc5e2
--- /dev/null
+++ b/scripts/__fixtures__/linux-isa/avx512-extended-register-leak-in-avx2.disasm.txt
@@ -0,0 +1,7 @@
+0000000000401140 <alderlake_style_fn_with_extended_register_leak>:
+ 401140: 55 push %rbp
+ 401141: 48 89 e5 mov %rsp,%rbp
+ 401144: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0
+ 401148: 62 71 7c 08 58 f2 vaddps %ymm16,%ymm17,%ymm18
+ 40114e: c5 fc 77 vzeroupper
+ 401151: c3 ret
diff --git a/scripts/__fixtures__/linux-isa/avx512-opmask-freestanding-leak-in-avx2.disasm.txt b/scripts/__fixtures__/linux-isa/avx512-opmask-freestanding-leak-in-avx2.disasm.txt
new file mode 100644
index 00000000..69461706
--- /dev/null
+++ b/scripts/__fixtures__/linux-isa/avx512-opmask-freestanding-leak-in-avx2.disasm.txt
@@ -0,0 +1,7 @@
+0000000000401120 <alderlake_style_fn_with_opmask_leak>:
+ 401120: 55 push %rbp
+ 401121: 48 89 e5 mov %rsp,%rbp
+ 401124: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0
+ 401128: c5 f8 90 c8 kmovw %eax,%k1
+ 40112c: c5 fc 77 vzeroupper
+ 40112f: c3 ret
diff --git a/scripts/__fixtures__/linux-isa/avx512vl-mnemonic-on-ymm.disasm.txt b/scripts/__fixtures__/linux-isa/avx512vl-mnemonic-on-ymm.disasm.txt
new file mode 100644
index 00000000..713037c9
--- /dev/null
+++ b/scripts/__fixtures__/linux-isa/avx512vl-mnemonic-on-ymm.disasm.txt
@@ -0,0 +1,7 @@
+0000000000401100 <alderlake_style_fn_with_avx512vl_leak>:
+ 401100: 55 push %rbp
+ 401101: 48 89 e5 mov %rsp,%rbp
+ 401104: c4 e2 7d 58 c1 vpbroadcastd %xmm1,%ymm0
+ 401108: 62 f2 7d 08 25 c1 vpternlogd $0xff,%ymm0,%ymm0,%ymm0
+ 40110e: c5 fc 77 vzeroupper
+ 401111: c3 ret
diff --git a/scripts/__fixtures__/linux-isa/clean-avx-only-vp-exceptions.disasm.txt b/scripts/__fixtures__/linux-isa/clean-avx-only-vp-exceptions.disasm.txt
new file mode 100644
index 00000000..496fa255
--- /dev/null
+++ b/scripts/__fixtures__/linux-isa/clean-avx-only-vp-exceptions.disasm.txt
@@ -0,0 +1,7 @@
+0000000000401180 <sandybridge_style_fn_with_legal_vp_permute_and_test>:
+ 401180: 55 push %rbp
+ 401181: 48 89 e5 mov %rsp,%rbp
+ 401184: c4 e3 7d 18 c1 01 vpermilps %ymm1,%ymm0,%ymm0
+ 40118a: c4 e2 7d 17 c1 vptest %ymm0,%ymm1
+ 40118f: c5 fc 77 vzeroupper
+ 401192: c3 ret
diff --git a/scripts/__fixtures__/linux-isa/clean-baseline-realistic-size.disasm.txt b/scripts/__fixtures__/linux-isa/clean-baseline-realistic-size.disasm.txt
new file mode 100644
index 00000000..cd33795c
--- /dev/null
+++ b/scripts/__fixtures__/linux-isa/clean-baseline-realistic-size.disasm.txt
@@ -0,0 +1,22 @@
+0000000000401200 <clean_baseline_fn_realistic_size>:
+ 401200: 55 push %rbp
+ 401201: 48 89 e5 mov %rsp,%rbp
+ 401204: 48 83 ec 20 sub $0x20,%rsp
+ 401208: 0f 10 45 f0 movups -0x10(%rbp),%xmm0
+ 40120c: 66 0f 6f c1 movdqa %xmm1,%xmm0
+ 401210: f3 0f b8 c0 popcnt %eax,%eax
+ 401214: 66 0f 3a 44 c1 00 pclmulqdq $0x0,%xmm1,%xmm0
+ 40121a: 0f 29 45 e0 movaps %xmm0,-0x20(%rbp)
+ 40121e: 8b 45 fc mov -0x4(%rbp),%eax
+ 401221: 83 c0 01 add $0x1,%eax
+ 401224: 89 45 fc mov %eax,-0x4(%rbp)
+ 401227: 8b 45 fc mov -0x4(%rbp),%eax
+ 40122a: 3b 45 f8 cmp -0x8(%rbp),%eax
+ 40122d: 7c e9 jl 401218 <clean_baseline_fn_realistic_size+0x18>
+ 40122f: 0f 28 45 e0 movaps -0x20(%rbp),%xmm0
+ 401233: 0f 11 45 f0 movups %xmm0,-0x10(%rbp)
+ 401237: 8b 45 f8 mov -0x8(%rbp),%eax
+ 40123a: 48 8d 65 f8 lea -0x8(%rbp),%rsp
+ 40123e: 5b pop %rbx
+ 40123f: 5d pop %rbp
+ 401240: c3 ret
diff --git a/scripts/lib/isa-guard-linux-rules.sh b/scripts/lib/isa-guard-linux-rules.sh
index de813e72..6ce35112 100644
--- a/scripts/lib/isa-guard-linux-rules.sh
+++ b/scripts/lib/isa-guard-linux-rules.sh
@@ -25,47 +25,103 @@
# - "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.
+# - "does this file contain an AVX-512 (or AVX512VL, its 128/256-bit
+# sibling) instruction specifically" (has_avx512_or_above). AVX-512 is
+# the only x86 extension that defines 512-bit registers, opmask (%k0-7)
+# registers/operands, the extended register numbers 16-31, or the
+# merge/zero-masking "{z}" suffix, so any of those is exact, not a
+# guess -- and so is a hit on one of the AVX-512-exclusive mnemonics
+# (vpternlog*, vrndscale*, k* register-mask ops, ...) below, whatever
+# register width they run at: AVX512VL is exactly "these EVEX
+# instructions, but legal on xmm/ymm too", not a different instruction
+# set, so a mnemonic that only exists as EVEX is AVX-512-or-above
+# regardless of the operand register it is applied to
+# (review-isalinux.md Runde 2, Auflage c: k0 and freestanding %kN, plus
+# AVX512VL on ymm/xmm, were both previously missed).
+# review-isalinux.md Runde 2, Auflage d also corrected the one boundary
+# this file used to draw only heuristically: "AVX-only vs. AVX2". Most
+# 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 at all, only 256-bit floating-point and the handful of
+# byte-shuffle/test forms named in AVX2_FLOAT_OR_PERMUTE_EXCEPTIONS below).
+# That is not a parsing problem, it is a plain textual fact: any mnemonic
+# beginning "vp" (an AVX2/AVX-512 integer op, not one of the float/permute
+# exceptions) that appears on the same disassembly line as a %ymm register
+# operand is, by definition, AVX2-or-above -- has_avx2_marker now checks
+# exactly that, in addition to the 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).
+# Both are exact on a HIT; the residual (documented, not silently assumed
+# away) gap is a miss: an AVX2-only mnemonic this file has not enumerated,
+# spelled some other way. That residual is not load-bearing for catching
+# the K1 shape (a "dynamic" build secretly compiled at a fixed high ISA
+# level): the ceiling checks below always pair this with
+# has_avx512_or_above, which alone already catches that shape exactly, as
+# either an AVX-512 hit in a sub-AVX-512 tier or an AVX-or-above hit in a
+# baseline module.
set -euo pipefail
has_avx_or_above() {
- grep -qE '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$1"
+ grep -qE '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)|[[:space:]]k[a-z]{2,}([[:space:]]|$)' <<<"$1"
}
+# AVX-512-exclusive mnemonics: no pre-AVX-512 encoding exists for any of
+# these at any operand width, so a hit is AVX-512(VL)-or-above regardless
+# of whether it runs on %zmm, %ymm or %xmm (review-isalinux.md Runde 2,
+# Auflage c). "k*" covers the opmask register-manipulation instructions
+# (kmovw, kandw, kortestw, ktestw, kshiftlw, kunpckbw, ...) -- no other x86
+# mnemonic is spelled with a bare leading 'k'.
+AVX512_EXCLUSIVE_MNEMONICS='vpternlog[dq]|vpmov[bwdq]2m|vpmovm2[bwdq]|vrndscale(ps|pd|ss|sd)|vfixupimm(ps|pd|ss|sd)|vgetexp(ps|pd|ss|sd)|vrcp14(ps|pd|ss|sd)|vrsqrt14(ps|pd|ss|sd)|vpcompress[bwdq]|vpexpand[bwdq]|vpconflict[dq]|vplzcnt[dq]|v4fmaddps|v4fmaddss|v4fnmaddps|v4fnmaddss|vp4dpwssd(s)?'
+
has_avx512_or_above() {
- grep -qE '%zmm[0-9]+|\{%k[1-7]\}' <<<"$1"
+ local asm="$1"
+ # %zmm: the 512-bit register itself, exact.
+ # %k0-%k7: the opmask registers, whether written freestanding as a plain
+ # operand (kmovw %eax,%k1, kortestw %k1,%k1) or inside the "{%k1}"
+ # write-mask suffix on another instruction -- the same "%k[0-7]" text
+ # matches both shapes, k0 included (the old pattern only matched k1-7
+ # inside braces and missed both freestanding operands and k0 entirely).
+ # "{z}": the zero-masking suffix, meaningless outside EVEX.
+ # %[xy]mm16-31: the extended register numbers VEX cannot address at all
+ # (VEX is 4 register-select bits, 0-15 only); any hit is EVEX, i.e.
+ # AVX-512 or AVX512VL.
+ grep -qE '%zmm[0-9]+|%k[0-7]\b|\{z\}|%[xy]mm(1[6-9]|2[0-9]|3[01])\b' <<<"$asm" \
+ && return 0
+ grep -qE "[[:space:]]($AVX512_EXCLUSIVE_MNEMONICS)([[:space:]]|\$)" <<<"$asm"
}
# 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.
+# load/store, and gather. A hit here is unambiguous.
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'
+# "vp"-mnemonics that are legal under plain AVX (they shuffle/test bits
+# rather than do 256-bit *integer arithmetic*, the actual AVX/AVX2 line,
+# review-isalinux.md Runde 2 Auflage d) despite starting with "vp" like
+# every genuine AVX2 integer op does. Excluded from the vp*+%ymm rule below
+# so that rule stays exact rather than over-firing on these.
+AVX2_FLOAT_OR_PERMUTE_EXCEPTIONS='vperm2f128|vpermilps|vpermilpd|vptest'
+
has_avx2_marker() {
- grep -qE "[[:space:]]($AVX2_ONLY_MNEMONICS)([[:space:]]|\$)" <<<"$1"
+ local asm="$1"
+ if grep -qE "[[:space:]]($AVX2_ONLY_MNEMONICS)([[:space:]]|\$)" <<<"$asm"; then
+ return 0
+ fi
+ # Any "vp*" integer mnemonic (not one of the float/permute exceptions
+ # above) on the same line as a %ymm operand is unambiguously AVX2: plain
+ # AVX never defined a 256-bit integer instruction at all, so there is no
+ # legal AVX reading of e.g. "vpaddd %ymm1,%ymm0,%ymm0". This closes the
+ # gap the K1 review found: a sandybridge/ivybridge/piledriver-tier module
+ # accidentally built with -mavx2 and using only vpaddd/vpand/vpcmpeqd on
+ # %ymm (none of which is in AVX2_ONLY_MNEMONICS) used to pass this guard
+ # vacuously.
+ local candidates
+ candidates="$(grep -E '[[:space:]]vp[a-z0-9]+[[:space:]].*%ymm[0-9]+' <<<"$asm" || true)"
+ [ -n "$candidates" ] || return 1
+ grep -vE "[[:space:]]($AVX2_FLOAT_OR_PERMUTE_EXCEPTIONS)[[:space:]]" <<<"$candidates" | grep -q .
}
# --- tier table: llama.cpp GGML_CPU_ALL_VARIANTS, x86, non-MSVC branch -----
@@ -137,6 +193,55 @@ tier_of_variant() {
return 1
}
+# BLOCKER B2 (review-isalinux.md Runde 2): a real SONAME sibling suffix is
+# ONLY digits separated by dots ("0", "0.1.2", the shape
+# libFoo.so -> libFoo.so.N -> libFoo.so.N.n.n symlink chains produce). The
+# old glob pattern ("$exact".[0-9]*) only required the suffix to START with
+# a digit, so "libggml-cpu-haswell.so.0.so" (extension exactly ".so",
+# LOADABLE by ggml's own dlopen scan -- see the "extension .0" comment
+# above find_variant_file in verify-sidecar-isa.sh) matched it and was
+# silently treated as an already-checked sibling, never disassembled. A
+# crafted or corrupted file only needs a digit as its first suffix
+# character to hide behind a real module that way. Anchored full-match
+# regex, not a glob, so "0.so" cannot sneak past as "starts with a digit".
+is_soname_suffix() {
+ [[ "$1" =~ ^[0-9]+(\.[0-9]+)*$ ]]
+}
+
+is_soname_sibling() {
+ local base="$1" exact="$2" suffix
+ case "$base" in
+ "$exact".*)
+ suffix="${base#"$exact".}"
+ is_soname_suffix "$suffix"
+ ;;
+ *)
+ return 1
+ ;;
+ esac
+}
+
+# BLOCKER B2, second half: classify_linux_module only proves a filename
+# LOOKS like a SONAME sibling; it never touches the filesystem, so it
+# cannot prove the bytes actually match. The caller (verify-sidecar-isa.sh,
+# which has both files on disk) MUST additionally prove that before
+# trusting "identical bytes already checked under that name" -- the claim
+# the guard used to make without ever measuring it (review-isalinux.md
+# Runde 2 B2: stage_dynamic_isa_companions's plain `cp` happens to
+# dereference symlinks into identical bytes today, but this guard exists
+# to measure the packaged output, not to trust the build step that
+# produced it).
+# $1: the sibling file's path
+# $2: the canonical (already-classified, already-disassembled) file's
+# path
+# Returns 0 if the two files are byte-identical (cmp -s), 1 otherwise
+# (including either file missing).
+verify_sibling_identical_bytes() {
+ local sibling="$1" canonical="$2"
+ [ -f "$sibling" ] && [ -f "$canonical" ] || return 1
+ cmp -s "$sibling" "$canonical"
+}
+
# 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
@@ -176,21 +281,17 @@ classify_linux_module() {
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
+ if is_soname_sibling "$base" "$exact"; then
+ printf 'sibling:%s\n' "$exact"
+ return 0
+ fi
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
+ if is_soname_sibling "$base" "$exact"; then
+ printf 'sibling:%s\n' "$exact"
+ return 0
+ fi
done
printf 'unknown\n'
return 1
@@ -244,3 +345,92 @@ evaluate_module_asm() {
;;
esac
}
+
+# BLOCKER B1 (review-isalinux.md Runde 2): evaluate_module_asm above only
+# ever asks "does the text I was handed contain an AVX marker". Handed an
+# EMPTY string (objdump crashed, printed nothing, or its
+# `2>/dev/null`-swallowed stderr masked a real failure) every role except
+# baseline-with-a-hit reads that as "clean", exactly the fail-open hole the
+# review measured directly:
+# evaluate_module_asm baseline "" -> exit 0, "OK: ... carries no AVX-or-above instruction"
+# A real objdump -d dump of a compiled module is at minimum dozens of
+# instruction lines; this count is deliberately far below any real module
+# staged by build-llama.sh (the same "catch a broken parser, not bound a
+# real binary" reasoning win-isa-guard.mjs's own --min-lines already uses,
+# see verify-sidecar-isa.sh:616), so a real Linux run tightening this
+# further is expected, not a sign this number was wrong.
+MIN_DISASM_LINES=20
+
+# Count objdump/llvm-objdump AT&T-syntax instruction lines: an address,
+# a colon, then a tab (the disassembled-instruction shape every fixture in
+# scripts/__fixtures__/linux-isa/*.disasm.txt already uses, and the same
+# shape real objdump -d output has -- see e.g. " 401020:\tpush %rbp").
+# A label line ("0000000000401020 <fn_name>:") has no leading tab after its
+# colon and is correctly NOT counted.
+count_disasm_lines() {
+ grep -cE '^[[:space:]]*[0-9a-fA-F]+:[[:space:]]*[0-9a-fA-F][0-9a-fA-F ]*[[:space:]]' <<<"$1" || true
+}
+
+# Fail-closed gate for B1: a module whose disassembly has fewer than
+# MIN_DISASM_LINES real instruction lines never reaches has_avx_or_above et
+# al at all -- it is reported RED here, with its own message and, pointed
+# at by the caller, whatever objdump itself printed to stderr, rather than
+# silently reading "no AVX found in nothing" as a pass.
+# $1: disassembly text
+# $2: label for the message
+# $3: minimum line count (optional, default MIN_DISASM_LINES; the red
+# probe below can pass a lower bound for a deliberately tiny fixture)
+# stdout: "OK: ..." or "FAIL: ..."; returns 0 or 1.
+check_min_disasm_lines() {
+ local asm="$1" label="${2:-module}" min="${3:-$MIN_DISASM_LINES}" n
+ n="$(count_disasm_lines "$asm")"
+ if [ "$n" -lt "$min" ]; then
+ printf 'FAIL: %s: only %s disassembled instruction line(s) found (need >= %s); an empty or near-empty disassembly is not proof the module carries no AVX-or-above instruction, it means the disassembler produced nothing usable (crashed, printed an error, or was fed the wrong file) and every ISA verdict for this module is unproven\n' "$label" "$n" "$min"
+ return 1
+ fi
+ printf 'OK: %s: %s disassembled instruction line(s) found (>= %s), disassembly looks real\n' "$label" "$n" "$min"
+ return 0
+}
+
+# BLOCKER A2 (review-isalinux.md Runde 2): the Windows branch of
+# verify-sidecar-isa.sh proves both directions -- every staged module is a
+# KNOWN one (checked_base_modules loop) AND every EXPECTED base module was
+# actually found (the missing-name loop right after it), plus an exact
+# count match so a glob running empty or a name matching twice cannot pass
+# vacuously. The Linux branch used to only check ggml-base and ggml-vulkan
+# by name and relied on the "unrecognised module" catch-all for everything
+# else, which cannot notice an expected module that is simply ABSENT (an
+# absent file classifies nothing, so the catch-all never sees it). This is
+# the same check, Linux side, kept here (rather than inline in
+# verify-sidecar-isa.sh) so it can be proven by the selftest with a plain
+# list of names, no COMPANIONS_DIR needed.
+# $1: newline-separated list of base-module names actually classified
+# while walking the staged files (classify_linux_module's "base:"
+# branch only ever emits one name per exact filename, so duplicates
+# here mean two different staged filenames both matched the same
+# expected name, not a normal outcome)
+# stdout: "OK: ..." or "FAIL: ..."; returns 0 or 1.
+check_base_module_coverage() {
+ local found_csv="$1" name f found missing=() found_count=0
+ while IFS= read -r f; do
+ [ -n "$f" ] || continue
+ found_count=$((found_count + 1))
+ done <<<"$found_csv"
+ for name in "${EXPECTED_BASE_LINUX_MODULES[@]}"; do
+ found=""
+ while IFS= read -r f; do
+ [ "$f" = "$name" ] && { found=1; break; }
+ done <<<"$found_csv"
+ [ -n "$found" ] || missing+=("$name")
+ done
+ if [ "${#missing[@]}" -gt 0 ]; then
+ printf 'FAIL: expected base Linux module(s) missing from the companions directory: %s (EXPECTED_BASE_LINUX_MODULES); a partial build or a stage step silently dropping a file must turn this guard red, not pass on whatever happened to be there\n' "${missing[*]}"
+ return 1
+ fi
+ if [ "$found_count" -ne "${#EXPECTED_BASE_LINUX_MODULES[@]}" ]; then
+ printf 'FAIL: found %s base Linux module(s) but expected exactly %s (%s); a name matched twice would otherwise pass this guard vacuously\n' "$found_count" "${#EXPECTED_BASE_LINUX_MODULES[@]}" "${EXPECTED_BASE_LINUX_MODULES[*]}"
+ return 1
+ fi
+ printf 'OK: all %s expected base Linux module(s) present, no duplicates\n' "$found_count"
+ return 0
+}
diff --git a/scripts/verify-sidecar-isa.selftest.sh b/scripts/verify-sidecar-isa.selftest.sh
index 09c4335b..815eb6d6 100755
--- a/scripts/verify-sidecar-isa.selftest.sh
+++ b/scripts/verify-sidecar-isa.selftest.sh
@@ -91,6 +91,42 @@ assert_eq "an unrelated new .so is unknown (fail closed, the skeptic's actual fi
assert_eq "a plain typo/near-miss name is unknown, not fuzzy-matched" "unknown" \
"$(classify_linux_module libggml-cpu-haswel.so lib so || true)"
+# BLOCKER B2 (review-isalinux.md Runde 2): a versioned-looking suffix that
+# is NOT purely digits-and-dots (a loadable ".so" tacked back on the end,
+# or arbitrary text after the first digit) must never be trusted as a
+# SONAME sibling -- it is exactly the shape ggml's own loader (prefix
+# "libggml-cpu-", extension exactly ".so") would happily dlopen.
+assert_eq "libggml-cpu-haswell.so.0.so is unknown, NOT a sibling (loadable by ggml, must be disassembled, RED PROBE)" "unknown" \
+ "$(classify_linux_module libggml-cpu-haswell.so.0.so lib so || true)"
+assert_eq "libggml-base.so.1evil.so is unknown, NOT a sibling (RED PROBE)" "unknown" \
+ "$(classify_linux_module libggml-base.so.1evil.so lib so || true)"
+assert_eq "libggml-base.so.1 is still correctly a sibling (pure digit suffix, not regressed)" "sibling:libggml-base.so" \
+ "$(classify_linux_module libggml-base.so.1 lib so)"
+assert_eq "libggml-cpu-x64.so.1.2.3 is still correctly a sibling (multi-part digit suffix, not regressed)" "sibling:libggml-cpu-x64.so" \
+ "$(classify_linux_module libggml-cpu-x64.so.1.2.3 lib so)"
+
+echo "== verify_sibling_identical_bytes (B2, second half: bytes, not just filenames) =="
+sibling_scratch="$(mktemp -d)"
+printf 'identical-bytes' > "$sibling_scratch/canonical.so"
+printf 'identical-bytes' > "$sibling_scratch/sibling-same.so.1"
+printf 'DIFFERENT-bytes!' > "$sibling_scratch/sibling-different.so.1"
+if verify_sibling_identical_bytes "$sibling_scratch/sibling-same.so.1" "$sibling_scratch/canonical.so"; then
+ printf ' ok byte-identical sibling verified via cmp -s\n'; pass_count=$((pass_count + 1))
+else
+ printf ' FAIL byte-identical sibling should have verified\n' >&2; fail_count=$((fail_count + 1))
+fi
+if verify_sibling_identical_bytes "$sibling_scratch/sibling-different.so.1" "$sibling_scratch/canonical.so"; then
+ printf ' FAIL a sibling with DIFFERENT bytes must NOT verify (RED PROBE)\n' >&2; fail_count=$((fail_count + 1))
+else
+ printf ' ok a sibling with different bytes correctly fails verification (RED PROBE)\n'; pass_count=$((pass_count + 1))
+fi
+if verify_sibling_identical_bytes "$sibling_scratch/does-not-exist.so.1" "$sibling_scratch/canonical.so"; then
+ printf ' FAIL a missing sibling file must NOT verify (RED PROBE)\n' >&2; fail_count=$((fail_count + 1))
+else
+ printf ' ok a missing sibling file correctly fails verification (RED PROBE)\n'; pass_count=$((pass_count + 1))
+fi
+rm -rf "$sibling_scratch"
+
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)"
@@ -141,6 +177,76 @@ 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 "== has_avx512_or_above: AUFLAGE c, freestanding opmask/k0/AVX512VL on ymm/xmm =="
+avx512vl_mnemonic_ymm="$(fixture avx512vl-mnemonic-on-ymm.disasm.txt)"
+avx512_opmask_freestanding="$(fixture avx512-opmask-freestanding-leak-in-avx2.disasm.txt)"
+avx512_extended_register="$(fixture avx512-extended-register-leak-in-avx2.disasm.txt)"
+if has_avx512_or_above "$avx512vl_mnemonic_ymm"; then
+ printf ' ok an AVX-512-exclusive mnemonic (vpternlogd) on %%ymm, no zmm/mask in sight, IS caught (AVX512VL)\n'; pass_count=$((pass_count + 1))
+else
+ printf ' FAIL vpternlogd on %%ymm should be caught by has_avx512_or_above\n' >&2; fail_count=$((fail_count + 1))
+fi
+if has_avx512_or_above "$avx512_opmask_freestanding"; then
+ printf ' ok a freestanding opmask operand (kmovw %%eax,%%k1, no braces) IS caught\n'; pass_count=$((pass_count + 1))
+else
+ printf ' FAIL freestanding %%k1 opmask operand should be caught by has_avx512_or_above\n' >&2; fail_count=$((fail_count + 1))
+fi
+if has_avx512_or_above "kmovw %eax,%k0"; then
+ printf ' ok k0 specifically (previously excluded, k1-7 only) IS caught\n'; pass_count=$((pass_count + 1))
+else
+ printf ' FAIL k0 should be caught by has_avx512_or_above\n' >&2; fail_count=$((fail_count + 1))
+fi
+if has_avx512_or_above "$avx512_extended_register"; then
+ printf ' ok an extended EVEX-only register (%%ymm16-%%ymm31) with no mask/mnemonic hint IS caught\n'; pass_count=$((pass_count + 1))
+else
+ printf ' FAIL %%ymm16.. register should be caught by has_avx512_or_above (VEX cannot address it at all)\n' >&2; fail_count=$((fail_count + 1))
+fi
+if has_avx512_or_above "$clean_avx2"; then
+ printf ' FAIL clean-avx2 fixture must still NOT trip the widened has_avx512_or_above\n' >&2; fail_count=$((fail_count + 1))
+else
+ printf ' ok clean-avx2 fixture still does not trip the widened has_avx512_or_above (not over-firing)\n'; pass_count=$((pass_count + 1))
+fi
+
+echo "== has_avx2_marker: AUFLAGE d, precise vp*-integer-on-ymm detection =="
+avx2_integer_ymm_leak="$(fixture avx2-integer-ymm-leak-in-avx-only.disasm.txt)"
+clean_avx_only_vp_exceptions="$(fixture clean-avx-only-vp-exceptions.disasm.txt)"
+if has_avx2_marker "$avx2_integer_ymm_leak"; then
+ printf ' ok a plain vp*-integer mnemonic (vpaddd, not in the curated AVX2_ONLY_MNEMONICS list) on %%ymm IS caught\n'; pass_count=$((pass_count + 1))
+else
+ printf ' FAIL vpaddd on %%ymm should be caught by has_avx2_marker (plain AVX defines no 256-bit integer op at all)\n' >&2; fail_count=$((fail_count + 1))
+fi
+if has_avx2_marker "$clean_avx_only_vp_exceptions"; then
+ printf ' FAIL vpermilps/vptest on %%ymm are legal under plain AVX and must NOT trip has_avx2_marker (over-firing)\n' >&2; fail_count=$((fail_count + 1))
+else
+ printf ' ok vpermilps/vptest on %%ymm (the documented float/permute exceptions) do not trip has_avx2_marker\n'; pass_count=$((pass_count + 1))
+fi
+if has_avx2_marker " 401000: c5 f9 fe c1 vpaddd %xmm1,%xmm0,%xmm0"; then
+ printf ' FAIL vpaddd on %%xmm (legal under plain AVX at 128 bits) must NOT trip has_avx2_marker\n' >&2; fail_count=$((fail_count + 1))
+else
+ printf ' ok vpaddd on %%xmm does not trip has_avx2_marker (128-bit vp* is plain AVX, not AVX2)\n'; pass_count=$((pass_count + 1))
+fi
+
+echo "== evaluate_module_asm: the new detection wired into the actual ceiling decision =="
+set +e
+out="$(evaluate_module_asm avx2 "$avx512vl_mnemonic_ymm" "avx512vl-leak")"; status=$?
+set -e
+assert_eq "avx2/avx512vl-mnemonic-on-ymm exits 1 (RED PROBE, AUFLAGE c wired in)" "1" "$status"
+assert_eq "avx2/avx512vl-mnemonic-on-ymm verdict text (RED PROBE)" "FAIL: avx512vl-leak contains an AVX-512 instruction; this tier (AVX2 at most) must never reach AVX-512" "$out"
+
+set +e
+out="$(evaluate_module_asm avx2 "$avx512_opmask_freestanding" "opmask-leak")"; status=$?
+set -e
+assert_eq "avx2/opmask-freestanding-leak exits 1 (RED PROBE)" "1" "$status"
+
+set +e
+out="$(evaluate_module_asm avx-only "$avx2_integer_ymm_leak" "vp-ymm-leak")"; status=$?
+set -e
+assert_eq "avx-only/vp-integer-on-ymm-leak exits 1 (RED PROBE, AUFLAGE d wired in)" "1" "$status"
+assert_eq "avx-only/vp-integer-on-ymm-leak verdict text (RED PROBE)" "FAIL: vp-ymm-leak contains an AVX2-only instruction; this tier (SSE42 AVX F16C FMA at most) must never reach AVX2" "$out"
+
+out="$(evaluate_module_asm avx-only "$clean_avx_only_vp_exceptions" "clean-vp-exceptions")"; status=$?
+assert_eq "avx-only/clean-vp-exceptions (vpermilps, vptest) still exits 0 (not over-firing)" "0" "$status"
+
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"
@@ -179,6 +285,50 @@ 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 "== check_min_disasm_lines (BLOCKER B1: empty/near-empty disassembly must be RED) =="
+clean_baseline_realistic="$(fixture clean-baseline-realistic-size.disasm.txt)"
+
+set +e
+out="$(check_min_disasm_lines "" "empty-module")"; status=$?
+set -e
+assert_eq "empty disassembly exits 1 (RED PROBE, the exact bug the review measured: evaluate_module_asm baseline \"\" used to exit 0)" "1" "$status"
+assert_eq "empty disassembly verdict text (RED PROBE)" 'FAIL: empty-module: only 0 disassembled instruction line(s) found (need >= 20); an empty or near-empty disassembly is not proof the module carries no AVX-or-above instruction, it means the disassembler produced nothing usable (crashed, printed an error, or was fed the wrong file) and every ISA verdict for this module is unproven' "$out"
+
+set +e
+out="$(check_min_disasm_lines "$clean_baseline" "too-short-module")"; status=$?
+set -e
+assert_eq "a too-short real-looking disassembly (7 lines, below MIN_DISASM_LINES=20) exits 1 (RED PROBE)" "1" "$status"
+
+out="$(check_min_disasm_lines "$clean_baseline_realistic" "realistic-module")"; status=$?
+assert_eq "a realistically-sized disassembly (21 lines) exits 0" "0" "$status"
+
+# The deliberately-tiny decision-logic fixtures above (5-7 lines each) are
+# legitimate inputs to evaluate_module_asm/has_avx*_or_above directly (they
+# test the CLASSIFICATION rule, not module size), so check_min_disasm_lines
+# takes an explicit lower bound here the same way win-isa-guard.mjs's own
+# red probe passes --min-lines 0 for the same reason
+# (verify-sidecar-isa.sh:616-619).
+out="$(check_min_disasm_lines "$clean_baseline" "tiny-logic-fixture" 5)"; status=$?
+assert_eq "the same 7-line fixture passes with an explicit min of 5 (tiny logic fixtures are not themselves the bug)" "0" "$status"
+
+echo "== check_base_module_coverage (BLOCKER A2: a missing expected base module must be RED) =="
+full_base_csv="$(printf '%s\n' "${EXPECTED_BASE_LINUX_MODULES[@]}")"
+out="$(check_base_module_coverage "$full_base_csv")"; status=$?
+assert_eq "all 7 expected base modules present exits 0" "0" "$status"
+
+missing_mtmd_csv="$(printf '%s\n' ggml ggml-base ggml-vulkan llama llama-common llama-server-impl)"
+set +e
+out="$(check_base_module_coverage "$missing_mtmd_csv")"; status=$?
+set -e
+assert_eq "mtmd missing (e.g. dropped by a stage bug) exits 1 (RED PROBE, AUFLAGE b)" "1" "$status"
+assert_eq "mtmd missing verdict text (RED PROBE)" "FAIL: expected base Linux module(s) missing from the companions directory: mtmd (EXPECTED_BASE_LINUX_MODULES); a partial build or a stage step silently dropping a file must turn this guard red, not pass on whatever happened to be there" "$out"
+
+duplicate_csv="$(printf '%s\n' ggml ggml ggml-base ggml-vulkan llama llama-common llama-server-impl mtmd)"
+set +e
+out="$(check_base_module_coverage "$duplicate_csv")"; status=$?
+set -e
+assert_eq "a name matched twice (count mismatch) exits 1 (RED PROBE)" "1" "$status"
+
echo
echo "$pass_count passed, $fail_count failed"
[ "$fail_count" -eq 0 ] || exit 1
diff --git a/scripts/verify-sidecar-isa.sh b/scripts/verify-sidecar-isa.sh
index f9018482..62953cc5 100755
--- a/scripts/verify-sidecar-isa.sh
+++ b/scripts/verify-sidecar-isa.sh
@@ -641,6 +641,50 @@ fi
# --- The disassembler (Linux only from here on) -----------------------------
+# AUFLAGE e (review-isalinux.md Runde 2): objdump's `-D` disassembles EVERY
+# section, including .rodata/.data, and will happily print an instruction
+# mnemonic for whatever data bytes happen to live there -- a false alarm
+# that has nothing to do with the code this guard actually cares about.
+# `-d` (used below, both for objdump and llvm-objdump) is the deliberate
+# choice against that: it only disassembles sections objdump's own ELF
+# section-flag reading considers executable (SHF_EXECINSTR: .text, .plt,
+# .init, .fini, ...), so a constant table or string literal placed in
+# .rodata is never fed to the classifier at all. That is a real, structural
+# narrowing, not a guess.
+#
+# It does not fully retire the risk, and this guard does not pretend it
+# does: a linear disassembler walking an EXECUTABLE section can still
+# print a "false" instruction out of padding bytes, alignment NOPs, or an
+# inlined jump/lookup table placed inside .text next to real code -- the
+# exact class of finding review-k1-avx.md's "Zusatzbefund" hit on the
+# Windows side (dumpbin decoded verr/verw/vmread/vmwrite/vmcall/vmfunc out
+# of data bytes; win-isa-guard.mjs's fix was ownership resolution via the
+# linker .map, ordinary Linux objdump output has no equivalent). This
+# script's own header already explains why Linux does not need that
+# specific allowlist machinery (no statically-linked, runtime-dispatched
+# CRT/STL the way MSVC ships): the modules this guard checks are gcc-built
+# ggml/llama.cpp code with no comparable runtime-dispatch fast path, so an
+# UNCONDITIONAL AVX mnemonic anywhere in a baseline/sub-ceiling module's
+# executable section is already the K1 shape, not a legitimate self-guarded
+# fast path that needs dominance-checking to clear.
+#
+# How to tell a genuine hit from a data-byte misread if this guard ever
+# does go red on a real Linux build: the FAIL diagnostic below prints the
+# first 5 matching lines with their addresses. For each address, run
+# `objdump -d --no-show-raw-insn "$file" | grep -B5 -A2 '^ <addr>:'` (or
+# `nm -D "$file"` / `objdump -t "$file"` to find which symbol's range that
+# address falls in) and read the surrounding lines: real code disassembles
+# into a coherent instruction stream (a function prologue nearby, sane
+# operands, a `ret`/jump that makes sense as control flow); a data-byte
+# misread typically appears right after a function's actual `ret` -- inside
+# padding, an alignment NOP run, or a jump table -- and the "instructions"
+# immediately before/after it will themselves look like nonsense (odd
+# byte-length encodings, operands that reference nothing). If in doubt,
+# cross-check against the same file's .rodata contents (`objdump -s -j
+# .rodata "$file"`) for the same byte pattern -- data that legitimately
+# belongs in .rodata occasionally gets placed in a read-only .text-adjacent
+# section by the linker, and finding the exact bytes there settles it.
+#
# Every call site captures this function's stdout via `$(disassemble ...)`
# to get the disassembly text, so a diagnostic printed with plain vlog (which
# writes to stdout) would be silently swallowed INTO that captured text
@@ -651,21 +695,48 @@ fi
# substitution.
log_disassembler_choice() { printf '\033[1;36m[verify-sidecar-isa]\033[0m %s\n' "$*" >&2; }
+# BLOCKER B1 (review-isalinux.md Runde 2): this used to run every
+# disassembler with `2>/dev/null`, so a failing invocation (wrong flag,
+# unreadable file, a disassembler that does not understand this ELF at all)
+# printed NOTHING on stdout, the caller read that as "no AVX-or-above
+# instruction found", and the whole module passed vacuously green -- the
+# doctrine this very script states two lines above the old code ("a guard
+# that silently skips its own check when its tool is missing is worse than
+# no guard") violated by the one disassembler call that actually runs the
+# check. Fixed the same way R5 already fixed the Windows half of this
+# script (dumpbin, no `2>/dev/null`, see verify-sidecar-isa.sh:342-348): a
+# nonzero exit is captured explicitly (never left to `set -e` abort the
+# whole script silently mid-command-substitution, the same
+# find_variant_file trap documented above) and turns into a vdie carrying
+# the disassembler's own stderr, not a quiet pass.
DISASSEMBLER_LOGGED=""
disassemble() {
local file="$1"
+ local err_tmp; err_tmp="$(mktemp)"
+ local out="" status=0 tool=""
if command -v objdump >/dev/null 2>&1; then
- [ -n "$DISASSEMBLER_LOGGED" ] || { log_disassembler_choice "disassembler: objdump ($(command -v objdump))"; DISASSEMBLER_LOGGED=1; }
- objdump -d "$file" 2>/dev/null
+ tool="objdump ($(command -v objdump))"
+ [ -n "$DISASSEMBLER_LOGGED" ] || { log_disassembler_choice "disassembler: $tool"; DISASSEMBLER_LOGGED=1; }
+ out="$(objdump -d "$file" 2>"$err_tmp")" || status=$?
elif command -v llvm-objdump >/dev/null 2>&1; then
- [ -n "$DISASSEMBLER_LOGGED" ] || { log_disassembler_choice "disassembler: llvm-objdump ($(command -v llvm-objdump))"; DISASSEMBLER_LOGGED=1; }
- llvm-objdump -d "$file" 2>/dev/null
+ tool="llvm-objdump ($(command -v llvm-objdump))"
+ [ -n "$DISASSEMBLER_LOGGED" ] || { log_disassembler_choice "disassembler: $tool"; DISASSEMBLER_LOGGED=1; }
+ out="$(llvm-objdump -d "$file" 2>"$err_tmp")" || status=$?
elif command -v dumpbin >/dev/null 2>&1; then
- [ -n "$DISASSEMBLER_LOGGED" ] || { log_disassembler_choice "disassembler: dumpbin ($(command -v dumpbin))"; DISASSEMBLER_LOGGED=1; }
- dumpbin /disasm "$file" 2>/dev/null
+ tool="dumpbin ($(command -v dumpbin))"
+ [ -n "$DISASSEMBLER_LOGGED" ] || { log_disassembler_choice "disassembler: $tool"; DISASSEMBLER_LOGGED=1; }
+ out="$(dumpbin /disasm "$file" 2>"$err_tmp")" || status=$?
else
+ rm -f "$err_tmp"
vdie "no disassembler found (need objdump, llvm-objdump or dumpbin), cannot prove the ISA claims on this runner"
fi
+ if [ "$status" -ne 0 ]; then
+ local err_text; err_text="$(cat "$err_tmp")"
+ rm -f "$err_tmp"
+ vdie "$tool failed to disassemble $file (exit $status): ${err_text:-<no stderr output>}. A failed disassembler run is not the same as 'no AVX found' and must not be read as a pass (BLOCKER B1, review-isalinux.md Runde 2)"
+ fi
+ rm -f "$err_tmp"
+ printf '%s' "$out"
}
# has_avx_or_above and the tier-ceiling rules live in one shared file
@@ -711,6 +782,7 @@ 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=()
+found_base_names=()
for base in "${staged_files[@]}"; do
cls="$(classify_linux_module "$base" "$LIB_PREFIX" "$LIB_EXT" || true)"
case "$cls" in
@@ -718,6 +790,7 @@ for base in "${staged_files[@]}"; do
name="${cls#base:}"
module_role["$COMPANIONS_DIR/$base"]="baseline"
module_label["$COMPANIONS_DIR/$base"]="$name"
+ found_base_names+=("$name")
;;
variant:*)
rest="${cls#variant:}"
@@ -727,7 +800,25 @@ for base in "${staged_files[@]}"; do
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"
+ # BLOCKER B2, second half (review-isalinux.md Runde 2): a filename
+ # that LOOKS like a SONAME sibling is not proof it IS one. Measure
+ # it: the sibling must be byte-identical (cmp -s) to the canonical
+ # file this guard is about to disassemble under its own name. A
+ # sibling whose canonical file never got staged, or whose bytes
+ # differ, is exactly the case this guard exists to catch (a crafted
+ # or corrupted "sibling" that ggml's loader would happily dlopen)
+ # and must be treated the same as any other unrecognised module, not
+ # silently trusted on filename alone.
+ canonical="${cls#sibling:}"
+ canonical_path="$COMPANIONS_DIR/$canonical"
+ sibling_path="$COMPANIONS_DIR/$base"
+ if [ ! -e "$canonical_path" ]; then
+ unclassified+=("$base (claims to be a SONAME sibling of $canonical, but $canonical is not staged in $COMPANIONS_DIR, cannot verify identical bytes)")
+ elif verify_sibling_identical_bytes "$sibling_path" "$canonical_path"; then
+ vlog "$base: SONAME sibling of $canonical, bytes verified identical (cmp -s), not disassembled again"
+ else
+ unclassified+=("$base (claims to be a SONAME sibling of $canonical but its bytes DIFFER, cmp -s failed; refusing to trust an unverified sibling)")
+ fi
;;
*)
unclassified+=("$base")
@@ -735,7 +826,20 @@ for base in "${staged_files[@]}"; do
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"
+ 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 byte-verified SONAME 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"
+fi
+
+# BLOCKER A2 (review-isalinux.md Runde 2): the classification loop above
+# only proves every STAGED file is recognised; it says nothing about a
+# module that is simply ABSENT (an absent file classifies nothing, so it
+# never reaches the loop at all). check_base_module_coverage closes that,
+# the Linux equivalent of the Windows branch's checked_base_modules
+# presence-and-count check above.
+found_base_csv="$(printf '%s\n' "${found_base_names[@]}")"
+if verdict="$(check_base_module_coverage "$found_base_csv")"; then
+ vlog "$verdict"
+else
+ vdie "$verdict"
fi
fail_count=0
@@ -743,11 +847,22 @@ for path in "${!module_role[@]}"; do
role="${module_role[$path]}"
label="${module_label[$path]} ($path)"
asm="$(disassemble "$path")"
+ # BLOCKER B1 (review-isalinux.md Runde 2): an empty or near-empty
+ # disassembly must fail its OWN check before it ever reaches
+ # evaluate_module_asm, not read as "no AVX found, so it passes". See
+ # check_min_disasm_lines's own header for why 20 and not a tighter bound.
+ if lines_verdict="$(check_min_disasm_lines "$asm" "$label")"; then
+ vlog "$lines_verdict"
+ else
+ printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s\n' "$lines_verdict" >&2
+ fail_count=$((fail_count + 1))
+ continue
+ fi
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" >&2
- grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || true
+ grep -E '%[xyz]mm[0-9]+|%k[0-7]\b|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)|[[:space:]]k[a-z]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || true
fail_count=$((fail_count + 1))
fi
done
@@ -756,11 +871,18 @@ exe_name="$(out_name_for "$TRIPLE")"
exe_path="$BIN_DIR/$exe_name"
if [ -f "$exe_path" ]; then
asm="$(disassemble "$exe_path")"
- if verdict="$(evaluate_module_asm baseline "$asm" "$exe_name ($exe_path)")"; then
- vlog "$verdict"
+ exe_label="$exe_name ($exe_path)"
+ if lines_verdict="$(check_min_disasm_lines "$asm" "$exe_label")"; then
+ vlog "$lines_verdict"
+ if verdict="$(evaluate_module_asm baseline "$asm" "$exe_label")"; then
+ vlog "$verdict"
+ else
+ printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s\n' "$verdict" >&2
+ grep -E '%[xyz]mm[0-9]+|%k[0-7]\b|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)|[[:space:]]k[a-z]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || true
+ fail_count=$((fail_count + 1))
+ fi
else
- printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s\n' "$verdict" >&2
- grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&2 || true
+ printf '\033[1;31m[verify-sidecar-isa] FAIL:\033[0m %s\n' "$lines_verdict" >&2
fail_count=$((fail_count + 1))
fi
else