How are function sizes calculated by readelf

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am trying to understand how readelf utility calculates function size. I wrote a simple program



#include <stdio.h>

int main()
printf("Test!n");



Now to check function size I used this (is this OK ? ):



readelf -sw a.out|sort -n -k 3,3|grep FUNC



which yielded:



 1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)
2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)
29: 0000000000400470 0 FUNC LOCAL DEFAULT 13 deregister_tm_clones
30: 00000000004004a0 0 FUNC LOCAL DEFAULT 13 register_tm_clones
31: 00000000004004e0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
34: 0000000000400500 0 FUNC LOCAL DEFAULT 13 frame_dummy
48: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5
50: 00000000004005b4 0 FUNC GLOBAL DEFAULT 14 _fini
51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
58: 0000000000400440 0 FUNC GLOBAL DEFAULT 13 _start
64: 00000000004003e0 0 FUNC GLOBAL DEFAULT 11 _init
45: 00000000004005b0 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
60: 000000000040052d 16 FUNC GLOBAL DEFAULT 13 main
56: 0000000000400540 101 FUNC GLOBAL DEFAULT 13 __libc_csu_init


Now if I check the main function's size, it shows 16. How did it arrive at that? Is that the stack size ?



Compiler used gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1)



GNU readelf (GNU Binutils for Ubuntu) 2.24







