Search code examples
assemblygccx86disassemblyobjdump

Discrepancy in outputs of `size` and `objdump`?


I have compiled the following C function (in sum.c) into object code:

int sum(int a, int b)
{
    return (a + b);
}

using

gcc -c sum.c

When I check the sizes of different sections using size:

size sum.o
   text    data     bss     dec     hex filename
    112       0       0     112      70 sum.o

it tells me that the text section is allocated 112 bytes. But when I disassemble it using objdump:

objdump -d sum.o

sum.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <sum>:
   0:   f3 0f 1e fa             endbr64 
   4:   55                      push   %rbp
   5:   48 89 e5                mov    %rsp,%rbp
   8:   89 7d fc                mov    %edi,-0x4(%rbp)
   b:   89 75 f8                mov    %esi,-0x8(%rbp)
   e:   8b 55 fc                mov    -0x4(%rbp),%edx
  11:   8b 45 f8                mov    -0x8(%rbp),%eax
  14:   01 d0                   add    %edx,%eax
  16:   5d                      pop    %rbp
  17:   c3                      retq   

There are only 17 bytes worth of instructions in the .text section. Is there something that I am missing?


Solution

  • Use size -A and objdump -D to get all the information you want.

    On my system size without -A adds the size of the .eh_frame section onto text (probably because it is read-only and will be loaded together with the text).