<div dir="ltr">On Mon, Sep 18, 2017 at 4:07 PM, Joe Groff <span dir="ltr">&lt;<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><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"><div style="word-wrap:break-word"><span class="gmail-"><br><div><br><blockquote type="cite"><div>On Sep 18, 2017, at 3:31 PM, Saleem Abdulrasool via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:</div><br class="gmail-m_-6205311420769480074Apple-interchange-newline"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div class="gmail_quote"><div dir="auto"><br class="gmail-m_-6205311420769480074Apple-interchange-newline">On Mon, Sep 18, 2017 at 9:36 AM John McCall &lt;<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>&gt; wrote:<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"><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Sep 17, 2017, at 10:15 AM, Saleem Abdulrasool &lt;<a href="mailto:compnerd@compnerd.org" target="_blank">compnerd@compnerd.org</a>&gt; wrote:</div><br class="gmail-m_-6205311420769480074m_-8048642078909164791Apple-interchange-newline"><div><div>On Sat, Sep 16, 2017 at 6:19 PM, John McCall<span class="gmail-m_-6205311420769480074Apple-converted-space"> </span><span>&lt;<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>&gt;</span><span class="gmail-m_-6205311420769480074Apple-converted-space"> </span>wr<wbr>ote:<br><div class="gmail_extra"><div class="gmail_quote"><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 class="gmail-m_-6205311420769480074m_-8048642078909164791gmail-">&gt; On Sep 16, 2017, at 6:06 PM, Saleem Abdulrasool via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:<br>&gt; Hello,<br>&gt;<br>&gt; I&#39;d like to propose that we change the locations that we use to store the type metadata, protocol conformances, type references, reflection strings, field metadata, and associated types.<br>&gt;<br>&gt; I think that it is possible to simplify the design for the linker tables by changing section names and relying on the linker to perform the work necessary to generate the tables so that they can be walked later.<br>&gt;<br>&gt; Switching sections would mean that we would lose interoperability with previously built libraries.  Given that there is ABI stability work going on for at least the Darwin target, I figure that this would be the best time to do this.<br>&gt;<br>&gt; Would this be acceptable?  Is compatibility something that we need to worry about?<br><br></span>Compatibility is not something that we&#39;re currently promising.  I think this is a fine time to be working on this problem.<br><br>It&#39;s not clear from your proposal whether you&#39;re just proposing changing sections or whether you&#39;re interested in more invasive changes to metadata emission.  Can you be more specific.</blockquote><div><br></div><div>Certainly.</div><div><br></div><div>Right now, we have two special object files which must be included in a certain order to ensure that the sections that I mentioned earlier are bounded and grouped.  However, this is unneessary.  As long as the section name is a valid C identifier, the linker will group and bound the sections with special variables that it will synthesize (__{start,stop}_[SectionName])<wbr>.  This will allow us to replace the two file approach with a single file approach.  Furthermore, it will allow the file to be injected anywhere (it drops the need for the files to appear in a specific order).  Finally, it simplifies the logic so that we can write the entire thing in C rather than having to roll the begin/end content in assembly.</div></div></div></div></div></blockquote><div><br></div></div></div><div style="word-wrap:break-word"><div>Yes, if that&#39;s the case, that would be massively useful.</div><div><br></div><div>The runtime needs to be able to find these bounds in an arbitrary image, since there may be multiple images in the program containing Swift code.  Are those symbols available dynamically even if it they aren&#39;t used statically?</div></div></blockquote><div dir="auto"><br></div><div dir="auto">It should be possible to preserve the symbols.  In general, it is possible to dead strip symbols.  So having the object that needs to be injected reference them is sufficient to ensure that they aren&#39;t dead stripped.  After that, they can be dynamically looked up even if they aren&#39;t statically used.</div><div dir="auto"><br></div><div dir="auto">I&#39;ll try to get to this change soon!</div></div></div></div></blockquote><br></div></span><div>The symbols would not only have to not be stripped but also be exported with protected or default visibility in order for dlsym to find them normally. Is it possible to get the linker to export these implicit symbols with protected visibility? If not, we might still need an asm stub to define visible symbols as aliases for the implicit section symbols. That stub could at least be order-independent and portable, which would be an improvement over what we have now.</div></div></blockquote><div><br></div><div>The default is default visibility, which IMO is not really what we want.  Ideally, we want protected visibility.  Now, this is possible to, but, the code for is every so slightly distasteful.</div><div><br></div><div>```</div><div>__attribute__((__section__(&quot;section&quot;))) const int i = 0;</div><div>__attribute__((__visibility__(&quot;protected&quot;))) extern void *__start_section;</div><div>__attribute__((__visibility__(&quot;protected&quot;))) extern void *__stop_section;</div><div>__UINTPTR_TYPE__ get_section_size(void) { return __stop_section - __start_section; }</div><div>```</div><div><br></div><div>The thing is that we need the local function (in this case, `get_section_size`) to both preserve the symbols as well as to ensure that the symbols receive the proper visibility.  In the worst case, we would need a structure that is preserved to aid in keeping the reference to the symbols.</div><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"><div style="word-wrap:break-word"><span class="gmail-HOEnZb"><font color="#888888"><div>-Joe</div></font></span></div></blockquote></div><br>-- <br><div class="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>