15e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Copyright (C) 2007-2010 The Android Open Source Project
25e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine**
35e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** This software is licensed under the terms of the GNU General Public
45e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** License version 2, as published by the Free Software Foundation, and
55e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** may be copied, distributed, and modified under those terms.
65e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine**
75e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** This program is distributed in the hope that it will be useful,
85e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** but WITHOUT ANY WARRANTY; without even the implied warranty of
95e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
105e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine** GNU General Public License for more details.
115e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine*/
125e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
135e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
145e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Contains declarations of types, constants and structures
155e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * describing ELF file format.
165e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
175e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
185e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#ifndef ELFF_ELH_H_
195e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFF_ELH_H_
205e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
215e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#include <stdint.h>
225e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#include "elff-common.h"
235e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
245e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine//=============================================================================
255e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine// ELF file definitions
265e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine//=============================================================================
275e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
285e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
295e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * ELF format documentation uses Elf##_Xxx notation for data types, where
305e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * ## stands for CPU architecture (32, or 64 bit), and Xxx stands for a
315e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * specific type. For the sake of compliance, we will follow doc's notation
325e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * when defining types used in ELF file descriptors. However, for the sake of
335e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * code simplicity, we will drop CPU architecture index from the types that
345e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * have equal sizes on both, 32 and 64 bit architectures.
355e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
365e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
375e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
385e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Architecture independent types.
395e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
405e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
415e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint8_t   Elf_Byte;
425e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef int8_t    Elf_Sbyte;
435e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
445e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint16_t  Elf_Half;
455e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef int16_t   Elf_Shalf;
465e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
475e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint32_t  Elf_Word;
485e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef int32_t   Elf_Sword;
495e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
505e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint64_t  Elf_Xword;
515e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef int64_t   Elf_Sxword;
525e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
535e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
545e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Architecture dependent types.
555e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
565e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
575e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 32-bit ELF address. */
585e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint32_t  Elf32_Addr;
595e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 32-bit ELF offset. */
605e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint32_t  Elf32_Off;
615e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
625e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 64-bit ELF address. */
635e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint64_t  Elf64_Addr;
645e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 64-bit ELF offset. */
655e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef uint64_t  Elf64_Off;
665e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
675e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine//=============================================================================
685e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine// ELF file header
695e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine//=============================================================================
705e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
715e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Byte size of the fixed portion of ELF header. */
725e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define EI_NIDENT	16
735e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
745e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Common (architecture independent portion of) ELF file header,
755e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * that starts at offset 0 in ELF file.
765e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
775e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef struct Elf_CommonHdr {
785e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  union {
795e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine    struct {
805e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      /* ei_mag0 - ei_mag3 contain ELF header signature. See ELFMAGx bellow. */
815e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_mag0;
825e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_mag1;
835e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_mag2;
845e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_mag3;
855e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
865e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      /* File class (32, or 64 bits). See ELFCLASSxxx bellow. */
875e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_class;
885e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
895e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      /* Data encoding (endianness). See ELFDATAxxx bellow. */
905e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_data;
915e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
925e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      /* ELF header version number. */
935e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine      Elf_Byte  ei_version;
945e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine    } ei_info;
955e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine    unsigned char e_ident[EI_NIDENT];
965e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  };
975e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
985e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* File type (executable, shared object, etc.) */
995e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_type;
1005e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1015e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Processor type. */
1025e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_machine;
1035e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1045e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* File version. */
1055e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word      e_version;
1065e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine} Elf_CommonHdr;
1075e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1085e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1095e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* ELF header signature. */
1105e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFMAG0		0x7f
1115e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFMAG1		'E'
1125e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFMAG2		'L'
1135e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFMAG3		'F'
1145e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFMAG		"\177ELF"
1155e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SELFMAG		4
1165e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1175e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
1185e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Possible ei_class values.
1195e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
1205e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1215e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Invalid. */
1225e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFCLASSNONE  0
1235e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* It's 32-bit ELF file. */
1245e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFCLASS32    1
1255e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* It's 64-bit ELF file. */
1265e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFCLASS64    2
1275e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1285e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
1295e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Possible ei_data values.
1305e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
1315e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1325e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Invalid. */
1335e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFDATANONE   0
1345e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* ELF data is formatted in little-endian. */
1355e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFDATA2LSB   1
1365e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* ELF data is formatted in big-endian. */
1375e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define ELFDATA2MSB   2
1385e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1395e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Tempated (architecture dependent) ELF file header.
1405e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Template param:
1415e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine *  Elf_Addr - Actual type for address encoding (Elf32_Addr, or Elf64_Addr).
1425e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine *  Elf_Off - Actual type for offset encoding (Elf32_Off, or Elf64_Off).
1435e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
1445e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetemplate <typename Elf_Addr, typename Elf_Off>
1455e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinestruct Elf_FHdr {
1465e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Common header. */
1475e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_CommonHdr common;
1485e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1495e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Module entry point. */
1505e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Addr      e_entry;
1515e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1525e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Programm header table offset (in bytes) from the beginning of the file.
1535e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * Zero if there is no programm header in this file.
1545e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
1555e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Off       e_phoff;
1565e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1575e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Section header table offset (in bytes) from the beginning of the file.
1585e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * Zero if there is no section header in this file.
1595e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
1605e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Off       e_shoff;
1615e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1625e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Processor-specific flags. */
1635e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word      e_flags;
1645e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1655e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* This header size in bytes. */
1665e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_ehsize;
1675e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1685e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Byte size of an entry in programm header table. All entries
1695e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * in the table are the same size.
1705e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
1715e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_phentsize;
1725e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1735e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Number of entries in programm header table. */
1745e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_phnum;
1755e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1765e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Byte size of an entry in section header table. All entries
1775e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * in the table are the same size.
1785e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
1795e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_shentsize;
1805e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1815e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Number of entries in section header table. */
1825e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_shnum;
1835e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1845e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Zero-based index of an entry for name string table section in the section
1855e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * header table. If no such section exists in the file this field contains
1865e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * SHN_UNDEF value.
1875e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
1885e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Half      e_shstrndx;
1895e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine};
1905e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 32-bit ELF header. */
1915e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef Elf_FHdr<Elf32_Addr, Elf32_Off> Elf32_FHdr;
1925e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 64-bit ELF header. */
1935e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef Elf_FHdr<Elf64_Addr, Elf64_Off> Elf64_FHdr;
1945e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1955e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine//=============================================================================
1965e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine// ELF section header
1975e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine//=============================================================================
1985e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
1995e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* Templated (architecture dependent) section header for ELF file.
2005e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Template param:
2015e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine *  Elf_Addr - Actual type for address encoding (Elf32_Addr, or Elf64_Addr).
2025e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine *  Elf_Off - Actual type for offset encoding (Elf32_Off, or Elf64_Off).
2035e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
2045e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetemplate <typename Elf_Addr, typename Elf_Off>
2055e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinestruct Elf_SHdr {
2065e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Index (byte offset) of section name in the name string table section. */
2075e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_name;
2085e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2095e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Section type and semantics. */
2105e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_type;
2115e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2125e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Section flags and attributes. */
2135e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_flags;
2145e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2155e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Section address in the memory image of the process. */
2165e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Addr    sh_addr;
2175e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2185e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Byte offset from the beginning of the ELF file to the first
2195e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * byte in the section.
2205e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
2215e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Off     sh_offset;
2225e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2235e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Section size in bytes. */
2245e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_size;
2255e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2265e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Section header table index link. Depends on section type. */
2275e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_link;
2285e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2295e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Extra section information, depending on the section type. */
2305e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_info;
2315e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2325e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Address alignment constrains. 0 and 1 means that section has no
2335e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   * alignment constrains.
2345e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine   */
2355e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_addralign;
2365e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2375e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  /* Entry size for sections that hold some kind of a table. */
2385e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine  Elf_Word    sh_entsize;
2395e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine};
2405e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 32-bit section header. */
2415e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef Elf_SHdr<Elf32_Addr, Elf32_Off> Elf32_SHdr;
2425e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/* 64-bit section header. */
2435e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkinetypedef Elf_SHdr<Elf64_Addr, Elf64_Off> Elf64_SHdr;
2445e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2455e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
2465e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Special section indices
2475e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
2485e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_UNDEF       0
2495e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_LORESERVE   0xff00
2505e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_LOPROC      0xff00
2515e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_HIPROC      0xff1f
2525e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_LOOS        0xff20
2535e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_HIOS        0xff3f
2545e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_ABS         0xfff1
2555e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_COMMON      0xfff2
2565e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_XINDEX      0xffff
2575e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHN_HIRESERVE   0xffff
2585e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2595e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine/*
2605e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine * Values for sh_type
2615e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine */
2625e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_NULL            0
2635e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_PROGBITS        1
2645e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_SYMTAB          2
2655e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_STRTAB          3
2665e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_RELA            4
2675e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_HASH            5
2685e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_DYNAMIC         6
2695e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_NOTE            7
2705e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_NOBITS          8
2715e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_REL             9
2725e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_SHLIB           10
2735e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_DYNSYM          11
2745e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_INIT_ARRAY      14
2755e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_FINI_ARRAY      15
2765e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_PREINIT_ARRAY   16
2775e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_GROUP           17
2785e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_SYMTAB_SHNDX    18
2795e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#define SHT_NUM             19
2805e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine
2815e0720014efeafbf6228ae4cd93b3968c1de53fcVladimir Chtchetkine#endif  // ELFF_ELH_H_
282