So, I'm writing an LLVM pass for my Master's. Until now, I had been compiling LLVM myself and compiling the pass within LLVM's source tree, following more-or-less the standard instructions. This works fine in my main machine, which has plenty of memory for compiling LLVM, but not in my netbook, which has only 1GB of RAM, which is not nearly enough to compile and link Clang/LLVM.
Fortunately, it is possible (and easy) to compile a pass against the precompiled Debian LLVM packages. For that you'll need the package llvm-dev, which depends on llvm-3.5-dev. (Debian is still using Clang/LLVM 3.5; llvm.org/apt has more recent packages, if you happen to need them.)
With the packages installed, all you have to do is adjust your project's Makefile to use the installed headers. (Alternatively, you could probably use CMake to compile your module, just like you can do with an LLVM you compiled yourself, but I got it working with a Makefile and right now I'm more interested in finishing my Master's than figuring out build systems.)
Some additional -D (macro definition) flags also seem to be required for the LLVM headers to work:
CXX := c++ -fPIC -Wall -W -std=c++11 -g \ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \ -I/usr/include/llvm-3.5/ -I/usr/include/llvm-c-3.5/
Then, you have to write the rules to build your pass, which should be compiled to a shared library. My project's rules look like this:
LLVMTyr.so: Tyr.cpp.o $(CXX) -shared -o LLVMTyr.so Tyr.cpp.o Tyr.cpp.o: Tyr.cpp $(CXX) Tyr.cpp -c -o Tyr.cpp.o
If compilation succeeds, you can run your pass by running LLVM's opt with the option -load ./YourLibrary.so. For instance:
# Generate an LLVM IR file with Clang. clang -S -emit-llvm test.c -o test.ll # Use it as input to your pass. opt -load ./LLVMTyr.so (your pass' options) test.ll
Copyright © 2010-2023 Vítor De Araújo
O conteúdo deste blog, a menos que de outra forma especificado, pode ser utilizado segundo os termos da licença Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International.
Powered by Blognir.