<div dir="ltr">Hi,<div><br></div><div>I believe that is fixed in <a href="https://reviews.llvm.org/rL311586">https://reviews.llvm.org/rL311586</a> thanks to Petr Hosek. Can you try to build the head of the development branch and see if your problem has been fixed? This is the build instruction: <a href="http://lld.llvm.org/#build">http://lld.llvm.org/#build</a><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 9, 2017 at 10:54 AM, vit9696 via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am currently switching to ldd from ld.bfd on a cross-platform embedded project and am facing a behaviour difference when using the same linker scripts with ld.bfd and ldd. Could anybody please give me a more reliable direction I should go with to get the same behaviour from both of the linkers?<br>
<br>
Target binary format is a 32-bit ELF executable, which is expected to consist of a single RWX segment starting from base 0x80000000. (Since I can reproduce the difference with at least mips, ppc32, x86, I attached the x86 linker script to the message as an example.) What is expected from the resulting binary (and what ld.bfd produces) is that no ELF headers are allocated in the address space, e.g.<br>
<br>
<br>
Elf file type is EXEC (Executable file)<br>
Entry point 0x80001a0f<br>
There are 1 program headers, starting at offset 52<br>
<br>
Program Headers:<br>
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align<br>
  LOAD           0x001000 0x80000000 0x80000000 0x08284 0x08284 RWE 0x1000<br>
<br>
 Section to Segment mapping:<br>
  Segment Sections...<br>
   00     .text .rodata .eh_frame .data<br>
<br>
<br>
However, what ldd does is different. (To create a single segment I use --omagic argument, it works fine and is unrelated). The first segment is created at a lower address, with ELF headers in it, and then the actual text section exactly at 0x80000000:<br>
<br>
<br>
Elf file type is EXEC (Executable file)<br>
Entry point 0x80002670<br>
There are 3 program headers, starting at offset 52<br>
<br>
Program Headers:<br>
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align<br>
  PHDR           0x000034 0x7ffff034 0x7ffff034 0x00060 0x00060 R   0x4<br>
  LOAD           0x000000 0x7ffff000 0x7ffff000 0x0a098 0x0a098 RWE 0x1000<br>
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x0<br>
<br>
 Section to Segment mapping:<br>
  Segment Sections...<br>
   00<br>
   01     .text .rodata .data<br>
   02<br>
<br>
<br>
>From what I understand if a linker script is used and the headers fail to allocate, then they should not be present in the resulting binary. However, it seems like ldd treats custom headers and automatically generated headers differently (well, that's at least how I see it at the moment). I think, if the headers are custom, they may not appear in the address space, otherwise they (always?) do. I came up with this conclusion because adding the following command appears to produce a correct binary:<br>
<br>
PHDRS<br>
{<br>
  main PT_LOAD;<br>
}<br>
<br>
<br>
Elf file type is EXEC (Executable file)<br>
Entry point 0x80002670<br>
There are 1 program headers, starting at offset 52<br>
<br>
Program Headers:<br>
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align<br>
  LOAD           0x001000 0x80000000 0x80000000 0x09098 0x09098 RWE 0x1000<br>
<br>
 Section to Segment mapping:<br>
  Segment Sections...<br>
   00     .text .rodata .data<br>
<br>
<br>
However, this is not valid for at least ld.bfd, which produces an error in this case:<br>
ld: no sections assigned to phdrs<br>
<br>
At this step I feel a little confused, because even though I have a workaround, it is unclear whether both behaviours (with and without the mentioned workaround) are expected in the first place? Or might it actually be a bug in either of the linkers? Ideally I have some workaround that works in both of the linkers, but if it is not possible, I could continue going with PHDRS hack.<br>
<br>
Best regards,<br>
Vit<br>
<br>
<br><br>
<br>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>