google / bloaty

Bloaty: a size profiler for binaries
Apache License 2.0
4.66k stars 337 forks source link

bloaty broken on ubuntu 22.04 #348

Closed jbulow closed 12 months ago

jbulow commented 1 year ago

Built bloaty from source and ran the first example and the output looks weird and is far from what is expected:

./bloaty bloaty -d compileunits
    FILE SIZE        VM SIZE
 --------------  --------------
  33.6%  6.24Mi  32.7%  1.96Mi    [130 Others]
  11.8%  2.18Mi   0.0%       0    [section .debug_loclists]
   6.9%  1.28Mi   6.8%   420Ki    t19__constant_string_pIcEbPKT_
   1.7%   316Ki  17.9%  1.08Mi    underflowEv
   5.1%   966Ki  14.0%   862Ki    e_implILm1EJSt14default_deleteIN6bloaty6ReImplEEEEC2Ev
   4.0%   751Ki   2.0%   120Ki    or_traitsIT_E15difference_typeES3_S3_St26random_access_iterator_tag
   3.1%   586Ki   0.7%  42.5Ki    InputFileFactoryD4Ev
   2.9%   543Ki   1.8%   113Ki    upOutput5PrintERKNS_13OutputOptionsEPSo
   2.8%   536Ki   0.0%       0    [section .debug_rnglists]
   2.8%   527Ki   7.0%   431Ki    lt_deleteIS1_EED2Ev
   2.7%   520Ki   1.5%  94.3Ki    SaIcEEEEC4Ev
   2.7%   507Ki   0.5%  29.7Ki    cSt11char_traitsIcESaIcEE12_Alloc_hiderC2EPcRKS3_
   2.5%   480Ki   2.9%   181Ki    lMap> >
   2.5%   477Ki   1.3%  78.3Ki    <bool (*)(const bloaty::RollupRow&, const bloaty::RollupRow&)> >
   2.5%   477Ki   0.5%  33.7Ki    ressofIcEPT_RS0_
   2.4%   450Ki   1.2%  71.5Ki    11char_traitsIcESaIcEEESt10unique_ptrIN6bloaty6RollupESt14default_deleteISB_EEEE7_M_addrEv
   2.2%   413Ki   4.5%   278Ki    std::_Rb_tree_const_iterator<std::pair<long unsigned int const, bloaty::RangeMap::Entry> > > >
   2.2%   410Ki   1.7%   104Ki    ty7OptionsC4Ev
   2.0%   375Ki   0.3%  19.3Ki    cESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
   1.9%   361Ki   0.7%  42.4Ki    v
   1.8%   348Ki   1.9%   116Ki    lphaNumC2EPKc
 100.0%  18.5Mi 100.0%  6.01Mi    TOTAL

Any hints on how to analyze this problem?

moncefmechri commented 1 year ago

I'm seeing the same behavior. -d compileunits seems broken and prints (part of) unmangled symbols instead of filenames.

The application studied is a large, statically-linked C++20 Linux x86_64 debug binary, built using GCC 12. Bloaty has been built from source today, also with GCC 12.

moncefmechri commented 1 year ago

The issue for me seems to occur when the application studied is built with GCC 12. Taking bloaty as an example:

Built with GCC 12:

