src/blfwk/ELF.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#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_Ehdr::e_ehsize
Elf32_Half e_ehsize
The ELF header&#39;s size in bytes.
Definition: apps/elftosb/common/ELF.h:71
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_Ehdr::e_flags
Elf32_Word e_flags
Processor-specific flags associated with the file.
Definition: apps/elftosb/common/ELF.h:70
Elf32_Sym
ELF symbol table entry.
Definition: apps/elftosb/common/ELF.h:277
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_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_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_Ehdr
ELF file header.
Definition: apps/elftosb/common/ELF.h:61
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_Ehdr::e_phnum
Elf32_Half e_phnum
Number of entries in the program header table.
Definition: apps/elftosb/common/ELF.h:73
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