[llvm-dev] Linking Linux kernel with LLD

George Rimar via llvm-dev llvm-dev at lists.llvm.org
Wed Feb 8 07:59:30 PST 2017


>I have just checked it, the startup.elf and realmode.elf are fine. Only few changes are required for mainline kernel and one >commit has to be reverted from lld and a few patches have to be applied.

>
>The only step when I have used BFD is linking vmlinux. I have manually set LD variable in vmlinux_link() function. The vmlinux >produced by lld doesn't work yet. I will compare it to the one produced by GNU ld and try to figure out what is wrong (maybe >you can suggest some useful objdump flags?)
>
>Regards,
>Dmitry

Just want to share latest results of investigation from my side.
I traced kernel linked with LLD to find where it fails.

LLD linked kernel starts execution and then I came up to protected_mode_jump? function, which intention to jump to startup_64:
    jmpl *%eax # Jump to the 32-bit entrypoint
(https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/boot/pmjump.S#L76)
(https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/kernel/head_64.S#L48)

It does not happen. Code executes right before jmpl and then fail on this call for me, so startup_64 never called.

startup_64 is a part of vmlinux binary. So as you said vmlinux has troubles and after doing readelf -a on LLD linked and bfd linked ones, I found that LLD outputs vmlinux as executable and bfd output is DSO. Had no chance to investigate why that happens, but pretty sure that is the not fine.

Invocation line for us does not contain -shared:

-m elf_x86_64
--script home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/vmlinux.lds
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/head_64.o
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/misc.o
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/string.o
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/cmdline.o
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/error.o
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/piggy.o
home/umb/linux_kernel/linux/linux/arch/x86/boot/compressed/cpuflags.o
-o vmlinux

George.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170208/7ae05798/attachment.html>


More information about the llvm-dev mailing list