[llvm-dev] Linking Linux kernel with LLD

George Rimar via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 9 01:27:16 PST 2017


>That address seems to come from >here: https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/boot/pm.c#L124
>
>```
>protected_mode_jump(boot_params.hdr.code32_start,
>   (u32)&boot_params + (ds() << 4));
>```
>
>That boot_params.hdr.code32_start field is probably either invalid (bad reloc or something else causing the bootloader to >calculate the wrong address) or valid but the thing it thinks it is pointing to wasn't loaded (missing PT_LOAD etc.).

boot_params.hdr.code32_start field is valid :) It is 0x100000, like expected (btw thanks for those links on info how kernel boots, they were pretty useful). I checked it is valid using trace:

void go_to_protected_mode(void)
{
if (boot_params.hdr.code32_start == 0x100000)
  puts("go_to_protected_mode 1\n");
else
  puts("go_to_protected_mode 2\n");
while (1) {};

I had to use infinite loop here, because QEMU does not crash for me, but do domething what looks like reboot and clears all my traces output. Infinite loop helps to see traces text, if placed before dead point.

>
>Btw, how did you narrow it down to that specific instruction? That's pretty handy.

I used very simple approach, did not know how to do that properly :), so inserted infinite loops in asm code:
foo:
 jmp foo

And watched for behavior of QEMU. If it just hanged that was fine, I knew I am inside my loop, if QEMU rebooted, I knew it crashed at point I was looking for. So tracing bfd linked kernel and using documentation I found that startup_64 ?is next destination POI, and found that this instruction is the last before QEMU reboots for me.

>I think you can also get DSO with -pie I think, but I don't see that either. This is quite mysterious. I also did a quick look at the >linker script and didn't see anything at first glance that would cause DSO output (can linker scripts even control EType?). The >bootloader might not even look at the EType though.
>
>-- Sean Silva

I think best way would be to look at what is invocation for BFD here. I am pretty sure -shared/-pie flag is just lost because of some configuration issue, probably it checks that we are running bfd may be. Just a guess.

George.


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


More information about the llvm-dev mailing list