<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 22, 2017, at 5:39 PM, Saleem Abdulrasool via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><div class="">Now, as it so happens, both PE and PE+ have limitations on the file size at 4GiB.&nbsp; This means that we are guaranteed that the relative difference is guaranteed to fit within 32-bits. This is where things get really interesting!</div><div class=""><br class=""></div><div class="">We cannot generate the relocation because we are emitting the values at pointer width.&nbsp; However, the value that we are emitting is a relative offset, which we just determined to be limited to 32-bits in width.&nbsp; The thing is, the IMAGE_REL_AMD64_REL32 doesn't actually seem to care about the cross-setionness as you pointed out.&nbsp; So, rather than emitting a pointer-width value (`.quad`), we could emit a pad (`.long 0`) and follow that with the relative displacement (`.long &lt;expr&gt;`).&nbsp; This would be representable in the PE/COFF model.<br class=""></div><div class=""><br class=""></div><div class="">If I understand the layout correctly, the type metadata fields are supposed to be pointer sized.&nbsp; I assume that we would like to maintain that across the formats.&nbsp; It may be possible to alter the emission to change the relative pointer emission to emit a pair of longs instead for PE/COFF with a 64-bit pointer value.&nbsp; Basically, we cannot truncate the relocation to a IMAGE_REL_AMD64_REL32 but we could generate the appropriate relocation and pad to the desired width.</div><div class=""><br class=""></div><div class="">Are there any pitfalls that I should be aware of trying to adjust the emission to do this?&nbsp; The only downsides that I can see is that the &nbsp;emission would need to be taret dependent (that is check the output object format and the target pointer width).</div></div></div></div></div></blockquote><br class=""></div><div>Beware of sign extension.</div><div><br class=""></div><div>If you have a 32-bit signed offset, and you pad it to 64 bits by prepending a 32-bit zero, the result is not a 64-bit signed offset. Negative offsets would become large positive offsets. You would also have to adjust all code that reads these offsets. Such code must read only 32 bits and sign-extend if necessary to get 64 bits.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">--&nbsp;</div><div class="">Greg Parker &nbsp; &nbsp; <a href="mailto:gparker@apple.com" class="">gparker@apple.com</a>&nbsp; &nbsp; &nbsp;Runtime Wrangler</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>