[LLVMdev] Compile Linux Kernel with LLVM gcc frontend
Andrew Lenharth
andrewl at lenharth.org
Sun Sep 2 16:07:36 PDT 2007
On 8/31/07, Haifeng He <hehaifeng2nd at gmail.com> wrote:
> Hi,
>
> I am curious about if the current LLVM implementation can handle Linux
> kernel (or any particular version of Linux kernel). The first question I have
> is that, how to create LLVM bytecode of Linux kernel using LLVM
> gcc frontend. What changes should I make to the compiling process
> Linux kernel?
The linux kernel can be compiled with llvm, we do it regularly and
boot it. We do usually rip out all the assembly into a side library
(this isn't necessary for the inline asm, but for what we are doing it
is).
Besides dealing with the asm, you need to change:
CC to be llvm-gcc -emit-llvm
LD to be llvm-ld
you also need to modify the final linking rules to give you a bytecode
and stop (or if you want to compile all the way, to run llc first).
I've used both an llc -march=c and an llc -march=x86 compiled kernel.
Oh, and turn off most optimizations. There is still an optimization
or two that breaks the kernel, and I haven't had the time to find it.
> Secondly, is it possible to compile the assembly code in Linux kernel into LLVM
> bytecode? I noticed that llvm-as is for LLVM assembly code only. Is
> there a LLVM assembly frontend for x86 assembly code?
Not currently. More and more of the things the kernel has assembly
for, such as locks, are finding their way into llvm, but the
privileged state operations do not have LLVM corespondents (but they
do in a research project we are working on (SVA and/or LLVA), there
was a paper last year about them, and they are used in an upcoming
SOSP paper).
Andrew
More information about the llvm-dev
mailing list