Re: detect empty functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Feb 5, 2014 at 7:33 PM, vijay nag <vijunag@xxxxxxxxx> 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@xxxxxxxxx> wrote:
>> Hi, is there a way to find if a function has empty body ?
>>
>> Thanks and Regards,
>> Prathamesh

My apologies for top-posting.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux