Elmord's Magic Valley

Software, lingüística e rock'n'roll. Às vezes em Português, sometimes in English.

Compiling an LLVM pass against Debian's pre-packaged LLVM

2015-08-21 11:46 -0300. Tags: comp, prog, llvm, in-english

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.)

Makefile

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

Comentários / Comments (3)

cpnogueira, 2015-08-22 15:10:50 -0300 #

OMG! An English post! <o>


Vítor De Araújo, 2015-08-22 15:52:00 -0300 #

Run to the hills! :P


Euqueriaeracomentar, 2015-09-01 12:11:46 -0300 #

No need for a comment


Deixe um comentário / Leave a comment

Main menu

Posts recentes

Comentários recentes

Tags

em-portugues (213) comp (137) prog (68) in-english (50) life (47) pldesign (35) unix (34) lang (32) random (28) about (27) mind (25) lisp (23) mundane (22) fenius (20) ramble (17) web (17) img (13) rant (12) hel (12) privacy (10) scheme (10) freedom (8) copyright (7) bash (7) music (7) academia (7) lash (7) esperanto (7) home (6) mestrado (6) shell (6) conlang (5) emacs (5) misc (5) latex (4) editor (4) book (4) php (4) worldly (4) android (4) politics (4) etymology (4) wrong (3) security (3) tour-de-scheme (3) kbd (3) c (3) film (3) network (3) cook (2) poem (2) physics (2) wm (2) treta (2) philosophy (2) comic (2) lows (2) llvm (2) perl (1) en-esperanto (1) audio (1) old-chinese (1) kindle (1) german (1) pointless (1) translation (1)

Elsewhere

Quod vide


Copyright © 2010-2020 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.