[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A relocation is an action which the linker must take when linking. It describes a change to the contents of a section. The change is normally based on the final value of one or more symbols. Relocations are created by the assembler when it creates an object file.
Most relocations are simple. A typical simple relocation is to set 32
bits at a given offset in a section to the value of a symbol. This type
of relocation would be generated for code like int *p = &i;
where
`p' and `i' are global variables. A relocation for the symbol
`i' would be generated such that the linker would initialize the
area of memory which holds the value of `p' to the value of the
symbol `i'.
Slightly more complex relocations may include an addend, which is a constant to add to the symbol value before using it. In some cases a relocation will require adding the symbol value to the existing contents of the section in the object file. In others the relocation will simply replace the contents of the section with the symbol value. Some relocations are PC relative, so that the value to be stored in the section is the difference between the value of a symbol and the final address of the section contents.
In general, relocations can be arbitrarily complex. For example, relocations used in dynamic linking systems often require the linker to allocate space in a different section and use the offset within that section as the value to store. In the IEEE object file format, relocations may involve arbitrary expressions.
When doing a relocatable link, the linker may or may not have to do anything with a relocation, depending upon the definition of the relocation. Simple relocations generally do not require any special action.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |