From dbbdf057406111be1a699adc134a834f455ca18d Mon Sep 17 00:00:00 2001 From: Zequan Wu Date: Wed, 2 Jun 2021 13:41:31 -0700 Subject: [PATCH] Load .symtab and .strtab sections before .debug_info to deduplicate PUBLIC records. For chrome, the symbol file size dropped from 661 MB to 577 MB. The number of PUBLIC records dropped from 559416 to 91930. Change-Id: I7f703d619f2acc7c83f002e6f588f6a6569e5c87 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2916731 Reviewed-by: Lei Zhang --- src/common/linux/dump_symbols.cc | 54 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/common/linux/dump_symbols.cc b/src/common/linux/dump_symbols.cc index c939c669..e8d0bd80 100644 --- a/src/common/linux/dump_symbols.cc +++ b/src/common/linux/dump_symbols.cc @@ -702,32 +702,6 @@ bool LoadSymbols(const string& obj_file, } #endif // NO_STABS_SUPPORT - // Look for DWARF debugging information, and load it if present. - const Shdr* dwarf_section = - FindElfSectionByName(".debug_info", SHT_PROGBITS, - sections, names, names_end, - elf_header->e_shnum); - - // .debug_info section type is SHT_PROGBITS for mips on pnacl toolchains, - // but MIPS_DWARF for regular gnu toolchains, so both need to be checked - if (elf_header->e_machine == EM_MIPS && !dwarf_section) { - dwarf_section = - FindElfSectionByName(".debug_info", SHT_MIPS_DWARF, - sections, names, names_end, - elf_header->e_shnum); - } - - if (dwarf_section) { - found_debug_info_section = true; - found_usable_info = true; - info->LoadedSection(".debug_info"); - if (!LoadDwarf(obj_file, elf_header, big_endian, - options.handle_inter_cu_refs, module)) { - fprintf(stderr, "%s: \".debug_info\" section found, but failed to load " - "DWARF debugging information\n", obj_file.c_str()); - } - } - // See if there are export symbols available. const Shdr* symtab_section = FindElfSectionByName(".symtab", SHT_SYMTAB, @@ -785,6 +759,34 @@ bool LoadSymbols(const string& obj_file, found_usable_info = found_usable_info || result; } } + + // Only Load .debug_info after loading symbol table to avoid duplicate + // PUBLIC records. + // Look for DWARF debugging information, and load it if present. + const Shdr* dwarf_section = + FindElfSectionByName(".debug_info", SHT_PROGBITS, + sections, names, names_end, + elf_header->e_shnum); + + // .debug_info section type is SHT_PROGBITS for mips on pnacl toolchains, + // but MIPS_DWARF for regular gnu toolchains, so both need to be checked + if (elf_header->e_machine == EM_MIPS && !dwarf_section) { + dwarf_section = + FindElfSectionByName(".debug_info", SHT_MIPS_DWARF, + sections, names, names_end, + elf_header->e_shnum); + } + + if (dwarf_section) { + found_debug_info_section = true; + found_usable_info = true; + info->LoadedSection(".debug_info"); + if (!LoadDwarf(obj_file, elf_header, big_endian, + options.handle_inter_cu_refs, module)) { + fprintf(stderr, "%s: \".debug_info\" section found, but failed to load " + "DWARF debugging information\n", obj_file.c_str()); + } + } } if (options.symbol_data != NO_CFI) {