<div dir="ltr">Hi Ed,<div><br></div><div>It looks like lld is failing at mapping two sections far apart from each other into two different segments. Since it puts these two sections (.text and .data) in the same ELF segment, the segment is forced to be huge because the start addresses of these sections are far apart from each other. I would begin by investigating how TargetLayout<ELFT>::assignSectionsToSegments() works and go from there. This function lives at lld/lib/ReaderWriter/ELF/TargetLayout.cpp. I don't believe you can try any other flags to try to get this done without fixing this logic.</div><div><br></div><div>Rafael Auler</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 1, 2015 at 12:00 PM, <a href="mailto:ed@modk.it">ed@modk.it</a> <span dir="ltr"><<a href="mailto:ed@modk.it" target="_blank">ed@modk.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi All,<div><br></div><div>Congratulations on the major progress on the llvm linker lld over the past year including the new linker script support.  This really makes it possible to ditch binutils altogether.  It looks like lld's MEMORY sections are currently parsed but not evaluated, but so far that hasn't been a problem.</div><div><br></div><div>The only snag is I can't figure out how to define the start of the .data section in a sane way.  Let's say we want our flash (.text) section to start at address 0x20000 with a max size of 0x8000 bytes and a data section start at 0x20005000 with a max length of 0x3000 bytes.  We'd usually accomplish this with a combination of MEMORY and SECTION entries in the linker script tied together by region aliases, the "AT" directive and the ">" operator:</div><div><br></div><div>







<p><span>MEMORY</span></p>
<p><span>{</span></p>
<p><span>    flash (rx) : ORIGIN = </span><span>0x20000</span><span>, LENGTH = </span><span>0x8000</span></p>
<p><span>    ram (rwx) : ORIGIN = </span><span>0x20005000</span><span>, LENGTH = </span><span>0x00003000</span></p>
<p><span>}</span></p>
<p><span><br>
</span></p>
<p><span>REGION_ALIAS(</span><span>"REGION_TEXT"</span><span>, flash);</span></p>
<p><span>REGION_ALIAS(</span><span>"REGION_RAM"</span><span>, ram);</span></p>
<p><span><br>
</span></p>
<p><span>SECTIONS</span></p>
<p><span>{</span></p>
<p><span>    .text :</span></p>
<p><span>    {</span></p>
<p><span>        ...</span></p>
<p><span>    } > REGION_TEXT</span></p>
<p><span>    </span></p>
<p><span>    _etext = .;</span></p>
<p><span>    .data :</span></p>
<p><span>    {</span></p>
<p><span>       ...</span></p>
<p><span>    } > REGION_RAM AT > REGION_TEXT</span></p>
<p><span></span><br></p>
<p><span>}</span></p>
<p><br></p><p>But the MEMORY entries don't seem to be evaluated and ">", "AT", and "REGION_ALIAS" don't seem to be hooked up either.  Command line options like "<span style="font-family:arial,helvetica,sans-serif">-Tdata=org=0x20005000" or "--section-start=.data=</span><span style="font-family:arial,helvetica,sans-serif"> 0x20005000" are also not working.  </span></p><p><span style="font-family:arial,helvetica,sans-serif"><br></span></p><p><span style="font-family:arial,helvetica,sans-serif">However, t</span><span style="font-family:arial,helvetica,sans-serif">he following linker script gets us close:</span></p><p><span style="font-family:arial,helvetica,sans-serif"><br></span></p><p><span>SECTIONS</span></p><p><span>    {</span></p><p><span>        . = </span>0x20000;</p><p><span>        .text :</span></p><p><span>        {</span></p><p><span>           ...</span></p><p><span>        }</span></p><p><span>    </span>  </p><p><span>        _etext = .;</span></p><p><span>        </span><span>. = 0x20005000;</span></p><p><span>        _data = .;</span></p><p><span>        .data :</span></p><p><span>        {</span></p><p><span>           ...</span>   </p><p><span>        }</span></p><p>



























































</p><p><span>}</span></p><p><span><br></span></p><p><span style="font-family:arial,helvetica,sans-serif">The only problem is the resulting elf and binary files are HUGE (e.g. elf is 500mb vs 50k) as the linker seems to be filling the space between the end of text and the beginning of data.  A "</span>llvm-readobj -s" on the resulting elf is nearly identical to one created with binutils except binults-ld puts .data at Address: 0x20005000 Offset: 0xD000 and llvm-lld has data at Address: 0x20005000 Offset: 0x1FFED000 (based on start address of 0x18000.)</p>







<p><span style="font-family:arial,helvetica,sans-serif">Any thoughts on a supported linker flag or linker script option that can help here?  Or a source file to dive into to get something working?  I'd be willing to take a pass at completing the MEMORY section implementation if that's the most sane way to move forward but would love a pointer in the right direction.</span></p><p><span style="font-family:arial,helvetica,sans-serif"><br></span></p><p><span style="font-family:arial,helvetica,sans-serif">Thanks,</span></p><p><span style="font-family:arial,helvetica,sans-serif">Ed</span></p></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><br></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" rel="noreferrer" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>