|
From: Oswald, M. <mic...@si...> - 2008-03-20 12:15:40
|
Hello,
I am using valgrind (ver. 3.3.0 on SuSE Linux Enterprise Server 9, gcc 3.3.3) on a large project which uses the POST++ persistent object library. In principle, it imports some data from files and creates a lot of (modified) STL containers of objects in a shared memory segment. The binary image of this segment is then saved and, when needed from a process, loaded and mmapped to a fixed address. The objects and containers can then be normally accessed.
When using valgrind on a process which uses POST (I added some valgrind client requests to tell valgrind about the shared memory), the program crashes when accessing a specific part of the shared memory. It doesn't do this when running the program without valgrind and most of the runs with valgrind are fine too (if they are in another range of the shared memory).
Valgrind reports something like this:
==10251== Invalid read of size 4
==10251== at 0x804EBCA: main (TESTmib.C:127)
==10251== Address 0x40103d48 is not stack'd, malloc'd or (recently) free'd
==10251==
==10251== Jump to the invalid address stated on the next line
==10251== at 0x40103D40: ???
==10251== by 0x694B20F: (below main) (in /lib/tls/libc.so.6)
==10251== Address 0x40103d40 is not stack'd, malloc'd or (recently) free'd
Program catch signal 6.
Whereas the given problematic address (0x40103d48) seems to be rather in the code segment.
After some research it turned out, that I can get the same error with gdb (running the program without valgrind) when the link order of the libraries is invalidated. This means for example, that I have to link a program with libPOST libA libB libC and so on in this explicit order which has to be the same as from the process, who generated the binary image. Only with the right link order the addresses match when the code of the C++ objects in the shared memory is executed.
Now it seems that valgrind, since it provides a slightly different memory model, runs into problems because even when the link order of the libraries is the same, the addresses of some objects may not be the same and the code of one library (say libB) then jumps into the void.
So a few questions:
- How does valgrind handle mmap calls with MAP_FIXED?
- Does valgrind respect the link order of the libraries when loading these (I would assume this)?
- Does anybody have an idea how to get valgrind to work with such a process?
lg,
Michael
|