Compiling user mode linux with LLVM

Hello,

I've recently started working on compiling UML with LLVM: the goal is to
produce a bitcode version of vmlinux.

With some tweaks to the build process, I can use:
make ARCH=um CROSS_COMPILE=llvm- CFLAGS="-emit-llvm"

to produce vmlinux bitcode.

The question is with respect linker script support. Since llvm-ld does not
support linker scripts--please correct me if I'm wrong--it's clear that some
work is necessary to get things running.

There was a thread on the mailing list last September about this question:

I've recently started working on compiling UML with LLVM: the goal is to
produce a bitcode version of vmlinux.

I haven't tried UML, but I've produced (and run) native kernels with LVLM.

As an experiment, I've tried using llc to convert the vmlinux.bc output into
native assembly, then use "as" and "ld" to produce a native vmlinux, but the
ld step fails with:

ld: ./vmlinux_native.o: bad reloc symbol index (0x9c113c >= 0x4af6) for
offset 0x18585 in section `.text'
./vmlinux_native.o: could not read symbols: Bad value

I'm not sure what this is about.

I've not pursued this specific issue further since my goal is to run the
bitcode directly, e.g. via lli.

You might contact Will Dietz (CC'ed) who has JITed the kernel.

I'm also aware of the clever tricks the kernel uses that need to be
addressed, mentioned in the second paragraph of Andrew's above reply. As an
example, the symbol __initcall_start is defined in a linker script
(vmlinux.lds) and is used in the kernel as part of the initialization.

Has anyone successfully modified the kernel initialization code to get UML
working with LLVM? If so, I'm interested in the approach taken so as to
avoid wasting time.

You can easily write a script that walks the init sections and creates
a global array of function points that would normally be constructed
by the linker script.

Andrew