Given a binary file and the source code used to produce it, is there a way of identifying what version of the compiler produced the binary file just from those two pieces of information.
Try strings executableFilePath | grep "rustc version 1"
For me, this seems to work:
$ cargo new hello_world
Creating binary (application) `hello_world` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ cd hello_world
$ cargo build --release
Compiling hello_world v0.1.0 (/home/frank/hello_world)
Finished `release` profile [optimized] target(s) in 0.08s
$ strings target/release/hello_world | grep "rustc version 1"
rustc version 1.84.0 (9fc6b4312 2025-01-07)
Note that this notable does work in --release
mode (i.e. without full debug information), at least with default compiler settings. Though I don’t know if it might no longer work if the binary had been stripped.
(You don’t need the source code, just the executable itself.)
1 Like
Typical strip leaves it, but you can
cargo clean \
&& cargo build --release \
&& strip -R .comment target/release/"$(basename "$(pwd)")" \
&& strings target/release/"$(basename "$(pwd)")" | grep 'rustc version'
And to see what's in there without strings
,
readelf -p .comment target/release/"$(basename "$(pwd)")"
(But this still isn't a security measure for various reasons; speaking very generally, compiler output can have tells.)