<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body 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);">
Thanks, Peter.  That patch pointed me to the exact line of code that I needed to know about!</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);">
I don't think it needs to be configurable via the command line unless others run into a problem with this change, too.  I happened to be working with some other software (that I can't change) that made some overly strict assumptions about how things were linked
 and it did not like having the segments split up.<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);">
-Troy<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Peter Smith <peter.smith@linaro.org><br>
<b>Sent:</b> Tuesday, October 15, 2019 5:20 AM<br>
<b>To:</b> Troy Johnson <troyj@cray.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] [LLD] Placing more sections in same segment as data?</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div dir="ltr"></div>
<br>
<div class="x_gmail_quote">
<div dir="ltr" class="x_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="x_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="x_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="x_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 width="186" style="width:139.5pt; padding:0in">
<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" width="153" height="44" style="width:1.5937in; height:0.4583in" data-outlook-trace="F:1|T:1" src="cid:16dcebd988f1ce351621"></span></a><span style="font-family:Arial,sans-serif; color:rgb(89,89,89)"></span></p>
</td>
<td width="144" style="width:1.5in; padding:0in">
<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" width="25" height="25" style="width:0.2604in; height:0.2604in" data-outlook-trace="F:1|T:1" 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" width="25" height="25" style="width:0.2604in; height:0.2604in" data-outlook-trace="F:1|T:1" 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" width="25" height="25" style="width:0.2604in; height:0.2604in" data-outlook-trace="F:1|T:1" 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>
</div>
</body>
</html>