Hi, I'm trying to compile linux-2.6.23.16 with llvm-2.3. Is it at all possible? I get "Not an ELF" error. I pass "-emit-llvm" option to spit LLVM IR, which can be JITed at runtime $ make CROSS_COMPILE=llvm- CFLAGS="-O2 -emit-llvm" Error: not ELF make[2]: *** [scripts/mod/elfconfig.h] Error 1 make[1]: *** [scripts/mod] Error 2 make: *** [scripts] Error 2 using the verbose option - $ make V=1 CROSS_COMPILE=llvm- CFLAGS="-O2 -emit-llvm" /bin/bash scripts/checksyscalls.sh llvm-gcc -Wp,-MD,./.missing-syscalls.d -nostdinc -isystem /home/ashish/llvm/llvm-gcc4.2-2.3.source/obj/../install/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/include -D__KERNEL__ -Iinclude -include include/linux/autoconf.h -O2 -emit-llvm -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(missing_syscalls)" -D"KBUILD_MODNAME=KBUILD_STR(missing_syscalls)" make -f scripts/Makefile.build obj=scripts make -f scripts/Makefile.build obj=scripts/genksyms make -f scripts/Makefile.build obj=scripts/mod scripts/mod/mk_elfconfig x86_64 < scripts/mod/empty.o > scripts/mod/elfconfig.h Error: not ELF make[2]: *** [scripts/mod/elfconfig.h] Error 1 make[1]: *** [scripts/mod] Error 2 make: *** [scripts] Error 2 $cat scripts/Makefile.build hostprogs-y := modpost mk_elfconfig always := $(hostprogs-y) empty.o modpost-objs := modpost.o file2alias.o sumversion.o # dependencies on generated files need to be listed explicitly $(obj)/modpost.o $(obj)/file2alias.o $(obj)/sumversion.o: $(obj)/elfconfig.h quiet_cmd_elfconfig = MKELF $@ cmd_elfconfig = $(obj)/mk_elfconfig $(ARCH) < $< > $@ $(obj)/elfconfig.h: $(obj)/empty.o $(obj)/mk_elfconfig FORCE $(call if_changed,elfconfig) targets += elfconfig.h It seems like Makefile.build is trying to make an ELF file out of scripts/mod/empty.o which has been compiled using LLVM to emit LLVM code. How to fix this? Am I missing something? Please help. Thanks, Ashish
On 2008-09-27 05:19, Ashish Bijlani wrote:> Hi, > > I'm trying to compile linux-2.6.23.16 with llvm-2.3. Is it at all > possible? I get "Not an ELF" error. I pass "-emit-llvm" option to spit > LLVM IR, which can be JITed at runtime > >If you want to build a kernel you can't use the JIT anyway, so why not just build native code? Best regards, --Edwin
I plan to use virtualization infrastructure to JIT VM Kernel Code. Michael Engel has done that in the past to have dynamic aspect in the Kernel: http://llvm.org/pubs/2005-03-14-ACP4IS-AspectsKernel.pdf He used L4 based Hypervisor and Virtual Machines. Can this not be done or am I missing something? -Ashish On Sat, Sep 27, 2008 at 3:13 AM, Török Edwin <edwintorok at gmail.com> wrote:> On 2008-09-27 05:19, Ashish Bijlani wrote: >> Hi, >> >> I'm trying to compile linux-2.6.23.16 with llvm-2.3. Is it at all >> possible? I get "Not an ELF" error. I pass "-emit-llvm" option to spit >> LLVM IR, which can be JITed at runtime >> >> > > If you want to build a kernel you can't use the JIT anyway, so why not > just build native code? > > Best regards, > --Edwin > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Fri, Sep 26, 2008 at 9:19 PM, Ashish Bijlani <ashish.bijlani at gmail.com> wrote:> Hi, > > I'm trying to compile linux-2.6.23.16 with llvm-2.3. Is it at all > possible?Yes, but it requires significant hacking, and the result for 2.6 is a mostly bitcode kernel with a few userspace shared libraries linked in as objcode (yes, the kernel builds .so files and includes them in the binary). There are a few changes here and there you can make to the kernel code to produce significantly nicer bitcodes too (e.g. rather than having module level asm that makes symbols weak, you can just have gcc do it). The modification to the make system is not difficult, but it requires some work and an understanding of the kernel build system. Andrew
Thanks for the help. I've a couple of questions though: How does LLVM deal with inline assembly? I'm trying to compile kernel and I get this error probably because LLVM is not able to handle inline assembly. I'm using LLVM-2.3 code snippet from "arch/x86_64/kernel/asm-offsets.c" .... #define DEFINE(sym, val) \ asm volatile("\n->" #sym " %0 " #val : : "i" (val)) .... DEFINE(__NR_syscall_max, sizeof(syscalls) - 1); return 0; # make CROSS_COMPILE=llvm- V=1 llvm-gcc -Wp,-MD,arch/x86_64/kernel/.syscall.o.d -nostdinc -isystem /home/ashish/llvm/llvm-gcc4.2-2.3.source/obj/../install/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/include -D__KERNEL__ -Iinclude -include include/linux/autoconf.h -emit-llvm -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -mtune=generic -m64 -mno-red-zone -mcmodel=kernel -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -funit-at-a-time -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -maccumulate-outgoing-args -fomit-frame-pointer -g -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(syscall)" -D"KBUILD_MODNAME=KBUILD_STR(syscall)" -c -o arch/x86_64/kernel/.tmp_syscall.o arch/x86_64/kernel/syscall.c arch/x86_64/kernel/syscall.c:22: error: '__NR_syscall_max' undeclared here (not in a function) arch/x86_64/kernel/syscall.c:24: error: array index in initializer not of integer type arch/x86_64/kernel/syscall.c:24: error: (near initialization for 'sys_call_table') In file included from arch/x86_64/kernel/syscall.c:25: include/asm-x86_64/unistd.h:16: error: array index in non-array initializer include/asm-x86_64/unistd.h:16: error: (near initialization for 'sys_call_table') include/asm-x86_64/unistd.h:18: error: array index in non-array initializer Note that I use "-emit-llvm" option with llvm-gcc. Is this correct of am I missing something? How can I fix this error? Thanks, Ashish On Sat, Sep 27, 2008 at 7:03 PM, Andrew Lenharth <andrewl at lenharth.org> wrote:> On Fri, Sep 26, 2008 at 9:19 PM, Ashish Bijlani > <ashish.bijlani at gmail.com> wrote: >> Hi, >> >> I'm trying to compile linux-2.6.23.16 with llvm-2.3. Is it at all >> possible? > > Yes, but it requires significant hacking, and the result for 2.6 is a > mostly bitcode kernel with a few userspace shared libraries linked in > as objcode (yes, the kernel builds .so files and includes them in the > binary). There are a few changes here and there you can make to the > kernel code to produce significantly nicer bitcodes too (e.g. rather > than having module level asm that makes symbols weak, you can just > have gcc do it). > > The modification to the make system is not difficult, but it requires > some work and an understanding of the kernel build system. > > Andrew > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >