Skip to content

Commit

Permalink
Ignore read-only mappings of ELF files at non-fixed addresses.
Browse files Browse the repository at this point in the history
Such a mapping is likely part of some transient operation by the dynamic
linker, such as parsing the ELF header while loading an object.  If the
address of that mapping is recycled it may trigger disposal of the
corresponding debug info since it overlaps with a new mapping.  The
result of this is that valgrind is unable to hook malloc() calls in the
client, so memcheck reports zero heap usage.

Fix the problem by ignoring read-only non-fixed ELF file mappings.  This
might not be the best way to address the problem, but it seems to work.
Older versions of valgrind ignored read-only mappings completely.
  • Loading branch information
markjdb committed Jan 7, 2019
1 parent b293096 commit 2c57a7b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion coregrind/m_aspacemgr/aspacemgr-linux.c
Expand Up @@ -1493,7 +1493,8 @@ static void init_nsegment ( /*OUT*/NSegment* seg )
seg->mode = 0;
seg->offset = 0;
seg->fnIdx = -1;
seg->hasR = seg->hasW = seg->hasX = seg->hasT = seg->isCH = False;
seg->hasR = seg->hasW = seg->hasX = seg->hasT
= seg->isCH = seg->isFF = False;
}

/* Make an NSegment which holds a reservation. */
Expand Down Expand Up @@ -2211,6 +2212,7 @@ VG_(am_notify_client_mmap)( Addr a, SizeT len, UInt prot, UInt flags,
if (ML_(am_resolve_filename)(fd, buf, VKI_PATH_MAX)) {
seg.fnIdx = ML_(am_allocate_segname)( buf );
}
seg.isFF = (flags & VKI_MAP_FIXED);
}
add_segment( &seg );
AM_SANITY_CHECK;
Expand Down Expand Up @@ -2452,6 +2454,7 @@ SysRes VG_(am_mmap_named_file_fixed_client_flags)
} else if (ML_(am_resolve_filename)(fd, buf, VKI_PATH_MAX)) {
seg.fnIdx = ML_(am_allocate_segname)( buf );
}
seg.isFF = (flags & VKI_MAP_FIXED);
add_segment( &seg );

AM_SANITY_CHECK;
Expand Down Expand Up @@ -2762,6 +2765,7 @@ static SysRes VG_(am_mmap_file_float_valgrind_flags) ( SizeT length, UInt prot,
if (ML_(am_resolve_filename)(fd, buf, VKI_PATH_MAX)) {
seg.fnIdx = ML_(am_allocate_segname)( buf );
}
seg.isFF = (flags & VKI_MAP_FIXED);
add_segment( &seg );

AM_SANITY_CHECK;
Expand Down
4 changes: 4 additions & 0 deletions coregrind/m_debuginfo/debuginfo.c
Expand Up @@ -1205,6 +1205,10 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
/* Ignore mappings with permissions we can't possibly be interested in. */
if (!(is_rx_map || is_rw_map || is_ro_map))
return 0;
/* Ignore non-fixed read-only mappings. The dynamic linker may be
* mapping something for its own transient purposes. */
if (!seg->isFF && is_ro_map)
return 0;

/* Peer at the first few bytes of the file, to see if it is an ELF */
/* object file. Ignore the file if we do not have read permission. */
Expand Down
1 change: 1 addition & 0 deletions include/pub_tool_aspacemgr.h
Expand Up @@ -112,6 +112,7 @@ typedef
Bool hasT; // True --> translations have (or MAY have)
// been taken from this segment
Bool isCH; // True --> is client heap (SkAnonC ONLY)
Bool isFF; // True --> is a fixed file mapping
}
NSegment;

Expand Down

0 comments on commit 2c57a7b

Please sign in to comment.