16 个版本
0.3.6 | 2022 年 6 月 20 日 |
---|---|
0.3.5 | 2022 年 2 月 12 日 |
0.3.4 | 2021 年 11 月 16 日 |
0.3.3 | 2020 年 11 月 17 日 |
0.1.1 | 2018 年 7 月 15 日 |
#59 在 Cargo 插件 中
44,686 每月下载量
用于 12 个crate(4 个直接使用)
39KB
703 行
cargo-binutils
Cargo 子命令,用于调用 Rust 工具链中随附的 LLVM 工具
注意 这不是一个官方的 Rust 项目。
该项目由 嵌入式工具团队 开发和维护。
特性
- LLVM 工具输出中的所有 Rust 符号都将自动去混淆。
- 如果在使用 "构建和检查" 模式时使用该工具,则不需要将工件路径作为参数传递。
安装
$ cargo install cargo-binutils
$ rustup component add llvm-tools-preview
使用
这
$ rust-$tool ${args[@]}
基本上是
$ $(find $(rustc --print sysroot) -name llvm-$tool) ${args[@]}
除了这些 rust-*
工具,它们是 llvm-tools-preview
组件中 llvm 工具的直接代理之外,该包还提供了一些 Cargo 子命令,这些命令将首先构建项目,然后在输出工件上运行 llvm 工具。这是
$ cargo size --example foo
的简化形式
$ cargo build --example foo
$ rust-size target/examples/foo
这些命令与 cargo build
相似,您可以使用 --bin NAME
指定特定的二进制文件,使用 --example NAME
指定示例或默认二进制文件,如果不传递 --bin
或 --example
,则使用默认二进制文件。
对于 cargo-objdump
,将编译目标的架构作为 -arch-name=$target
传递给 llvm-objdump
。 -arch-name
指定将对象文件反汇编到哪个架构。
您可以通过运行 rust-$tool -help
获取每个工具的 CLI 的更多信息。
所有Cargo子命令都接受一个--verbose
/ -v
标志。在详细模式下,rust-$tool
调用将输出到stderr。
构建和检查模式:一些子命令接受以下标志:--bin
、--example
、--lib
、--target
和--release
。这些标志可以用来让子命令首先构建相应的二进制文件、示例或库,并自动将工件路径传递给LLVM工具。此模式仅在从Cargo项目内部使用子命令时才有效。
免责声明 注意,cargo-binutils
仅代理llvm-tools-preview
组件中的LLVM工具,Rust项目不对这些工具的可用性和CLI做出任何保证--即,这些工具的可用性和CLI可能会随着新的Rust版本发布而变化。
示例
nm
列出可执行文件中的所有符号
$ 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
按大小排序列出可执行文件中的所有符号(从小到大)。
$ 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
将Cargo(ELF)输出转换为二进制格式。
$ cargo objcopy --release -- -O binary app.bin
$ stat --printf="%s\n" app.bin
1642
objdump
反汇编二进制文件。
$ 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
以System V格式打印二进制文件大小
$ 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
从构建工件中删除所有符号
$ 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
提供到lld
的链接。用于更改链接器或当-C 链接器-flavor
不起作用时提供解决方案。
.cargo/config
[target.wasm32-unknown-unknown]
linker = "rust-lld"
最低支持的Rust版本(MSRV)
该crate保证可以在稳定版Rust 1.46.0及以上版本上编译。它可能可以使用较旧版本编译,但在任何新的补丁版本中可能会发生变化。
许可证
根据您的选择,许可为以下之一
- Apache License,版本2.0(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证(LICENSE-MIT 或 http://opensource.org/licenses/MIT)
。
贡献
除非您明确声明,否则您提交的任何贡献,根据Apache-2.0许可证的定义,应按上述方式双许可,不附加任何额外条款或条件。
行为准则
此crate的贡献是在Rust行为准则的条款下组织的,该crate的维护者、嵌入式WG工具团队承诺将介入以维护该行为准则。
依赖项
~4–6MB
~104K SLoC