Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp05.tex V1 - 09/04/2008 6:13pm Page 1256

Appendix E: The ELF Binary Format


❑ SH_HASHdefines a section that holds a hash table so that entries in symbol tables can be
found more quickly (as mentioned previously).
❑ SH_DYNAMICholds information on dynamic linking, as discussed in Section E.2.6.

The type valuesSHT_HIPROC,SHT_LOPROC,SHT_HIUSER,andSHT_LOUSERalso exist. They are
reserved for processor- and application-specificpurposes and are of no further interest here.
❑ sh_flagsindicate the following: whether the section can be written to (SHF_WRITE), whether vir-
tual memory is to be reserved (SHF_ALLOC), and whether the section contains executable machine
code (SHF_EXECINSTR).
❑ sh_addrspecifies the position in virtual address space to which the section is to be mapped.
❑ sh_offsetspecifies the position in the file at which the section begins.
❑ sh_sizespecifies the size of the section in bytes.
❑ sh_linkreferences another section header table entry that is interpreted differently according to
section type. This is discussed in more detail in the next bulleted list.
❑ sh_infois used in conjunction withsh_link. Again, its exact meaning is discussed in the next
bulleted list.
❑ sh_addralignspecifies how the section data are to be aligned in memory.
❑ sh_entsizespecifies the size, in bytes, of the entries of the section if they are all of the same
size — such as in a symbol table.

sh_linkandsh_infoare used with different meanings depending on section type, as described here:

❑ Sections of theSHT_DYMAMICtype usesh_linkto reference the string table employed by the
section data.sh_infois not used and is therefore set to 0.
❑ Hash tables (sections of theSHT_HASHtype) usesh_linkto reference the symbol table whose
entries are hashed.sh_infois not used.
❑ Relocation sections of theSHT_RELandSHT_RELAtype usesh_linkto reference the associated
symbol table.sh_infoholds the index of the section in the section header table to which the
relocations refer.
❑ sh_linkspecifies which string table is used for symbol tables (SHT_SYMTABandSHT_DYNSYM), and
sh_infoindicates the index position in the symbol table immediately after the last local symbol
(of theSTB_LOCALtype).

As usual, there is a separate data structure for 64-bit systems but its contents do not differ from those of
the 32-bit variant, as you can see here:

<elf.h>
typedef struct elf64_shdr {
Elf64_Word sh_name; /* Section name, index in string tbl */
Elf64_Word sh_type; /* Type of section */
Elf64_Xword sh_flags; /* Miscellaneous section attributes */
Elf64_Addr sh_addr; /* Section virtual addr at execution */
Elf64_Off sh_offset; /* Section file offset */
Elf64_Xword sh_size; /* Size of section in bytes */
Elf64_Word sh_link; /* Index of another section */
Free download pdf