A.out: Difference between revisions

Jump to navigation Jump to search
2,050 bytes added ,  3 years ago
I extended this article with the description of relocation info structure. I also made some minor changes.
[unchecked revision][unchecked revision]
m (Added positions and ELF link)
(I extended this article with the description of relocation info structure. I also made some minor changes.)
Line 33:
|}
===The exec header===
Every binary file begins with an exec structure, which is 32 orbytes in size. Some later versions of a.out are modified to allow 64 bit code execution. Their header is 64 bytes in size:, however.
 
32 bit executable header:
<source lang="c">
struct exec {
{
unsigned long a_midmag;
 
unsigned long a_text;
unsigned longuint32_t a_midmag;
unsigned long a_data;
unsigneduint32_t long a_bssa_text;
unsigneduint32_t long a_symsa_data;
uint32_t a_bss;
unsigned long a_entry;
uint32_t a_syms;
unsigned long a_trsize;
unsigned longuint32_t a_entry;
unsigned long a_drsize;
unsigned longuint32_t a_trsize;
unsigned longuint32_t a_drsize;
 
};
</source>
Line 93 ⟶ 98:
|a_drsize
|Contains the size in bytes of the data relocation table.
|}
===The relocation info structure===
Relocation records have a standard format which is described by the relocation_info structure:
<source lang="c">
struct relocation_info
{
 
int32_t r_address;
 
uint32_t r_symbolnum : 24,
r_pcrel : 1,
r_length : 2,
r_extern : 1,
r_baserel : 1,
r_jmptable : 1,
r_relative : 1,
r_copy : 1;
 
};
</source>
The fields have the following functions:
{| class="wikitable"
|-
! Position in bits (32 bit)
! Field
! Description
|-
|0-31
|r_address
| Contains the byte offset of a pointer that needs to be link-edited. Text relocation offsets are reckoned from the start of the text segment, and data relocation offsets from the start of the data segment. The link editor adds the value that is already stored at this offset into the new value that it computes using this relocation record.
|-
|32-55
|r_symbolnum
|Contains the ordinal number of a symbol structure in the symbol table (it is not a byte offset).
|-
|56
|r_pcrel
|If this is set, the link editor assumes that it is updating a pointer that is part of a machine code instruction using pc-relative addressing. The address of the relocated pointer is implicitly added to its value when the running program uses it.
|-
|57-58
|r_length
|Contains the log base 2 of the length of the pointer in bytes.
|-
|59
|r_extern
|Set if this relocation requires an external reference.
|-
|60
|r_baserel
|If set, the symbol is to be relocated to an offset into the GOT.
|-
|61
|r_jmptable
|If set, the symbol is to be relocated to an offset into the PLT.
|-
|62
|r_relative
|If set, this relocation is relative to the load address of the image this object file is going to be a part of.
|-
|63
|r_copy
|If set, this relocation record identifies a symbol whose contents should be copied to the location given in r_address.
|}
 
1

edit

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu