[binutils-gdb] gprofng: Properly generate file offset for gmon.out

H.J. Lu hjl@sourceware.org
Tue Sep 8 10:26:16 GMT 2026


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d570d754422b4990f590829c4bed905a327bc7b

commit 2d570d754422b4990f590829c4bed905a327bc7b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Aug 10 11:54:24 2026 +0800

    gprofng: Properly generate file offset for gmon.out
    
    When generating the map file for gmon.out, get the file offset from the
    filepos field of core_text_sect.  This fixes
    
    FAIL: tmpdir/gp-gmon
    
    on Linux/x86-64.
    
            PR gprofng/34502
            * src/gp-gmon.cc (gen_gmon_map): Get the file offset from the
            filepos field of core_text_sect.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 gprofng/src/gp-gmon.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gprofng/src/gp-gmon.cc b/gprofng/src/gp-gmon.cc
index f8a8adb7fc9..81fe48e2586 100644
--- a/gprofng/src/gp-gmon.cc
+++ b/gprofng/src/gp-gmon.cc
@@ -504,7 +504,7 @@ gen_gmon_map (char *name)
   bfd_vma loadaddr, vaddr = core_text_sect->vma; //lma?
   bfd_size_type msize = core_text_sect->size;
   int timestamp = 1;
-  int offset = 0;
+  int offset = core_text_sect->filepos;
   int check = -1;
   int modeflags = PROT_READ | PROT_EXEC; //0x05
   char *new_file_path;
@@ -522,6 +522,7 @@ gen_gmon_map (char *name)
   mpage = ~(page_size - 1);
   // Round down to page size alignment
   loadaddr = vaddr & mpage;
+  offset &= mpage;
   // Compensate for the alignment gain
   msize += vaddr - loadaddr;
   // Round up to a multiple of page size;


More information about the Binutils-cvs mailing list