-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
README.tpl
144 lines (101 loc) · 5.07 KB
/
README.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# cargo-show-asm
A cargo subcommand that displays the Assembly, LLVM-IR, MIR and WASM generated for Rust source code.
# Install
```console
$ cargo install cargo-show-asm
```
# Features
- Platform support:
- OS: Linux and macOS. Limited support for Windows
- Rust: nightly and stable.
- Architectures: `x86`, `x86_64`, `aarch64`, etc.
- Cross-compilation support.
- Displaying:
- Assembly in Intel or AT&T syntax.
- Corresponding Rust source code alongside assembly.
- llvm-ir.
- rustc MIR
- Wasm code
- llvm-mca analysis
<USAGE>
You can start by running `cargo asm` with no parameters - it will suggest 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>::write_char" [20]
"<&mut W as core::fmt::Write>::write_fmt" [38]
"<&mut W as core::fmt::Write>::write_str" [90]
"<F as nom::internal::Parser<I,O,E>>::parse" [263]
# ...
```
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<T>::initialize::h9c5c7d5bd745000b"
```
`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
```
# My function isn't there!
`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)]`.
Alternatively if your function is too small - `rustc` might decide to inline it automatically
with the same result. Marking it with `#[inline(never)]` fixes this problem.
See https://github.com/rust-lang/rust/pull/116505 for more details
# Include related functions?
So suppose you have a function `foo` that calls some other function - `bar`. With `--context N`
or it's short variant `-c N` you can ask cargo-show-asm to include body of bar to the input.
This is done recursively up to N steps. See https://github.com/pacak/cargo-show-asm/issues/247
# What about `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 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).
# Shell completion
`cargo-asm` comes with shell completion generated by [`bpaf`](https://crates.io/crates/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.
# Colorful line parser output
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
```
# License
This project is licensed under either of
* Apache License, Version 2.0, (LICENSE-APACHE or <http://www.apache.org/licenses/LICENSE-2.0>)
* MIT license (LICENSE-MIT or <http://opensource.org/licenses/MIT>)
at your option.
# Contribution
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.