This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: detect empty functions


On Wed, Feb 5, 2014 at 7:33 PM, vijay nag <vijunag@gmail.com> wrote:
> Hello,
>
> You can use the below program to find the length of the function
> compiled for X86 target.
>
> Note that assembly instruction for "function()" is immediately
> followed by assembly for "functionEnd"
>
> Key things to note here
>
> 1) Compiler still emits epilogue/prologue for a function with empty
> body. However you could disable this using -fomit-frame-ptr in which
> case function
>     body will only have "ret" instruction and in which case difference
> would be 1.
>     0x80483a4 <function>            ret
>
>                                    â
>    â0x80483a5 <functionEnd>         ret
>
>    So size of the function would be 0x80483a5 - 0x80483a4 = 1
>
>  2)In case if you need frame-ptr, there will be a minimum of 4
> instructions and in this case difference would be 5.
>     0x80483a4 <function>            push   %ebp
>
>                                    â
>    â0x80483a5 <function+1>          mov    %esp,%ebp
>
>                                    â
>    â0x80483a7 <function+3>          pop    %ebp
>
>                                    â
>    â0x80483a8 <function+4>          ret
>
>                                    â
>    â0x80483a9 <functionEnd>         push   %ebp
>
>                                    â
>    â0x80483aa <functionEnd+1>       mov    %esp,%ebp
>
>                                    â
>    â0x80483ac <functionEnd+3>       pop    %ebp
>
>                                    â
>    â0x80483ad <functionEnd+4>       ret
>
>      So size of the function would be 0x80483a9 - 0x80483a4 = 5
>
>
> cat fsize.c
> #include <stdio.h>
>
> int function(){
> }
>
> int functionEnd(){
> }
>
> int main()
> {
>   printf("%x\n", &functionEnd - &function);
> }
>
> vijayNag
>
> On Wed, Feb 5, 2014 at 7:00 PM, Prathamesh Kulkarni
> <bilbotheelffriend@gmail.com> wrote:
>> Hi, is there a way to find if a function has empty body ?
>>
>> Thanks and Regards,
>> Prathamesh

My apologies for top-posting.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]