Issue 61640
Summary Wrong code for inline assembly with `-masm=intel` on x86_64
Labels new issue
Assignees
Reporter lhmouse
    Godbolt: https://gcc.godbolt.org/z/bn15EWhsq

```c++
using my_function = int (int, int);
extern my_function* my_fptr;

int
ptc_indirect_call(int a, int b)
  {
    return my_fptr(a, b);
  }

int
asm_indirect_call(int a, int b)
 {
    __asm__ ("jmp qword ptr [my_fptr@GOTPCREL]");
 __builtin_unreachable();
 }
```

```asm
ptc_indirect_call(int, int):                # @ptc_indirect_call(int, int)
        mov     rax, qword ptr [rip + my_fptr@GOTPCREL]
        mov     rax, qword ptr [rax]
        jmp rax                             # TAILCALL
asm_indirect_call(int, int): # @asm_indirect_call(int, int)

        jmp my_fptr@GOTPCREL
```

The inline asm statement gets compiled as a direct call and will jump to nonexecutable data.
(the at&t syntax however doesn't suffer from this issue.)

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to