$ ./bloaty -d compileunits ./bloaty
    FILE SIZE        VM SIZE
 --------------  --------------
  35.6%  13.8Mi  45.0%  3.06Mi    [168 Others]
  15.0%  5.80Mi   0.0%       0    [section .debug_loclists]
  11.7%  4.52Mi   3.6%   254Ki    w> >, __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const bloaty::RollupRow&, const bloaty::RollupRow&)> >
   5.1%  1.99Mi   3.0%   211Ki    ZN6bloaty7Options17set_verbose_levelEi
   3.9%  1.50Mi   1.3%  88.1Ki    2_EEEC4Ev
   3.0%  1.14Mi   4.9%   338Ki    _EENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEESaISD_EE12_M_check_lenEmPKc
   2.9%  1.13Mi   0.0%       0    [section .debug_rnglists]
   0.8%   307Ki  15.7%  1.07Mi    ar> >&, std::vector<std::__cxx11::basic_string<char> >*, bloaty::Rollup*) const::PerThreadData*>
   2.5%   999Ki   1.3%  92.3Ki    S7_JS7_EEEvPT_DpOT0_
   2.4%   936Ki   0.5%  34.8Ki    ly<bool (*)(const re2::StringPiece&, const re2::RE2&, const re2::RE2::Arg* const*, int), re2::StringPiece>
   2.3%   923Ki  11.8%   820Ki    D2Ev
   1.8%   709Ki   1.5%   101Ki    12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE12_Vector_implC2Ev
   1.7%   678Ki   0.9%  62.0Ki    5_ESaIS8_EE12_M_drop_nodeEPSt13_Rb_tree_nodeIS8_E
   1.6%   622Ki   0.7%  46.9Ki    cewise_construct_tSt5tupleIJRS7_EESQ_IJEEEEERSK_DpOT_
   1.5%   614Ki   0.4%  30.2Ki    9__gnu_cxx17__normal_iteratorIPS3_S5_EET_SN_St12__false_type
   1.5%   596Ki   0.4%  30.3Ki    7__normal_iteratorIPS7_S9_EEDpOT_
   1.5%   585Ki   0.6%  42.3Ki    char_traitsIcESaIcEEEEC2Ev
   1.3%   528Ki   6.2%   432Ki    ollupRow>
   1.3%   520Ki   1.3%  89.1Ki    cxx::__normal_iterator<bloaty::RollupRow*, std::vector<bloaty::RollupRow> >, __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(const bloaty::RollupRow&, const bloaty::RollupRow&)> >
   1.3%   519Ki   0.4%  28.6Ki    12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EED4Ev
   1.2%   491Ki   0.6%  42.7Ki    sl16strings_internal8SplitterINS7_6ByCharENS7_10AllowEmptyES3_E18ConvertToContainerIS5_S3_Lb0EEclERKSC_E8raw_viewEEvN9__gnu_cxx17__normal_iteratorIPS3_S5_EET_SN_St12__false_type
 100.0%  38.7Mi 100.0%  6.81Mi    TOTAL

Built with GCC 10:

$ ./bloaty -d compileunits ./bloaty
    FILE SIZE        VM SIZE
 --------------  --------------
  36.1%  17.4Mi  49.1%  3.35Mi    [165 Others]
  15.1%  7.26Mi   3.5%   241Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/descriptor.cc
   6.9%  3.33Mi   2.8%   195Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/descriptor.pb.cc
   5.2%  2.49Mi   4.9%   343Ki    /home/mmechri/coding/bloaty-gcc10/third_party/capstone/arch/ARM/ARMDisassembler.c
   4.8%  2.29Mi   1.2%  83.2Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/text_format.cc
   3.2%  1.56Mi   1.2%  87.1Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/generated_message_reflection.cc
   2.8%  1.33Mi   0.5%  34.2Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/descriptor_database.cc
   2.5%  1.21Mi   0.9%  62.9Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/extension_set.cc
   2.3%  1.12Mi   0.4%  29.7Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/generated_message_util.cc
   1.3%   631Ki  15.6%  1.07Mi    /home/mmechri/coding/bloaty-gcc10/third_party/capstone/arch/M68K/M68KDisassembler.c
   2.2%  1.06Mi   0.7%  46.2Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/wire_format.cc
   2.1%  1012Ki   1.0%  67.2Ki    /home/mmechri/coding/bloaty-gcc10/third_party/capstone/arch/Mips/MipsDisassembler.c
   2.0%   980Ki   1.3%  87.4Ki    /home/mmechri/coding/bloaty-gcc10/third_party/capstone/arch/AArch64/AArch64Disassembler.c
   1.9%   948Ki   1.1%  76.2Ki    /home/mmechri/coding/bloaty-gcc10/third_party/capstone/arch/SystemZ/SystemZDisassembler.c
   1.9%   936Ki  11.7%   820Ki    /home/mmechri/coding/bloaty-gcc10/third_party/capstone/arch/X86/X86Mapping.c
   1.7%   853Ki   1.5%   103Ki    /home/mmechri/coding/bloaty-gcc10/src/bloaty.cc
   1.7%   841Ki   0.5%  37.9Ki    /home/mmechri/coding/bloaty-gcc10/third_party/re2/re2/re2.cc
   1.6%   781Ki   0.4%  29.0Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/message.cc
   1.6%   766Ki   0.7%  47.8Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/repeated_field.cc
   1.5%   752Ki   0.6%  42.9Ki    /home/mmechri/coding/bloaty-gcc10/third_party/protobuf/src/google/protobuf/map_field.cc
   1.5%   730Ki   0.4%  28.0Ki    /home/mmechri/coding/bloaty-gcc10/third_party/re2/re2/dfa.cc
 100.0%  48.0Mi 100.0%  6.82Mi    TOTAL

Given that recent GCCs default to DWARF 5, I tried to build with GCC 12 while generating DWARF 4 debug info by passing -gdwarf-4, but this raises a new error:

$ ./bloaty -d compileunits ./bloaty
bloaty: Overflow in vm range, vmaddr=18383370559946752, vmsize=18428360703149604864
moncefmechri commented 1 year ago

I confirm #357 fixes the issue for me.