MIPS ELF header definitions

From Dmz-portal

Jump to: navigation, search

We start with some generic ELF header definitions and then follow with MIPS specific definitions.

See http://www.sco.com/developers/gabi for more details of gABI descriptions


Contents

Header Structure

#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_shtrndx;
} Elf32_Ehdr;
typedef struct {
       unsigned char   e_ident[EI_NIDENT];
       Elf64_Half      e_type;
       Elf64_Half      e_machine;
       Elf64_Word      e_version;
       Elf64_Addr      e_entry;
       Elf64_Off       e_phoff;
       Elf64_Off       e_shoff;
       Elf64_Word      e_flags;
       Elf64_Half      e_ehsize;
       Elf64_Half      e_phentsize;
       Elf64_Half      e_phnum;
       Elf64_Half      e_shentsize;
       Elf64_Half      e_shnum;
       Elf64_Half      e_shtrndx;
} Elf64_Ehdr;
Type Comment
e_ident See below
e_type See below
e_machine Machine: EM_MIPS (8)
e_version Version of format: EV_CURRENT (1)
e_entry Process entry address
e_phoff Program header table file offset
e_shoff Section header table file offset
e_flags Flags: See below
e_ehsize ELF header size in bytes
e_phentsize Program header entry size
e_phnum Number of program headers
e_shentsize Section header entry size
e_shnum Number of section headers
e_shstrndx Section name string table section header index

e_ident

Flag Name Index Description
EI_MAG0-3 0-3 Magic string: 0x7f, 'E', 'L', 'F'
EI_CLASS 4 Class of format: ELFCLASS32 (1) or ELFCLASS64 (2)
EI_DATA 5 Endianness: ELFDATALSB (1) or ELFDATAMSB (2)
EI_VERSION 6 Version of format: EV_CURRENT (1)
EI_PAD 7-15

e_type

Flag Name Value Description
ET_NONE 0 No file type
ET_REL 1 Relocatable file
ET_EXE 2 Executable file
ET_DYN 3 Dynamic shared object file
ET_CORE 4 Core file
ET_LOOS 0xfe00 OS-specific range start
ET_HIOS 0xfeff OS-specific range end
ET_LOPROC 0xff00 Processor-specific range start
ET_HIPROC 0xffff Processor-specific range end

e_flags

Flag Name Value Description
EF_MIPS_NOREORDER 0x00000001 At least one .noreorder assembly directive appeared in a source contributing to the object
EF_MIPS_PIC 0x00000002 This file contains position-independent code
EF_MIPS_CPIC 0x00000004 This file's code follows standard conventions for calling position-independent code.

It use to mean something for IRIX, but seems to be always on for gcc.

EF_MIPS_XGOT 0x00000008 This file contains large (32-bit) GOT
EF_MIPS_UCODE 0x00000010 This file contains UCODE (obsolete)
EF_MIPS_64BIT_WHIRL 0x00000010 This file contains WHIRL intermediate relocation language code (SGI/Open64)
EF_MIPS_ABI2 0x00000020 This file follows the n32 abi
EF_MIPS_ABI_ON32 0x00000040 (obsolete)
EF_MIPS_OPTIONS_FIRST 0x00000080 The .MIPS.options section in this file contains one or more descriptors, currently types ODK_GP_GROUP and/or ODK_IDENT, which should be processed first by ld.
EF_MIPS_32BITMODE 0x00000100 binaries compiled for a 32bit ABI, but a 64bit ISA, have this flag set, as the kernel will refuse to execute 64bt code (i.e. not o32 or n32 ABI).
E_MIPS_FP64 0x00000200 32-bit machine but FP registers are 64 bit (-mfp64).
E_MIPS_NAN2008 0x00000400 Code in file uses the IEEE 754-2008 NaN encoding convention.
E_MIPS_ABI_O32 0x00001000 This file follows the first MIPS 32 bit ABI (UCODE). Unknown if this flag is actually used.
E_MIPS_ABI_O64 0x00002000 This file follows the UCODE MIPS 64 bit ABI (obsolete)
E_MIPS_ABI_EABI32 0x00003000 Embedded Application Binary Interface for 32-bit
E_MIPS_ABI_EABI64 0x00004000 Embedded Application Binary Interface for 64-bit
EF_MIPS_ARCH_ASE_MDMX 0x08000000 Uses MDMX multimedia extensions
EF_MIPS_ARCH_ASE_M16 0x04000000 Uses MIPS-16 ISA extensions
EF_MIPS_ARCH_ASE_MICROMIPS 0x02000000 Uses MicroMips. Actually not an extension, but a full architecture
EF_MIPS_ARCH_1 0x00000000 Contains MIPS I instruction set
EF_MIPS_ARCH_2 0x10000000 Contains MIPS II instruction set
EF_MIPS_ARCH_3 0x20000000 Contains MIPS III instruction set
EF_MIPS_ARCH_4 0x30000000 MIPS IV is the fourth version of the architecture. It is a superset of MIPS III and is compatible with all existing versions of MIPS.
EF_MIPS_ARCH_5 0x40000000 Never introduced
EF_MIPS_ARCH_32 0x50000000 This file will run on a machine with the architecture describe for Mips32 Revision 1
EF_MIPS_ARCH_64 0x60000000 This file will run on a machine with the architecture describe for Mips64 Revision 1
EF_MIPS_ARCH_32R2 0x70000000 This file will run on a machine with the architecture describe for Mips32 Revision 2
EF_MIPS_ARCH_64R2 0x80000000 This file will run on a machine with the architecture describe for Mips64 Revision 2


e_flag range masks to isolate flags

Flag Name Value Description
EF_MIPS_ABI 0x0000f000 Mask used to isolate 4 bit ABI field
EF_MIPS_ARCH_ASE 0x0f000000 Mask used to isolate the Application Specific Extensions used by this object file
EF_MIPS_ARCH 0xf0000000 Mask used to isolate the 4-bit field for Architecture in this file
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox