<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On May 21, 2016, at 1:01 PM, Saleem Abdulrasool via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><div class=""><div dir="ltr" class="">On Thu, May 19, 2016 at 12:29 PM, Joe Groff <span dir="ltr" class=""><<a href="mailto:jgroff@apple.com" target="_blank" class="">jgroff@apple.com</a>></span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br class="">
> On May 19, 2016, at 12:22 PM, Tom Birch <<a href="mailto:froody@gmail.com" class="">froody@gmail.com</a>> wrote:<br class="">
><br class="">
> Would it be acceptable to make relative pointers optional, so we can pay the extra load-time cost on platforms where it's hard/undesirable to implement them?<br class="">
<br class="">
</span>That's also a reasonable answer, since sliding DLLs is already fairly costly. We'd need a bunch of extra tests to ensure both the relative and absolute forms work, though maybe with David Farler's work to abstract relative addresses it's already straightforward to have the RelativePointer<..> templates in the runtime work in a platform-independent way.</blockquote><div class=""><br class=""></div><div class="">Would be interesting to at least see if this is possible. Any hints on where to get started with testing/prototyping such an approach?</div></div></div></div></div></blockquote><div><br class=""></div>Well, there are four places you need to worry about:</div><div> - The parts of IRGen that emit constant relative references; these should all be using ConstantBuilder, so it should be easy to update them.</div><div> - The parts of IRGen that emit code to dereference relative references; I'm not sure any of these actually exist right now.</div><div> - The runtime, where like Joe says, it should be easy to abstract a template class on the runtime-traits class that's either a relative or absolute reference.</div><div> - MetadataReader, which will need to do the right thing based on the runtime-traits class.</div><div><br class=""></div><div>I think the hardest part of this is probably coming up with a pithy name. :) It's important that callers not call something called addRelativeReference and have it just randomly add an absolute reference depending on target platform; the fact that it's sometimes relative and sometimes absolute is something that people adding new metadata features should be actively conscious of (among other things, because absolute references always have to be pointer-sized, not just 32 bits, and so the layout of the object may change). So we should call it something that doesn't directly connote absolute vs. relative: maybe NearReference or LocalReference?</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="HOEnZb"><font color="#888888" class=""><br class="">
-Joe<br class="">
</font></span><div class="HOEnZb"><div class="h5"><br class="">
> cheers,<br class="">
> Tom<br class="">
><br class="">
> On Thu, May 19, 2016 at 9:51 AM Joe Groff via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class="">
><br class="">
> > On May 18, 2016, at 6:01 PM, Saleem Abdulrasool <<a href="mailto:compnerd@compnerd.org" class="">compnerd@compnerd.org</a>> wrote:<br class="">
> ><br class="">
> > On Wednesday, May 18, 2016, Joe Groff <<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>> wrote:<br class="">
> ><br class="">
> > > On May 18, 2016, at 1:51 PM, Saleem Abdulrasool via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:<br class="">
> > ><br class="">
> > > Hi,<br class="">
> > ><br class="">
> > > It seems that there are assumptions about the ability to create relative address across sections which doesn't seem possible on Windows ARM.<br class="">
> > ><br class="">
> > > Consider the following swift code:<br class="">
> > ><br class="">
> > > final class _ContiguousArrayStorage<Element> { }<br class="">
> > ><br class="">
> > > When compiled for Windows x86 (via swiftc -c -target i686-windows -parse-as-library -parse-stdlib -module-name Swift -o Swift.obj reduced.swift) it will generate the metadata pattern as:<br class="">
> > ><br class="">
> > > __TMPCs23_ContiguousArrayStorage:<br class="">
> > > ...<br class="">
> > > .long __TMnCs23_ContiguousArrayStorage-(__MPCs23_ContiguousArrayStorage+128)<br class="">
> > > ...<br class="">
> > ><br class="">
> > > This generates a IMAGE_REL_I386_REL32 relocation which is the 32-bit relative displacement of the target.<br class="">
> > ><br class="">
> > > On Windows ARM (swiftc -c -target i686-windows -parse-pas-library -parse-stdlib -module-name Swift -o Swift.obj reduced.swift) it will generate similar assembly:<br class="">
> > ><br class="">
> > > _TMPCs23_ContiguousArrayStorage:<br class="">
> > > ...<br class="">
> > > .long _TMnCs23_ContiguousArrayStorage-(_MPCs23_ContiguousArrayStorage+128)<br class="">
> > > ...<br class="">
> > ><br class="">
> > > However, this generates an IMAGE_REL_ARM_ADDR32 relocation which is the 32-bit VA of the target. If the symbol are in the same section, it is possible to get a relative value. However, I don't really see a way to generate a relative offset across sections. There is no relocation in the COFF ARM specification which provides the 32-bit relative displacement of the target. There are 20, 23, and 24 bit relative displacements designed specifically for branch instructions, but none that would operate on generic data.<br class="">
> > ><br class="">
> > > Is there a good way to address this ABI issue? Or perhaps do we need something more invasive to support such targets? Now, I might be completely overlooking something simple that I didn't consider, so pointing that out would be greatly appreciated as well.<br class="">
> ><br class="">
> > That's unfortunate. One possibly-crazy solution would be to use a different object format that does support the necessary relocations, such as LLVM's win32-macho target. That would forgo interoperability with non-LLVM toolchains, of course<br class="">
> ><br class="">
> > Yeah, it would make interoperability harder. But, is there a loader for macho on Windows?<br class="">
><br class="">
> Sorry, if it wasn't clear, I meant that you could use mach-o (or ELF, or any object format really) for .o and .a files. You'd still link them into PE executables and DLLs.<br class="">
><br class="">
> -Joe<br class="">
> _______________________________________________<br class="">
> swift-dev mailing list<br class="">
> <a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">
> <a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class="">
<br class="">
</div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature">Saleem Abdulrasool<br class="">compnerd (at) compnerd (dot) org</div>
</div></div>
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></body></html>