Bug 402985 - commit 64aa729bfae7 ("Accept read-only PT_LOAD segments and .rodata.") breaks debuginfo tracking on FreeBSD
Summary: commit 64aa729bfae7 ("Accept read-only PT_LOAD segments and .rodata.") breaks...
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.13.0
Platform: Other FreeBSD
: NOR normal
Target Milestone: ---
Assignee: Paul Floyd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-07 23:12 UTC by Mark Johnston
Modified: 2020-10-07 08:55 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Johnston 2019-01-07 23:12:37 UTC
SUMMARY
A number of us have been working on getting valgrind 3.13 working well on FreeBSD.  Commit 64aa729bfae7 changed some logic which is interacting badly with FreeBSD's dynamic linker.  Our linker, when loading a shared library, mmap()s the first page of the file to read its ELF header; the header is unmapped once the task of loading the object is finished.  The problem is that the header is mapped at a non-fixed address which may be reused during a subsequent load of a different file.  When the reuse occurs and the new file is activated, valgrind believes that the new file overlaps with the old one and erroneously discards symbols for the old file.

STEPS TO REPRODUCE
1. Check out commit 1c7e497629539f73c5bc364b3e13dea8358fd76c from github.com/freebsdfoundation/valgrind and build valgrind on FreeBSD-CURRENT.
2. Run memcheck on any application which uses malloc().

OBSERVED RESULT
memcheck reports zero heap usage because the bug described above breaks redirection of malloc().

ADDITIONAL INFORMATION
I attempted my own fix: https://github.com/FreeBSDFoundation/valgrind/commit/2c57a7b44a52d5e944dcc5686d6733bf2b917f32

The idea is to track whether a given segment was mapped with MAP_FIXED, and ignore mappings of ELF objections if the mapping is read-only and not fixed.  It seems to work, but since we currently have quite a few failing regression tests on FreeBSD it's hard to determine whether it introduces new problems.
Comment 1 Paul Floyd 2020-10-07 08:55:36 UTC
This patch is integrated in the current valgrind/valgrind-devel port.