LLVM Out-of-Source Pass

The LLVM software project provides an elegant feature to build plugins/extension out of the full-blown source tree. Two of the benefits of this feature are 1) that build times are reduced and 2) a self-produced LLVM build is not required to just implement some small extension. The documentation of this feature is available here. I recently tried the out-of-source build by using the Hello transform pass (/lib/Transforms/Hello) and performing the following steps:

When trying to build the pass for LLVM 3.7.1, I unfortunately encountered the following error message, while running CMake:

This problem is already discussed on the web, e.g. StackOverflow, and the root cause is that the CMake variable LLVM_ENABLE_PLUGINS is not set. To get this variable defined, an additional CMake file, HandleLLVMOptions has to be included. By the way, please note that this file is also helpful if LLVM headers are used in the code, because otherwise -std=c++11 is not appended to the C++ compiler flags automatically. Otherwise, the -std=c++11 flag has to be added manually. Including HandleLLVMOptions next yields this error message:

The StackOverflow link above offers a solution for this new problem by defining two CMake variables, which is an acceptable work-around for LLVM 3.7.1. However, the good news is that this problem is fixed in the latest LLVM release 3.8.0 (released on March 8, 2016). Given the fixed code, only two CMake files have to be included, i.e. HandleLLVMOptions and AddLLVM. Note: the variable LLVM_ENABLE_PLUGINS is meanwhile set in the file LLVMConfig.cmake so that for 3.8.0 only AddLLVM is strictly required, if -std=c++11 is added manually or C++11 is not needed in the LLVM pass.

Leave a Reply

Your email address will not be published. Required fields are marked *