[asm] How to do a memory indirect jump using x86 `asm!`?

I have a static mut FUNC_PTR: *const () that store a pointer to an FFI function, and I want to jump to that function using an asm! block, like this (in AT&T syntax):

    "jmpl *({symbol})",
    symbol = sym FUNC_PTR,
    options(att_syntax, noreturn),

However, I couldn't find a way to rewrite this code in Intel syntax. I've tried the following syntaxes:

jmp [{symbol}]
jmp dword ptr [{symbol}]
jmp {symbol}

But no matter what I write, the compiler always interprets it as jmp {symbol}, i.e. it always treats {symbol} as the jump target address, rather than a memory operand that contains the actual target address. The compiler seems to be simply "ignoring" the square brackets and the dword ptr specifier, which is very weird to me.

This is a minimal example: Compiler Explorer

This is what the compiler emits with cargo rustc -- --emit asm:

jmp     __some_mangled_symbol

But this is what I want, which couldn't be achieved without using options(att_syntax):

jmpl    *__some_mangled_symbol

On x86_64, RIP-relative addressing ([rip + {symbol}]) does the magic. But this doesn't work for 32-bit x86, since it doesn't have an EIP-relative addressing mode.

Is this a bug of LLVM or the compiler? Where can I seek help for this problem?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.