This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Making a direct function call from inline assembly
- From: "McIntosh, David" <David dot McIntosh at tdsecurities dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 11 May 2011 11:49:04 -0400
- Subject: Re: Making a direct function call from inline assembly
References: <201008121844.58918.jobnoorman@gmail.com> <201008131125.58963.jobnoorman@gmail.com> <4C651129.6060309@redhat.com> <201008131138.37230.jobnoorman@gmail.com>
>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.
This does not seem to work in a Linux invironment when using the -fpic option (which makes sense I think). Is there any way to do this when -fpic is used?? Thanks.
NOTICE: Confidential message which may be privileged. Unauthorized use/disclosure prohibited. If received in error, please go to www.td.com/legal for instructions.
AVIS : Message confidentiel dont le contenu peut être privilégié. Utilisation/divulgation interdites sans permission. Si reçu par erreur, prière d'aller au www.td.com/francais/avis_juridique pour des instructions.