GCC inline asm: direct memory link restriction

I need GCC to create a consistent set of instructions for embedded asm, but one of the instructions I use is sometimes compiled in 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 am not sure what the reason for the second version is, but I do not want this. Is there a restriction indicating that the memory reference should only be direct, i.e. Not through the register?


Update:

This variation always gives the same instruction:

    __asm__ ("mov ref@GOTPCREL(%rip),%rax");

Compiles:

mov 0x200910(%rip),%rax
+4
source share
1 answer

Answering my own question:

This variation always gives the same instruction:

__asm__ ("mov ref@GOTPCREL(%rip),%rax");

Compiles:

mov 0x200910(%rip),%rax

For x86, where RIP-relative is not available, it accepts two commands:

__asm__ ("mov $_GLOBAL_OFFSET_TABLE_,%%eax; \
          add ref@GOT,%%eax;");

Compiles:

mov $0x2ff7,%eax
add 0xfffffff0,%eax

%eax RIP-relative , , .

+3

Source: https://habr.com/ru/post/1544372/


All Articles