Making a direct function call from inline assembly

Andrew Haley aph@redhat.com
Fri Aug 13 15:22:00 GMT 2010


On 08/13/2010 10:38 AM, Job Noorman wrote:
> On Friday 13 August 2010 11:32:25 you wrote:
>> On 08/13/2010 10:25 AM, Job Noorman wrote:
>>> //file main.cpp
>>> void func() {}
>>>
>>> int main()
>>> {
>>>
>>>     //this works but GCC generates an indirect call:
>>>     //    movl $_Z4funcv, %eax
>>>     //    call *%eax
>>>     asm("call *%0" : : "r"(func));
>>>     
>>>     //this is what I conceptually want to do but doesn't work because
>>>     //GCC generates
>>>     //    call $_Z4funcv
>>>     //which gives an error from the assembler:
>>>     //    main.cpp: Assembler messages:
>>>     //    main.cpp:20: Error: suffix or operands invalid for `call'
>>>     //I would like to find a way to make GCC generate the following:
>>>     //    call _Z4funcv
>>>     //(note there is no "$")
>>>     asm("call %0" : : "i"(func));
>>>
>>> }
>>
>>     asm("call %P0" : : "i"(func));

> Wow thanks a lot!
> Is this feature documented somewhere? I've been looking through the manuals 
> but haven't found it.

I have no idea.  I just looked in the gcc source code.

Andrew.



More information about the Gcc-help mailing list