I'm not going to accept this answer, because likely someone else will tell me a better way to do it. But, browsing the site I saw an old picture of Radare that seemed to kind of do what I want with an S=
option. This is showing the breakdown by section. That seemed like a good place to start.
Turns out that's now really close to the undocumented iS=
option.
Using that on both binaries, I saw the difference really quick,
[0x00000000]> iS=
00 0x00000000 |--------------------------------------------------------------------------------------------------| 0x00000000 0 ---
01 0x08048114 |-#------------------------------------------------------------------------------------------------| 0x08048127 19 r-- .interp
02 0x08048128 |-#------------------------------------------------------------------------------------------------| 0x08048148 32 r-- .note.ABI_tag
03 0x08048148 |-#------------------------------------------------------------------------------------------------| 0x0804816c 36 r-- .note.gnu.build_id
04 0x0804816c |-#------------------------------------------------------------------------------------------------| 0x08048198 44 r-- .hash
05 0x08048198 |-#------------------------------------------------------------------------------------------------| 0x080481b8 32 r-- .gnu.hash
06 0x080481b8 |-##-----------------------------------------------------------------------------------------------| 0x08048218 96 r-- .dynsym
07 0x08048218 |--#-----------------------------------------------------------------------------------------------| 0x08048267 79 r-- .dynstr
08 0x08048268 |--#-----------------------------------------------------------------------------------------------| 0x08048274 12 r-- .gnu.version
09 0x08048274 |--#-----------------------------------------------------------------------------------------------| 0x08048294 32 r-- .gnu.version_r
10 0x08048294 |--#-----------------------------------------------------------------------------------------------| 0x0804829c 8 r-- .rel.dyn
11 0x0804829c |--##----------------------------------------------------------------------------------------------| 0x080482bc 32 r-- .rel.plt
12 0x080482bc |---#----------------------------------------------------------------------------------------------| 0x080482ec 48 r-x .init
13 0x080482ec |---#----------------------------------------------------------------------------------------------| 0x0804833c 80 r-x .plt
14 0x08048340 |---###--------------------------------------------------------------------------------------------| 0x080484dc 412 r-x .text
15 0x080484dc |-----#--------------------------------------------------------------------------------------------| 0x080484f8 28 r-x .fini
16 0x080484f8 |-----#--------------------------------------------------------------------------------------------| 0x08048534 60 r-- .rodata
17 0x08048534 |-----#--------------------------------------------------------------------------------------------| 0x08048538 4 r-- .eh_frame
18 0x08049538 |-----#--------------------------------------------------------------------------------------------| 0x08049540 8 rw- .ctors
19 0x08049540 |-----#--------------------------------------------------------------------------------------------| 0x08049548 8 rw- .dtors
20 0x08049548 |-----#--------------------------------------------------------------------------------------------| 0x0804954c 4 rw- .jcr
21 0x0804954c |-----##-------------------------------------------------------------------------------------------| 0x0804961c 208 rw- .dynamic
22 0x0804961c |------#-------------------------------------------------------------------------------------------| 0x08049620 4 rw- .got
23 0x08049620 |------#-------------------------------------------------------------------------------------------| 0x0804963c 28 rw- .got.plt
24 0x0804963c |-------#------------------------------------------------------------------------------------------| 0x08049644 8 rw- .data
25 0x08049644 |-------#------------------------------------------------------------------------------------------| 0x0804964c 0 rw- .bss
26* 0x00000000 |-------############-------------------------------------------------------------------------------| 0x00000a68 2.6K --- .stab
27* 0x00000000 |------------------###################################################################-------------| 0x00003a5c 14.6K --- .stabstr
28* 0x00000000 |------------------------------------------------------------------------------------#-------------| 0x00000039 57 --- .comment
29* 0x00000000 |------------------------------------------------------------------------------------##------------| 0x000000fd 253 --- .shstrtab
30* 0x00000000 |-------------------------------------------------------------------------------------------#####--| 0x00000440 1K --- .symtab
31* 0x00000000 |------------------------------------------------------------------------------------------------##| 0x0000020c 524 --- .strtab
32 0x08048034 |##------------------------------------------------------------------------------------------------| 0x08048114 224 r-x PHDR
33 0x08048114 |-#------------------------------------------------------------------------------------------------| 0x08048127 19 r-- INTERP
34 0x08048000 |######--------------------------------------------------------------------------------------------| 0x08048538 1.3K r-x LOAD0
35 0x08049538 |-----###------------------------------------------------------------------------------------------| 0x0804964c 268 rw- LOAD1
36 0x0804954c |-----##-------------------------------------------------------------------------------------------| 0x0804961c 208 rw- DYNAMIC
37 0x08048128 |-#------------------------------------------------------------------------------------------------| 0x0804816c 68 r-- NOTE
38 0x00000000 |--------------------------------------------------------------------------------------------------| 0x00000000 0 rwx GNU_STACK
39 0x08048000 |#-------------------------------------------------------------------------------------------------| 0x08048034 52 rw- ehdr
=> 0x00000000 |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^| 0xffffffffffffffff
That .stabstr
thing was huge. I found this on Stack Overflow,
I'd be surprised if the debugging format was stabs on either platform unless you had explicitly requested it with -gstabs
as an argument to gcc.
I enabled that option and suddenly my new binary had one too, and it was pretty close in size to the old one.
main
so I played withgcc
until I got something good. But, I want to understand what else changed.file
give you on the two binaries? Perhaps one is stripped and the other isn't? Also one could be statically linked and perhaps not against glibc at all (for example musl-libc comes to mind as libc which is standards-compliant and yields small binaries)