<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 14 Oct 2019 at 19:57, Troy Johnson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<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">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
I've noticed that lld keeps the data section more isolated than the gold or bfd linkers.  For example, readelf -l applied to the "same" executable linked with those three linkers reveals the following under "Section to Segment mapping":<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
lld:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
05     .data .got.plt .bss</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
gold:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
03     .eh_frame .init_array .fini_array .preinit_array .dynamic .got .got.plt .data .bss</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
bfd:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
05     .eh_frame .preinit_array .init_array .fini_array .dynamic .got .got.plt .data .bss</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
This separation seems to result in lld creating two LOAD RW segments whenever gold or bfd would create only one.  For example, also from readelf -l output:<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<span>  LOAD           0x0000000000001a80 0x0000000000203a80 0x0000000000203a80<br>
</span>
<div>                 0x00000000000002a8 0x00000000000002a8  RW     0x1000<br>
</div>
<div>  LOAD           0x0000000000001d28 0x0000000000204d28 0x0000000000204d28<br>
</div>
<span>                 0x0000000000000060 0x000000000000015c  RW     0x1000</span><br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Could someone explain why the lld behavior is different?  Is there a way to make it match the gold/bfd behavior?  I've looked through the options list and read some of the lld code, but so far have not been able to find a solution.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<br></div></div></blockquote><div><br></div><div>I think this is likely to be <a href="https://reviews.llvm.org/D58892">https://reviews.llvm.org/D58892</a> "Split RW PT_LOAD on the PT_GNU_RELRO boundary", which was made as part of a suggestion in a comment for a related change <a href="https://reviews.llvm.org/D56828">https://reviews.llvm.org/D56828</a>  . The root cause of the justification is that it enables better use of .<a href="http://bss.rel.ro">bss.rel.ro</a> sections. Unfortunately other than turning off RELRO with -znorelo I'm not aware of an easier way to change this behaviour. It may be possible to write a linker script with a PHDRS command but I've not tried it. If I were to try I'd start by getting the linker script from ld.bfd --verbose, and then add a PHDRS command to it.</div><div><br></div><div>If there is a good case for needing the ld.bfd behaviour I suggest raising a PR, I'm thinking that this could be configurable via a command line option.</div><div><br></div><div>Hope this helps</div><div><br></div><div>Peter</div><div><br></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"><div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
Thanks,<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="gmail-m_9211762252904869550Signature">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<p style="line-height:11.5pt"><b><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(38,202,211)">Troy Johnson, Ph.D.</span></b><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(153,140,135)">  |  Manager
 & Lead, Compiler Optimization</span></p>
<p style="line-height:11.5pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(153,140,135)">Cray, a Hewlett Packard Enterprise company</span><span style="font-family:Arial,sans-serif;color:black"></span></p>
<p style="line-height:11.5pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(153,140,135)">2131 Lindau Lane, Suite 1000  |  Bloomington, MN 55425</span><span style="font-family:Arial,sans-serif;color:black"></span></p>
<p style="line-height:11.5pt"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(153,140,135)"><a href="mailto:prosien@cray.com" rel="noopener noreferrer" target="_blank"><span>troyj@cray.com</span></a></span><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(38,202,211)">  <b><a href="http://www.cray.com" rel="noopener noreferrer" target="_blank"><span>www.cray.com</span></a></b></span><span style="font-family:Arial,sans-serif;color:black"></span><b><span style="font-size:5pt;font-family:Arial,sans-serif;color:rgb(38,202,211)">
</span></b><span style="font-family:Arial,sans-serif;color:black"></span></p>
<table style="border-collapse:collapse">
<tbody>
<tr>
<td style="width:139.5pt;padding:0in" width="186">
<p><a href="https://www.cray.com/" rel="noopener noreferrer" target="_blank"><span style="font-size:11pt;color:rgb(89,89,89)"><img alt="signature_957042053" style="width: 1.5937in; height: 0.4583in;" width="153" height="44" src="cid:16dcebd988f1ce351621"></span></a><span style="font-family:Arial,sans-serif;color:rgb(89,89,89)"></span></p>
</td>
<td style="width:1.5in;padding:0in" width="144">
<p><a href="https://twitter.com/cray_inc" rel="noopener noreferrer" target="_blank"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(5,99,193)"><img alt="signature_921593785" style="width: 0.2604in; height: 0.2604in;" width="25" height="25" src="cid:16dcebd988f1ce351622"></span></a><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(89,89,89)">  </span><a href="https://www.youtube.com/channel/UCS483ZExauoVgpG8dLn5p1w" rel="noopener noreferrer" target="_blank"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(5,99,193)"><img alt="signature_1210040077" style="width: 0.2604in; height: 0.2604in;" width="25" height="25" src="cid:16dcebd988f1ce351623"></span></a><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(89,89,89)">  </span><a href="https://www.linkedin.com/company/cray-inc-/" rel="noopener noreferrer" target="_blank"><span style="font-size:11pt;font-family:Arial,sans-serif;color:rgb(5,99,193)"><img alt="signature_152254817" style="width: 0.2604in; height: 0.2604in;" width="25" height="25" src="cid:16dcebd988f1ce351624"></span></a><span style="font-family:Arial,sans-serif;color:rgb(89,89,89)"></span></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>