1

In Seoul Virtual Machine Monitor project, I encountered this inline assembler code

asm volatile ("call %P0; 1:" : : "i"(foo))

which compiles and runs well when optimized with -O2; but fails to compile with -O0 optimization, yielding this error:

error: impossible constraint in ‘asm’

foo is a 32 bits int taken as an immediate value for the call instruction.

When I googled, this suggests me to replace "i" constraint by "ic", which I did; and now the code compile but with :

Warning: indirect call without « * »

How can I avoid this warning?

NB:

  • gcc version is 4.9.2
  • asm %P modifier is to prevent GCC to append $ in front of the int value. That is to generate "call foo" instead of "call $foo".
Mahouk
  • 902
  • 9
  • 28
  • 1
    Just do what it says: put a `*` before the `%P0`. Well, actually that might break the other case. Check generated asm code. – Jester Jan 16 '16 at 15:40
  • 1
    Provide a [mcve]. Show the surrounding C code. – too honest for this site Jan 16 '16 at 15:41
  • 2
    Also note that is possibly wrong code, since the called procedure might modify registers as per the calling convention, but the compiler doesn't know that. Why is inline asm needed for this anyway? Just use a function pointer, e.g. `((void (*)())foo)();` – Jester Jan 16 '16 at 15:42
  • Of course, adding * satisfies the compiler but doesn't make any difference. The assembly output code is the same (I suppose gcc fixed it smartly). But it turns out that the program encounters some runtime errors when optimzed with -O0, and that is very weird because I don't expect a code to behave differently at runtime just because the optimization level changed... – Mahouk Jan 18 '16 at 00:26
  • One workaround might be to switch to Intel assembly syntax using `.intel_syntax noprefix` (https://stackoverflow.com/a/9347957/4071916), because then the indirect call syntax matches the direct call syntax. – qbt937 Sep 08 '21 at 07:51

0 Answers0