MabezDev / xtensa-rust-quickstart

A demo crate for the xtensa uC's (ESP32, ESP8266)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LLVM error: Cannot use this version of ReplaceAllUsesWith!

Gasper opened this issue · comments

When compiling the project for the first time using xargo it will bild the core library, as well as compiler_builtins. Compiling the latter fails with the following error:

    Running `/home/esp/esp/esp-rust/rust-xtensa/build/x86_64-unknown-linux-gnu/stage2/bin/rustc --crate-name compiler_builtins /home/esp/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.18/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C codegen-units=1 --cfg 'feature="compiler-builtins"' --cfg 'feature="default"' --cfg 'feature="mem"' -C metadata=0a0a647390c34640 -C extra-filename=-0a0a647390c34640 --out-dir /tmp/xargo.sIC8I8rzgdg0/target/xtensa-unknown-none-elf/release/deps --target xtensa-unknown-none-elf -L dependency=/tmp/xargo.sIC8I8rzgdg0/target/xtensa-unknown-none-elf/release/deps -L dependency=/tmp/xargo.sIC8I8rzgdg0/target/release/deps --cap-lints allow -C link-arg=-nostartfiles -C debuginfo=0 -C link-arg=-Wl,-Tlink.x --emit llvm-bc,link --sysroot /home/esp/.xargo -Z force-unstable-if-unmarked`
rustc: ../lib/CodeGen/SelectionDAG/SelectionDAG.cpp:8209: void llvm::SelectionDAG::ReplaceAllUsesWith(llvm::SDNode*, llvm::SDNode*): Assertion `(!From->hasAnyUseOfValue(i) || From->getValueType(i) == To->getValueType(i)) && "Cannot use this version of ReplaceAllUsesWith!"' failed.
error: could not compile `compiler_builtins`.

Caused by:
  process didn't exit successfully: `/home/esp/esp/esp-rust/rust-xtensa/build/x86_64-unknown-linux-gnu/stage2/bin/rustc --crate-name compiler_builtins /home/esp/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.18/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C codegen-units=1 --cfg 'feature="compiler-builtins"' --cfg 'feature="default"' --cfg 'feature="mem"' -C metadata=0a0a647390c34640 -C extra-filename=-0a0a647390c34640 --out-dir /tmp/xargo.sIC8I8rzgdg0/target/xtensa-unknown-none-elf/release/deps --target xtensa-unknown-none-elf -L dependency=/tmp/xargo.sIC8I8rzgdg0/target/xtensa-unknown-none-elf/release/deps -L dependency=/tmp/xargo.sIC8I8rzgdg0/target/release/deps --cap-lints allow -C link-arg=-nostartfiles -C debuginfo=0 -C link-arg=-Wl,-Tlink.x --emit llvm-bc,link --sysroot /home/esp/.xargo -Z force-unstable-if-unmarked` (signal: 6, SIGABRT: process abort signal)
error: `"cargo" "build" "--release" "--manifest-path" "/tmp/xargo.sIC8I8rzgdg0/Cargo.toml" "--target" "xtensa-unknown-none-elf" "-v" "-p" "compiler_builtins"` failed with exit code: Some(101)
   0: error_chain::make_backtrace
   1: <error_chain::State as core::default::Default>::default
   2: <std::process::Command as xargo::extensions::CommandExt>::run
   3: xargo::sysroot::build
   4: xargo::sysroot::update
   5: xargo::main_inner
   6: std::rt::lang_start::{{closure}}
   7: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
      std::panicking::try::do_call
             at src/libstd/panicking.rs:292
   8: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:78
   9: std::panicking::try
             at src/libstd/panicking.rs:270
      std::panic::catch_unwind
             at src/libstd/panic.rs:394
      std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  10: main
  11: __libc_start_main
  12: _start

Probable cause

Not sure what is really root cause of this, but I boiled it down to a single line in compiler_builtins code src/float/mul.rs:177 - return F::from_repr(product_high);
I guess it has something to do with casting wide int into float (the LLVM assert is complaining about incompatible types), but it could also be due Xtensa float support which is claimed in data layout.
I couldn't replicate the issue with just standalone compiler_builtins crate, but it happens every time following quickstart procedure.

Workaround

My workaround was very hacky: adding #[cfg(all(feature = "c"))] in front of pub mod float; in lib.rs, directly in ~/.cargo/registry/src/github.com-XXXXXXXXX/compiler_builtins-0.1.18
After that comiler_builtins crate built without errors and I the quickstart project built normally. I havent tried using floats with it, though.

Versions used

I used the latest default branches for both of the projects:
espressif/llvm-project: xtensa_release_9.0.1 / 654ba115e556 (Feb 5, 2020)
MabezDev/rust-xtensa: xtensa-target / 2d3ec14f5877(Feb 4, 2020)

May be related

#9

This is fixed by using the following LLVM/Rust:

  • built-in-llvm (548213793ce91714) branch on MabezDev/rust-xtensa
  • xtensa_release_9.0.1_with_rust_patches (1ad7aa125beddf) on MabezDev/llvm-project

Glad you got all your issues fixed :). Sorry it hadn't been merged already, just haven't had much time to spend on this in recent weeks.