On some targets the code is causing issues, assuming due to non-zeroed memory
Don't assume. Profile. If reads from uninitialized memory are your problem you could install a signal handler for SIGSEGV, then when your program is at a state where you can start "probing" it use mprotect
to mark all pages in the data segment as PROT_NONE
and then inside the SIGSEGV handler re-add the PROT_READ
and PROT_WRITE
flags as required, taking notes which parts of your program did access which portion of the address space. But this will give you only coarse granularity and fail miserably for memory allocated from pools like malloc
and new
do.
Valgrind is exactly the tool for the job you have at hand.
Afaik Linux is "faking" malloc't memory which didn't belong to the process before to zero
On Linux ever since kernel version 2.6.33 memory allocated directly using mmap will always be initialized to zero. This is not so much a "fake" zero, rather than Linux will initially map to an all-zero page at first, so that reads come out as zero and upon the first write request a fresh page will be allocated, cleared to zero and replace the placeholder page map.