Anonymous user
ELF Tutorial: Difference between revisions
Jump to navigation
Jump to search
m
→ELF Sections: Fix more typing errors
[unchecked revision] | [unchecked revision] |
m (Fix typing errors) |
m (→ELF Sections: Fix more typing errors) |
||
Line 366:
===The String Table===
The string table conceptually is quite simple: it's just a number of consecutive zero-terminated strings. String literals used in the program are stored in one of the tables. There are a number of different string tables that may be present in an ELF object such as .strtab (the default string table), .shstrtab (the section string table) and .dynstr (string table for dynamic linking).
The simplest program loader may copy all string tables into memory, but a more complete solution would omit any that are not necessary during runtime such, notably those not flagged with '''SHF_ALLOC''' in their respective section header (such as .shstrtab, since section names aren't used in program runtime).
Line 409:
===Relocation Sections===
Relocatable ELF files have many uses in kernel programming, especially as modules and drivers that can be loaded at startup, and are especially useful because they are position
Relocation starts with a table of relocation entries, which can be located using the relevant section header. There are actually two different kinds of relocation structures; one with an explicit added (section type '''SHT_RELA'''), one without (section type '''SHT_REL'''). Relocation entires in the table are continuous and the number of entries in a given table can be found by dividing the size of the table (given by '''sh_size''' in the section header) by the size of each entry (given by '''sh_entsize'''). Each relocation table is specific to a single section, so a single file may have multiple relocation tables (but all entries within a given table will be the same relocation structure type).
Line 426:
</source>
The above are the
<source lang="cpp">
Line 439:
</source>
As previously mentioned, the '''r_info''' field in '''Elf32_Rel'''('''a''') refers to 2
====Relocation Example====
Line 478:
====Relocating a Symbol====
As the following function is fairly complex, it's been broken up into smaller
<source lang="cpp">
Line 491:
</source>
The above code defines the macro functions that are used to complete relocation calculations. It also
<source lang="cpp">
Line 502:
</source>
Next the value of the symbol being relocated is accessed. If the symbol table index stored in '''r_info''' is undefined, then the value defaults to 0. The code also references a function called '''elf_get_symval'''(), which was implemented previously. If the value returned by the function is equal to '''ELF_RELOC_ERR''', relocation is
<source lang="cpp">
Line 527:
</source>
Finally, this segment of code details the actual relocation process, performing the necessary calculating the relocated symbol and returning it's value on success. If the relocation type is unsupported an error message is displayed, relocation is
==The ELF Program Header==
|