Arm Elfa08
Arm Elfa08
ARM ELF
Development Systems Business Unit
Engineering Software Group
Abstract
This specification defines the ARM-specific features of Executable and Linking Format (ELF).
Keywords
ARM ELF, ELF, ELF relocation types, Executable and Linking Format (ELF)
Distribution list
Name Function Name Function
Contents
1.2 References 4
2 SCOPE 5
3.1 Introduction 6
3.1.1 File Format 6
3.1.2 Data Representation 7
3.1.3 Character Representations 7
3.3 Sections 13
3.3.1 Special Sections 17
3.6 Relocation 23
4.3 Symbols 30
5.1 Background 33
5.1.1 Re-locatable executable ELF 33
5.1.2 Entry points 33
5.1.3 Static base 33
5.4 Symbols 35
5.4.1 Weak symbols 35
5.4.2 Reserved symbol names 35
5.4.3 Case sensitivity 35
5.4.4 Sub-class and super-class symbols 35
5.4.5 Function address constants and pointers to code 35
5.4.6 Mapping symbols 36
5.4.7 Symbol table order 36
6 FUTURE DIRECTIONS 42
1.2 References
This document refers to the following document and reproduces book 1 of it as section 3, below.
Ref Doc No Author(s) Title
TIS-ELF ftp://ftp.x86.org/manuals/tools/elf.pdf Tool Interface Standards Executable and Linking Format
(TIS) Committee (ELF) Specification (version 1.2)
2 SCOPE
This specification defines ARM Executable and Linking Format (ARM ELF). It follows the structure of the Tool
Interface Standards (TIS) Committee’s version 1.2 specification of ELF (TIS-ELF). TIS-ELF is divided into three
major sections that TIS-ELF calls books:
o Book 1 defines generic, 32-bit ELF. All users of 32-bit ELF use the definitions given in book 1. Section 3 of
this specification reproduces the content of book 1 of TIS-ELF (Copyright Tool Interface Standards Committee
1995).
o Book 2 defines processor specifics, the definitions used by all users of ELF for a given processor (in the case
of TIS-ELF, for the Intel x86 architecture). Section 4 of this specification corresponds to book 2 of TIS-ELF
and includes the ARM- and Thumb-specific definitions needed by all users of ARM ELF.
o Book 3 defines operating system specifics. Section 5 of this specification corresponds to book 3 of TIS-ELF
and includes ARM- and Thumb-specific definitions relating to the ARM Embedded Applications Binary
Interface (ARM EABI). The ARM EABI underlies many ARM- and Thumb-based operating environments that
follow the single address-space model.
Some operating systems—especially those founded on multiple virtual address spaces—define their own
conventions for using ARM ELF—especially in relation to shared objects and dynamic linking. These OS-specific
definitions build on sections 4 and 5 of this specification, but replace section 5 of this specification with their own
version of book 3 of TIS-ELF. ARM LINUX does this, for example.
3.1 Introduction
Section 3 of this specification describes the object file format called ELF (Executable and Linking Format). There
are three main types of object files:
o A re-locatable file holds code and data suitable for linking with other object files to create an executable or a
shared object file.
o An executable file holds a program suitable for execution.
o A shared object file holds code and data suitable for linking in two contexts. First, the link editor may process it
with other re-locatable and shared object files to create another object file. Second, the dynamic linker
combines it with an executable file and other shared objects to create a process image.
Created by an assembler or compiler and link editor, object files are binary representations of programs intended
to execute directly on a processor. Programs that require other abstract machines are excluded.
After the introductory material, this section focuses on the file format and how it pertains to building programs.
Subsections 3.7 onwards describe those parts of the object file containing the information necessary to execute a
program.
An ELF header resides at the beginning and holds a road map describing the file's organization. Sections hold the
bulk of object file information for the linking view: instructions, data, symbol table, relocation information, and so
on. Descriptions of special sections appear later in this section. Subsections 3.7 onwards describe segments and
the program execution view of the file.
A program header table, if present, tells the system how to create a process image. Files used to build a process
image (execute a program) must have a program header table; re-locatable files do not need one. A section
header table contains information describing the file's sections. Every section has an entry in the table; each entry
gives information such as the section name, the section size, and so on. Files used during linking must have a
section header table; other object files may or may not have one.
Note Although the figure shows the program header table immediately after the ELF header, and the section
header table following the sections, actual files may differ. Moreover, sections and segments have no
specified order. Only the ELF header has a fixed position in the file.
All data structures that the object file format defines follow the natural size and alignment guidelines for the
relevant class. If necessary, data structures contain explicit padding to ensure 4-byte alignment for 4-byte objects,
to force structure sizes to a multiple of 4, and so on. Data also have suitable alignment from the beginning of the
file. Thus, for example, a structure containing an Elf32_Addr member will be aligned on a 4-byte boundary within
the file.
For portability reasons, ELF uses no bit fields.
o Character values between 0 and 127 should correspond to the 7-bit ASCII code. That is, character sets with
encodings above 127 should include the 7-bit ASCII code as a subset.
o Multi-byte character encodings with values above 127 should contain only bytes with values outside the range
of 0 to 127. That is, a character set that uses more than one byte per character should not embed a byte
resembling a 7-bit ASCII character within a multi-byte, non-ASCII character.
o Multi-byte characters should be self-identifying. That allows, for example, any multi-byte character to be
inserted between any pair of multi-byte characters, without changing the characters' interpretations.
These cautions are particularly relevant for multilingual applications.
Note There are naming conventions for ELF constants that have processor ranges specified. Names such as
DT_, PT_, for processor specific extensions, incorporate the name of the processor: DT_M32_SPECIAL,
for example. However, pre-existing processor extensions not using this convention will be supported.
Pre-existing Extensions
DT_JMP_REL
#define EI_NIDENT 16
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
} Elf32_Ehdr;
e_ident—The initial bytes mark the file as an object file and provide machine-independent data with which to
decode and interpret the file's contents. Complete descriptions appear below, in ELF Identification.
Although the core file contents are unspecified, type ET_CORE is reserved to mark the file type. Values from
ET_LOPROC through ET_HIPROC (inclusive) are reserved for processor-specific semantics. Other values are
reserved and will be assigned to new object file types as necessary.
e_machine—This member's value specifies the required architecture for an individual file.
Name Value Meaning
ET_NONE 0 No machine
EM_M32 1 AT&T WE 32100
EM_SPARC 2 SPARC
EM_386 3 Intel Architecture
EM_68K 4 Motorola 68000
EM_88K 5 Motorola 88000
EM_860 7 Intel 80860
EM_MIPS 8 MIPS RS3000 Big-Endian
EM_MIPS_RS4_BE 10 MIPS RS4000 Big-Endian
RESERVED 11-16 Reserved for future use
EM_ARM 40 ARM/Thumb Architecture
Other values are reserved and will be assigned to new machines as necessary. Processor-specific ELF names
use the machine name to distinguish them. For example, the flags mentioned below use the prefix EF_; a flag
named WIDGET for the EM_XYZ machine would be called EF_XYZ_WIDGET.
e_version—This member identifies the object file version.
Name Value Meaning
EV_NONE 0 Invalid version
EV_CURRENT 1 Current version
The value 1 signifies the original file format; extensions will create new versions with higher numbers. The value of
EV_CURRENT, though given as 1 above, will change as necessary to reflect the current version number.
e_entry—This member gives the virtual address to which the system first transfers control, thus starting the
process. If the file has no associated entry point, this member holds zero.
e_phoff—This member holds the program header table's file offset in bytes. If the file has no program header
table, this member holds zero.
e_shoff—This member holds the section header table's file offset in bytes. If the file has no section header table,
this member holds zero.
e_flags—This member holds processor-specific flags associated with the file. Flag names take the form
EF_machine_flag.
e_ehsize—This member holds the ELF header's size in bytes.
e_phentsize—This member holds the size in bytes of one entry in the file's program header table; all entries are
the same size.
e_phnum—This member holds the number of entries in the program header table. Thus the product of
e_phentsize and e_phnum gives the table's size in bytes. If a file has no program header table, e_phnum
holds the value zero.
e_shentsize—This member holds a section header's size in bytes. A section header is one entry in the section
header table; all entries are the same size.
e_shnum—This member holds the number of entries in the section header table. Thus the product of
e_shentsize and e_shnum gives the section header table's size in bytes. If a file has no section header
table, e_shnum holds the value zero.
e_shstrndx—This member holds the section header table index of the entry associated with the section name
string table. If the file has no section name string table, this member holds the value SHN_UNDEF. See Sections
and String Table below for more information.
EI_MAG0 to EI_MAG3—A file's first 4 bytes hold a magic number, identifying the file as an ELF object file.
Name Value Meaning
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_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.
Name Value Meaning
ELFDATANONE 0 Invalid data encoding
ELFDATA2LSB 1 See Data encodings, below
ELFDATA2MSB 2 See Data encodings, below
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 above 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 at the lowest address.
0
0x01 0x01
0 1
0 1 2 3
Encoding ELFDATA2MSB specifies 2's complement values, with the most significant byte at the lowest address.
0
0x01 0x01
0 1
0 1 2 3
3.3 Sections
An object file's section header table lets one locate all the file's sections. The section header table is an array of
Elf32_Shdr structures as described below. A section header table index is a subscript into this array. The ELF
header's e_shoff member gives the byte offset from the beginning of the file to the section header table;
e_shnum tells how many entries the section header table contains; e_shentsize gives the size in bytes of
each entry.
Some section header table indexes are reserved; an object file will not have sections for these special indexes.
Name Value
SHN_UNDEF 0
SHN_LORESERVE 0xff00
SHN_LOPROC 0xff00
SHN_HIPROC 0xff1f
SHN_ABS 0xfff1
SHN_COMMON 0xfff2
SHN_HIRESERVE 0xffff
SHN_UNDEF—This value marks an undefined, missing, irrelevant, or otherwise meaningless section reference.
For example, a symbol “defined” relative to section number SHN_UNDEF is an undefined symbol.
Note Although index 0 is reserved as the undefined value, the section header table contains an entry for index
0. That is, if the e_shnum member of the ELF header says a file has 6 entries in the section header
table, they have the indexes 0 through 5. The contents of the initial entry are specified later in this
section.
SHN_LORESERVE—This value specifies the lower bound of the range of reserved indexes.
SHN_LOPROC through SHN_HIPROC—Values in this inclusive range are reserved for processor-specific
semantics.
SHN_ABS—This value specifies absolute values for the corresponding reference. For example, symbols defined
relative to section number SHN_ABS have absolute values and are not affected by relocation.
SHN_COMMON—Symbols defined relative to this section are common symbols, such as FORTRAN COMMON or
unallocated C external variables.
SHN_HIRESERVE—This value specifies the upper bound of the range of reserved indexes. The system reserves
indexes between SHN_LORESERVE and SHN_HIRESERVE, inclusive; the values do not reference the section
header table. That is, the section header table does not contain entries for the reserved indexes.
Sections contain all information in an object file, except the ELF header, the program header table, and the
section header table. Moreover, object files' sections satisfy several conditions.
o Every section in an object file has exactly one section header describing it. Section headers may exist that do
not have a section.
o Each section occupies one contiguous (possibly empty) sequence of bytes within a file.
o Sections in a file may not overlap. No byte in a file resides in more than one section.
o An object file may have inactive space. The various headers and the sections might not cover every byte in an
object file. The contents of the inactive data are unspecified.
sh_link—This member holds a section header table index link, whose interpretation depends on the section type.
A table below describes the values.
sh_info—This member holds extra information, whose interpretation depends on the section type. A table below
describes the values.
sh_addralign—Some sections have address alignment constraints. For example, if a section holds a double-
word, the system must ensure double-word alignment for the entire section. That is, the value of sh_addr must
be congruent to 0, modulo the value of sh_addralign. Currently, only 0 and positive integral powers of two are
allowed. Values 0 and 1 mean the section has no alignment constraints.
sh_entsize—Some sections hold a table of fixed-size entries, such as a symbol table. For such a section, this
member gives the size in bytes of each entry. The member contains 0 if the section does not hold a table of fixed-
size entries. A section header's sh_type member specifies the section's semantics.
Name Value
SHT_NULL 0
SHT_PROGBITS 1
SHT_SYMTAB 2
SHT_STRTAB 3
SHT_RELA 4
SHT_HASH 5
SHT_DYNAMIC 6
SHT_NOTE 7
SHT_NOBITS 8
SHT_REL 9
SHT_SHLIB 10
SHT_DYNSYM 11
SHT_LOPROC 0x70000000
SHT_HIPROC 0x7fffffff
SHT_LOUSER 0x80000000
SHT_HIUSER 0xffffffff
SHT_NULL—This value marks the section header as inactive; it does not have an associated section. Other
members of the section header have undefined values.
SHT_PROGBITS—The section holds information defined by the program, whose format and meaning are
determined solely by the program.
SHT_SYMTAB and SHT_DYNSYM—These sections hold a symbol table.
SHT_STRTAB—The section holds a string table.
SHT_RELA—The section holds relocation entries with explicit addends, such as type Elf32_Rela for the 32-bit
class of object files. An object file may have multiple relocation sections. See Relocation below for details.
SHT_HASH—The section holds a symbol hash table.
SHT_DYNAMIC—The section holds information for dynamic linking.
SHT_NOTE—This section holds information that marks the file in some way.
SHT_NOBITS—A section of this type occupies no space in the file but otherwise resembles SHT_PROGBITS.
Although this section contains no bytes, the sh_offset member contains the conceptual file offset.
SHT_REL—The section holds relocation entries without explicit addends, such as type Elf32_Rel for the 32-bit
class of object files. An object file may have multiple relocation sections. See Relocation below for details.
SHT_SHLIB—This section type is reserved but has unspecified semantics.
SHT_LOPROC through SHT_HIPROC—Values in this inclusive range are reserved for processor-specific
semantics.
SHT_LOUSER—This value specifies the lower bound of the range of indexes reserved for application programs.
SHT_HIUSER—This value specifies the upper bound of the range of indexes reserved for application programs.
Section types between SHT_LOUSER and SHT_HIUSER may be used by the application, without conflicting with
current or future system-defined section types.
Other section type values are reserved. As mentioned before, the section header for index 0 (SHN_UNDEF)
exists, even though the index marks undefined section references. This entry holds the following.
A section header's sh_flags member holds 1-bit flags that describe the section's attributes. Defined values
appear below; other values are reserved.
Name Value
SHF_WRITE 0x1
SHF_ALLOC 0x2
SHF_EXECINSTR 0x4
SHF_MASKPROC 0xf0000000
If a flag bit is set in sh_flags, the attribute is on for the section. Otherwise, the attribute is off or does not apply.
Undefined attributes are set to zero.
SHF_WRITE—The section contains data that should be writable during process execution.
SHF_ALLOC—The section occupies memory during process execution. Some control sections do not reside in
the memory image of an object file; this attribute is off for those sections.
SHF_EXECINSTR—The section contains executable machine instructions.
SHF_MASKPROC—All bits included in this mask are reserved for processor-specific semantics.
Two members in the section header, sh_link and sh_info, hold special information, depending on section
type.
o Dynamic. A set of object files, libraries, system shared resources and other shared libraries are linked
together to create the executable. When this executable is loaded, other shared resources and dynamic
libraries must be made available in the system for the program to run successfully.
The general method used to resolve references at execution time for a dynamically linked executable file is
described in the linkage model used by the operating system, and the actual implementation of this linkage
model will contain processor-specific components.
There are also sections that support debugging, such as .debug and .line, and program control, including
.bss, .data, .data1, .rodata, and .rodata1.
.bss—This section holds uninitialized data that contribute to the program's memory image. By definition, the
system initializes the data with zeros when the program begins to run. The section occupies no file space, as
indicated by the section type, SHT_NOBITS.
.comment—This section holds version control information.
.data and .data1—These sections hold initialized data that contribute to the program's memory image.
.debug—This section holds information for symbolic debugging. The contents are unspecified. All section names
with the prefix .debug are reserved for future use.
.dynamic—This section holds dynamic linking information and has attributes such as SHF_ALLOC and
SHF_WRITE. Whether the SHF_WRITE bit is set is determined by the operating system and processor.
.hash—This section holds a symbol hash table.
.line—This section holds line number information for symbolic debugging, which describes the correspondence
between the source program and the machine code. The contents are unspecified.
.note—This section holds information in the format that is described in the Note Section in subsection 3.7.2.
.rodata and .rodata1—These sections hold read-only data that typically contribute to a non-writable segment in
the process image. See Program Header in subsection 3.7.1 for more information.
.shstrtab—This section holds section names.
.strtab—This section holds strings, most commonly only the strings that represent the names associated with
symbol table entries. If a file has a loadable segment that includes the symbol string table, the section's attributes
will include the SHF_ALLOC bit; otherwise, that bit will be off.
.symtab—This section holds a symbol table, as Symbol Table in subsection 3.5 describes. If a file has a loadable
segment that includes the symbol table, the section's attributes will include the SHF_ALLOC bit; otherwise, that bit
will be off.
.text—This section holds the text, or executable instructions, of a program.
Section names with a dot (.) prefix are reserved for the system, although applications may use these sections if
their existing meanings are satisfactory. Applications may use names without the prefix to avoid conflicts with
system sections. The object file format lets one define sections not in the list above. An object file may have more
than one section with the same name.
Index +0 +1 +2 +3 +4 +5 +6 +7 +8 +9
0 \0 n a m e . \0 V a r
10 I a b l e \0 a b l e
20 \0 \0 x x \0
Index String
0 none
1 name.
7 Variable
11 able
16 able
24 null string
As the example shows, a string table index may refer to any byte in the section. A string may appear more than
once; references to sub-strings may exist; and a single string may be referenced multiple times. Unreferenced
strings also are allowed.
Name Value
STN_UNDEF 0
st_name—This member holds an index into the object file's symbol string table, which holds the character
representations of the symbol names.
st_value—This member gives the value of the associated symbol. Depending on the context this may be an
absolute value, an address, and so on; details appear below.
st_size—Many symbols have associated sizes. For example, a data object's size is the number of bytes
contained in the object. This member holds 0 if the symbol has no size or an unknown size.
st_info—This member specifies the symbol's type and binding attributes. A list of the values and meanings
appears below. The following code shows how to manipulate the values.
#define ELF32_ST_BIND(i) ((i)>>4)
#define ELF32_ST_TYPE(i) ((i)&0xf)
#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
STB_LOCAL—Local symbols are not visible outside the object file containing their definition. Local symbols of the
same name may exist in multiple files without interfering with each other.
STB_GLOBAL—Global symbols are visible to all object files being combined. One file's definition of a global
symbol will satisfy another file's undefined reference to the same global symbol.
STB_WEAK—Weak symbols resemble global symbols, but their definitions have lower precedence.
STB_LOPROC through STB_HIPROC—Values in this inclusive range are reserved for processor-specific
semantics.
In each symbol table, all symbols with STB_LOCAL binding precede the weak and global symbols. A symbol's
type provides a general classification for the associated entity.
Name Value
STT_NOTYPE 0
STT_OBJECT 1
STT_FUNC 2
STT_SECTION 3
STT_FILE 4
STT_LOPROC 13
STT_HIPROC 15
STT_LOPROC through STT_HIPROC—Values in this inclusive range are reserved for processor-specific
semantics. If a symbol's value refers to a specific location within a section, its section index member, st_shndx,
holds an index into the section header table. As the section moves during relocation, the symbol's value changes
as well, and references to the symbol continue to point to the same location in the program. Some special section
index values give other semantics.
STT_FILE—A file symbol has STB_LOCAL binding, its section index is SHN_A BS, and it precedes the other
STB_LOCAL symbols for the file, if it is present.
The symbols in ELF object files convey specific information to the linker and loader. See the operating system
sections for a description of the actual linking model used in the system.
SHN_ABS—The symbol has an absolute value that will not change because of relocation.
SHN_COMMON—The symbol labels a common block that has not yet been allocated. The symbol's value gives
alignment constraints, similar to a section's sh_addralign member. That is, the link editor will allocate the storage
for the symbol at an address that is a multiple of st_value. The symbol's size tells how many bytes are required.
SHN_UNDEF—This section table index means the symbol is undefined. When the link editor combines this object
file with another that defines the indicated symbol, this file's references to the symbol will be linked to the actual
definition.
As mentioned above, the symbol table entry for index 0 (STN_UNDEF) is reserved; it holds the following.
3.6 Relocation
Relocation is the process of connecting symbolic references with symbolic definitions. For example, when a
program calls a function, the associated call instruction must transfer control to the proper destination address at
execution. In other words, relocatable files must have information that describes how to modify their section
contents, thus allowing executable and shared object files to hold the right information for a process's program
image. Relocation entries are these data.
Relocation Entries
typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;
typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
Elf32_Sword r_addend;
} Elf32_Rela;
r_offset—This member gives the location at which to apply the relocation action. For a relocatable file, the value
is the byte offset from the beginning of the section to the storage unit affected by the relocation. For an executable
file or a shared object, the value is the virtual address of the storage unit affected by the relocation.
r_info—This member gives both the symbol table index with respect to which the relocation must be made, and
the type of relocation to apply. For example, a call instruction's relocation entry would hold the symbol table index
of the function being called. If the index is STN_UNDEF, the undefined symbol index, the relocation uses 0 as the
symbol value. Relocation types are processor-specific; descriptions of their behavior appear in section 4. When
the text in section 4 refers to a relocation entry's relocation type or symbol table index, it means the result of
applying ELF32_R_TYPE or ELF32_R_SYM, respectively, to the entry's r_info member.
#define ELF32_R_SYM(i) ((i)>>8)
#define ELF32_R_TYPE(i) ((unsigned char)(i))
#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
r_addend—This member specifies a constant addend used to compute the value to be stored into the re-
locatable field.
As shown above, only Elf32_Rela entries contain an explicit addend. Entries of type Elf32_Rel store an implicit
addend in the location to be modified. Depending on the processor architecture, one form or the other might be
necessary or more convenient. Consequently, an implementation for a particular machine may use one form
exclusively or either form depending on context.
A relocation section references two other sections: a symbol table and a section to modify. The section header's
sh_info and sh_link members, described in Sections above, specify these relationships. Relocation entries for
different object files have slightly different interpretations for the r_offset member.
o In re-locatable files, r_offset holds a section offset. That is, the relocation section itself describes how to
modify another section in the file; relocation offsets designate a storage unit within the second section.
o In executable and shared object files, r_offset holds a virtual address. To make these files' relocation entries
more useful for the dynamic linker, the section offset (file interpretation) gives way to a virtual address
(memory interpretation).
Although the interpretation of r_offset changes for different object files to allow efficient access by the relevant
programs, the relocation types' meanings stay the same.
p_type—This member tells what kind of segment this array element describes or how to interpret the array
element's information. Type values and their meanings are given in Figure 3-20, below.
p_offset—This member gives the offset from the beginning of the file at which the first byte of the segment
resides.
p_vaddr—This member gives the virtual address at which the first byte of the segment resides in memory.
p_paddr—On systems for which physical addressing is relevant, this member is reserved for the segment's
physical address. This member requires operating system specific information.
p_filesz—This member gives the number of bytes in the file image of the segment; it may be zero.
p_memsz—This member gives the number of bytes in the memory image of the segment; it may be zero.
p_flags—This member gives flags relevant to the segment. Defined flag values are given in Figure 3-21, below.
p_align—Loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page
size. This member gives the value to which the segments are aligned in memory and in the file. Values 0 and 1
mean that no alignment is required. Otherwise, p_align should be a positive, integral power of 2, and p_addr
should equal p_offset, modulo p_align.
Some entries describe process segments; others give supplementary information and do not contribute to the
process image.
Name Value
PT_NULL 0
PT_LOAD 1
PT_DYNAMIC 2
PT_INTERP 3
PT_NOTE 4
PT_SHLIB 5
PT_PHDR 6
PT_LOPROC 0x70000000
PT_HIPROC 0x7fffffff
PT_NULL—The array element is unused; other members' values are undefined. This type lets the program
header table have ignored entries.
PT_LOAD—The array element specifies a loadable segment, described by p_filesz and p_memsz. The bytes
from the file are mapped to the beginning of the memory segment. If the segment's memory size (p_memsz) is
larger than the file size (p_filesz), the extra bytes are defined to hold the value 0 and to follow the segment's
initialized area. The file size may not be larger than the memory size. Loadable segment entries in the program
header table appear in ascending order, sorted on the p_vaddr member.
PT_DYNAMIC—The array element specifies dynamic linking information. See subsection 5.8.
PT_INTERP—The array element specifies the location and size of a null-terminated path name to invoke as an
interpreter.
PT_NOTE—The array element specifies the location and size of auxiliary information.
PT_SHLIB—This segment type is reserved but has unspecified semantics.
PT_PHDR—The array element, if present, specifies the location and size of the program header table itself, both
in the file and in the memory image of the program. This segment type may not occur more than once in a file.
Moreover, it may occur only if the program header table is part of the memory image of the program. If it is
present, it must precede any loadable segment entry.
PT_LOPROC through PT_HIPROC—Values in this inclusive range are reserved for processor-specific semantics.
Note Unless specifically required elsewhere, all program header segment types are optional. That is, a file's
program header table may contain only those elements relevant to its contents.
namesz and name—The first namesz bytes in name contain a null-terminated character representation of the
entry's owner or originator. There is no formal mechanism for avoiding name conflicts. By convention, vendors use
their own name, such as "XYZ Computer Company,'' as the identifier. If no name is present, namesz contains 0.
Padding is present, if necessary, to ensure 4-byte alignment for the descriptor. Such padding is not included in
namesz.
descsz and desc—The first descsz bytes in desc hold the note descriptor. ELF places no constraints on a
descriptor's contents. If no descriptor is present, descsz contains 0. Padding is present, if necessary, to ensure 4-
byte alignment for the next note entry. Such padding is not included in descsz.
type—This word gives the interpretation of the descriptor. Each originator controls its own types; multiple
interpretations of a single type value may exist. Thus, a program must recognize both the name and the type to
understand a descriptor. Types currently must be non-negative. ELF does not define what descriptors mean.
To illustrate, the note segment shown in Figure 3-24, below, holds two entries.
Note The system reserves note information with no name (namesz==0) and with a zero-length name
(name[0]=='\0') but currently defines no types. All other names must have at least one non-null
character.
Note Note information is optional. The presence of note information does not affect a program's TIS
conformance, provided the information does not affect the program's execution behavior. Otherwise, the
program does not conform to the TIS ELF specification and has undefined behavior.
+0 +1 +2 +3
namesz 7
descsz 0
type 1 No descriptor
name X Y Z
C o \0 pad
namesz 7
descsz 8
type 3
name X Y Z
C o \0 pad
desc word 0
word 1
_DYNAMIC
DT_JMP_REL
Section names reserved for a processor architecture are formed by placing an abbreviation of the architecture
name ahead of the section name. The name should be taken from the architecture names used for e_machine.
For instance .FOO.psect is the psect section defined by the FOO architecture. Existing extensions are called by
their historical names.
Note The byte order of a field in an ELF file is its byte order in the target execution environment. This may
differ from the byte order in the host (static linker) execution environment.
Note Bracketed SHF_ALLOC flags are set only if the section is contained in a loadable program segment
(one of type PT_LOAD or PT_DYNAMIC).
Note There may be more than one section with the same name in a file.
4.3 Symbols
Symbol value
These statements repeat the definitions given in section 3.5.1, Symbol Values). In a re-locatable file:
o For a COMMON symbol defined in the SHN_COMMON section, st_value gives its alignment constraint (the
allocated address of the symbol must be zero modulo st_value).
o For a symbol definition, st_value gives its offset within the section identified by st_shndx.
These statements make more specific the definitions given in section 3.5.1, Symbol Values. In executable and
shared object files, for a symbol definition, st_value is a virtual address:
o For symbols defined in sections included in executable program segments, st_value is a target-system virtual
address.
o Otherwise, st_value is a virtual address in an address space specific to the operating environment.
Symbol size
For a symbol definition of type STT_FUNC, st_size gives the length of the function in bytes, or 0 if this is unknown.
For a symbol definition of type STT_OBJECT, st_size gives the length in bytes of the associated data object, or 0
if this is unknown.
S denotes the value of the symbol whose index is given in the r_info field of the relocation directive.
B denotes the base address of the consolidated section in which the symbol is defined. For relocations of
type R_ARM_SBREL32, this is the lowest static data address (the static base). For relocations of type
R_ARM_AMP_VCALL9, this is the base address of the AMP co-processor code section.
Multiple relocation
A field may be relocated many times, but this should not be exploited to generate a compound relocation because
an intermediate step may overflow, even when the compound relocation would not (consider, for example, adding
0x1000004 to, then subtracting 0x1000000 from, a 16-bit field).
Fields of size 8, 16, and 32 bits are aligned on 1-, 2-, and 4-byte boundaries, respectively (types 2, 3, 5, 8, 9).
ARM instructions are 4-byte aligned (relocation types 1, 4, 6, 12, 13, 15). Thumb instructions are 2-byte aligned
(relocation types 7, 10, 11, 14, 16).
An ARM ELF consumer never needs to interpret an instruction word to determine how to relocate it. The sub-field
to relocate and the unit of relocation (byte, half word, word, or double word) are evident from the relocation type.
Labeling the least significant bit of a 32-bit ARM instruction word, or 16-bit Thumb instruction word, bit 0,
instruction fields to be relocated are given in the following two figures.
R_ARM_THM_ABS5 Bits 6-10 encode a 5-bit unsigned offset in units of 4-byte words (Thumb LDRB/LDRH
cannot be relocated).
R_ARM_THM_PC22 Bits 0-10 encode the 11 most significant bits of the branch offset, bits 0-10 of the next
instruction word the 11 least significant bits. The unit is 2-byte Thumb instructions.
R_ARM_THM_PC8 Bits 0-7 encode an 8-bit unsigned offset in units of 4-byte words. An initial offset of
255 must be interpreted as an offset of –1 (so the initial offset range is [-1, 254]).
R_ARM_THM_SWI8 Bits 0-7 encode the Thumb SWI number.
R_ARM_THM_XPC22 Bits 0-10 encode the 11 most significant bits of the branch offset, bits 1-10 of the next
instruction word the 10 least significant bits. The unit is 2-byte Thumb instructions. Bit
0 must be 0. The hardware forces bits 1 of the computed address to 0, and bit 0 (the
Thumb bit) to 0.
Note When a Thumb LDR [pc, …] instruction is subject to a REL-sort relocation of type R_ARM_THM_PC8,
there must be a way to encode the offset to the place containing the instruction in the initial value of the
instruction. Using the value 255 to encode –1 does this.
5.1 Background
Note The program loader entry point may be 0. EF_ARM_HASENTRY distinguishes this case from that in
which there is no program loader entry point.
Note EF_ARM_EABIMASK masks an 8-bit version number, the version of the ARM EABI to which this ELF
file conforms. This EABI version is version 1. A value of 0 denotes unknown conformance.
5.4 Symbols
Figure 5-5, Program header fields for statically linked ARM executables
Field Value
p_type PT_LOAD
p_vaddr The virtual address at which the segment should be loaded.
p_paddr Unused in the ARM EABI. Set to zero by ARM tools.
p_flags Any combination of PF_X, PF_R, PF_W, PF_ARM_SB
p_align >= 4—all ARM and Thumb segments are at least word-aligned.
Figure 5-6, Interpretation of program header p_flags values by ARM ELF consumers
PF_R 0x2 The program will read data from the segment.
PF_W 0x4 The program will write to the segment.
PF_ARM_SB 0x10000000 The segment contains the data pointed to by the static base.
Note Flag settings encode an assertion about the executable segment by its producer.
Note A consumer should grant the least access consistent with the segment’s requirements.
Note In general, an ARM executable segment must also be readable. A limited PC-relative addressing range
in both ARM and Thumb instruction sets virtually mandates that instructions and literal data are
interleaved in a segment.
Note The last entry in the dynamic array must have tag DT_NULL.
Note The relative order of DT_NEEDED entries may be important to a dynamic linker. Otherwise the order of
entries in the dynamic array has no significance.
Following the dynamic array, the dynamic segment may include a hash table section, symbol table section, string
table section, and relocation table section. The order of these sections is unimportant. The offset of each in the
dynamic segment is given by the corresponding entry in the dynamic array.
Optionally, section headers of the following types may describe the sub-sections of the dynamic segment:
o SHT_DYNAMIC—the dynamic array itself.
o SHT_HASH—the symbol hash table.
o SHT_DYNSYM—the symbol table.
o SHT_STRTAB—the string table.
o SHT_REL or SHT_RELA—the relocation section.
Dynamic linkers do not use this section view.
Tag Purpose
DT_REL The offset of an SHT_REL relocation section in the dynamic segment.
DT_RELSZ The byte size of the relocation section.
DT_NULL Marks the end of the dynamic section.
The relocation section contains a sequence of R-type relocation directives in which an ELF32_R_SYM field with
value n is interpreted as a reference to the displacement of program segment n from its statically linked address.
The R_ARM_RBASE type informs a consumer that following relocation directives relocate places in the segment
indexed by its ELF32_R_SYM field. Its r_offset field is zero.
The R_ARM_RABS32 type directs a consumer to relocate the specified place by the displacement of the segment
indexed by the ELF32_R_SYM field of the relocation directive.
PC-relative re-location is defined using the difference of two displacements to support the displacement of a
program by more than the maximum BL offset. For example, rigidly displacing a program from 0x0 (ROM) to
0x80000000 (RAM).
6 FUTURE DIRECTIONS
4 DT_HASH The offset of the hash table section in the dynamic segment. optional
5 DT_STRTAB The offset of the string table section in the dynamic segment. mandatory
6 DT_SYMTAB The offset of the symbol table section in the dynamic mandatory
segment.
7 DT_RELA The offset of an SHT_RELA-type relocation section. multiple
Both bucket and chain hold symbol table indexes. Indexes start at 0. Bucket can have any convenient size.
Bucket and chain implement a chained overflow hash table access structure for the symbol table. If h is the result
of applying the ELF hash function (see below) to a symbol s name, bucket[h % nBuckets] is the symbol table
index of the start of the chain of symbols that hash to this bucket.
For each symbol index s, chain[s] gives the index of the next symbol that hashes to the same bucket. There is one
chain entry for each symbol in the symbol table (nChains = number of symbols). Zero indexes the dummy symbol
and is used as the null chain pointer.