Skip to content

Ship more LLVM tools with the Rust toolchain #49584

Closed
@japaric

Description

@japaric

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:

@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 for lld.

  • 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 for lld.

  • These tools will be installed somewhere in the sysroot but won't be added to the user's $PATH.
    This is also the case for lld.

  • 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 make llvm-{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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-embeddedWorking group: Embedded systems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions