pacak / cargo-show-asm

cargo subcommand showing the assembly, LLVM-IR and MIR generated for Rust code
Apache License 2.0
712 stars 35 forks source link

Support `rustc_codegen_cranelift` #286

Closed AccessViolation95 closed 5 months ago

AccessViolation95 commented 5 months ago

It would be nice if cargo-show-asm supported rustc_codegen_cranelift. It would be useful for comparing the output of Cranelift and LLVM.

In order to make rustc use Cranelift, I have installed it following these instructions: https://github.com/rust-lang/rustc_codegen_cranelift

My project's Cargo.toml looks like this:

# This line needs to come before anything else in Cargo.toml
cargo-features = ["codegen-backend"]

[package]
name = "quick_test"
version = "0.1.0"
edition = "2021"

[profile.release]
codegen-backend = "cranelift"

The output I get when running cargo asm is:

error: Unknown option `-x86-asm-syntax`

error: could not compile `quick_test` (bin "quick_test") due to 1 previous error

Cargo failed with exit status: 101
pacak commented 5 months ago

By default cargo-show-asm doesn't perform disassembly, but asks rustc to produce raw asm files, parses them and makes them accessible for users. Problem with cranelift backend is that it doesn't support emitting asm files.

But if you compile cargo-show-asm with "disasm" feature you can pass --disasm option along with usual flags. This should, in theory, support cranelift as well.

AccessViolation95 commented 5 months ago

Ah, that works, thanks!