<br><br>среда, 3 августа 2016 г. пользователь Rui Ueyama  написал:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Aug 2, 2016 at 3:00 AM, Eugene Leviant <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','evgeny.leviant@gmail.com');" target="_blank">evgeny.leviant@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">evgeny777 added a comment.<br>
<br>
I think the main reason, we're using virtual input sections is that this the only way to calculate correct symbol offset. As you may know location counter is not incremented while we add input sections to output section, and the true size of input sections is known only after call to OutputSectionBase<ELFT>::assignOffsets().<br>
<br>
So if you suggest an algorithm, which can calculate correct symbol value (w/o using virtual input sections) in the case below:<br>
<br>
  .foo : { *(.foo); end_foo = .; *(.bar) }<br>
<br>
then we can probably switch to absolute symbols (BTW we can also use synthetic symbols - there is a little difference, if any).<br>
Another interesting question is what will happen if we define absolute symbol in shared object and reference it in executable? For example:<br>
<br>
  /* script for linking shared library */<br>
  SECTIONS { .text : { text_start = .; *(.text) } }<br>
<br>
So, when shared library is loaded by application, what value would text_start have, in case it is absolute? I don't know yet, but will try.<br></blockquote><div><br></div><div>At first, I suggested you use empty dummy input sections to define linker-script-defined symbols in the hope that in that way we don't need to fix symbol addresses later (I was hoping that symbol addresses are automatically fixed as attached input sections get final output addresses.) Now that we know it doesn't work for many possible use cases. Then maybe we want to eliminated dummy sections and directly define symbols as absolute (or section) symbols.</div></div></div></div></blockquote><div><br></div><div>Like I said, the main problem is calculating this "absolute value". How are you going to do this? Also, like George said, it is not correct to use absolute values for symbols defined inside output section description</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>In this patch, you are trying to support assignments to symbols. However, we eventually want to support something like this, too.</div><div><br></div><div>  SECTIONS { .text : { foo.o(.text); . = ALIGN(128); bar.o(.text) } }<br></div></div></div></div></blockquote><div><br></div><div>I do not see any problem in doing this. I think we use the same SymbolInputSection<ELFT> but with non-zero size, so proper layout will be calculated automatically in assignOffsets. Does this make sense?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Looks like this doesn't fit to the current architecture. Currently, we create a list of input sections and assign them addresses later. But in order to process the above script, one pass would fit well. So I'm wondering if we should merge LinkerScript::createSections and LinkerScript::assignOffsets.</div></div></div></div></blockquote><div><br></div><div>How can this be done? We have createThunks() in between. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<span><br>
<br>
================<br>
Comment at: ELF/LinkerScript.cpp:278<br>
@@ -176,3 +277,3 @@<br>
 // Process ONLY_IF_RO and ONLY_IF_RW.<br>
 template <class ELFT> void LinkerScript<ELFT>::filter() {<br>
   // In this loop, we remove output sections if they don't satisfy<br>
----------------<br>
</span><span>ruiu wrote:<br>
> Why did you have to make a change to this function?<br>
</span>Two main reasons:<br>
<br>
1) During filtering process some output sections may be removed. Those sections may contain symbols and SymbolInputSection object have already been created for them. To avoid crashes and/or creating dummy symbols I have to remove those virtual sections as well<br>
<br>
2) The old implementation is not technically correct, because it removes only first output section found in name lookup. We're still using OutputSectionFactory<ELFT>, so we may have several sections with the same name.<br>
<br>
Another reason (though much less significant) is that one-by-one removal from std::vector must be slow, because it stores elements on continuous region of memory.<br>
<br>
<br>
<a href="https://reviews.llvm.org/D22683" rel="noreferrer" target="_blank">https://reviews.llvm.org/D22683</a><br>
<br>
<br>
<br>
</blockquote></div><br></div></div>
</blockquote>