Compiling Linux Kernel

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?



* Lei Shang
* PhD candidate, Computer Science & Engineering,
* University of New South Wales, Sydney, Australia, 2052
* Email: Mobile: 0425711216
* Homepage:

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 :slight_smile: (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