gnzlbg / cargo-asm

cargo subcommand showing the assembly or llvm-ir generated for Rust code
https://github.com/gnzlbg/cargo-asm
Other
1.19k stars 37 forks source link

Cargo build fails due to LLVM bug for rustc 1.27.1 #25

Closed petr-tik closed 6 years ago

petr-tik commented 6 years ago

Intro and thanks!

First of all, thanks for a great extension - you and the rest of the community is one of the reasons I enjoy using rust! I read about cargo asm on reddit and am looking forward to using and hopefully helping stabilise it.

Problem description

I installed cargo-asm tonight to look at the asm output for my open-source project

$$$$ cargo asm -h
cargo-asm 0.1.16

My project builds using vanilla rustc 1.27.1

$$$$ cargo build --release
   Compiling fnv v1.0.6
   Compiling order_book v0.1.0 (file:///home/petr_tik/Coding/order_book)
    Finished release [optimized + debuginfo] target(s) in 9.20s

but the build breaks when I run cargo asm

Stacktrace

$$$$ cargo asm 

[ERROR]: cargo build failed!

stderr:

   Compiling fnv v1.0.6
     Running `rustc --crate-name fnv /home/petr_tik/.cargo/registry/src/github.com-1ecc6299db9ec823/fnv-1.0.6/lib.rs --color always --crate-type lib --emit=dep-info,link -C opt-level=3 -C debuginfo=2 -C metadata=5881d5b4694d1337 -C extra-filename=-5881d5b4694d1337 --out-dir /home/petr_tik/Coding/order_book/target/release/deps -L dependency=/home/petr_tik/Coding/order_book/target/release/deps --cap-lints allow --emit asm -C llvm-args=-x86-asm-syntax=intel`
   Compiling order_book v0.1.0 (file:///home/petr_tik/Coding/order_book)
     Running `rustc --crate-name order_book src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C debuginfo=2 -C metadata=12b7d539aa0f5d9d -C extra-filename=-12b7d539aa0f5d9d --out-dir /home/petr_tik/Coding/order_book/target/release/deps -L dependency=/home/petr_tik/Coding/order_book/target/release/deps --extern fnv=/home/petr_tik/Coding/order_book/target/release/deps/libfnv-5881d5b4694d1337.rlib --emit asm -C llvm-args=-x86-asm-syntax=intel`
DICompileUnit not listed in llvm.dbg.cu
!30643 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1328, producer: "clang LLVM (rustc version 1.27.1 (5f2b325f6 2018-07-07))", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !1662, globals: !30644)
LLVM ERROR: Broken module found, compilation aborted!
error: Could not compile `order_book`.

Caused by:
  process didn't exit successfully: `rustc --crate-name order_book src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C debuginfo=2 -C metadata=12b7d539aa0f5d9d -C extra-filename=-12b7d539aa0f5d9d --out-dir /home/petr_tik/Coding/order_book/target/release/deps -L dependency=/home/petr_tik/Coding/order_book/target/release/deps --extern fnv=/home/petr_tik/Coding/order_book/target/release/deps/libfnv-5881d5b4694d1337.rlib --emit asm -C llvm-args=-x86-asm-syntax=intel` (exit code: 1)

thread 'main' panicked at 'cargo build failed: ()', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Ideas/inference to related issues

seems related to #6 https://github.com/rust-lang/rust/issues/52039

Steps to reproduce

git clone https://github.com/petr-tik/dark_rusty_pool.git
cd dark_rusty_pool
cargo test
cargo build --release
cargo asm

TODO

Please let me know what other information you need and/or how I can help

gnzlbg commented 6 years ago

Hi! Thanks for the report. So I cannot reproduce with rust nightly :/

Could you try:

RUSTFLAGS="--emit=asm" cargo build --release

and report the output?

petr-tik commented 6 years ago

hi and wow for the quick reply.

According to the readme cargo asm supports rust stable, so I have been building with most recent stable compiler in examples above

$$$$ rustc -V
rustc 1.27.1 (5f2b325f6 2018-07-07)

As you suggested

$$$$ RUSTFLAGS="--emit=asm" cargo build --release
   Compiling order_book v0.1.0 (file:///home/petr_tik/Coding/order_book)
DICompileUnit not listed in llvm.dbg.cu
!46476 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1856, producer: "clang LLVM (rustc version 1.27.1 (5f2b325f6 2018-07-07))", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
LLVM ERROR: Broken module found, compilation aborted!
error: Could not compile `order_book`.

To learn more, run the command again with --verbose.

running same with verbose

$$$$ RUSTFLAGS="--emit=asm" cargo build --release --verbose
       Fresh fnv v1.0.6
   Compiling order_book v0.1.0 (file:///home/petr_tik/Coding/order_book)
     Running `rustc --crate-name order_book src/main.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C debuginfo=2 -C metadata=12b7d539aa0f5d9d -C extra-filename=-12b7d539aa0f5d9d --out-dir /home/petr_tik/Coding/order_book/target/release/deps -L dependency=/home/petr_tik/Coding/order_book/target/release/deps --extern fnv=/home/petr_tik/Coding/order_book/target/release/deps/libfnv-5881d5b4694d1337.rlib --emit=asm`
DICompileUnit not listed in llvm.dbg.cu
!30643 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1328, producer: "clang LLVM (rustc version 1.27.1 (5f2b325f6 2018-07-07))", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !1662, globals: !30644)
LLVM ERROR: Broken module found, compilation aborted!
error: Could not compile `order_book`.

Caused by:
  process didn't exit successfully: `rustc --crate-name order_book src/main.rs --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C debuginfo=2 -C metadata=12b7d539aa0f5d9d -C extra-filename=-12b7d539aa0f5d9d --out-dir /home/petr_tik/Coding/order_book/target/release/deps -L dependency=/home/petr_tik/Coding/order_book/target/release/deps --extern fnv=/home/petr_tik/Coding/order_book/target/release/deps/libfnv-5881d5b4694d1337.rlib --emit=asm` (exit code: 1)
gnzlbg commented 6 years ago

So this is a bug in that Rust stable version that happens to trigger for your crate :/

The only thing I could do is report the bug, but the bug is already reported and fixed on nightly, so, this has been efficient! :D

The stable toolchain that you are using might work for other crates, but for this particular one my recommendation is for you to use the nightly one in combination with cargo asm until Rust 1.28 is released (that release should hopefully contain the fix, otherwise you might have to wait until Rust 1.29...).

I will add a note about this to the readme.

petr-tik commented 6 years ago

thanks for the swift triage and fix suggestion - again you (and others) are one of the strongest reasons to use rust.

petr-tik commented 6 years ago

quick n00b question that I cannot seem to google the answer for.

How can I set toolchain=nightly in the Cargo.toml of my project?

gnzlbg commented 6 years ago

I don't think you can (maybe .cargo/config? check that in the cargo book).

To switch toolchains I personally do that manually: rustup default nightly changes to nightly, and rustup default stable to stable. There are beginner channels on IRC and Discord with lot of people answering questions, so if you are getting started I recommend you to join #rust-beginners on IRC to get quick feedback.

petr-tik commented 6 years ago

off-top to the original issue, but I found a way (more googling is usually the answer) - you might find it useful too

Create a rust-toolchain file in the root dir with the description of required toolchain

http://galuh.me/rust-notes/rust-toolchain.html

petr-tik commented 6 years ago

thanks again - closing