<div dir="ltr"><a href="/"></a>In this case I think there might be a bit too much context - The Java Short Vector Math Library is enormous and spans tens of thousands of lines of assembly. An example of imagerel being used in it in the surrounding context is <a href="https://github.com/openjdk/jdk/blob/7d6a2f3740bf42652bdf05bb922d1f2b2ae60d6a/src/jdk.incubator.vector/windows/native/libjsvml/jsvml_d_tanh_windows_x86.S#L98">https://github.com/openjdk/jdk/blob/7d6a2f3740bf42652bdf05bb922d1f2b2ae60d6a/src/jdk.incubator.vector/windows/native/libjsvml/jsvml_d_tanh_windows_x86.S#L98</a><div><br></div><div>Does the .reloc example rely on the instruction bytes being assembled into a certain location (In this case, 4 bytes behind the current location)? That might be rather brittle and easy to break if the instruction just so happens to have the relocation itself in a different position as the example</div><div><br></div><div>best regards,</div><div>Julian</div></div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 8, 2024 at 6:21 PM Jan Beulich <<a href="mailto:jbeulich@suse.com">jbeulich@suse.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 08.11.2024 09:53, Julian Waters wrote:<br>
> There are times where it is needed to have the functionality of the<br>
> .rva directive as an operator on an expression. Take the following<br>
> handwritten assembly from the Java Short Vector Math Library:<br>
> <br>
> vmovupd   xmm4, XMMWORD PTR<br>
> [imagerel(__jsvml_dtanh_ha_data_internal)+2704+rdx+rcx]<br>
> <br>
> In this instance, .rva obviously cannot be used to obtain the virtual<br>
> address of the symbol for use in an instruction. Does GAS have any<br>
> undocumented specifier that can obtain the image relative offset of an<br>
> expression? If it does not, could we consider adding the @imgrel<br>
> operator from clang for this purpose?<br>
<br>
Just a few weeks ago I was pondering that, discarding the idea in the<br>
end. The reason for discarding it was that I couldn't think of a<br>
legitimate use case. The example you provide above looks similarly<br>
contrived, yet that may simply be because of lack of context. My<br>
basic question is: Why would code calculate any operand against the<br>
image base, rather than using proper symbol references?<br>
<br>
As to the (potential) "operator" itself: I don't really like @imgrel.<br>
It doesn't fit with the corresponding directive being .rva. Hence<br>
I'd prefer @rva, but I can of course see that for Clang compatibility<br>
we may want to also support its "operator".<br>
<br>
As to there being anything undocumented you can use instead: There's<br>
something documented really, but perhaps a little clumsy to use. A<br>
simple example would be (in AT&T syntax)<br>
<br>
        mov     $0, %eax<br>
        .reloc .-4, rva32, symbol<br>
<br>
Roughly your example above ought to translate to<br>
<br>
        {disp32} vmovupd   xmm4, [rdx+rcx]<br>
        .reloc .-4, rva32, __jsvml_dtanh_ha_data_internal+2704<br>
<br>
or maybe (as there are issues with addends, and I'm not sure whether<br>
they affect COFF as well)<br>
<br>
        vmovupd   xmm4, [rdx+rcx+2704]<br>
        .reloc .-4, rva32, __jsvml_dtanh_ha_data_internal<br>
<br>
Jan<br>
</blockquote></div>