SIGN IN SIGN UP

fix: load the AMD backend at runtime (#359) (#402)

## Summary

- Restore Linux AMD detection for `default-features = false` consumers without adding libdrm `NEEDED` entries to the main executable or downstream binaries.
- Move the existing libamdgpu_top reader into a separately packaged `liball_smi_amd.so` companion and load it through a narrow versioned C ABI.

## Implementation

- Add safe absolute-path discovery, canonicalization, world-writable-path rejection, nullable function-table validation, exact host/plugin version checks, wire-format validation, serialized calls, and graceful load/sampling failure handling.
- Keep AMD PCI/sysfs detection and the loader enabled on every glibc Linux feature configuration while retaining `amd` as an accepted compatibility no-op.
- Report the loaded plugin path, plugin/ABI/libamdgpu_top versions, and exact unavailable reason through the existing `amd.libamdgpu_top.abi` doctor check, distinct from musl and cargo-feature state.
- Package the companion beside Linux release binaries, under Homebrew `lib/all-smi`, and under Debian `/usr/lib/all-smi`, with old-tag compatibility in self-healing release/package workflows.
- Document deployment, search order, Cargo-install limitations, architecture, and linkage verification.

## Validation

- `cargo fmt --all -- --check`
- `cargo check -p all-smi --lib --tests`
- `cargo check -p all-smi-amd-plugin --lib --tests`
- `cargo check -p all-smi --bin all-smi`
- `cargo check -p all-smi --no-default-features --lib`
- `cargo test -p all-smi --lib device::readers::amd::tests::`
- `cargo test -p all-smi --no-default-features --lib device::readers::amd::tests::`
- `cargo test -p all-smi-amd-plugin --lib tests::metadata_matches_exact_dependency_pin`
- `cargo test -p all-smi-amd-plugin --lib reader::tests::`
- `cargo clippy -p all-smi --lib --tests -- -D warnings`
- `cargo clippy -p all-smi-amd-plugin --lib --tests -- -D warnings`
- Debug builds plus `objdump -p`: the host lists no libdrm dependency; the companion lists `libdrm.so.2` and `libdrm_amdgpu.so.1`.
- `all-smi doctor --only amd --json`: explicit companion path passes with plugin 0.26.1 / ABI v1 / libamdgpu_top 0.11.5; a nonexistent path warns accurately and startup succeeds.
- Modified workflow YAML parses; modified Homebrew step bodies pass `bash -n`; root crate packaging succeeds.

## Review notes

- Correctness review verified every acceptance path, buffer ownership, version refusal, feature independence, package layout, and graceful fallback behavior.
- Security review verified no current-directory or bare-name lookup, canonical absolute loading, world-writable rejection, bounded ABI-header reads, null function-pointer rejection, and paired opaque-handle/buffer destruction.
- Performance review verified one-time plugin discovery/loading, one reader per detected AMD backend, serialized FFI access, cached static device data, and unchanged native sampling behavior inside the companion.
- The available Linux aarch64 runner exposes NVIDIA hardware rather than AMD hardware, so live AMD sampling could not be exercised locally; the existing libamdgpu_top reader was moved without behavioral changes and all loader/linkage/doctor paths were exercised.

Closes #359
J
Jeongkyu Shin committed
d602fe6a9ddafc2901ffc7bb4ece0b36925fb1b7
Parent: 427ae94
Committed by GitHub <noreply@github.com> on 8/24/2026, 3:06:43 PM