From 88f69009b155c5c7d8b904e0b46e1d3e57b09314 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Wed, 19 Nov 2025 09:00:54 +0100 Subject: [PATCH] Darwin macho debuginfo: fix RW load count 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 | 4 ++-- coregrind/m_ume/macho.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/coregrind/m_debuginfo/readmacho.c b/coregrind/m_debuginfo/readmacho.c index 48ef5aaf5..f75726f55 100644 --- a/coregrind/m_debuginfo/readmacho.c +++ b/coregrind/m_debuginfo/readmacho.c @@ -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; diff --git a/coregrind/m_ume/macho.c b/coregrind/m_ume/macho.c index ec7257084..239b7fc02 100644 --- a/coregrind/m_ume/macho.c +++ b/coregrind/m_ume/macho.c @@ -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"); } -- 2.47.3