eb-local.isa_audit

module eb-local.isa_audit  src/isa_audit.zig[source][autodoc]

eb-local audit-isa: the instructions in an installed prefix that need a CPU feature the target does not have. Every ELF file under the path is disassembled by objdump; each instruction’s mnemonic, encoding and vector width select the features it needs from tables generated by tools/isa_tables/gen.py, and a feature missing from the target’s set is a violation. Code that selects its instruction set at run time is listed in an allow file and reported as dispatch, which does not fail the audit.

Types

pub const Mask = u256[source][autodoc]

A set of features, one bit per interned name.

pub const Arch = enum[source][autodoc]

The architectures the audit reads: the machine of the ELF file selects one.

x86_64[source]
aarch64[source]
pub const Target = struct[source][autodoc]

An EESSI software subdirectory, its architecture and the features its CPU has.

name: []const u8[source]
arch: Arch[source]
has: Mask[source]
pub const Db = struct[source][autodoc]

The tables of the generator, parsed.

names: std.ArrayList([]const u8) = .empty[source]
ids: std.StringHashMapUnmanaged(u8) = .empty[source]
x86_index: std.StringHashMapUnmanaged(Span) = .empty[source]
x86_rows: std.ArrayList(X86Row) = .empty[source]
a64_index: std.StringHashMapUnmanaged(std.ArrayList(Rule)) = .empty[source]
a64_any: std.ArrayList(Rule) = .empty[source]
targets: std.ArrayList(Target) = .empty[source]
shstk: u8 = 0[source]
pub fn load(a: Allocator) LoadError!*Db[source][autodoc]

Parse the embedded tables into a database allocated from a.

pub fn idOf(db: *const Db, feature_name: []const u8) ?u8[source][autodoc]

The id a feature name has, if the tables mention it.

pub fn nameOf(db: *const Db, feature: u8) []const u8[source][autodoc]

The name of a feature id.

pub fn target(db: *const Db, want: []const u8) ?Target[source][autodoc]

The target want names: a full EESSI subdirectory, or a trailing part of one that only one subdirectory ends with.

pub const Verdict = struct[source][autodoc]

What one instruction needs: the features the target must have, the features the tables do not classify, and whether the mnemonic is unknown for a vector encoding.

need: Mask = 0[source]
unclassified: Mask = 0[source]
unknown_mnemonic: bool = false[source]
zmm: bool = false[source]
pub const Line = struct[source][autodoc]

One line of disassembly.

address: u64[source]
bytes: []const u8[source]
mnemonic: []const u8[source]
operands: []const u8[source]
pub const AllowEntry = struct[source][autodoc]

A package whose files hold code chosen at run time, and the features that code may use.

needle: []const u8[source]
mask: Mask[source]
pub const Finding = struct[source][autodoc]

One feature a file needs and the target lacks: how many instructions, the first one, and whether the allow list covers it.

feature: []const u8[source]
count: u64[source]
address: []const u8[source]
instruction: []const u8[source]
dispatch: bool[source]
pub const FileReport = struct[source][autodoc]

A file with at least one finding.

path: []const u8[source]
instructions: u64[source]
zmm: u64[source]
findings: []const Finding[source]
pub const Unclassified = struct[source][autodoc]

A feature or mnemonic the tables cannot judge, and how often it occurs.

name: []const u8[source]
kind: []const u8[source]
count: u64[source]
pub const Problem = struct[source][autodoc]

A file or directory the audit could not read or disassemble, and why.

path: []const u8[source]
message: []const u8[source]
pub const Report = struct[source][autodoc]

The result of an audit, and the document --json prints.

schema_version: u32 = jsonout.schema_version[source]
kind: []const u8 = "audit-isa"[source]
target: []const u8[source]
arch: []const u8[source]
files_audited: u64[source]
files_skipped: u64[source]
instructions: u64[source]
zmm: u64[source]
violation_count: u64[source]
dispatch_count: u64[source]
failed: bool[source]
files: []const FileReport[source]
unclassified: []const Unclassified[source]
errors: []const Problem[source]
pub const Options = struct[source][autodoc]

What the command line asks for.

path: []const u8[source]
target: []const u8[source]
json: bool = false[source]
allow: ?[]const u8 = null[source]
objdump: ?[]const u8 = null[source]

Error sets

pub const LoadError = Allocator.Error || error{BadTable}[source][autodoc]

Why Db.load read nothing: memory, or a table the generator did not write.

Functions

pub fn parseLine(line: []const u8) ?Line[source][autodoc]

Parse ADDRESS:<tab or spaces>BYTES<tab>MNEMONIC OPERANDS as GNU objdump and llvm-objdump print it; null for any other line. Instruction prefixes before the mnemonic are skipped, and a symbol or comment after the operands is cut.

pub fn x86Encoding(bytes: []const u8) u8[source][autodoc]

The encoding of an x86-64 instruction from its bytes: V for VEX, E for EVEX, X for XOP, L for the rest.

pub fn vectorWidth(operands: []const u8) u16[source][autodoc]

The widest vector register or memory operand the operands name, 0 for none.

pub fn aliasOf(mn: []const u8, buf: *[32]u8) ?[]const u8[source][autodoc]

The mnemonic of the instruction an assembler alias stands for (vcmpltps, vpcmpnleub, vpcomltb, pclmullqlqdq), written into buf.

pub fn classifyX86(db: *const Db, ln: Line) Verdict[source][autodoc]

What an x86-64 instruction needs.

pub fn classifyA64(db: *const Db, ln: Line) Verdict[source][autodoc]

What an aarch64 instruction needs: the feature of the first rule its mnemonic and operands match.

pub fn parseAllow(a: Allocator, db: *const Db, text: []const u8) Allocator.Error![]const AllowEntry[source][autodoc]

Parse “PACKAGE feature[,feature…] # reason” lines. A feature the tables do not name is ignored.

pub fn allowed(entries: []const AllowEntry, path: []const u8, feature: u8) bool[source][autodoc]

True when a file under /software/PACKAGE/ may use the feature.

pub fn renderText(a: Allocator, r: Report) Allocator.Error![]const u8[source][autodoc]

The text audit-isa prints for a report.

pub fn run(a: Allocator, o: Options, path_env: []const u8, tmpdir: []const u8, envp: proc.Envp) u8[source][autodoc]

Audit the ELF files under o.path against o.target: 0 when no instruction exceeds the target, 1 when one does, 2 on a usage or tool error.