Linker and Libraries Guide

ELF Identification

As mentioned above, ELF provides an object file framework to support multiple processors, multiple data encoding, and multiple classes of machines. To support this object file family, the initial bytes of the file specify how to interpret the file, independent of the processor on which the inquiry is made and independent of the file's remaining contents.

The initial bytes of an ELF header (and an object file) correspond to the e_ident member.

Table 7-7 e_ident[ ] Identification Index

Name 

Value 

Purpose  

EI_MAG0

0

File identification  

EI_MAG1

1

File identification  

EI_MAG2

2

File identification  

EI_MAG3

3

File identification  

EI_CLASS

4

File class  

EI_DATA

5

Data encoding  

EI_VERSION

6

File version  

EI_PAD

7

Start of padding bytes  

EI_NIDENT

16

Size of e_ident[]

These indexes access bytes that hold the following values:

EI_MAG0 - EI_MAG3

A file's first 4 bytes hold a magic number, identifying the file as an ELF object file.

Table 7-8 Magic Number

Name 

Value 

Position  

ELFMAG0

0x7f

e_ident[EI_MAG0]

ELFMAG1

'E'

e_ident[EI_MAG1]

ELFMAG2

'L'

e_ident[EI_MAG2]

ELFMAG3

'F'

e_ident[EI_MAG3]

EI_CLASS

The next byte, e_ident[EI_CLASS], identifies the file's class, or capacity.

Table 7-9 File Class

Name 

Value 

Meaning  

ELFCLASSNONE

0

Invalid class  

ELFCLASS32

1

32-bit objects  

ELFCLASS64

2

64-bit objects  

The file format is designed to be portable among machines of various sizes, without imposing the sizes of the largest machine on the smallest. Class ELFCLASS32 supports machines with files and virtual address spaces up to 4 gigabytes; it uses the basic types defined above.

Class ELFCLASS64 is reserved for 64-bit architectures such as SPARCV9.

EI_DATA

Byte e_ident[EI_DATA] specifies the data encoding of the processor-specific data in the object file. The following encodings are currently defined.

Table 7-10 Data Encoding

Name 

Value 

Meaning  

ELFDATANONE

0

Invalid data encoding  

ELFDATA2LSB

1

See Figure 7-2.

ELFDATA2MSB

2

See Figure 7-3.

More information on these encodings appears below. Other values are reserved and will be assigned to new encodings as necessary.

EI_VERSION

Byte e_ident[EI_VERSION] specifies the ELF header version number. Currently, this value must be EV_CURRENT, as explained in Table 7-5 for e_version.

EI_PAD

This value marks the beginning of the unused bytes in e_ident. These bytes are reserved and set to zero; programs that read object files should ignore them. The value of EI_PAD will change in the future if currently unused bytes are given meanings.

A file's data encoding specifies how to interpret the basic objects in a file. As described above, class ELFCLASS32 files use objects that occupy 1, 2, and 4 bytes. Under the defined encodings, objects are represented as shown below. Byte numbers appear in the upper left corners.

Encoding ELFDATA2LSB specifies 2's complement values, with the least significant byte occupying the lowest address.

Figure 7-2 Data Encoding ELFDATA2LSB

Graphic

Encoding ELFDATA2MSB specifies 2's complement values, with the most significant byte occupying the lowest address.

Figure 7-3 Data Encoding ELFDATA2MSB

Graphic