iqlusioninc / usbarmory.rs

Bare metal Rust support for USB armory MkII devices
Apache License 2.0
58 stars 4 forks source link

Trouble building blinky example #17

Closed tarcieri closed 4 years ago

tarcieri commented 4 years ago

A couple different problems on a couple different OSes. Both are using rustc 1.42.0-nightly (8a79d08fa 2020-01-27) and trying to build commit d6814dca.

CentOS Linux release 8.1.1911 (Core):

$ cargo build --example blinky
   Compiling stable_deref_trait v1.1.1
   Compiling imx6ul-pac v0.0.0 (/home/bascule/usbarmory.rs/firmware/imx6ul-pac)
   Compiling syn v1.0.13
   Compiling cortex-m v0.6.1
   Compiling vcell v0.1.2
   Compiling heapless v0.5.3
   Compiling cortex-m-semihosting v0.3.5 (https://github.com/japaric/cortex-m-semihosting?branch=cortex-a#585e741c)
   Compiling rtfm-core v0.3.0
   Compiling proc-macro2 v1.0.7
   Compiling typenum v1.11.2
   Compiling semver v0.9.0
   Compiling cortex-a v0.0.0 (/home/bascule/usbarmory.rs/firmware/cortex-a)
   Compiling indexmap v1.3.0
   Compiling byteorder v1.3.2
   Compiling volatile-register v0.2.0
   Compiling rustc_version v0.2.3
   Compiling bare-metal v0.2.5
   Compiling hash32 v0.1.1
   Compiling quote v1.0.2
   Compiling generic-array v0.12.3
   Compiling generic-array v0.13.2
   Compiling usbarmory-rt v0.0.0 (/home/bascule/usbarmory.rs/firmware/usbarmory-rt)
   Compiling as-slice v0.1.2
   Compiling usbarmory v0.0.0 (/home/bascule/usbarmory.rs/firmware/usbarmory)
   Compiling panic-serial v0.0.0 (/home/bascule/usbarmory.rs/firmware/panic-serial)
   Compiling exception-reset v0.0.0 (/home/bascule/usbarmory.rs/firmware/exception-reset)
   Compiling aligned v0.3.2
   Compiling rtfm-syntax v0.4.0
   Compiling cortex-a-rtfm-macros v0.0.0 (/home/bascule/usbarmory.rs/firmware/cortex-a-rtfm/macros)
   Compiling cortex-a-rtfm v0.0.0 (/home/bascule/usbarmory.rs/firmware/cortex-a-rtfm)
error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "-flavor" "gnu" "-L" "/home/bascule/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7a-none-eabi/lib" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/examples/blinky-7c1cb1cf32b4b616.1ixzcbfuvvs4wfpz.rcgu.o" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/examples/blinky-7c1cb1cf32b4b616.3nlrd3ix8yy4ti42.rcgu.o" "-o" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/examples/blinky-7c1cb1cf32b4b616" "--gc-sections" "-L" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps" "-L" "/home/bascule/usbarmory.rs/firmware/target/debug/deps" "-L" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/build/cortex-a-48830a2992b9ef47/out" "-L" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/build/usbarmory-rt-f406822cb3878049/out" "-L" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/build/cortex-m-semihosting-b0ea1e2080073036/out" "-L" "/home/bascule/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7a-none-eabi/lib" "--start-group" "-Bstatic" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libpanic_serial-66286a041628919a.rlib" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libexception_reset-18f3bede256fdeeb.rlib" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory-1f9717453d14770d.rlib" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libimx6ul_pac-7c72ca58a856c5e4.rlib" "/home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libcortex_a-13119bce087a8ecf.rlib" "/home/bascule/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7a-none-eabi/lib/librustc_std_workspace_core-96c035bec0651bc8.rlib" "/home/bascule/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7a-none-eabi/lib/libcore-fff5f352cde90fc9.rlib" "--end-group" "/home/bascule/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7a-none-eabi/lib/libcompiler_builtins-ccb7b8fb4656b4d5.rlib" "-Bdynamic"
  = note: rust-lld: error: undefined symbol: __stack_top__
          >>> referenced by usbarmory-rt-no-vfp.o:(.text._start+0x14) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SupervisorCall
          >>> referenced by usbarmory-rt-common.o:(.text._exceptions+0x28) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: HypervisorCall
          >>> referenced by usbarmory-rt-common.o:(.text._HypervisorCall+0x4) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: PrefetchAbort
          >>> referenced by usbarmory-rt-common.o:(.text._PrefetchAbort+0x4) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: UndefinedInstruction
          >>> referenced by usbarmory-rt-common.o:(.text._UndefinedInstruction+0x4) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: FIQ
          >>> referenced by usbarmory-rt-common.o:(.text._FIQ+0x4) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI0
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI1
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI2
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI3
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI4
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI5
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI6
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI7
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI8
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI9
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI10
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI11
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI12
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: undefined symbol: SGI13
          >>> referenced by hf3emea5vo5219p
          >>>               usbarmory_rt-c9b2efd35e3cb602.hf3emea5vo5219p.rcgu.o:(usbarmory_rt::SGIS::h48cf788827a5d34b) in archive /home/bascule/usbarmory.rs/firmware/target/armv7a-none-eabi/debug/deps/libusbarmory_rt-c9b2efd35e3cb602.rlib

          rust-lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

error: aborting due to previous error

error: could not compile `usbarmory`.

This is macOS Catalina (16GB RAM host, potentially OOM?)

$ cargo build --example blinky
   Compiling quote v1.0.2
   Compiling typenum v1.11.2
   Compiling byteorder v1.3.2
   Compiling indexmap v1.3.0
   Compiling bare-metal v0.2.5
[1]    4783 killed     cargo build --example blinky
japaric commented 4 years ago
error[E0463]: can't find crate for `core`
  |
  = note: the `armv7a-none-eabi` target may not be installed

It should be noted in the docs that you need rustup target add armv7a-none-eabi


[bascule@strangelove firmware]$ cargo build --example blinky
(..)
  = note: rust-lld: error: undefined symbol: __stack_top__

The command needs to be run from the usbarmory directory (this is noted in the docs). That's the only directory that contains the Cargo configuration file (.cargo/config) to pass the -Tlink.x to the linker. The error you are seeing comes from not passing that linker script to the linker. I guess we could also move that Cargo configuration file to the the root of the workspace then builds from firmware should also work.


[1]    4783 killed     cargo build --example blinky

Intriguing. Can you re-run this as cargo build --example blinky -j1 -v to see which crate is generating the OOM. It could be that a build script has unintentional infinite recursion on mac.

tarcieri commented 4 years ago

Thanks! All working now and I was able to load an ELF image.

I think the OOM om Mac might've been a bug in that nightly release. I experienced something similar compiling an unrelated project.

I've updated to the latest nightly rustc 1.42.0-nightly (3761dcd34 2020-01-28) and am no longer experiencing the problem.