apps/elftosb/common/ELF.h
/*
* File: ELF.h
*
* Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
* See included license file for license details.
*/
#if !defined(_ELF_h_)
#define _ELF_h_
typedef uint32_t Elf32_Addr;
typedef uint16_t Elf32_Half;
typedef /*off_t*/ uint32_t Elf32_Off;
typedef int32_t Elf32_Sword;
typedef uint32_t Elf32_Word;
// All ELF structures are byte aligned. Any alignment padding is explicit.
#pragma pack(1)
enum
{
EI_MAG0 = 0,
EI_MAG1,
EI_MAG2,
EI_MAG3,
EI_CLASS,
EI_DATA,
EI_VERSION,
EI_PAD,
EI_NIDENT = 16,
// Magic number.
ELFMAG0 = 0x7f,
ELFMAG1 = 'E',
ELFMAG2 = 'L',
ELFMAG3 = 'F',
// EI_CLASS
ELFCLASSNONE = 0,
ELFCLASS32 = 1,
ELFCLASS64 = 2,
// EI_DATA
ELFDATANONE = 0,
ELFDATA2LSB = 1,
ELFDATA2MSB = 2
};
struct Elf32_Ehdr
{
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;
};
enum
{
ET_NONE,
ET_REL,
ET_EXEC,
ET_DYN,
ET_CORE,
ET_LOPROC,
ET_HIPROC
};
enum
{
EF_ARM_HASENTRY = 0x02,
EF_ARM_SYMSARESORTED = 0x04,
EF_ARM_DYNSYMSUSESEGIDX = 0x08,
EF_ARM_MAPSYMSFIRST = 0x10,
EF_ARM_EABIMASK = 0xff000000,
ARM_EABI_VERSION = 0x02000000
};
struct Elf32_Shdr
{
Elf32_Word sh_name;
Elf32_Word sh_type;
Elf32_Word sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
Elf32_Word sh_size;
Elf32_Word sh_link;
Elf32_Word sh_info;
Elf32_Word sh_addralign;
Elf32_Word sh_entsize;
};
enum
{
SHN_UNDEF = 0,
SHN_LORESERVE = 0xff00,
SHN_LOPROC = 0xff00,
SHN_HIPROC = 0xff1f,
SHN_ABS = 0xfff1,
SHN_COMMON = 0xfff2,
SHN_HIRESERVE = 0xffff
};
enum
{
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
};
enum
{
SHF_WRITE = 0x1,
SHF_ALLOC = 0x2,
SHF_EXECINSTR = 0x4
};
enum
{
SHF_ENTRYSECT = 0x10000000,
SHF_COMDEF = 0x80000000
};
#define BSS_SECTION_NAME ".bss"
#define DATA_SECTION_NAME ".data"
#define TEXT_SECTION_NAME ".text"
#define SHSTRTAB_SECTION_NAME ".shstrtab"
#define STRTAB_SECTION_NAME ".strtab"
#define SYMTAB_SECTION_NAME ".symtab"
struct Elf32_Phdr
{
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;
};
enum
{
PT_NULL = 0,
PT_LOAD = 1,
PT_DYNAMIC = 2,
PT_INTERP = 3,
PT_NOTE = 4,
PT_SHLIB = 5,
PT_PHDR = 6
};
enum
{
PF_X = 0x1,
PF_W = 0x2,
PF_R = 0x4
};
enum
{
STN_UNDEF = 0
};
struct Elf32_Sym
{
Elf32_Word st_name;
Elf32_Addr st_value;
Elf32_Word st_size;
unsigned char st_info;
unsigned char st_other;
Elf32_Half st_shndx;
};
#define ELF32_ST_BIND(i) ((i) >> 4)
#define ELF32_ST_TYPE(i) ((i)&0x0f)
#define ELF32_ST_INFO(b, t) \
(((b) << 4) + ((t)&0x0f))
enum
{
STB_LOCAL = 0,
STB_GLOBAL = 1,
STB_WEAK = 2,
// Processor-specific semantics.
STB_LOPROC = 13,
STB_HIPROC = 15
};
enum
{
STT_NOTYPE = 0,
STT_OBJECT = 1,
STT_FUNC = 2,
STT_SECTION = 3,
STT_FILE = 4,
STT_LOPROC = 13,
STT_HIPROC = 15
};
enum
{
STO_THUMB = 1
};
#define ARM_SEQUENCE_MAPSYM "$a"
#define DATA_SEQUENCE_MAPSYM "$d"
#define THUMB_SEQUENCE_MAPSYM "$t"
#define THUMB_BL_TAGSYM "$b"
#define FN_PTR_CONST_TAGSYM "$f"
#define INDIRECT_FN_CALL_TAGSYM "$p"
#define MAPPING_SYMBOL_COUNT_TAGSYM "$m"
#pragma pack()
#endif // _ELF_h_
Elf32_Ehdr::e_phentsize
Elf32_Half e_phentsize
Size in bytes of one entry in the program header table.
Definition: apps/elftosb/common/ELF.h:72
Elf32_Shdr
ELF section header.
Definition: apps/elftosb/common/ELF.h:135
Elf32_Shdr::sh_link
Elf32_Word sh_link
Section header table link index. Interpretation depends on section type.
Definition: apps/elftosb/common/ELF.h:143
Elf32_Phdr::p_offset
Elf32_Off p_offset
Offset in bytes from start of file to the first byte of the segment.
Definition: apps/elftosb/common/ELF.h:226
Elf32_Ehdr::e_ehsize
Elf32_Half e_ehsize
The ELF header&#39;s size in bytes.
Definition: apps/elftosb/common/ELF.h:71
Elf32_Sym::st_size
Elf32_Word st_size
Size associated with symbol. 0 if the symbol has no size or an unknown size.
Definition: apps/elftosb/common/ELF.h:281
Elf32_Phdr::p_memsz
Elf32_Word p_memsz
Size in bytes of the segment in memory. May be zero.
Definition: apps/elftosb/common/ELF.h:230
Elf32_Sym::st_shndx
Elf32_Half st_shndx
Section header table index for this symbol.
Definition: apps/elftosb/common/ELF.h:284
Elf32_Phdr::p_filesz
Elf32_Word p_filesz
Number of bytes of file data the segment consumes. May be zero.
Definition: apps/elftosb/common/ELF.h:229
Elf32_Phdr::p_paddr
Elf32_Addr p_paddr
Physical address, for systems where this is relevant.
Definition: apps/elftosb/common/ELF.h:228
Elf32_Shdr::sh_name
Elf32_Word sh_name
The section&#39;s name. Index into the section header string table section.
Definition: apps/elftosb/common/ELF.h:137
Elf32_Shdr::sh_type
Elf32_Word sh_type
Section type, describing the contents and semantics.
Definition: apps/elftosb/common/ELF.h:138
Elf32_Phdr::p_align
Elf32_Word p_align
Alignment constraint for segment addresses. Possible values are 0 and positive powers of 2...
Definition: apps/elftosb/common/ELF.h:232
Elf32_Phdr::p_flags
Elf32_Word p_flags
Flags relevant to the segment.
Definition: apps/elftosb/common/ELF.h:231
Elf32_Phdr
ELF program header.
Definition: apps/elftosb/common/ELF.h:223
Elf32_Ehdr::e_shstrndx
Elf32_Half e_shstrndx
Section header table index of the section name string table.
Definition: apps/elftosb/common/ELF.h:76
Elf32_Ehdr::e_ident
unsigned char e_ident[EI_NIDENT]
Magic number identifying the file format.
Definition: apps/elftosb/common/ELF.h:63
Elf32_Shdr::sh_addr
Elf32_Addr sh_addr
The address at which the section will appear in the memory image, or 0.
Definition: apps/elftosb/common/ELF.h:140
Elf32_Ehdr::e_flags
Elf32_Word e_flags
Processor-specific flags associated with the file.
Definition: apps/elftosb/common/ELF.h:70
Elf32_Sym::st_info
unsigned char st_info
Specified the symbol&#39;s type and binding attributes.
Definition: apps/elftosb/common/ELF.h:282
Elf32_Sym
ELF symbol table entry.
Definition: apps/elftosb/common/ELF.h:277
Elf32_Phdr::p_vaddr
Elf32_Addr p_vaddr
Virtual address at which the segment will reside in memory.
Definition: apps/elftosb/common/ELF.h:227
Elf32_Ehdr::e_phoff
Elf32_Off e_phoff
Program header table offset in bytes, or 0 if no program header table.
Definition: apps/elftosb/common/ELF.h:68
Elf32_Sym::st_name
Elf32_Word st_name
Index into file&#39;s string table.
Definition: apps/elftosb/common/ELF.h:279
Elf32_Shdr::sh_size
Elf32_Word sh_size
The section&#39;s size in bytes.
Definition: apps/elftosb/common/ELF.h:142
Elf32_Ehdr::e_shentsize
Elf32_Half e_shentsize
Size in bytes of an entry in the section header table.
Definition: apps/elftosb/common/ELF.h:74
Elf32_Shdr::sh_addralign
Elf32_Word sh_addralign
Address alignment constraint. Values are 0 and positive powers of 2.
Definition: apps/elftosb/common/ELF.h:145
Elf32_Ehdr::e_type
Elf32_Half e_type
Identifies the object file format.
Definition: apps/elftosb/common/ELF.h:64
Elf32_Ehdr::e_shnum
Elf32_Half e_shnum
Number of entries in the section header table.
Definition: apps/elftosb/common/ELF.h:75
Elf32_Shdr::sh_flags
Elf32_Word sh_flags
Section flags describing various attributes.
Definition: apps/elftosb/common/ELF.h:139
Elf32_Ehdr
ELF file header.
Definition: apps/elftosb/common/ELF.h:61
Elf32_Sym::st_other
unsigned char st_other
Currently 0 (reserved).
Definition: apps/elftosb/common/ELF.h:283
Elf32_Ehdr::e_version
Elf32_Word e_version
Object file version.
Definition: apps/elftosb/common/ELF.h:66
Elf32_Ehdr::e_machine
Elf32_Half e_machine
Specified the architecture for the object file.
Definition: apps/elftosb/common/ELF.h:65
Elf32_Shdr::sh_entsize
Elf32_Word sh_entsize
Size in bytes of section entries, or 0 if the section does not have fixed-size entries.
Definition: apps/elftosb/common/ELF.h:146
Elf32_Shdr::sh_offset
Elf32_Off sh_offset
Offset from beginning of the file to the first byte in the section.
Definition: apps/elftosb/common/ELF.h:141
Elf32_Sym::st_value
Elf32_Addr st_value
Value associated with the symbol. Depends on context.
Definition: apps/elftosb/common/ELF.h:280
Elf32_Ehdr::e_phnum
Elf32_Half e_phnum
Number of entries in the program header table.
Definition: apps/elftosb/common/ELF.h:73
Elf32_Phdr::p_type
Elf32_Word p_type
What type of segment this header describes.
Definition: apps/elftosb/common/ELF.h:225
Elf32_Shdr::sh_info
Elf32_Word sh_info
Extra information about the section. Depends on section type.
Definition: apps/elftosb/common/ELF.h:144
Elf32_Ehdr::e_shoff
Elf32_Off e_shoff
Section header table offset in bytes, or 0 if no section header table.
Definition: apps/elftosb/common/ELF.h:69
Elf32_Ehdr::e_entry
Elf32_Addr e_entry
Virtual address of the entry point, or 0.
Definition: apps/elftosb/common/ELF.h:67