[PATCH] gprof: Enable decompression before checking separate debug files
Li Guan
guanli.oerv@isrc.iscas.ac.cn
Mon Nov 16 18:15:35 GMT 2026
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.
Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
---
Notes:
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=35008
Validated on macOS 27.2 arm64 with Apple clang 21.0.0 and gprof configured
for x86_64-linux-gnu, using upstream tst-gmon.c and synthetic gmon records.
Compared embedded and separate debug files with none/zlib/zlib-gnu
compression. The two compressed separate-file cases lose source locations
without the fix; all six combinations produce correct lines and counts
with it. Full testsuite and riscv64 validation were not performed.
AI assistance was used for diagnosis and preparation of this patch.
I am submitting this patch under the Binutils policy exception for
LLM-generated code that is not legally significant:
https://sourceware.org/binutils/wiki/LLM_Generated_Content
The change only relocates an existing flag assignment and replaces a
short comment (3 insertions, 4 deletions). GNU's maintainer guidelines
state: "A change of just a few lines (less than 15 or so) is not legally
significant for copyright."
https://www.gnu.org/prep/maintain/maintain.html#Legally-Significant
gprof/corefile.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/gprof/corefile.c b/gprof/corefile.c
index 712dd243..5c181f19 100644
--- a/gprof/corefile.c
+++ b/gprof/corefile.c
@@ -205,12 +205,11 @@ open_separated_debug_file (bfd *abfd)
if (debug_bfd)
{
+ /* Enable decompression before BFD reads the section headers. */
+ debug_bfd->flags |= BFD_DECOMPRESS;
+
if (bfd_check_format (debug_bfd, bfd_object))
{
- /* Successfully opened the debug file.
- Enable decompression on the debug file. */
- debug_bfd->flags |= BFD_DECOMPRESS;
-
/* Store the debug BFD for use during symbol reading.
We'll use this for bfd_canonicalize_symtab and other symbol ops. */
core_debug_bfd = debug_bfd;
--
2.54.0
More information about the Binutils
mailing list