gprof: Enable decompression before checking separate debug files
Fixes gprof's output when DWARF debug info is compressed and in a separate file.
This patch addresses an issue where gprof would output <unknown>:0 for source file lines when using compressed DWARF debug information stored in separate files. The problem stemmed from BFD not initializing the decompression for these separate debug sections early enough. By enabling decompression before bfd_check_format, similar to how it’s handled for the main executable, the separate debug file is opened with the correct decompression behavior, resolving the incorrect source line reporting.
- proposer
Submitted a patch to resolve `gprof`'s incorrect source line reporting with compressed DWARF in separate debug files by enabling decompression earlier in the process.
“With compressed DWARF enabled by default, tst-gmon-gprof-l2 reports <unknown>:0 for f1, f2 and f3 instead of the expected source lines. BFD initializes compressed section sizes while checking the object format. Set BFD_DECOMPRESS before bfd_check_format(), as core_init() already does for the main executable, so the separate debug file is opened with the same section decompression behavior.”
- maintainer
Accepted the patch, indicating it has been applied.
“Thank you, applied.”
Technical Tradeoffs
- Modifies the initialization order in BFD to set BFD_DECOMPRESS before `bfd_check_format` for separate debug files.
- Addresses a specific issue related to compressed DWARF in separate files, potentially improving accuracy for users employing this configuration.
- Relies on the existing DWARF compression and BFD infrastructure.
In Details
This patch for gprof corrects the display of source line numbers when DWARF debug information is both compressed and located in a separate debug file. Previously, bfd_check_format would be called before BFD's internal decompression mechanisms were fully initialized for these external files, leading to section sizes being reported incorrectly. This resulted in gprof failing to map execution samples to their correct source lines, showing <unknown>:0. The fix ensures that BFD_DECOMPRESS is set before bfd_check_format is invoked for separate debug files, aligning its behavior with the p…
- gprof
- A performance analysis tool that collects and displays call graph and timing information.
- DWARF
- A debugging data format used by many compilers and debuggers to store information about program variables, functions, and types.
- compressed DWARF
- DWARF debug information that has been compressed to reduce file size.
- separate debug files
- Object files that contain only DWARF debug information, separate from the executable binary. This allows the executable to be smaller and the debug information to be managed independently.
- BFD
- Binary File Descriptor library, a GNU library that provides a common interface to various object file formats.
- section decompression
- The process of uncompressing data that has been compressed within a specific section of an object file.
- bfd_check_format
- A function within the BFD library used to determine and validate the format of a binary file.