• Stars
    star
    488
  • Rank 90,182 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cargo subcommands to invoke the LLVM tools shipped with the Rust toolchain

cargo-binutils

Cargo subcommands to invoke the LLVM tools shipped with the Rust toolchain

NOTE This is not an official Rust project.

This project is developed and maintained by the Embedded WG Tools team.

Features

  • All Rust symbols in the output of the LLVM tools are automatically demangled.
  • No need to pass the path to the artifact as an argument if using the tool in "build and inspect" mode.

Installation

$ cargo install cargo-binutils

$ rustup component add llvm-tools-preview

Usage

This:

$ rust-$tool ${args[@]}

is basically sugar for:

$ $(find $(rustc --print sysroot) -name llvm-$tool) ${args[@]}

Apart from these rust-* tools, which are direct proxies for the llvm tools in the llvm-tools-preview component, the crate also provides some Cargo subcommands that will first build the project and then run the llvm tool on the output artifact. This:

$ cargo size --example foo

is sugar for:

$ cargo build --example foo
$ rust-size target/examples/foo

These commands take similar options to cargo build and you can specify a specific binary with --bin NAME, an example with --example NAME or the default binary by not passing --bin or --example.

In the case of cargo-objdump the architecture of the compilation target is passed as -arch-name=$target to llvm-objdump. -arch-name specifies to which architecture disassemble the object file to.

You can get more information about the CLI of each tool by running rust-$tool -help.

All the Cargo subcommands accept a --verbose / -v flag. In verbose mode the rust-$tool invocation will be printed to stderr.

Build and inspect mode: Some subcommands accept the flags: --bin, --example, --lib, --target and --release. These can be used to make the subcommand first build the respective binary, example or library and have the path to the artifact be automatically passed to the LLVM tool. This mode only works when the subcommand is used from within a Cargo project.

Disclaimer Note that cargo-binutils simply proxies the LLVM tools in the llvm-tools-preview component and the Rust project makes no guarantee about the availability and the CLI of these tools -- i.e. the availability and CLI of these tools may change as new Rust releases are made.

Examples

nm

List all symbols in an executable

$ cargo nm --release
0800040a T BusFault
0800040a T DebugMonitor
0800040a T DefaultHandler
0800065e T HardFault
0800040a T MemoryManagement
0800040a T NonMaskableInt
0800040a T PendSV
0800040c T Reset
0800040a T SVCall
0800040a T SysTick
0800040a T UsageFault
08000408 T UserHardFault
08000008 R __EXCEPTIONS
08000040 R __INTERRUPTS
08000004 R __RESET_VECTOR
08000000 R __STACK_START

List all symbols in an executable sorted by size (smallest first).

$ cargo nm --release -- --print-size --size-sort
0800040a 00000002 T DefaultHandler
08000408 00000002 T UserHardFault
08000004 00000004 R __RESET_VECTOR
08000400 00000008 T main
08000008 00000038 R __EXCEPTIONS
0800040c 00000252 T Reset
08000040 000003c0 R __INTERRUPTS

objcopy

Transform the output of Cargo (ELF) into binary format.

$ cargo objcopy --release -- -O binary app.bin

$ stat --printf="%s\n" app.bin
1642

objdump

Disassemble a binary.

$ cargo objdump --release -- --disassemble --no-show-raw-insn
target/thumbv7m-none-eabi/debug/app:    file format ELF32-arm-little

Disassembly of section .text:
main:
 8000400:       push    {r7, lr}
 8000402:       bl      #608
 8000406:       b       #-8 <main+0x2>

UserHardFault:
 8000408:       trap

UsageFault:
 800040a:       trap

Reset:
 800040c:       push.w  {r4, r5, r6, r7, r8, lr}
 8000410:       movw    r0, #0
 8000414:       movw    r2, #0
 8000418:       movt    r0, #8192
 800041c:       movt    r2, #8192
(..)

size

Print binary size in System V format

$ cargo size --release -- -A -x
target/thumbv7m-none-eabi/release/app  :
section               size         addr
.vector_table        0x400    0x8000000
.text                0x26a    0x8000400
.rodata                0x2    0x800066a
.data                    0   0x20000000
.bss                     0   0x20000000
.debug_str          0x107e            0
.debug_loc           0x3e2            0
.debug_abbrev        0x31b            0
.debug_info         0x19f9            0
.debug_ranges         0xe8            0
.debug_macinfo         0x1            0
.debug_pubnames      0x9ff            0
.debug_pubtypes      0x8dd            0
.ARM.attributes       0x2e            0
.debug_frame          0x6c            0
.debug_line          0x69b            0
.debug_aranges        0x40            0
Total               0x531a

strip

Strip all symbols from the build artifact

$ stat --printf="%s\n" target/release/hello
4094240

$ cargo-strip --release -- --strip-all -o smaller-hello

$ stat --printf="%s\n" smaller-hello
424432

rust-lld

Provides a link to lld. Used to change the linker or providing a workaround if -C linker-flavor is not doing the job.

.cargo/config

[target.wasm32-unknown-unknown]
linker = "rust-lld"

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.60.0 and up. It might compile with older versions but that may change in any new patch release.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Code of Conduct

