4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
11 //! Types used in ELF file structures.
13 typedef uint32_t Elf32_Addr;
14 typedef uint16_t Elf32_Half;
15 typedef /*off_t*/ uint32_t Elf32_Off;
16 typedef int32_t Elf32_Sword;
17 typedef uint32_t Elf32_Word;
20 // All ELF structures are byte aligned. Any alignment padding is explicit.
27 * Constants for the various fields of Elf32_Ehdr.e_ident.
58 * \brief ELF file header.
62 unsigned char e_ident[EI_NIDENT]; //!< Magic number identifying the file format.
63 Elf32_Half e_type; //!< Identifies the object file format.
64 Elf32_Half e_machine; //!< Specified the architecture for the object file.
65 Elf32_Word e_version; //!< Object file version.
66 Elf32_Addr e_entry; //!< Virtual address of the entry point, or 0.
67 Elf32_Off e_phoff; //!< Program header table offset in bytes, or 0 if no program header table.
68 Elf32_Off e_shoff; //!< Section header table offset in bytes, or 0 if no section header table.
69 Elf32_Word e_flags; //!< Processor-specific flags associated with the file.
70 Elf32_Half e_ehsize; //!< The ELF header's size in bytes.
71 Elf32_Half e_phentsize; //!< Size in bytes of one entry in the program header table.
72 Elf32_Half e_phnum; //!< Number of entries in the program header table.
73 Elf32_Half e_shentsize; //!< Size in bytes of an entry in the section header table.
74 Elf32_Half e_shnum; //!< Number of entries in the section header table.
75 Elf32_Half e_shstrndx; //!< Section header table index of the section name string table.
79 * Constants for #Elf32_Ehdr.e_type.
82 ET_NONE, //!< No file type.
83 ET_REL, //!< Relocatable file.
84 ET_EXEC, //!< Executable file.
85 ET_DYN, //!< Shared object file.
86 ET_CORE, //!< Core file.
87 ET_LOPROC, //!< Low bound of processor-specific file types.
88 ET_HIPROC //!< High bound of processor-specific file types.
92 * ARM-specific #Elf32_Ehdr.e_flags
95 EF_ARM_HASENTRY = 0x02, //!< #Elf32_Ehdr.e_entry contains a program-loader entry point.
96 EF_ARM_SYMSARESORTED = 0x04, //!< Each subsection of the symbol table is sorted by symbol value.
97 EF_ARM_DYNSYMSUSESEGIDX = 0x08, //!< Symbols in dynamic symbol tables that are defined in sections included in program segment n have #Elf32_Sym.st_shndx = n + 1.
98 EF_ARM_MAPSYMSFIRST = 0x10, //!< Mapping symbols precede other local symbols in the symbol table.
99 EF_ARM_EABIMASK = 0xff000000, //!< This masks an 8-bit version number, the version of the ARM EABI to which this ELF file conforms. The current EABI version is #ARM_EABI_VERSION.
101 ARM_EABI_VERSION = 0x02000000 //!< Current ARM EABI version.
110 * \brief ELF section header.
112 * An object file's section header table lets one locate all the file's
113 * sections. The section header table is an array of #Elf32_Shdr structures.
114 * A section header table index is a subscript into this array. The ELF
115 * header's #Elf32_Ehdr::e_shoff member gives the byte offset from the beginning of
116 * the file to the section header table; #Elf32_Ehdr::e_shnum tells how many entries
117 * the section header table contains; #Elf32_Ehdr::e_shentsize gives the size in bytes
120 * Some section header table indexes are reserved. An object file will not
121 * have sections for these special indexes:
132 Elf32_Word sh_name; //!< The section's name. Index into the section header string table section.
133 Elf32_Word sh_type; //!< Section type, describing the contents and semantics.
134 Elf32_Word sh_flags; //!< Section flags describing various attributes.
135 Elf32_Addr sh_addr; //!< The address at which the section will appear in the memory image, or 0.
136 Elf32_Off sh_offset; //!< Offset from beginning of the file to the first byte in the section.
137 Elf32_Word sh_size; //!< The section's size in bytes.
138 Elf32_Word sh_link; //!< Section header table link index. Interpretation depends on section type.
139 Elf32_Word sh_info; //!< Extra information about the section. Depends on section type.
140 Elf32_Word sh_addralign; //!< Address alignment constraint. Values are 0 and positive powers of 2.
141 Elf32_Word sh_entsize; //!< Size in bytes of section entries, or 0 if the section does not have fixed-size entries.
145 * Special section indexes.
149 SHN_LORESERVE = 0xff00,
152 SHN_ABS = 0xfff1, //!< The symbol has an absolute value that will not change because of relocation.
153 SHN_COMMON = 0xfff2, //!< The symbol labels a common block that has not yet been allocated.
154 SHN_HIRESERVE = 0xffff
158 * Section type constants.
176 * Section flag constants.
179 SHF_WRITE = 0x1, //!< Section is writable.
180 SHF_ALLOC = 0x2, //!< Allocate section.
181 SHF_EXECINSTR = 0x4 //!< Section contains executable instructions.
185 * ARM-specific section flag constants
188 SHF_ENTRYSECT = 0x10000000, //!< The section contains an entry point.
189 SHF_COMDEF = 0x80000000 //!< The section may be multiply defined in the input to a link step.
192 #define BSS_SECTION_NAME ".bss"
193 #define DATA_SECTION_NAME ".data"
194 #define TEXT_SECTION_NAME ".text"
195 #define SHSTRTAB_SECTION_NAME ".shstrtab"
196 #define STRTAB_SECTION_NAME ".strtab"
197 #define SYMTAB_SECTION_NAME ".symtab"
205 * \brief ELF program header.
207 * An executable or shared object file's program header table is an array of
208 * structures, each describing a segment or other information the system needs
209 * to prepare the program for execution. An object file segment contains one
210 * or more sections. Program headers are meaningful only for executable and
211 * shared object files. A file specifies its own program header size with the
212 * ELF header's #Elf32_Ehdr::e_phentsize and #Elf32_Ehdr::e_phnum members.
216 Elf32_Word p_type; //!< What type of segment this header describes.
217 Elf32_Off p_offset; //!< Offset in bytes from start of file to the first byte of the segment.
218 Elf32_Addr p_vaddr; //!< Virtual address at which the segment will reside in memory.
219 Elf32_Addr p_paddr; //!< Physical address, for systems where this is relevant.
220 Elf32_Word p_filesz; //!< Number of bytes of file data the segment consumes. May be zero.
221 Elf32_Word p_memsz; //!< Size in bytes of the segment in memory. May be zero.
222 Elf32_Word p_flags; //!< Flags relevant to the segment.
223 Elf32_Word p_align; //!< Alignment constraint for segment addresses. Possible values are 0 and positive powers of 2.
227 * Segment type constants.
240 * Program header flag constants.
243 PF_X = 0x1, //!< Segment is executable.
244 PF_W = 0x2, //!< Segment is writable.
245 PF_R = 0x4 //!< Segment is readable.
250 //! \name Symbol table
254 STN_UNDEF = 0 //!< Undefined symbol index.
258 * \brief ELF symbol table entry.
260 * An object file's symbol table holds information needed to locate and
261 * relocate a program's symbolic definitions and references. A symbol
262 * table index is a subscript into this array. Index 0 both designates
263 * the first entry in the table and serves as the undefined symbol index.
267 Elf32_Word st_name; //!< Index into file's string table.
268 Elf32_Addr st_value; //!< Value associated with the symbol. Depends on context.
269 Elf32_Word st_size; //!< Size associated with symbol. 0 if the symbol has no size or an unknown size.
270 unsigned char st_info; //!< Specified the symbol's type and binding attributes.
271 unsigned char st_other; //!< Currently 0 (reserved).
272 Elf32_Half st_shndx; //!< Section header table index for this symbol.
275 //! \name st_info macros
276 //! Macros for manipulating the st_info field of Elf32_Sym struct.
278 #define ELF32_ST_BIND(i) ((i) >> 4) //!< Get binding attributes.
279 #define ELF32_ST_TYPE(i) ((i) & 0x0f) //!< Get symbol type.
280 #define ELF32_ST_INFO(b, t) (((b) << 4) + ((t) & 0x0f)) //!< Construct st_info value from binding attributes and symbol type.
284 * \brief Symbol binding attributes.
286 * These constants are mask values.
289 STB_LOCAL = 0, //!< Local symbol not visible outside the object file.
290 STB_GLOBAL = 1, //!< Symbol is visible to all object files being linked together.
291 STB_WEAK = 2, //!< Like global symbols, but with lower precedence.
293 // Processor-specific semantics.
299 * \brief Symbol types.
302 STT_NOTYPE = 0, //!< The symbol's type is not specified.
303 STT_OBJECT = 1, //!< The symbol is associated with a data object, such as a variable or array.
304 STT_FUNC = 2, //!< The symbol is associated with a function or other executable code.
305 STT_SECTION = 3, //!< The synmbol is associated with a section. Primarily used for relocation.
306 STT_FILE = 4, //!< A file symbol has STB_LOCAL binding, its section index is SHN_ABS, and it precedes the other STB_LOCAL symbols for the file, if it is present.
308 STT_LOPROC = 13, //!< Low bound of processor-specific symbol types.
309 STT_HIPROC = 15 //!< High bound of processor-specific symbol types.
313 * GHS-specific constants
316 STO_THUMB = 1 //!< This flag is set on #Elf32_Sym.st_other if the symbol is Thumb mode code.
319 #define ARM_SEQUENCE_MAPSYM "$a"
320 #define DATA_SEQUENCE_MAPSYM "$d"
321 #define THUMB_SEQUENCE_MAPSYM "$t"
323 #define THUMB_BL_TAGSYM "$b"
324 #define FN_PTR_CONST_TAGSYM "$f"
325 #define INDIRECT_FN_CALL_TAGSYM "$p"
326 #define MAPPING_SYMBOL_COUNT_TAGSYM "$m"