I'm trying to write some special routine in assembly, for x86-64 (even x86 example is fine). The problem: my immediates are only resolved at link time.
For example,
addq $Label2-Label1, %rax
will add the difference between the two labels/symbols to rax. Unfortunately, because GNU Assembler only does one pass (I don't know why, even Open Source assemblers like FASM do multiple passes), it cannot resolve those so it will make the linker do it.
Unfortunately, it will reserve 4 bytes (32-bit immediate) for the linker, which is not what I want, because the difference in labels is always within -128 to +127 range.
My question, how do I force or specify that the instruction should have an 8-bit immediate? Like, what's the syntax here? In AT&T syntax or Intel, either is fine. For example, in NASM you do:
add rax, byte Label2-Label1
to specify 8bit immediate. But how to do this in GAS? What's the syntax to force it to use 8-bit immediate even if it doesn't know the immediate itself... I'd ideally want this in GAS, for specific reasons, so please don't tell me to use NASM as an answer!
EDIT: I'm sorry I forgot to mention, that yes, it is a "forward reference" here. Both labels are defined after the instruction, that is why GAS can't resolve them, I thought it's a relocation, but yes using '.byte label2-label1' works for sure as I have tested it, so I know it should be possible if it had some syntax for it...