You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support cross-compilation of bare-metal binaries? #269
Embedded platforms where you cannot spare a byte should not add anything in the executable. Instead they should record the hash of every executable in a database and associate the hash with its Cargo.lock, compiler and LLVM version, build date, etc.
However, ELF executables (the format typically used produced by rustc when building bare-metal code) has the concept of a 'NOLOAD' section - this would leave the audit data in the ELF file, but it would not take up any space on the microcontroller. We already use this trick for debug info, defmt logs, etc, so it seems an ideal place to store dependency information.
I naively tried to just build a thumbv8m.main-none-eabi binary with cargo auditable build on my macOS machine, and I got a linker error:
Adding linker = "rust-lld" to .cargo/config.toml allowed the build to work, but it's not ideal (and most people won't have that set).
$ cargo audit bin ../target/thumbv8m.main-none-eabi/release/standalone-hello Fetching advisory database from `https://github.com/RustSec/advisory-db.git` Loaded 1277 security advisories (from /Users/jonathan/.cargo/advisory-db) Updating crates.io index Found 'cargo auditable' data in ../target/thumbv8m.main-none-eabi/release/standalone-hello (59 dependencies)Crate: bare-metalVersion: 0.2.5Warning: unmaintainedTitle: bare-metal is deprecatedDate: 2026-04-23ID: RUSTSEC-2026-0110URL: https://rustsec.org/advisories/RUSTSEC-2026-0110warning: 1 allowed warning found in ../target/thumbv8m.main-none-eabi/release/standalone-hello
/// Such setups are exceptionally rare and frankly it's a misconfiguration
/// that will break more than just cargo auditable, but I am feeling generous.
I mean, basically all the Rust bare-metal targets are configured to use rust-lld directly, so it's not that rare.
Unfortunately I don't know how to work out that rustc is using a bare linker, beyond holding a big database of target strings that will often be slightly out of date.
But the output is not machine-readable, and it actually compiles and links a small binary, which is pretty slow.
I'll try to implement the RUSTC_BOOTSTRAP JSON option and see if that works.
However, ELF executables (the format typically used produced by rustc when building bare-metal code) has the concept of a 'NOLOAD' section - this would leave the audit data in the ELF file, but it would not take up any space on the microcontroller.
cargo-auditable already omits SHF_ALLOC on ELF.
It would be great news if we happened to already pass the correct flags! I would like to get an experimental confirmation of this, however. @jonathanpallant now that you got it working, do you think you could measure the flashed binary size before and after to see if the audit info is correctly omitted?
Activity
bjorn3 commentedon Sep 30, 2026
cargo-auditable already omits SHF_ALLOC on ELF.
It failed to detect that you are using a bare linker. It looks at the
-Clinkerargument passed, not at target defaults:cargo-auditable/cargo-auditable/src/rustc_arguments.rs
Lines 40 to 62 in fb744c1
jonathanpallant commentedon Sep 30, 2026
Ah.
Adding
linker = "rust-lld"to.cargo/config.tomlallowed the build to work, but it's not ideal (and most people won't have that set).I mean, basically all the Rust bare-metal targets are configured to use
rust-llddirectly, so it's not that rare.Unfortunately I don't know how to work out that
rustcis using a bare linker, beyond holding a big database of target strings that will often be slightly out of date.Shnatsel commentedon Sep 30, 2026
I think there are two options to get this info from rustc. One is this:
Requires nightly, but we can just pass
RUSTC_BOOTSTRAP=1, and if it breaks then all non-bare-metal platforms will keep working so it's probably fine.Technically we also have this on stable:
But the output is not machine-readable, and it actually compiles and links a small binary, which is pretty slow.
I'll try to implement the
RUSTC_BOOTSTRAPJSON option and see if that works.It would be great news if we happened to already pass the correct flags! I would like to get an experimental confirmation of this, however. @jonathanpallant now that you got it working, do you think you could measure the flashed binary size before and after to see if the audit info is correctly omitted?
jonathanpallant commentedon Sep 30, 2026
No change in code size. But here's the section:
Shnatsel commentedon Oct 2, 2026
Done in #270
Release as v0.7.7