<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 class=""><span class="">MEMORY</span></p>
<p class=""><span class="">{</span></p>
<p class=""><span class=""> flash (rx) : ORIGIN = </span><span class="">0x20000</span><span class="">, LENGTH = </span><span class="">0x8000</span></p>
<p class=""><span class=""> ram (rwx) : ORIGIN = </span><span class="">0x20005000</span><span class="">, LENGTH = </span><span class="">0x00003000</span></p>
<p class=""><span class="">}</span></p>
<p class=""><span class=""><br>
</span></p>
<p class=""><span class="">REGION_ALIAS(</span><span class="">"REGION_TEXT"</span><span class="">, flash);</span></p>
<p class=""><span class="">REGION_ALIAS(</span><span class="">"REGION_RAM"</span><span class="">, ram);</span></p>
<p class=""><span class=""><br>
</span></p>
<p class=""><span class="">SECTIONS</span></p>
<p class=""><span class="">{</span></p>
<p class=""><span class=""> .text :</span></p>
<p class=""><span class=""> {</span></p>
<p class=""><span class=""> ...</span></p>
<p class=""><span class=""> } > REGION_TEXT</span></p>
<p class=""><span class=""> </span></p>
<p class=""><span class=""> _etext = .;</span></p>
<p class=""><span class=""> .data :</span></p>
<p class=""><span class=""> {</span></p>
<p class=""><span class=""> ...</span></p>
<p class=""><span class=""> } > REGION_RAM AT > REGION_TEXT</span></p>
<p class=""><span class=""></span><br></p>
<p class=""><span class="">}</span></p>
<p class=""><br></p><p class="">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 class=""><span style="font-family:arial,helvetica,sans-serif"><br></span></p><p class=""><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 class=""><span style="font-family:arial,helvetica,sans-serif"><br></span></p><p class=""><span class="">SECTIONS</span></p><p class=""><span class=""> {</span></p><p class=""><span class=""> . = </span>0x20000;</p><p class=""><span class=""> .text :</span></p><p class=""><span class=""> {</span></p><p class=""><span class=""> ...</span></p><p class=""><span class=""> }</span></p><p class=""><span class=""> </span> </p><p class=""><span class=""> _etext = .;</span></p><p class=""><span class=""> </span><span class="">. = 0x20005000;</span></p><p class=""><span class=""> _data = .;</span></p><p class=""><span class=""> .data :</span></p><p class=""><span class=""> {</span></p><p class=""><span class=""> ...</span> </p><p class=""><span class=""> }</span></p><p class="">
</p><p class=""><span class="">}</span></p><p class=""><span class=""><br></span></p><p class=""><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 class=""><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 class=""><span style="font-family:arial,helvetica,sans-serif"><br></span></p><p class=""><span style="font-family:arial,helvetica,sans-serif">Thanks,</span></p><p class=""><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>