How to get assembly output from building with Cargo?

后端 未结 3 1118
你的背包
你的背包 2020-12-24 11:18

While I\'ve seen docs on using rustc directly to output assembly, having to manually extract commands used by Cargo and edit them to write assembly is tedious.<

3条回答
  •  無奈伤痛
    2020-12-24 11:42

    In addition to kennytm's answer, you can also use the RUSTFLAGS environment variable and use the standard cargo commands:

    RUSTFLAGS="--emit asm" cargo build
    cat target/debug/deps/project_name-hash.s
    

    Or in release mode (with optimizations):

    RUSTFLAGS="--emit asm" cargo build --release
    cat target/release/deps/project_name-hash.s
    

    You can pass different values to the --emit parameter, including (but not limited to):

    • mir (Rust intermediate representation)
    • llvm-ir (LLVM intermediate representation)
    • llvm-bc (LLVM byte code)
    • asm (assembly)

提交回复
热议问题