-
Notifications
You must be signed in to change notification settings - Fork 84
empty thumb binary on macOS with 1.31.0 to 1.41.1 #251
Description
All,
I'm walking through the Rust Embedded Discovery book to familiarize myself with how Rust on microcontrollers works. I'm on a MacBook Pro with macOS 10.15.3 (Catalina) and up-to-date MacPorts for arm-none-eabi-{gcc,gdb,binutils}
. Both OpenOCD and arm-none-eabi-gdb run fine and communicate. I first detected the error in Chapter 05, when I attempted to load
the first binary built. I got the following result:
(gdb) load
Start address 0x0, load size 0
Transfer rate: 0 bits in <1 sec.
Diagnosis in #rust-embedded on Matrix revealed the following:
$ arm-none-eabi-size target/thumbv7em-none-eabihf/debug/led-roulette
text data bss dec hex filename
0 0 0 0 0 target/thumbv7em-none-eabihf/debug/led-roulette
So, I repeated the book in my Gentoo Linux VM, and received sane results. IOW, it looks like a bug in Rust on macOS.
I'm using rustup
to install Rust, on vanilla macOS, latest MacPorts, and I'm using the source repository for the Discovery book: https://github.com/rust-embedded/discovery
I've tried every major version of Rust from 1.31.0 through 1.41.1 with similar results. Copying the binary to my Linux system yield the same output
$ arm-none-eabi-size target/thumbv7em-none-eabihf/debug/led-roulette
text data bss dec hex filename
1732 0 0 1732 6c4 target/thumbv7em-none-eabihf/debug/led-roulette
$ arm-none-eabi-size ~/led-roulette text data bss dec hex filename
0 0 0 0 0 /home/jason/led-roulette
You can see above that I get a sane build product on Linux, but the binary from macOS (in my home directory) is obviously not right.
I've no idea how to further debug this as I'm relatively new to Rust. I'm hoping that someone on macOS can reproduce this (you don't need the board, openocd, or gdb to test). and dig in a little further.
STR:
$ git clone https://github.com/rust-embedded/discovery
$ cd discovery
$ rustup update
$ cargo install itm --vers 0.3.1 # may not be necessary for reproducing
$ rustup component add llvm-tools-preview
$ cargo install cargo-binutils --vers 0.1.4
$ cd src/05-led-roulette
$ cargo build --target thumbv7em-none-eabihf
$ arm-none-eabi-size target/thumbv7em-none-eabihf/debug/led-roulette
### OR ###
$ cargo readobj --target thumbv7em-none-eabihf --bin led-roulette -- -file-headers
If you use cargo readobj ...
, here's the difference between a good binary (built on Linux) and a bad binary (built on macOS)
--- ../../../good_readobj.txt 2020-03-03 16:35:14.000000000 -0500
+++ ../../../bad_readobj.txt 2020-03-03 16:39:15.000000000 -0500
@@ -1,5 +1,3 @@
-$ cargo readobj --target thumbv7em-none-eabihf --bin led-roulette -- -file-headers
- Finished dev [unoptimized + debuginfo] target(s) in 0.07s
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
@@ -11,13 +9,13 @@
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
- Entry point address: 0x800019D
+ Entry point address: 0x0
Start of program headers: 52 (bytes into file)
- Start of section headers: 853336 (bytes into file)
+ Start of section headers: 1288 (bytes into file)
Flags: 0x5000400
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
- Number of program headers: 2
+ Number of program headers: 3
Size of section headers: 40 (bytes)
- Number of section headers: 22
- Section header string table index: 20
+ Number of section headers: 15
+ Section header string table index: 13