Elmord's Magic Valley

Computers, languages, and computer languages. À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.)


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 \
           -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

Recent posts

Recent comments


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


Quod vide

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