# eb-local.elfcheck ::::{zig:module} eb-local.elfcheck :file: src/elfcheck.zig :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig `eb-local check`: what a program built by hand on EESSI depends on, and whether it can run here. It reads the ELF file's loader (PT_INTERP), run paths (DT_RPATH, DT_RUNPATH) and needed libraries (DT_NEEDED), finds each library as the loader would, and reports what breaks the "no LD_LIBRARY_PATH, one CPU target" rule: a foreign architecture, the host's loader or libraries under an EESSI stack, RUNPATH, a library not found, and run paths into another CPU target's software tree. :::: ## Types ::::{zig:type} eb-local.elfcheck.Elf :signature: pub const Elf = struct :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L34 What an ELF file says about its dynamic linking: its machine, its program interpreter (the loader), the libraries it names as `DT_NEEDED`, and its `DT_RPATH` and `DT_RUNPATH`; null where it has none. :::{zig:field} eb-local.elfcheck.Elf.machine :signature: machine: u16 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L35 ::: :::{zig:field} eb-local.elfcheck.Elf.interp :signature: interp: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L36 ::: :::{zig:field} eb-local.elfcheck.Elf.needed :signature: needed: []const []const u8 = &.{} :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L37 ::: :::{zig:field} eb-local.elfcheck.Elf.rpath :signature: rpath: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L38 ::: :::{zig:field} eb-local.elfcheck.Elf.runpath :signature: runpath: ?[]const u8 = null :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L39 ::: :::: ## Error sets ::::{zig:errorset} eb-local.elfcheck.ParseError :signature: pub const ParseError = error{ NotElf64, Unsupported, Truncated, Damaged } || sys.Error || Allocator.Error :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L47 Why `parse` read nothing: `NotElf64` for a file too short for an ELF header or without the ELF magic, `Unsupported` for a 32-bit or big-endian one, `Truncated` when the file ends before a part its headers name, and `Damaged` for a header field out of bounds, a string with no end, or a read that fails. :::: ## Functions :::{zig:function} eb-local.elfcheck.parse :signature: pub fn parse(a: Allocator, fd: sys.fd_t) ParseError!Elf :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L73 The dynamic-linking facts of the 64-bit little-endian ELF file open as `fd`; every string is copied into `a`. ::: :::{zig:function} eb-local.elfcheck.hostMachine :signature: pub fn hostMachine() u16 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L162 The ELF machine of this build, which is the node's. ::: :::{zig:function} eb-local.elfcheck.machineName :signature: pub fn machineName(m: u16) []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L173 The name `check` prints for the ELF machine `m`: `x86_64`, `aarch64`, `riscv64`, `i386`, `arm`, or "another architecture". ::: :::{zig:function} eb-local.elfcheck.loaderRoot :signature: pub fn loaderRoot(interp: []const u8) []const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L186 The loader's root directory from `PT_INTERP` (`dirname(dirname(interp))`), or `"/"` when the interpreter path has fewer than two parent directories. ::: :::{zig:function} eb-local.elfcheck.expandOrigin :signature: pub fn expandOrigin(a: Allocator, dir: []const u8, origin: []const u8) Allocator.Error![]const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L196 `dir` with $ORIGIN and ${ORIGIN} replaced by `origin`. ::: :::{zig:function} eb-local.elfcheck.targetOf :signature: pub fn targetOf(path: []const u8) ?[]const u8 :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L220 The CPU target of an EESSI software tree a path lies in: the parts after `/software/linux/` up to the next `software`, `modules` or `accel`, as EESSI and EESSI-extend lay out their trees; null outside one. ::: :::{zig:function} eb-local.elfcheck.isHostPath :signature: pub fn isHostPath(path: []const u8) bool :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L239 A host directory the EESSI compatibility layer replaces. ::: :::{zig:function} eb-local.elfcheck.parseLdSoConf :signature: pub fn parseLdSoConf(a: Allocator, text: []const u8, dirs: *std.ArrayList([]const u8), includes: *std.ArrayList([]const u8)) Allocator.Error!void :source: https://github.com/stackhands/eb-local/blob/629c1ef39cdece5bfa2145cc8e2e89ae7583d197/src/elfcheck.zig#L250 One ld.so.conf file: the directories it names go to `dirs` and the patterns of its `include` lines to `includes`, in file order. :::