A cargo subcommand that displays the Assembly, LLVM-IR, MIR and WASM generated for Rust source code.
console
$ cargo install cargo-show-asm
Platform support:
x86
, x86_64
, aarch64
, etc.Displaying:
```console Show the code rustc generates for any function
Usage: [-p SPEC] [--lib | --test TEST | --bench BENCH | --example EXAMPLE | --bin BIN] [--release |
--dev | --profile PROFILE] [--target TRIPLE] -C FLAG... -Z FLAG... [--native | --target-cpu CPU]
[--rust] [--simplify] -M ARG... [--intel | --att | --llvm | --llvm-input | --mir | --wasm |
--mca-intel | --mca-att] [--everything |
Usage: 1. Focus on a single assembly producing target: % cargo asm -p isin --lib # here we are targeting lib in isin crate 2. Narrow down a function: % cargo asm -p isin --lib from_ # here "from" is part of the function you are interested intel 3. Get the full results: % cargo asm -p isin --lib isin::base36::fromalphanum
Available positional items:
Available options:
-p, --package default
feature
--all-features Activate all available features
--features
You can start by running cargo asm
with no parameters - it will suggests how to narrow the
search scope - for workspace crates you need to specify a crate to work with, for crates
defining several targets (lib, binaries, examples) you need to specify exactly which target to
use. In a workspace cargo asm
lists only workspace members as suggestions but any crate from
workspace tree is available.
Once cargo asm
focuses on a single target it will run rustc producing assembly file and will
try to list of available public functions:
```console,ignore
$ cargo asm --lib
Try one of those
"<&T as core::fmt::Display>::fmt" [17, 12, 12, 12, 12, 19, 19, 12]
"<&mut W as core::fmt::Write>::writechar" [20]
"<&mut W as core::fmt::Write>::writefmt" [38]
"<&mut W as core::fmt::Write>::write_str" [90]
"
```
Name in quotes is demangled rust name, numbers in square brackets represent number of lines in asm file. Function with the same name can be present in several instances.
Specifying exact function name or a uniquely identifying part of it will print its assembly code
console,ignore
$ cargo asm --lib "cargo_show_asm::opts::focus::{{closure}}"
To pick between different alternatives you can either specify the index
console,ignore
$ cargo asm --lib "cargo_show_asm::opts::focus::{{closure}}" 2
Or start using full names with hex included:
```console,ignore $ cargo asm --lib --full-name
$ cargo asm --lib "once_cell::imp::OnceCell
cargo-show-asm
comes with a built in search function. Just pass partial name
instead of a full one and only matching functions will be listed
console
$ cargo asm --lib Debug
rustc
will only generate the code for your function if it knows what type it is, including
generic parameters and if it is exported (in case of a library) and not inlined (in case of a
binary, example, test, etc). If your function takes a generic parameter - try making a monomorphic
wrapper around it and make it pub
and #[inline(never)]
.
cargo-asm
?cargo-asm
is not maintained: https://github.com/gnzlbg/cargo-asm/issues/244. This crate is a reimplementation which addresses a number of its shortcomings, including:
cargo-asm
recompiles everything every time with 1 codegen unit, which is slow and also not necessarily what is in your release profile. cargo-show-asm
avoids that.
Because of how cargo-asm
handles demangling the output looks like asm but isn't actually asm. It contains a whole bunch of extra commas which makes reusing it more annoying.
cargo-asm
always uses colors unless you pass a flag while cargo-show-asm
changes its default behavior if output is not sent to a terminal.
cargo-show-asm
also supports MIR (note that the formatting of human-readable MIR is not stable).
cargo-asm
comes with shell completion generated by bpaf
,
use one of the lines below and place it into the place right for your shell.
console
$ cargo-asm --bpaf-complete-style-bash
$ cargo-asm --bpaf-complete-style-zsh
$ cargo-asm --bpaf-complete-style-fish
$ cargo-asm --bpaf-complete-style-elvish
You'll need to use it as cargo-asm
command rather than cargo asm
to take advantage of it.
You can install cargo-show-asm
with one of two features to get prettier command line
console
cargo install cargo-show-asm -F bright-color
cargo install cargo-show-asm -F dull-color
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.