As the system creates or augments a process image, it logically copies a file's segment to a virtual memory segment. When -- and if -- the system physically reads the file depends on the program's execution behavior, system load, and so forth. A process does not require a physical page unless it references the logical page during execution, and processes commonly leave many pages unreferenced. Therefore delaying physical reads frequently obviates them, improving system performance. To obtain this efficiency in practice, executable and shared object files must have segment images whose file offsets and virtual addresses are congruent, modulo the page size. By aligning segments to the maximum page size, the files will be suitable for paging regardless of physical page size.
The following examples show 8 K alignment; virtual addresses and file offsets for segments are congruent modulo 8 K (0x2000). Actual minimum page sizes are machine specific.
|File offset||File||Virtual address|
|Program header table|
|. . .|
|. . .|
|[. . .]|
Program header segments
The end of the data segment requires special handling for uninitialized data, which the system defines to begin with zero values. Thus if a file's last data page includes information not in the logical memory page, the extraneous data must be set to zero, not the unknown contents of the executable file. Impurities in the other three pages are not logically part of the process image; whether the system expunges them is unspecified. The memory image for this program follows, assuming 2KB (0x800) pages. For simplicity, this example illustrates only one page size.
|. . .|
|. . .|
|0x1024 zero bytes|
|0x2dc zero bytes|
Process image segments
One aspect of segment loading differs between executable
files and shared objects. Executable file segments
typically contain absolute code. To let the process
execute correctly, the segments must reside at the virtual
addresses used to build the executable file. Thus the
system uses the
p_vaddr values unchanged as virtual
On the other hand, shared object segments typically contain position-independent code.
This lets a segment's virtual address change from one process to another, without invalidating execution behavior. Though the system chooses virtual addresses for individual processes, it maintains the segments' relative positions. Because position-independent code uses relative addressing between segments, the difference between virtual addresses in memory must match the difference between virtual addresses in the file. ``Example shared object segment addresses'' shows possible shared object virtual address assignments for several processes, illustrating constant relative positioning. The table also illustrates the base address computations. The maximum page size used in ``Example shared object segment addresses'' is 8KB.
Example shared object segment addresses