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(sidecar): make the ISA guard actually run on Linux, and add the RPATH guard (K1, Runde 2 B1/B3)

purpleac45d9033431
diff --git a/scripts/verify-sidecar-isa.sh b/scripts/verify-sidecar-isa.sh
index fba53583..5702cb68 100755
--- a/scripts/verify-sidecar-isa.sh
+++ b/scripts/verify-sidecar-isa.sh
@@ -9,14 +9,15 @@
# 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" CPU variant, and llama-server / ggml-base
-# themselves) 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).
+# 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
@@ -67,13 +68,28 @@ esac
COMPANIONS_DIR="$(resource_llama_dir_for "$TRIPLE")"
[ -d "$COMPANIONS_DIR" ] || vdie "no companion directory at $COMPANIONS_DIR, build first (scripts/build-llama.sh $TRIPLE)"
-# Companion files are named ggml-cpu-<variant>.<ext> possibly with a version
-# suffix on Linux (SONAME symlinks, dereferenced to real files by
-# stage_dynamic_isa_companions, see there). Match by prefix, same rule ggml
-# itself uses to find them at runtime.
+# Companion files are named ggml-cpu-<variant>.<ext> on Windows, but
+# libggml-cpu-<variant>.<ext> on Linux: ggml/CMakeLists.txt only strips the
+# "lib" prefix "if (WIN32)", so a pattern with no leading wildcard never
+# matches on Linux at all (this was BLOCKER B1: the guard never ran
+# correctly there, neither green nor red for the right reason). The leading
+# "*" makes an optional "lib" prefix match on both platforms; the variant
+# name and extension stay anchored so the widened glob cannot accidentally
+# pick up an unrelated file (a name that merely contains the variant name
+# as a substring, or a file with a different extension, still fails to
+# match). Possibly with a version suffix on Linux (SONAME symlinks,
+# dereferenced to real files by stage_dynamic_isa_companions, see there).
find_variant_file() {
local variant="$1"
- find "$COMPANIONS_DIR" -maxdepth 1 -type f -iname "ggml-cpu-${variant}.${LIB_EXT}*" -print -quit
+ find "$COMPANIONS_DIR" -maxdepth 1 -type f -iname "*ggml-cpu-${variant}.${LIB_EXT}*" -print -quit
+}
+
+# Same "lib" prefix rule applies to every other companion module name
+# (ggml-base, ggml-vulkan, ...), so every lookup in this script goes
+# through one of these two helpers rather than re-typing the glob.
+find_named_module() {
+ local name="$1"
+ find "$COMPANIONS_DIR" -maxdepth 1 -type f -iname "*${name}.${LIB_EXT}*" -print -quit
}
missing=()
@@ -88,22 +104,75 @@ if [ "${#missing[@]}" -gt 0 ]; then
fi
vlog "all ${#EXPECTED_VARIANTS[@]} expected CPU variants present for $TRIPLE"
-f="$(find_variant_file vulkan)"
+f="$(find_named_module ggml-vulkan)"
[ -n "$f" ] || vdie "ggml-vulkan.$LIB_EXT missing from $COMPANIONS_DIR, the GPU backend did not build as a loadable module"
vlog "ggml-vulkan.$LIB_EXT present"
+GGML_BASE_FILE="$(find_named_module ggml-base)"
+[ -n "$GGML_BASE_FILE" ] || vdie "ggml-base.$LIB_EXT missing from $COMPANIONS_DIR, the shared runtime every backend links against did not build"
+vlog "ggml-base.$LIB_EXT present at $GGML_BASE_FILE"
+
+# --- RPATH/RUNPATH: no leftover build-tree path (BLOCKER B3) ---------------
+#
+# CMake writes a build-tree RPATH into linked ELF files by default, even
+# with no explicit RPATH line anywhere in CMakeLists.txt
+# (CMAKE_BUILD_WITH_INSTALL_RPATH defaults to OFF). That build-tree RPATH is
+# very often an ABSOLUTE path into the CI runner's own build directory, a
+# path that will not exist once the sidecar ships. Grepping CMakeLists.txt
+# source for the literal word "RPATH" (what this project did before) cannot
+# see this: it is CMake's own default, not a line anyone wrote. The only
+# way to know is to read what actually landed in the binary.
+check_no_absolute_build_rpath() {
+ local file="$1"
+ command -v readelf >/dev/null 2>&1 || { vlog "readelf not available, skipping RPATH check for $file"; return 0; }
+ local tag_lines
+ tag_lines="$(readelf -d "$file" 2>/dev/null | grep -E '\(RPATH\)|\(RUNPATH\)' || true)"
+ if [ -z "$tag_lines" ]; then
+ vlog "$file: no RPATH/RUNPATH entry"
+ return 0
+ fi
+ # readelf prints the entry as e.g.
+ # "0x000000000000001d (RUNPATH) Library runpath: [/home/runner/work/.../build/bin]"
+ # An entry that starts with "/" inside the brackets is an absolute path;
+ # "$ORIGIN" is the only form this project's build is supposed to emit.
+ if grep -qE 'Library r(un)?path: \[/' <<<"$tag_lines"; then
+ vdie "$file carries an absolute build-tree path in RPATH/RUNPATH: $tag_lines"
+ fi
+ vlog "$file: RPATH/RUNPATH present and not an absolute build-tree path: $tag_lines"
+}
+
+if [[ "$TRIPLE" == *-linux-* ]]; then
+ check_no_absolute_build_rpath "$GGML_BASE_FILE"
+ exe_check_path="$BIN_DIR/$(out_name_for "$TRIPLE")"
+ [ -f "$exe_check_path" ] && check_no_absolute_build_rpath "$exe_check_path"
+fi
+
# --- The disassembler ------------------------------------------------------
+# 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
+# instead of ever reaching the terminal, defeating the point of logging it
+# at all (found the hard way: the tool-name line never appeared, even though
+# the code "ran"). log_disassembler_choice writes to stderr (>&2)
+# specifically so it survives being called from inside a command
+# substitution.
+log_disassembler_choice() { printf '\033[1;36m[verify-sidecar-isa]\033[0m %s\n' "$*" >&2; }
+
+DISASSEMBLER_LOGGED=""
disassemble() {
local file="$1"
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
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
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
else
- vdie "no disassembler found (need objdump, llvm-objdump or dumpbin)"
+ vdie "no disassembler found (need objdump, llvm-objdump or dumpbin), cannot prove the ISA claims on this runner"
fi
}
@@ -127,20 +196,29 @@ for variant in "${BASELINE_TARGETS[@]}"; do
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
- grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&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 "$variant ($f): no AVX-or-above instruction found, as expected"
fi
done
+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" ]; then
asm="$(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
- grep -E '%[yz]mm[0-9]+|[[:space:]]v[a-z0-9]{2,}([[:space:]]|$)' <<<"$asm" | head -5 >&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 "$exe_name: no AVX-or-above instruction found, as expected"