Description
Summary
Ship llvm tools like llvm-nm
and llvm-size
with the Rust toolchain.
Rationale
Binary size and performance are critical to embedded development due to the resource constrained
nature of the systems embedded applications run in. Thus it's very important to have tools to
inspect the binaries produced by the compiler.
One could use GNU binutils for this task but that requires installing one set of tools per target
architecture (arm-none-eabi-*
for ARM Cortex-M, avr-*
for AVR, etc.); and on some platforms
(e.g. Windows) it can be hard to find a set of pre-compiled tools, specially for not yet widespread
architectures (e.g. RISCV).
The alternative to GNU binutils are LLVM tools. Thanks to LLVM being multi-architecture a single
set of LLVM binutils supports several architectures (ARM Cortex-M, AVR, MSP430, RISCV, etc); in
fact, LLVM tools support all the architectures that rustc
supports.
By having LLVM tools installed with the Rust toolchain we save users one, possibly difficult,
installation step while also providing them a single set of tools they can use for both native and
embedded development.
Also, we are already shipping LLD with the Rust toolchain to ease WASM development.
Detailed proposal
The following tools will be built and shipped with the Rust toolchain:
-
Binary inspection tools
llvm-nm
llvm-objdump
llvm-size
-
Binary manipulation tools
llvm-objcopy
, used to transform ELF files into binary files, which are the type of files some
flashing tools use
Apart from these tools useful for embedded development other tools are being requested by the
general Rust community for profiling:
llvm-cov
(cc @whitequark)llvm-profdata
(cc @sfackler)
@japaric (embedded WG) discussed this proposal with @alexcrichton (team-core, team-infra) and we tentatively agreed on the following points:
-
These tools will unconditionally be shipped with the Rust toolchain. That means there won't be a
llvm-binutils
rustup component for them. This is also the case forlld
. -
These tools will only be available on some platforms. Where "some" are mainly tier 1 platforms
(x86_64 Windows / Linux / macOS). This is also the case forlld
. -
These tools will be installed somewhere in the sysroot but won't be added to the user's
$PATH
.
This is also the case forlld
. -
We make no guarantees whatsoever about the stability or availability of these tools. If a LLVM
upgrade changes the CLI or output format of one of these tools it's up to the end user to adjust
their invocations accordingly. Similarly, if LLVM drops support for any of these tools then that
tool will stop being available in the sysroot. -
The embedded WG will create and maintain at set of Cargo subcommands (e.g.
cargo size
) that makellvm-{nm,objcopy,objdump,size}
available to the end user. -
We should check how adding these tools affects the binary size of the Rust toolchain installed by
rustup. These tools are statically linked to LLVM by default, which means they'll be relatively
large. We can explore dynamically linking them to LLVM in the future.
cc @rust-lang/dev-tools