share|improve this question
























    up vote
    1
    down vote

    favorite












    I am trying to understand how readelf utility calculates function size. I wrote a simple program



    #include <stdio.h>

    int main()
    printf("Test!n");



    Now to check function size I used this (is this OK ? ):



    readelf -sw a.out|sort -n -k 3,3|grep FUNC



    which yielded:



     1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)
    2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)
    29: 0000000000400470 0 FUNC LOCAL DEFAULT 13 deregister_tm_clones
    30: 00000000004004a0 0 FUNC LOCAL DEFAULT 13 register_tm_clones
    31: 00000000004004e0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
    34: 0000000000400500 0 FUNC LOCAL DEFAULT 13 frame_dummy
    48: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5
    50: 00000000004005b4 0 FUNC GLOBAL DEFAULT 14 _fini
    51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
    58: 0000000000400440 0 FUNC GLOBAL DEFAULT 13 _start
    64: 00000000004003e0 0 FUNC GLOBAL DEFAULT 11 _init
    45: 00000000004005b0 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
    60: 000000000040052d 16 FUNC GLOBAL DEFAULT 13 main
    56: 0000000000400540 101 FUNC GLOBAL DEFAULT 13 __libc_csu_init


    Now if I check the main function's size, it shows 16. How did it arrive at that? Is that the stack size ?



    Compiler used gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1)



    GNU readelf (GNU Binutils for Ubuntu) 2.24







    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying to understand how readelf utility calculates function size. I wrote a simple program



      #include <stdio.h>

      int main()
      printf("Test!n");



      Now to check function size I used this (is this OK ? ):



      readelf -sw a.out|sort -n -k 3,3|grep FUNC



      which yielded:



       1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)
      2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)
      29: 0000000000400470 0 FUNC LOCAL DEFAULT 13 deregister_tm_clones
      30: 00000000004004a0 0 FUNC LOCAL DEFAULT 13 register_tm_clones
      31: 00000000004004e0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
      34: 0000000000400500 0 FUNC LOCAL DEFAULT 13 frame_dummy
      48: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5
      50: 00000000004005b4 0 FUNC GLOBAL DEFAULT 14 _fini
      51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
      58: 0000000000400440 0 FUNC GLOBAL DEFAULT 13 _start
      64: 00000000004003e0 0 FUNC GLOBAL DEFAULT 11 _init
      45: 00000000004005b0 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
      60: 000000000040052d 16 FUNC GLOBAL DEFAULT 13 main
      56: 0000000000400540 101 FUNC GLOBAL DEFAULT 13 __libc_csu_init


      Now if I check the main function's size, it shows 16. How did it arrive at that? Is that the stack size ?



      Compiler used gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1)



      GNU readelf (GNU Binutils for Ubuntu) 2.24







      share|improve this question












      I am trying to understand how readelf utility calculates function size. I wrote a simple program



      #include <stdio.h>

      int main()
      printf("Test!n");



      Now to check function size I used this (is this OK ? ):



      readelf -sw a.out|sort -n -k 3,3|grep FUNC



      which yielded:



       1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)
      2: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.2.5 (2)
      29: 0000000000400470 0 FUNC LOCAL DEFAULT 13 deregister_tm_clones
      30: 00000000004004a0 0 FUNC LOCAL DEFAULT 13 register_tm_clones
      31: 00000000004004e0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
      34: 0000000000400500 0 FUNC LOCAL DEFAULT 13 frame_dummy
      48: 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5
      50: 00000000004005b4 0 FUNC GLOBAL DEFAULT 14 _fini
      51: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
      58: 0000000000400440 0 FUNC GLOBAL DEFAULT 13 _start
      64: 00000000004003e0 0 FUNC GLOBAL DEFAULT 11 _init
      45: 00000000004005b0 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
      60: 000000000040052d 16 FUNC GLOBAL DEFAULT 13 main
      56: 0000000000400540 101 FUNC GLOBAL DEFAULT 13 __libc_csu_init


      Now if I check the main function's size, it shows 16. How did it arrive at that? Is that the stack size ?



      Compiler used gcc version 4.8.5 (Ubuntu 4.8.5-2ubuntu1~14.04.1)



      GNU readelf (GNU Binutils for Ubuntu) 2.24









      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 10 at 10:53









      Zoso

      115




      115




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          The size given by readelf is the size of the binary object; for main, that’s the sequence of machine instructions which implement your function. On my system, I see



          57: 00000000004004d7 21 FUNC GLOBAL DEFAULT 13 main


          from readelf, which matches up nicely with the compiled code as shown by gcc -S or objdump -d:



          0000000000000000 <main>:
          0: 55 push %rbp
          1: 48 89 e5 mov %rsp,%rbp
          4: bf 00 00 00 00 mov $0x0,%edi
          9: e8 00 00 00 00 callq e <main+0xe>
          e: b8 00 00 00 00 mov $0x0,%eax
          13: 5d pop %rbp
          14: c3 retq


          The 21 bytes are the bytes 55, 48, 89, e5 etc.






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436742%2fhow-are-function-sizes-calculated-by-readelf%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            The size given by readelf is the size of the binary object; for main, that’s the sequence of machine instructions which implement your function. On my system, I see



            57: 00000000004004d7 21 FUNC GLOBAL DEFAULT 13 main


            from readelf, which matches up nicely with the compiled code as shown by gcc -S or objdump -d:



            0000000000000000 <main>:
            0: 55 push %rbp
            1: 48 89 e5 mov %rsp,%rbp
            4: bf 00 00 00 00 mov $0x0,%edi
            9: e8 00 00 00 00 callq e <main+0xe>
            e: b8 00 00 00 00 mov $0x0,%eax
            13: 5d pop %rbp
            14: c3 retq


            The 21 bytes are the bytes 55, 48, 89, e5 etc.






            share|improve this answer
























              up vote
              3
              down vote



              accepted










              The size given by readelf is the size of the binary object; for main, that’s the sequence of machine instructions which implement your function. On my system, I see



              57: 00000000004004d7 21 FUNC GLOBAL DEFAULT 13 main


              from readelf, which matches up nicely with the compiled code as shown by gcc -S or objdump -d:



              0000000000000000 <main>:
              0: 55 push %rbp
              1: 48 89 e5 mov %rsp,%rbp
              4: bf 00 00 00 00 mov $0x0,%edi
              9: e8 00 00 00 00 callq e <main+0xe>
              e: b8 00 00 00 00 mov $0x0,%eax
              13: 5d pop %rbp
              14: c3 retq


              The 21 bytes are the bytes 55, 48, 89, e5 etc.






              share|improve this answer






















                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                The size given by readelf is the size of the binary object; for main, that’s the sequence of machine instructions which implement your function. On my system, I see



                57: 00000000004004d7 21 FUNC GLOBAL DEFAULT 13 main


                from readelf, which matches up nicely with the compiled code as shown by gcc -S or objdump -d:



                0000000000000000 <main>:
                0: 55 push %rbp
                1: 48 89 e5 mov %rsp,%rbp
                4: bf 00 00 00 00 mov $0x0,%edi
                9: e8 00 00 00 00 callq e <main+0xe>
                e: b8 00 00 00 00 mov $0x0,%eax
                13: 5d pop %rbp
                14: c3 retq


                The 21 bytes are the bytes 55, 48, 89, e5 etc.






                share|improve this answer












                The size given by readelf is the size of the binary object; for main, that’s the sequence of machine instructions which implement your function. On my system, I see



                57: 00000000004004d7 21 FUNC GLOBAL DEFAULT 13 main


                from readelf, which matches up nicely with the compiled code as shown by gcc -S or objdump -d:



                0000000000000000 <main>:
                0: 55 push %rbp
                1: 48 89 e5 mov %rsp,%rbp
                4: bf 00 00 00 00 mov $0x0,%edi
                9: e8 00 00 00 00 callq e <main+0xe>
                e: b8 00 00 00 00 mov $0x0,%eax
                13: 5d pop %rbp
                14: c3 retq


                The 21 bytes are the bytes 55, 48, 89, e5 etc.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 10 at 11:09









                Stephen Kitt

                140k22305365




                140k22305365






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436742%2fhow-are-function-sizes-calculated-by-readelf%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?