Append the following code to ~/.bashrc:
Modify LLVM_INSTALL_DIR accordingly.
LLVM_INSTALL_DIR=$HOME/Env/llvm
export PATH=${LLVM_INSTALL_DIR}/bin:$PATH
export LLVM_DIR=${LLVM_INSTALL_DIR}/lib/cmake
export CMAKE_PREFIX_PATH=${LLVM_INSTALL_DIR}/lib/cmake
export LD_LIBRARY_PATH=${LLVM_INSTALL_DIR}/lib:$LD_LIBRARY_PATH
run . ~/.bashrc
Pay attention to [profile.dev] in Cargo.toml. This is to avoid incremental compilation.
run cargo rustc -- --emit=llvm-bc
The generated bc is in target/debug/deps/hello-*.bc
runllvm-dis *.bc to generate human-readable *.ll file
In dir HelloWorld:
mkdir cmake-build-debug
cd cmake-build-debug
cmake ..
make
We can find the generated libHelloPass.so in helloWorld/cmake-build-debug/lib/HelloPass/libHelloPass.so
opt -load libHelloPass.so -hello hello-*.bc
we can print the function name and the first instruction of the function.