Anonymous user
ELF: Difference between revisions
Removed irrelevant information relating to GeekOS and added generic steps to loading an ELF executable.
[unchecked revision] | [unchecked revision] |
(german grammar mistake correction) |
(Removed irrelevant information relating to GeekOS and added generic steps to loading an ELF executable.) |
||
Line 122:
[[Image:Elfdiagram.png|frame|Executable image and elf binary can being mapped onto each other]]
The ELF file format is described in the [http://www.skyfree.org/linux/references/ELF_Format.pdf ELF Specification]. The most relevant sections for this project are 1.1 to 1.4 and 2.1 to 2.7.
The steps involved in identifying the sections of the ELF file are:
* Read the ELF Header. The ELF header will always be at the very beginning of an ELF file. The ELF header contains information about how the rest of the file is laid out.
* Find the Program Headers
The following is a rough outline of the steps that an ELF executable loader must perform:
* Parse the ELF executable's program headers to determine the number of program segments that must be loaded. Each program header has an associated type, as described in Figure 2-2 of the ELF specification. Only those with a type of <tt>PT_LOAD</tt> describe a loadable segment.
* Load each of the loadable segments. This is performed as follows:
** Allocate virtual memory for each segment, at the address specified by the <tt>p_vaddr</tt> member in the program header. The size of the segment in memory is specified by the <tt>p_memsz</tt> member.
** Copy the segment data from the file offset specified by the <tt>p_offset</tt> member to the virtual memory address specified by the <tt>p_vaddr</tt> member. The size of the segment in the file is contained in the <tt>p_filesz</tt> member. This can be zero.
** The <tt>p_memsz</tt> member specifies the size the segment occupies in memory. This can be zero. If the <tt>p_filesz</tt> and <tt>p_memsz</tt> members differ, this indicates that the segment is padded with zeros. All bytes in memory between the ending offset of the file size, and the segment's virtual memory size are to be cleared with zeros.
▲# Check that the file starts with the ELF magic number (4 bytes) as described in figure 1-4 (and subsequent table) on page 11 in the ELF specification.
* Read the executable's entry point from the ELF header.
* Jump to the executable's entry point in the newly loaded memory.
==Relocation==
|