<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 8, 2017 at 7:59 AM, George Rimar <span dir="ltr"><<a href="mailto:grimar@accesssoftek.com" target="_blank">grimar@accesssoftek.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:calibri,arial,helvetica,sans-serif"><span class="gmail-">
<p><span style="color:rgb(33,33,33);font-size:12pt">>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.</span><br>
</p>
</span><div style="color:rgb(33,33,33)">
<div><span class="gmail-">
<div>> </div>
<div>>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?)</div>
<div>> </div>
<div>>Regards,</div>
<div>>Dmitry<br>
</div>
<div><br>
</div>
</span><div>Just want to share latest results of investigation from my side. </div>
<div>I traced kernel linked with LLD to find where it fails.<br>
</div>
<div><br>
</div>
<div>LLD linked kernel starts execution and then <span style="font-size:12pt">I came up to </span><span style="font-size:12pt">protected_mode_jump</span><span style="font-size:12pt"> fun</span><span style="font-size:12pt">ction, which intention to
jump to </span><span style="font-size:12pt">startup_64</span><span style="font-size:12pt">:</span></div>
<div> jmpl<span class="gmail-m_-4712762429947468636Apple-tab-span" style="white-space:pre-wrap"> </span>*%eax<span class="gmail-m_-4712762429947468636Apple-tab-span" style="white-space:pre-wrap">
</span># Jump to the 32-bit entrypoint<br>
</div>
<div>(<a href="https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/boot/pmjump.S#L76" style="font-size:12pt" target="_blank">https://github.com/torvalds/<wbr>linux/blob/<wbr>5924bbecd0267d87c24110cbe2041b<wbr>5075173a25/arch/x86/boot/<wbr>pmjump.S#L76</a>)<br>
</div>
<div>(<a href="https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/kernel/head_64.S#L48" target="_blank">https://github.com/torvalds/<wbr>linux/blob/<wbr>5924bbecd0267d87c24110cbe2041b<wbr>5075173a25/arch/x86/kernel/<wbr>head_64.S#L48</a>)<br>
</div>
<div><br>
</div>
<div>It does not happen. Code executes right before jmpl and then fail on this call for me, so <span style="color:rgb(33,33,33);font-family:calibri,arial,helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">startup_64</span>
never called.<br></div></div></div></div></blockquote><div><br></div><div>That address seems to come from here: <a href="https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/boot/pm.c#L124">https://github.com/torvalds/linux/blob/5924bbecd0267d87c24110cbe2041b5075173a25/arch/x86/boot/pm.c#L124</a></div><div><br></div><div>```</div><div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span>protected_mode_jump(boot_params.hdr.code32_start,</div><div><span class="gmail-Apple-tab-span" style="white-space:pre"> </span> (u32)&boot_params + (ds() << 4));</div></div><div>```</div><div><br></div><div>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.). </div><div><br></div><div><br></div><div>Btw, how did you narrow it down to that specific instruction? That's pretty handy.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:calibri,arial,helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div>
</div>
<div><br>
</div>
<div>startup_64 is a part of vmlinux binary. So as you said vmlinux has troubles and a<span style="font-size:12pt">fter doi</span><span style="font-size:12pt">ng readelf -a on LLD linked and bfd linked ones, I found that LLD outputs <span style="color:rgb(33,33,33);font-family:calibri,arial,helvetica,sans-serif;font-size:16px;background-color:rgb(255,255,255)">vmlinux</span> as executable
and bfd output is DSO. Had no chance to investigate why that happens, </span><span style="font-size:12pt">but pretty sure that is t</span><span style="font-size:12pt">he
</span><span style="font-size:12pt">not fine</span><span style="font-size:12pt">.</span><span style="font-family:arial,sans-serif;font-size:small;color:rgb(34,34,34)"> </span></div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:calibri,arial,helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div>
<div><br>
</div>
<div>Invocation line for us does not contain -shared:<br>
</div>
<div><br>
</div>
<div>
<div>-m elf_x86_64</div>
<div>--script home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/vmlinux.lds</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/head_64.o</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/misc.o</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/string.o</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/cmdline.o</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/error.o</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/piggy.o</div>
<div>home/umb/linux_kernel/linux/<wbr>linux/arch/x86/boot/<wbr>compressed/cpuflags.o</div>
<div>-o vmlinux</div></div></div></div></div></blockquote><div><br></div><div><br></div><div>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.</div><div><br></div><div>-- Sean Silva</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:calibri,arial,helvetica,sans-serif"><div style="color:rgb(33,33,33)"><div><div><div><span class="gmail-HOEnZb"><font color="#888888"><br>
</font></span></div><span class="gmail-HOEnZb"><font color="#888888">
</font></span></div><span class="gmail-HOEnZb"><font color="#888888">
<div><br>
</div>
<div>George.<br>
</div>
<div><br>
<br>
</div>
<div><br>
</div>
</font></span></div>
</div>
</div>
</blockquote></div><br></div></div>