<div dir="ltr">On Wed, Apr 6, 2016 at 11:18 AM, Jordan Rose <span dir="ltr">&lt;<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@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-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hey, Saleem. How do you expect this to differ from normal symbol visibility? It seems to me that in a shared library, any public symbol is either exported or imported, depending on whether it has a definition, and any non-public symbol is default. (Unlike C, we expect to have sensible rules here.) I guess there&#39;s the difference between &quot;a public symbol from elsewhere in this library&quot; and &quot;a public symbol from some other library&quot;. Is that it?<br></blockquote><div><br></div><div>Well, there are four cases to consider:</div><div>- externally available: imported<br></div><div><div>- defined (and available for others): exported</div></div><div>- defined (statically): default -- won&#39;t even show up, so this is a no-op</div><div>- defined (non-statically defined for internal use): default</div><div><br></div><div>The thing is that there is no modeling for internal symbols which other shared objects can use.  The closest thing you can do is anonymize the symbol (so you don&#39;t have a name that you can call it by, but you have an integral ID).</div><div><br></div><div>A public symbol from elsewhere in this library is treated as a local symbol defined elsewhere in this library.  However, a public symbol from another library is treated differently.  These get a local symbol which is synthesized to perform the indirect addressing.  The symbol uses the form __USER_LABEL_PREFIX__ ## _imp_ ## name.  This will contain the real address or an indirect jump for the public symbol.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The difference between static and shared libraries seems unfortunate to have to expose to IRGen, but we may end up needing that anyway to handle Mach-O/ELF-style symbol visibility.<br></blockquote><div><br></div><div>Yes, it is unfortunate, but sounds like it could end up being beneficial.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Jordan<br>
<div><div class="h5"><br>
<br>
&gt; On Apr 6, 2016, at 10:21, Saleem Abdulrasool via swift-dev &lt;<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; I was playing around with the idea of swift and Windows since there are some interesting differences between COFF/PE and (ELF and MachO).<br>
&gt;<br>
&gt; PE/COFF does not directly address symbols in external modules (DSOs/dylibs/DLLs).  Instead, there is an indirect addressing model (thunks in Windows parlance).  Fortunately, LLVM has a nice way to model this: GlobalValues have an associated &quot;DLLStorageClass&quot; which indicates whether something is &quot;imported&quot; (provided by an external module), &quot;exported&quot; (provided to external modules), or &quot;default&quot; (everything else).<br>
&gt;<br>
&gt; Adjusting the IRGen to correctly annotate this part of the semantics should get us part of the way to supporting swift on PE/COFF.<br>
&gt;<br>
&gt; The thing to consider with this is that the DLL storage class is dependent on how the module(s) are being built.  For example, something may change from the exported storage to default if being built into a static library rather than a shared object and is not meant to be re-exported.<br>
&gt;<br>
&gt; Part of this information really needs to be threaded from the build system so that we know whether a given SIL module is external or internal.<br>
&gt;<br>
&gt; Given that this would potentially effect ABI stability, it seems like this is a good time to tackle it so that we can push this into the resilience work that is being done for swift 3.<br>
&gt;<br>
&gt; I would appreciate any pointers and suggestions as to how to best go about handling this.<br>
&gt;<br>
&gt; --<br>
&gt; Saleem Abdulrasool<br>
&gt; compnerd (at) compnerd (dot) org<br>
</div></div>&gt; _______________________________________________<br>
&gt; swift-dev mailing list<br>
&gt; <a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br>
<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>