I need GCC to produce a consistent set of instructions for inline asm, but one of the instructions I'm using is sometimes compiled two different ways:
__asm__ ("mov %1,%%rax;" \
: \
: "m"(ref) \
: "%rax");
Compile #1:
mov 0x200894(%rip),%rax
Compile #2:
mov 0x200894(%rip),%rdx
mov (%rdx),%rax
I'm not sure what the reason is for the second version, but I don't want it. Is there a constraint to specify that a memory reference should only be direct, i.e., not via register?
Update:
This variation always produces the exact same instruction:
__asm__ ("mov ref@GOTPCREL(%rip),%rax");
Compiles to:
mov 0x200910(%rip),%rax
0x200894(%rip)contains the result directly, in the second0x200894(%rip)contains a pointer to the result. What isref? Does it have the same type in both instances? Is it pointer to a function or object that's exported from a DLL (which sometimes might have to be an indirect reference through a 'GOT')?extern const char *ref, and the second version does only occur in a shared library--so it must have a GOT reference even though the variable is defined inside the library. Can I avoid that somehow?