编写LLVM Pass的文档:HowToWriteALLVMPass
1.写Makefile
# Makefile for hello pass
# Path to top level of LLVM hierarchy
LEVEL = ../../..
# Name of the library to build
LIBRARYNAME = Hello
# Make the shared library become a loadable module so the tools can
# dlopen/dlsym on the resulting library.
LOADABLE_MODULE = 1
# Include the makefile implementation stuff
include $(LEVEL)/Makefile.common
2.写Hello.cpp
3.得到Hello.so。
clang++ `llvm-config --libs --ldflags --cxxflags
` Hello.cpp -std=c++0x -fPIC -shared -o Hello.so
4.使用Hello.so。
opt -load /usr/local/arm/llvm3.8.0/lib/Transforms/Hello/Hello.so -hello <hello.bc> /dev/null
在尝试编写一个LLVM pass时,遇到以下问题(未解决,最终使用的第3步的方法):
CMake Error at CMakeLists.txt:16 (include):
include could not find load file:AddLLVM
CMake Error at CMakeLists.txt:17 (add_llvm_loadable_module):
Unknown CMake command "add_llvm_loadable_module".
-- Configuring incomplete, errors occurred!
Building LLVM with CMake 点击打开链接