google / bloaty

Bloaty: a size profiler for binaries
Apache License 2.0
4.71k stars 340 forks source link

why the same name section from compileunits is bigger than from symbols #309

Closed TxShon closed 2 years ago

TxShon commented 2 years ago

bloaty -d compileunits -n 0 --domain=file debug.so: FILE SIZE


1.0% 1.10Mi [section .rela.dyn] 0.9% 1.03Mi [section .rodata] 0.7% 824Ki [section .strtab]

bloaty -d symbols -n 0 --domain=file FILE SIZE


0.0% 8.30Ki [section .rela.dyn] 0.7% 819Ki [section .rodata] 0.0% 52.0Ki [section .strtab]

i had see the doc How Bloaty Works,but i did not find the relevant information.I want to know why the sizes of the same section can be different between compileunits and Symbols

haberman commented 2 years ago

Labels that are enclosed in square brackets (eg. [section .rodata]) are fallback labels. You asked Bloaty to report results by compileunit or by symbol, but Bloaty sometimes cannot figure out the right compileunit or symbol to attribute a given byte to.

When Bloaty can't figure it out, instead of just reporting [Unknown], it will try to give a more helpful result, using the one bit of information it does know, which is the section.

So [section .rela.dyn] really means, "Bloaty couldn't figure out a compileunit/symbol, but it can at least tell you that it is in section .rela.dyn.

The reason this number changed between -d compileunits and -d symbols is that Bloaty was able to figure out more when you analyzed by symbol. With -d compileunits there were more unknown bytes, so the size of these fallback labels increased.

This probably could be better explained in the documentation. Feel free to send a PR for that.