Two real x86-64 and ELF bugs that synthetic unit tests missed

When compiling portable Linux releases or writing binary relinkers and instruction-lowering passes (such as lowering FMA3 or AVX2 down to baseline AVX), a single unlowered instruction in a rarely executed branch raises SIGILL on older CPUs. Standard unit tests only catch code paths that actually run.

To verify binaries statically in CI, I built isa-audit: a zero-dependency, #![forbid(unsafe_code)] Rust tool that parses x86-64 ELF64 binaries, resynchronizes on STT_FUNC symbol boundaries, decodes legacy, REX, VEX, and EVEX instructions, and emits Text, JSON, or GitHub Code Scanning SARIF 2.1.0 reports.

Design constraints set before writing code

Bug 1: Symbol attribution dropped on relocatable object files

The initial ELF64 symbol loader ignored entries where st_value == 0 to filter out undefined external imports. Every synthetic linked ET_EXEC test passed because .text started at virtual address 0x401000.

As soon as the GCC ground-truth test compiled a real object file (g++ -c -O2 -mavx -mfma -o kernel.o), attribution for fma3_kernel silently returned None. In ET_REL object files, the first function in .text legitimately lives at offset 0x0, and multiple executable sections can share offset 0x0.

Fix: Replaced the heuristic with proper ELF semantics (st_shndx != SHN_UNDEF) and scoped symbol lookups by (section_index, vaddr) so symbols in separate relocatable sections never collide.

Bug 2: 26 false positives from baseline tzcnt

Following standard opcode tables, the decoder initially mapped F3 0F BC (tzcnt) to BMI1. Auditing isa-audit's own release binary caught the flaw immediately: it claimed a baseline x86-64-v1 Rust binary required x86-64-v3 because of 26 BMI1 instructions. Inspecting address 0x36574 in objdump -d showed why:

36570: 85 c0          test   %eax,%eax
36572: 74 0e          je     36582
36574: f3 0f bc c0    tzcnt  %eax,%eax   ; executes as rep bsf on pre-BMI1 CPUs

On pre-BMI1 x86-64 CPUs, F3 0F BC executes as rep bsf without raising #UD or SIGILL and returns the same result for non-zero inputs. Rust and LLVM intentionally emit it behind a zero check in baseline builds. Reclassifying F3 0F BC as baseline eliminated all 26 false positives while preserving strict detection for faulting VEX-encoded BMI1 instructions (andn, blsr, blsmsk, blsi, bextr).

Measured benchmarks

Single-threaded release build measured over 100 iterations on Linux x86-64:

Binary Executable bytes Instructions Recovery steps Throughput
isa-audit (self) 341,751 B 86,343 0 259.1 MiB/s (68.6M insns/s)
/usr/bin/objdump 274,050 B 65,085 0 281.6 MiB/s (70.1M insns/s)
/usr/bin/ls 134,923 B 30,891 0 Verified AVX and AVX-512 vs objdump

Every commit runs cargo fmt --check, cargo clippy --all-targets -- -D warnings, byte-by-byte ELF truncation fuzzing, six GCC ground-truth kernels, and cross-platform CLI integration tests across Ubuntu, macOS, and Windows in GitHub Actions.