Compile a linux kernel with LLVM?

Hi,

  I want to check some properties of linux kernel with llvm, but I don't know how to compile a

linux kernel to an llvm's .bc file. I have let llvm's gcc front-end ignore inline assembly by

modifying cfrontend/src/gcc/llvm-expand.c, and replace CC/as/ar in the Makefile of the kernel

with llvm-gcc/llvm-as/llvm-ar. However, the linux's "make" reports errors: "File format not

recognized" and "not ELF".

  Some people did this before?

Thanks.

ymxia@nudt.edu.cn wrote:

Hi,

  I want to check some properties of linux kernel with llvm, but I don't know how to compile a

linux kernel to an llvm's .bc file. I have let llvm's gcc front-end ignore inline assembly by

modifying cfrontend/src/gcc/llvm-expand.c, and replace CC/as/ar in the Makefile of the kernel

with llvm-gcc/llvm-as/llvm-ar. However, the linux's "make" reports errors: "File format not

recognized" and "not ELF".

  Some people did this before?

I am currently working on a similar project (compiling Linux with the LLVM compiler). However, my work modifies the inline assembly in the kernel to use LLVM intrinsics (most of which have not been added to LLVM yet).

First, make sure you change LD in the master Makefile to use gccld (instead of the native linker, ld). The final linking of vmlinux uses ld directly (which doesn't understand LLVM bytecode files). This needs to be changed to use gccld.

Second, you may need to adjust the rules for the vmlinux target a little bit. The gccld program will, given the -o <file> option, will create file and file.bc, where file.bc is the actual bytecode file and file is a script that runs lli on file.bc.

Third, if all you want to do is do program analysis on Linux, then all you need to build is vmlinux.bc. It won't be necessary to build bzImage.

If the problem continues, just use gmake/make without the -s option so that you can see what programs it is running. Chances are good that the error is caused by running a native tool on an LLVM bytecode file; looking at what gmake is doing will quickly tell you what program is being run.

Just out of curiousity, what sort of analysis do you want to do on vmlinux?

-- John T.

Dear John,

I am glad to receive your letter. Your advices are very helpful for me. Thank you very much.

Kindly excuse my not replying to your favour of the 7th July until today.

I want to analysis security of large source code, such as buffer overrun, security model, etc.

I have done some primitive experiments for that, and wich show the intermediate language of

LLVM is very effective, and other supports, such as def-use chain, call graph, loopinfo, alias

analysis, etc., are powerful. I like LLVM!

Without question, I will meet many problems when I study LLVM. Please prepare your favours. :slight_smile:

-Xia

John Criswell <criswell@cs.uiuc.edu>: