UASM supports generated RIP-rel addressing but it also generates unnecessary COFF relocation in some cases. Consider rip-rel.asm:
.code
lea rax, [lbl]
nop
lbl:
nop
end
Assemble with: uasm64.exe -win64 -Fl rip_rel.asm
You get:
UASM v2.49, Jun 21 2019, Masm-compatible assembler.
rip_rel.asm
.code
00000000 488D0500000000 lea rax, [lbl]
00000007 90 nop
00000008 lbl:
00000008 90 nop
end
The code 488D0500000000 means LEA RAX, [RIP+0]. Why zero? This is because it is relocated by COFF relocation REL32. You can use dumpbin to see it:
RELOCATIONS #1
Symbol Symbol
Offset Type Applied To Index Name
-------- ---------------- ----------------- -------- ------
00000003 REL32 00000000 6 lbl
In this case, the COFF relocation is unnecessary because the distance of the instruction from the label is known to UASM. Do you know any trick how to get rid of the COFF relocation?
The only solution seems to be manual RIP-rel addressing but I can't use it unfortunately:
.code
lea rax, [rip+(lbl-next)]
next:
nop
lbl:
nop
end
Listing file:
.code
00000000 488D0501000000 lea rax, [rip+(lbl-next)]
00000007 next:
00000007 90 nop
00000008 lbl:
00000008 90 nop
end
The code 488D0501000000 means LEA RAX, [RIP+1] and no COFF relocation is involved.
I could use a macro similar to the following:
RIPREL MACRO lbl:REQ
EXITM <(type lbl) ptr [rip + (lbl-end_of_current_instruction)]
ENDM
mov bl, [RIPREL(a_label)]
The problem here is the "end_of_current_instruction". As far as I know, there's no UASM symbol that would represent that.