Contribution to this crate is organized under the terms of the Rust Code of Conduct, the maintainer of this crate, the Embedded WG Tools team, promises to intervene to uphold that code of conduct.

More Repositories

1

rust-raspberrypi-OS-tutorials

📚 Learn to write an embedded OS in Rust 🦀
Rust
13,436
star
2

awesome-embedded-rust

Curated list of resources for Embedded and Low-level development in the Rust programming language
6,173
star
3

embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Rust
1,977
star
4

wg

Coordination repository of the embedded devices Working Group
1,892
star
5

heapless

Heapless, `static` friendly data structures
Rust
1,492
star
6

discovery

Discover the world of microcontrollers through Rust!
Rust
1,458
star
7

book

Documentation on how to use the Rust Programming Language to develop firmware for bare metal (microcontroller) devices
1,083
star
8

riscv

Low level access to RISC-V processors
Rust
820
star
9

cortex-m

Low level access to Cortex-M processors
Rust
801
star
10

cortex-m-quickstart

Template to develop bare metal applications for Cortex-M microcontrollers
Rust
786
star
11

svd2rust

Generate Rust register maps (`struct`s) from SVD files
Rust
685
star
12

rust-sysfs-gpio

A Rust Interface to the Linux sysfs GPIO interface (https://www.kernel.org/doc/Documentation/gpio/sysfs.txt)
Rust
383
star
13

cortex-m-rt

Minimal startup / runtime for Cortex-M microcontrollers
Rust
357
star
14

riscv-rt

Minimal runtime / startup for RISC-V CPU's.
Rust
299
star
15

embedded-alloc

A heap allocator for embedded systems
Rust
295
star
16

linux-embedded-hal

Implementation of the `embedded-hal` traits for Linux devices
Rust
233
star
17

gpio-cdev

Rust interface to the Linux GPIO Character Device API (/dev/gpiochip...)
Rust
210
star
18

embedonomicon

How to bootstrap support for a no_std target
Rust
206
star
19

rust-i2cdev

Rust library for interfacing with i2c devices under Linux
Rust
205
star
20

rust-spidev

Rust library providing access to spidev devices under Linux
Rust
121
star
21

not-yet-awesome-embedded-rust

A collection of items that are not yet awesome in Embedded Rust
120
star
22

cortex-a

Low level access to Cortex-A processors
Rust
120
star
23

bare-metal

Abstractions common to microcontrollers
Rust
114
star
24

meta-rust-bin

Yocto layer for installing Rust toolchain from pre-built binaries
BitBake
102
star
25

critical-section

Pluggable critical section
Rust
97
star
26

gpio-utils

Userspace Utilities for managing GPIOs in Linux
Rust
94
star
27

showcase

Awesome embedded projects by the Rust community!
CSS
91
star
28

nb

Minimal and reusable non-blocking I/O layer
Rust
87
star
29

rust-embedded.github.io

A collection of books and other documents about embedded Rust
84
star
30

blog

The Rust Embedded WG Blog
SCSS
71
star
31

svd

A CMSIS-SVD file parser
Rust
70
star
32

r0

Initialization code ("crt0") written in Rust
Rust
69
star
33

aarch64-cpu

Low level access to processors using the AArch64 execution state.
Rust
65
star
34

svdtools

Python package to handle vendor-supplied, often buggy SVD files.
Rust
60
star
35

debugonomicon

Shell
60
star
36

rust-sysfs-pwm

Linux PWM Access via Sysfs in Rust
Rust
47
star
37

register-rs

Unified interface for type-safe MMIO and CPU register access in Rust
Rust
46
star
38

fixedvec-rs

Heapless vector implementation for Rust
Rust
45
star
39

qemu-exit

Exit QEMU with user-defined code
Rust
40
star
40

cortex-m-semihosting

Semihosting for ARM Cortex-M processors
Rust
40
star
41

msp430

Low level access to MSP430 microcontrollers
Rust
36
star
42

msp430-quickstart

Template to develop bare metal applications for MSP430 microcontrollers
Rust
36
star
43

embedded-dma

Rust
35
star
44

volatile-register

Volatile access to memory mapped hardware registers
Rust
34
star
45

itm

Tool to parse and dump ITM packets
Rust
28
star
46

mutex-trait

Low level API definition of a Mutex
Rust
25
star
47

msp430-rt

Minimal startup / runtime for MSP430 microcontrollers
Rust
15
star
48

patterns

A book capturing different approaches or patterns for solving problems in Embedded Rust
15
star
49

docker-rust-cross

Docker images for testing rust code on many versions and architecures (DEPRECATED)
Shell
13
star
50

panic-semihosting

Report panic messages to the host stderr using semihosting
Rust
12
star
51

cortex-r

Low level access to Cortex-R processors
Shell
11
star
52

arm-dcc

Debug Communication Channel (DCC) API
Rust
9
star
53

rust-embedded-www

The Rust embedded website: http://www.rust-embedded.org
HTML
7
star
54

panic-itm

Log panic messages using the ITM (Instrumentation Trace Macrocell)
Rust
6
star
55

rust-embedded-provisioning

Terraform provisioning for Rust Embedded infrastructure
HCL
2
star
56

template

Rust
1
star
57

discovery-mb2

Rust Discovery Book for BBC micro::bit v2
Rust
1
star