blob: 23513af1d0dce300e78f7b415c5a9180cec88e27 [file] [log] [blame]
njna9104c02005-06-30 00:54:02 +00001
2-----------------------------------------------------------------------------
3Info about the relationship between Segments and SegInfos
4-----------------------------------------------------------------------------
5
6SegInfo is from the very original Valgrind code, and so it predates
7Segments. It's poorly named now; its really just a container for all
8the object file metadata (symbols, debug info, etc).
9
10Segments describe memory mapped into the address space, and so any
11address-space chaging operation needs to update the Segment structure.
12After the process is initalized, this means one of:
13
14 * mmap
15 * munmap
16 * mprotect
17 * brk
18 * stack growth
19
20A piece of address space may or may not be mmaped from a file.
21
22A SegInfo specifically describes memory mmaped from an ELF object file.
23Because a single ELF file may be mmaped with multiple Segments, multiple
24Segments can point to one Seginfo. A SegInfo can relate to a memory
25range which is not yet mmaped. For example, if the process mmaps the
26first page of an ELF file (the one containing the header), a SegInfo
27will be created for that ELF file's mappings, which will include memory
28which will be later mmaped by the client's ELF loader. If a new mmap
29appears in the address range of an existing SegInfo, it will have that
30SegInfo attached to it, presumably because its part of a .so file.
31Similarly, if a Segment gets split (by mprotect, for example), the two
32pieces will still be associated with the same SegInfo. For this reason,
33the address/length info in a SegInfo is not a duplicate of the Segment
34address/length.
35
36This is complex for several reasons:
37
38 1. We assume that if a process is mmaping a file which contains an
39 ELF header, it intends to use it as an ELF object. If a program
40 which just mmaps ELF files but just uses it as raw data (copy, for
41 example), we still treat it as a shared-library opening.
42 2. Even if it is being loaded as a shared library/other ELF object,
43 Valgrind doesn't control the mmaps. It just observes the mmaps
44 being generated by the client and has to cope. One of the reasons
45 that Valgrind has to make its own mmap of each .so for reading
46 symtab information is because the client won't necessary mmap the
47 right pieces, or do so in the wrong order for us.
48
49SegInfos are reference counted, and freed when no Segments point to them any
50more.
51
52> Aha. So the range of a SegInfo will always be equal to or greater
53> than the range of its parent Segment? Or can you eg. mmap a whole
54> file plus some extra pages, and then the SegInfo won't cover the extra
55> part of the range?
56
57That would be unusual, but possible. You could imagine ld generating an
58ELF file via a mapping this way (which would probably upset Valgrind no
59end).