1#ifndef _LINUX_ELF_H 2#define _LINUX_ELF_H 3 4#include <linux/types.h> 5#include <linux/auxvec.h> 6#include <linux/elf-em.h> 7#include <asm/elf.h> 8 9#ifndef elf_read_implies_exec 10 /* Executables for which elf_read_implies_exec() returns TRUE will 11 have the READ_IMPLIES_EXEC personality flag set automatically. 12 Override in asm/elf.h as needed. */ 13# define elf_read_implies_exec(ex, have_pt_gnu_stack) 0 14#endif 15 16/* 32-bit ELF base types. */ 17typedef __u32 Elf32_Addr; 18typedef __u16 Elf32_Half; 19typedef __u32 Elf32_Off; 20typedef __s32 Elf32_Sword; 21typedef __u32 Elf32_Word; 22 23/* 64-bit ELF base types. */ 24typedef __u64 Elf64_Addr; 25typedef __u16 Elf64_Half; 26typedef __s16 Elf64_SHalf; 27typedef __u64 Elf64_Off; 28typedef __s32 Elf64_Sword; 29typedef __u32 Elf64_Word; 30typedef __u64 Elf64_Xword; 31typedef __s64 Elf64_Sxword; 32 33/* These constants are for the segment types stored in the image headers */ 34#define PT_NULL 0 35#define PT_LOAD 1 36#define PT_DYNAMIC 2 37#define PT_INTERP 3 38#define PT_NOTE 4 39#define PT_SHLIB 5 40#define PT_PHDR 6 41#define PT_TLS 7 /* Thread local storage segment */ 42#define PT_LOOS 0x60000000 /* OS-specific */ 43#define PT_HIOS 0x6fffffff /* OS-specific */ 44#define PT_LOPROC 0x70000000 45#define PT_HIPROC 0x7fffffff 46#define PT_GNU_EH_FRAME 0x6474e550 47 48#define PT_GNU_STACK (PT_LOOS + 0x474e551) 49 50/* These constants define the different elf file types */ 51#define ET_NONE 0 52#define ET_REL 1 53#define ET_EXEC 2 54#define ET_DYN 3 55#define ET_CORE 4 56#define ET_LOPROC 0xff00 57#define ET_HIPROC 0xffff 58 59/* This is the info that is needed to parse the dynamic section of the file */ 60#define DT_NULL 0 61#define DT_NEEDED 1 62#define DT_PLTRELSZ 2 63#define DT_PLTGOT 3 64#define DT_HASH 4 65#define DT_STRTAB 5 66#define DT_SYMTAB 6 67#define DT_RELA 7 68#define DT_RELASZ 8 69#define DT_RELAENT 9 70#define DT_STRSZ 10 71#define DT_SYMENT 11 72#define DT_INIT 12 73#define DT_FINI 13 74#define DT_SONAME 14 75#define DT_RPATH 15 76#define DT_SYMBOLIC 16 77#define DT_REL 17 78#define DT_RELSZ 18 79#define DT_RELENT 19 80#define DT_PLTREL 20 81#define DT_DEBUG 21 82#define DT_TEXTREL 22 83#define DT_JMPREL 23 84#define DT_LOPROC 0x70000000 85#define DT_HIPROC 0x7fffffff 86 87/* This info is needed when parsing the symbol table */ 88#define STB_LOCAL 0 89#define STB_GLOBAL 1 90#define STB_WEAK 2 91 92#define STT_NOTYPE 0 93#define STT_OBJECT 1 94#define STT_FUNC 2 95#define STT_SECTION 3 96#define STT_FILE 4 97#define STT_COMMON 5 98#define STT_TLS 6 99 100#define ELF_ST_BIND(x) ((x) >> 4) 101#define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf) 102#define ELF32_ST_BIND(x) ELF_ST_BIND(x) 103#define ELF32_ST_TYPE(x) ELF_ST_TYPE(x) 104#define ELF64_ST_BIND(x) ELF_ST_BIND(x) 105#define ELF64_ST_TYPE(x) ELF_ST_TYPE(x) 106 107typedef struct dynamic{ 108 Elf32_Sword d_tag; 109 union{ 110 Elf32_Sword d_val; 111 Elf32_Addr d_ptr; 112 } d_un; 113} Elf32_Dyn; 114 115typedef struct { 116 Elf64_Sxword d_tag; /* entry tag value */ 117 union { 118 Elf64_Xword d_val; 119 Elf64_Addr d_ptr; 120 } d_un; 121} Elf64_Dyn; 122 123/* The following are used with relocations */ 124#define ELF32_R_SYM(x) ((x) >> 8) 125#define ELF32_R_TYPE(x) ((x) & 0xff) 126 127#define ELF64_R_SYM(i) ((i) >> 32) 128#define ELF64_R_TYPE(i) ((i) & 0xffffffff) 129 130typedef struct elf32_rel { 131 Elf32_Addr r_offset; 132 Elf32_Word r_info; 133} Elf32_Rel; 134 135typedef struct elf64_rel { 136 Elf64_Addr r_offset; /* Location at which to apply the action */ 137 Elf64_Xword r_info; /* index and type of relocation */ 138} Elf64_Rel; 139 140typedef struct elf32_rela{ 141 Elf32_Addr r_offset; 142 Elf32_Word r_info; 143 Elf32_Sword r_addend; 144} Elf32_Rela; 145 146typedef struct elf64_rela { 147 Elf64_Addr r_offset; /* Location at which to apply the action */ 148 Elf64_Xword r_info; /* index and type of relocation */ 149 Elf64_Sxword r_addend; /* Constant addend used to compute value */ 150} Elf64_Rela; 151 152typedef struct elf32_sym{ 153 Elf32_Word st_name; 154 Elf32_Addr st_value; 155 Elf32_Word st_size; 156 unsigned char st_info; 157 unsigned char st_other; 158 Elf32_Half st_shndx; 159} Elf32_Sym; 160 161typedef struct elf64_sym { 162 Elf64_Word st_name; /* Symbol name, index in string tbl */ 163 unsigned char st_info; /* Type and binding attributes */ 164 unsigned char st_other; /* No defined meaning, 0 */ 165 Elf64_Half st_shndx; /* Associated section index */ 166 Elf64_Addr st_value; /* Value of the symbol */ 167 Elf64_Xword st_size; /* Associated symbol size */ 168} Elf64_Sym; 169 170 171#define EI_NIDENT 16 172 173typedef struct elf32_hdr{ 174 unsigned char e_ident[EI_NIDENT]; 175 Elf32_Half e_type; 176 Elf32_Half e_machine; 177 Elf32_Word e_version; 178 Elf32_Addr e_entry; /* Entry point */ 179 Elf32_Off e_phoff; 180 Elf32_Off e_shoff; 181 Elf32_Word e_flags; 182 Elf32_Half e_ehsize; 183 Elf32_Half e_phentsize; 184 Elf32_Half e_phnum; 185 Elf32_Half e_shentsize; 186 Elf32_Half e_shnum; 187 Elf32_Half e_shstrndx; 188} Elf32_Ehdr; 189 190typedef struct elf64_hdr { 191 unsigned char e_ident[16]; /* ELF "magic number" */ 192 Elf64_Half e_type; 193 Elf64_Half e_machine; 194 Elf64_Word e_version; 195 Elf64_Addr e_entry; /* Entry point virtual address */ 196 Elf64_Off e_phoff; /* Program header table file offset */ 197 Elf64_Off e_shoff; /* Section header table file offset */ 198 Elf64_Word e_flags; 199 Elf64_Half e_ehsize; 200 Elf64_Half e_phentsize; 201 Elf64_Half e_phnum; 202 Elf64_Half e_shentsize; 203 Elf64_Half e_shnum; 204 Elf64_Half e_shstrndx; 205} Elf64_Ehdr; 206 207/* These constants define the permissions on sections in the program 208 header, p_flags. */ 209#define PF_R 0x4 210#define PF_W 0x2 211#define PF_X 0x1 212 213typedef struct elf32_phdr{ 214 Elf32_Word p_type; 215 Elf32_Off p_offset; 216 Elf32_Addr p_vaddr; 217 Elf32_Addr p_paddr; 218 Elf32_Word p_filesz; 219 Elf32_Word p_memsz; 220 Elf32_Word p_flags; 221 Elf32_Word p_align; 222} Elf32_Phdr; 223 224typedef struct elf64_phdr { 225 Elf64_Word p_type; 226 Elf64_Word p_flags; 227 Elf64_Off p_offset; /* Segment file offset */ 228 Elf64_Addr p_vaddr; /* Segment virtual address */ 229 Elf64_Addr p_paddr; /* Segment physical address */ 230 Elf64_Xword p_filesz; /* Segment size in file */ 231 Elf64_Xword p_memsz; /* Segment size in memory */ 232 Elf64_Xword p_align; /* Segment alignment, file & memory */ 233} Elf64_Phdr; 234 235/* sh_type */ 236#define SHT_NULL 0 237#define SHT_PROGBITS 1 238#define SHT_SYMTAB 2 239#define SHT_STRTAB 3 240#define SHT_RELA 4 241#define SHT_HASH 5 242#define SHT_DYNAMIC 6 243#define SHT_NOTE 7 244#define SHT_NOBITS 8 245#define SHT_REL 9 246#define SHT_SHLIB 10 247#define SHT_DYNSYM 11 248#define SHT_NUM 12 249#define SHT_LOPROC 0x70000000 250#define SHT_HIPROC 0x7fffffff 251#define SHT_LOUSER 0x80000000 252#define SHT_HIUSER 0xffffffff 253 254/* sh_flags */ 255#define SHF_WRITE 0x1 256#define SHF_ALLOC 0x2 257#define SHF_EXECINSTR 0x4 258#define SHF_MASKPROC 0xf0000000 259 260/* special section indexes */ 261#define SHN_UNDEF 0 262#define SHN_LORESERVE 0xff00 263#define SHN_LOPROC 0xff00 264#define SHN_HIPROC 0xff1f 265#define SHN_ABS 0xfff1 266#define SHN_COMMON 0xfff2 267#define SHN_HIRESERVE 0xffff 268 269typedef struct { 270 Elf32_Word sh_name; 271 Elf32_Word sh_type; 272 Elf32_Word sh_flags; 273 Elf32_Addr sh_addr; 274 Elf32_Off sh_offset; 275 Elf32_Word sh_size; 276 Elf32_Word sh_link; 277 Elf32_Word sh_info; 278 Elf32_Word sh_addralign; 279 Elf32_Word sh_entsize; 280} Elf32_Shdr; 281 282typedef struct elf64_shdr { 283 Elf64_Word sh_name; /* Section name, index in string tbl */ 284 Elf64_Word sh_type; /* Type of section */ 285 Elf64_Xword sh_flags; /* Miscellaneous section attributes */ 286 Elf64_Addr sh_addr; /* Section virtual addr at execution */ 287 Elf64_Off sh_offset; /* Section file offset */ 288 Elf64_Xword sh_size; /* Size of section in bytes */ 289 Elf64_Word sh_link; /* Index of another section */ 290 Elf64_Word sh_info; /* Additional section information */ 291 Elf64_Xword sh_addralign; /* Section alignment */ 292 Elf64_Xword sh_entsize; /* Entry size if section holds table */ 293} Elf64_Shdr; 294 295#define EI_MAG0 0 /* e_ident[] indexes */ 296#define EI_MAG1 1 297#define EI_MAG2 2 298#define EI_MAG3 3 299#define EI_CLASS 4 300#define EI_DATA 5 301#define EI_VERSION 6 302#define EI_OSABI 7 303#define EI_PAD 8 304 305#define ELFMAG0 0x7f /* EI_MAG */ 306#define ELFMAG1 'E' 307#define ELFMAG2 'L' 308#define ELFMAG3 'F' 309#define ELFMAG "\177ELF" 310#define SELFMAG 4 311 312#define ELFCLASSNONE 0 /* EI_CLASS */ 313#define ELFCLASS32 1 314#define ELFCLASS64 2 315#define ELFCLASSNUM 3 316 317#define ELFDATANONE 0 /* e_ident[EI_DATA] */ 318#define ELFDATA2LSB 1 319#define ELFDATA2MSB 2 320 321#define EV_NONE 0 /* e_version, EI_VERSION */ 322#define EV_CURRENT 1 323#define EV_NUM 2 324 325#define ELFOSABI_NONE 0 326#define ELFOSABI_LINUX 3 327 328#ifndef ELF_OSABI 329#define ELF_OSABI ELFOSABI_NONE 330#endif 331 332/* Notes used in ET_CORE */ 333#define NT_PRSTATUS 1 334#define NT_PRFPREG 2 335#define NT_PRPSINFO 3 336#define NT_TASKSTRUCT 4 337#define NT_AUXV 6 338#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */ 339 340 341/* Note header in a PT_NOTE section */ 342typedef struct elf32_note { 343 Elf32_Word n_namesz; /* Name size */ 344 Elf32_Word n_descsz; /* Content size */ 345 Elf32_Word n_type; /* Content type */ 346} Elf32_Nhdr; 347 348/* Note header in a PT_NOTE section */ 349typedef struct elf64_note { 350 Elf64_Word n_namesz; /* Name size */ 351 Elf64_Word n_descsz; /* Content size */ 352 Elf64_Word n_type; /* Content type */ 353} Elf64_Nhdr; 354 355#if ELF_CLASS == ELFCLASS32 356 357extern Elf32_Dyn _DYNAMIC []; 358#define elfhdr elf32_hdr 359#define elf_phdr elf32_phdr 360#define elf_note elf32_note 361 362#else 363 364extern Elf64_Dyn _DYNAMIC []; 365#define elfhdr elf64_hdr 366#define elf_phdr elf64_phdr 367#define elf_note elf64_note 368 369#endif 370 371 372#endif /* _LINUX_ELF_H */ 373