[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?)

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

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
-o vmlinux


-------------- 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