cargo-call-stack icon indicating copy to clipboard operation
cargo-call-stack copied to clipboard

`error: Did not find ELF magic number` on latest nightly

Open mauricelam opened this issue 1 year ago • 0 comments

When running cargo call-stack using the latest nightly, it fails with error: Did not find ELF magic number.

Repro steps:

  1. rustup install nightly-2023-12-02
  2. rustup component add rust-src --toolchain nightly-2023-12-02-x86_64-unknown-linux-gnu
  3. cd cargo-call-stack/firmware
  4. cargo +nightly-2023-12-02 call-stack --example function-pointer --target thumbv7m-none-eabi > cg.dot
$ cargo +nightly-2023-12-02 call-stack --example function-pointer --target thumbv7m-none-eabi > cg.dot
 Downloading crates ...
  Downloaded hashbrown v0.14.2
   Compiling compiler_builtins v0.1.103
   Compiling core v0.0.0 (/usr/local/google/home/yukl/.rustup/toolchains/nightly-2023-12-02-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling rustc-std-workspace-core v1.99.0 (/usr/local/google/home/yukl/.rustup/toolchains/nightly-2023-12-02-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/usr/local/google/home/yukl/.rustup/toolchains/nightly-2023-12-02-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
   Compiling panic-halt v0.2.0
   Compiling firmware v0.1.0 (/usr/local/google/home/yukl/cargo-call-stack/firmware)
    Finished release [optimized + debuginfo] target(s) in 11.44s
error: Did not find ELF magic number

cargo bisect-rustc shows the culprit as https://github.com/rust-lang/rust/commit/8c2b57721728233e074db69d93517614de338055

As far as I can tell, it is failing when trying to read the .o file inside target/thumbv7m-none-eabi/release/deps/libcompiler_builtins-7f005ebede32330f.rlib, because it is LLVM IR bitcode, not an ELF file

$ ar x target/thumbv7m-none-eabi/release/deps/libcompiler_builtins-7f005ebede32330f.rlib
$ file compiler_builtins-7f005ebede32330f.compiler_builtins.5df481aafd5f48ed-cgu.0.rcgu.o
compiler_builtins-7f005ebede32330f.compiler_builtins.5df481aafd5f48ed-cgu.0.rcgu.o: LLVM IR bitcode

I don't really understand what https://github.com/rust-lang/rust/pull/113923 is doing, and weren't able to find configuration flags that would make rustc revert back to creating ELF file for compiler_builtins. Any suggestions for a fix or workaround would be appreciated.

mauricelam avatar Dec 06 '23 22:12 mauricelam