How to add my own LLVM pass to rust compiler

My problem is that I want to record comparison instructions in a Rust program. There is a sancov pass to do that. However, I want something more flexible. Since Rust compiles its source codes to IR, I am curious that there is any way to use my own LLVM pass to modify IR. Do you guy know API to do so? Thanks in advance

If you just need to look at the instructions, you can ask the compiler to output the LLVM IR (or MIR or assembly).

It is a good solution by using -emit-llvm to get IR. However, from that IR files, creating an executable file is difficult. I found some solutions for that but they simply do not work for complicated projects

If you want to modify the compiler, you should post on https://internals.rust-lang.org/ instead.

2 Likes

Rust doesn't have an interface for LLVM plugins. You will have to modify https://github.com/rust-lang/rust/blob/master/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp and build your own rustc.

1 Like

thanks