]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin macho debuginfo: fix RW load count
authorPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 19 Nov 2025 08:00:54 +0000 (09:00 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Wed, 19 Nov 2025 08:00:54 +0000 (09:00 +0100)
Was counting all RW loads. However, load_thing_file() has the extra
requirement that the filesize be greater than 0. If the filesize is
0 then an anon map gets done and the associated segment doesn't get
flagged as being RW.

Also add the prot value to the macho load_segment mmap traces.

This fixes memcheck/tests/static_malloc

coregrind/m_debuginfo/readmacho.c
coregrind/m_ume/macho.c

index 48ef5aaf5f701a36d0a3fb112c15f830ac52d15e..f75726f550804ae308f8d173369733d43814e593 100644 (file)
@@ -140,8 +140,8 @@ Bool ML_(check_macho_and_get_rw_loads)( Int fd, Int* rw_loads )
       for (unsigned int i = 0U; i < mh->ncmds; ++i) {
          if (lc->cmd == LC_SEGMENT_CMD) {
             const struct SEGMENT_COMMAND* sc = (const struct SEGMENT_COMMAND*)lc;
-            if (sc->initprot == 3) {
-              ++*rw_loads;
+            if (sc->initprot == 3 && sc->filesize) {
+               ++*rw_loads;
             }
          }
          const char* tmp = (const char*)lc + lc->cmdsize;
index ec7257084e15066749f08e1aaef2e469734ae63a..239b7fc0263a2261cc1711235c9c65ad71a2d52d 100644 (file)
@@ -243,7 +243,7 @@ load_segment(int fd, vki_off_t offset, vki_off_t size,
    vmsize = VG_PGROUNDUP(segcmd->vmsize);
    if (filesize > 0) {
       addr = slided_addr;
-      VG_(debugLog)(2, "ume", "mmap fixed (file) (%#lx, %lu)\n", addr, filesize);
+      VG_(debugLog)(2, "ume", "mmap fixed (file) (%#lx, %lu, %x)\n", addr, filesize, prot);
       res = VG_(am_mmap_named_file_fixed_client)(addr, filesize, prot, fd, 
                                                  offset + segcmd->fileoff, 
                                                  filename);
@@ -260,7 +260,7 @@ load_segment(int fd, vki_off_t offset, vki_off_t size,
       // page-aligned part
       SizeT length = vmsize - filesize;
       addr = (Addr)(filesize + slided_addr);
-      VG_(debugLog)(2, "ume", "mmap fixed (anon) (%#lx, %lu)\n", addr, length);
+      VG_(debugLog)(2, "ume", "mmap fixed (anon) (%#lx, %lu, %u)\n", addr, length, prot);
       res = VG_(am_mmap_anon_fixed_client)(addr, length, prot);
       check_mmap(res, addr, length, "load_segment2");
    }