[LLVMdev] Compiling Linux Kernel

Andrew Lenharth andrewl at lenharth.org
Tue Feb 2 17:33:04 PST 2010

On Tue, Feb 2, 2010 at 7:13 PM, Lei Shang <shang1982 at gmail.com> wrote:
> Does anyone have experience to compile Linux kernel in LLVM-2.6?
> I am working on a C/C++ race detection framework and want to test in
> large applications. But I do have a lot of errors while compiling
> Linux kernel 2.6.3 using LLVM-2.6. Actually, I only need to get the
> .bc bitcode file.
> Anyboy does similar work before? Which Linux kernel version is used
> and any skills?

2.6.27 works with a few changes (some went upstream and are in later
kernels).  IPO breaks the kernel, but for analysis you don't need
that.  You will have a lot of assembly, semi-invisible entry points,
external code (to the analysis), and have to handle seeing the

But it's doable.  I compile it 50 times a day :) (clearly for research)

The following subset of -O3 work:

opt vmlinux.bc -f -o vmlinux.opt.bc -preverify -domtree -verify
-lowersetjmp -raiseallocs -simplifycfg -domtree -domfrontier -mem2reg
-globalopt -globaldce -deadargelim -simplifycfg -basiccg -prune-eh
-functionattrs -argpromotion -simplify-libcalls -jump-threading
-simplifycfg -domtree -domfrontier -scalarrepl -break-crit-edges
-condprop -tailcallelim -simplifycfg -reassociate -domtree -loops
-loopsimplify -domfrontier -lcssa -loop-rotate -licm -lcssa
-loop-unswitch -scalar-evolution -lcssa -iv-users -indvars
-loop-deletion -lcssa -loop-unroll -memdep -memcpyopt -memdep -sccp
-break-crit-edges -condprop -domtree -memdep -dse -adce -simplifycfg
-strip-dead-prototypes -print-used-types -deadtypeelim -constmerge
-preverify -domtree -verify

llc -disable-fp-elim -march=x86 -mcpu=,-mmx,-sse,-sse2
-code-model=kernel -f vmlinux.rec.bc -o vmlinux.s
llvm-gcc  -D__ASSEMBLY__ -m32 -DCONFIG_AS_CFI=1
-DCONFIG_AS_CFI_SIGNAL_FRAME=1 -Iinclude/asm-x86/mach-default -O0 -c
-o vmlinux.native vmlinux.s

(a couple of the flags come from the original 64bit port, and weren't
cleaned up (code-model), some are unnecessary but come from not
changing the makefiles too much, and some are just for debuging
(disable-fp-elim) which is handy when attaching gdb most of those


More information about the llvm-dev mailing list