<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jan 27, 2017 at 3:02 AM, George Rimar via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">grimar added a comment.<br>
<span class="m_-7889769643084381030m_-6281885705326799636gmail-"><br>
In <a href="https://reviews.llvm.org/D27415#657878" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2741<wbr>5#657878</a>, @ruiu wrote:<br>
<br>
> I probably do not understand what you are trying to solve.<br>
><br>
> Currently, LLD merges two mergeable input sections if they have the same name, types and section flags. But, you are saying that that is not always correct, right?<br>
><br>
> Can you briefly describe the exact semantics this patch is trying to implement, and then why you think that is the better behavior?<br>
<br>
<br>
</span>I am trying to solve issue I am demonstrating at <a href="https://reviews.llvm.org/D29217" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2921<wbr>7</a> page.<br>
It has:<br>
<br>
  .section .aaa.1,"a"<br>
  .byte 11<br>
  .section .aaa.2,"a"<br>
  .byte 22<br>
<br>
  .section .bbb.1,"aMS",@progbits,1<br>
  .asciz "foo"<br>
  .section .bbb.2,"aMS",@progbits,1<br>
  .asciz "foo"<br>
<br>
  .section .ccc.1,"a"<br>
  .byte 33<br>
  .section .ccc.2,"a"<br>
  .byte 44<br>
<br>
It has also symbols assignments to A and B that should mark the start/end of .ccc :<br>
<br>
  .rodata : { *(.aaa.*) *(.bbb.*) A = .; *(.ccc.*) B = .; }<br>
<br>
**1. LLD currently (clean head revision) do: **<br>
<br>
It creates 2 output .rodata sections:<br>
.rodata (.aaa.1 .aaa.2 .ccc.1 .ccc.2)<br>
.rodata (.bbb.1 .bbb.2)<br></blockquote><div><br></div><div>OK, so my understanding is this.</div><div><br></div><div>Assume you have four mergeable string input sections .foo.1, .foo.2, .bar.1 and .bar.2, where .foo.{1,2} are writable but .bar.{1,2} are not. Also assume you have this linker script.</div><div><br></div><div>  .rodata : { *(.foo.*) *(.bar.*); }<br></div><div><br></div><div>LLD currently creates two .rodata sections for those inputs. One for .foo.{1,2} and the other for .bar.{1,2}. This is because mergeable sections are merged based on section attributes.</div><div><br></div><div>Is this correct? What do you think is a correct behavior?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
And because of that it assigns values of A and B wrong currently. I think the cleanest way to fix is implement synthetic merge section instead of MergeOutputSection.<br>
(this is what this patch was about, right ?)<br>
That way output should be single .rodata section which consist of [ .aaa.1 .aaa.2, synthetic section holding <.bbb.1 and .bbb.2>, .ccc.1, .ccc.2]. And symbols will be assigned correctly then.<br>
Output will probably be equal to bfd/gold, btw.<br>
<br>
**2. Latest diff of this patch do:**<br>
<br>
It creates synthetic sections for mergeable sections early now. Before passing them to script. After that we have next input sections available to work with on linerscript side:<br>
<br>
[.aaa.1 .aaa.2 **SynteticMergeSection**(.bbb.<wbr>1) **SynteticMergeSection**(.bbb.<wbr>2) .ccc.1 .ccc.2]<br>
<br>
Since synthetic merge sections are already created, script just places all above in a single .rodata section. We loose string merging optimization here, because have 2 pre-created SynteticMergeSections.<br>
There is no way to merge 2 synthetic mergable sections together on this step (I do not think we want to implement this too).<br>
And we can not create single .bbb section for holding .bbb.1 and .bbb.2 early before proccessing linkerscript commands, because we do not know it will want to put them together.<br>
<br>
**3. Patch I want to do basing on what diff2 of this patch already did:**<br>
<br>
I want to create synthetic merge sections later. For linkerscript step it should be done after script prepares input sections list to create output sections. That was done in diff2.<br>
That way we have inputs:<br>
[.aaa.1 .aaa.2 **MergeInputSection(.bbb.1)** **MergeInputSection(.bbb.2)** .ccc.1 .ccc.2]<br>
<br>
Script will create single SynteticMergeSection for mergable input sections ind convert inputs to:<br>
[.aaa.1 .aaa.2 **SynteticMergeSection(.bbb.1, .bbb.2)** .ccc.1 .ccc.2]<br>
<br>
And we will end up with single .rodata with all optimizations working.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D27415" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2741<wbr>5</a><br>
<br>
<br>
<br>
</blockquote></div><br></div></div>