| 1 | #ifndef _LINUX_ELF_H
|
| 2 | #define _LINUX_ELF_H
|
| 3 |
|
| 4 | #include <linux/types.h>
|
| 5 | #include <asm/elf.h>
|
| 6 |
|
| 7 | #ifndef elf_read_implies_exec
|
| 8 | |
| 9 | have the READ_IMPLIES_EXEC personality flag set automatically.
|
| 10 | Override in asm/elf.h as needed.
|
| 11 | # define elf_read_implies_exec(ex, have_pt_gnu_stack) 0
|
| 12 | #endif
|
| 13 |
|
| 14 |
|
| 15 | typedef __u32 Elf32_Addr;
|
| 16 | typedef __u16 Elf32_Half;
|
| 17 | typedef __u32 Elf32_Off;
|
| 18 | typedef __s32 Elf32_Sword;
|
| 19 | typedef __u32 Elf32_Word;
|
| 20 |
|
| 21 |
|
| 22 | typedef __u64 Elf64_Addr;
|
| 23 | typedef __u16 Elf64_Half;
|
| 24 | typedef __s16 Elf64_SHalf;
|
| 25 | typedef __u64 Elf64_Off;
|
| 26 | typedef __s32 Elf64_Sword;
|
| 27 | typedef __u32 Elf64_Word;
|
| 28 | typedef __u64 Elf64_Xword;
|
| 29 | typedef __s64 Elf64_Sxword;
|
| 30 |
|
| 31 |
|
| 32 | #define PT_NULL 0
|
| 33 | #define PT_LOAD 1
|
| 34 | #define PT_DYNAMIC 2
|
| 35 | #define PT_INTERP 3
|
| 36 | #define PT_NOTE 4
|
| 37 | #define PT_SHLIB 5
|
| 38 | #define PT_PHDR 6
|
| 39 | #define PT_TLS 7
|
| 40 | #define PT_LOOS 0x60000000
|
| 41 | #define PT_HIOS 0x6fffffff
|
| 42 | #define PT_LOPROC 0x70000000
|
| 43 | #define PT_HIPROC 0x7fffffff
|
| 44 | #define PT_GNU_EH_FRAME 0x6474e550
|
| 45 |
|
| 46 | #define PT_GNU_STACK (PT_LOOS + 0x474e551)
|
| 47 |
|
| 48 |
|
| 49 | #define ET_NONE 0
|
| 50 | #define ET_REL 1
|
| 51 | #define ET_EXEC 2
|
| 52 | #define ET_DYN 3
|
| 53 | #define ET_CORE 4
|
| 54 | #define ET_LOPROC 0xff00
|
| 55 | #define ET_HIPROC 0xffff
|
| 56 |
|
| 57 |
|
| 58 | #define EM_NONE 0
|
| 59 | #define EM_M32 1
|
| 60 | #define EM_SPARC 2
|
| 61 | #define EM_386 3
|
| 62 | #define EM_68K 4
|
| 63 | #define EM_88K 5
|
| 64 | #define EM_486 6
|
| 65 | #define EM_860 7
|
| 66 |
|
| 67 | #define EM_MIPS 8
|
| 68 |
|
| 69 | #define EM_MIPS_RS4_BE 10
|
| 70 |
|
| 71 | #define EM_PARISC 15
|
| 72 |
|
| 73 | #define EM_SPARC32PLUS 18
|
| 74 |
|
| 75 | #define EM_PPC 20
|
| 76 | #define EM_PPC64 21
|
| 77 |
|
| 78 | #define EM_SH 42
|
| 79 |
|
| 80 | #define EM_SPARCV9 43
|
| 81 |
|
| 82 | #define EM_IA_64 50
|
| 83 |
|
| 84 | #define EM_X86_64 62
|
| 85 |
|
| 86 | #define EM_S390 22
|
| 87 |
|
| 88 | #define EM_CRIS 76
|
| 89 |
|
| 90 | #define EM_V850 87
|
| 91 |
|
| 92 | #define EM_M32R 88
|
| 93 |
|
| 94 | #define EM_H8_300 46
|
| 95 |
|
| 96 | |
| 97 | * This is an interim value that we will use until the committee comes
|
| 98 | * up with a final number.
|
| 99 |
|
| 100 | #define EM_ALPHA 0x9026
|
| 101 |
|
| 102 |
|
| 103 | #define EM_CYGNUS_V850 0x9080
|
| 104 |
|
| 105 |
|
| 106 | #define EM_CYGNUS_M32R 0x9041
|
| 107 |
|
| 108 | |
| 109 | * This is the old interim value for S/390 architecture
|
| 110 |
|
| 111 | #define EM_S390_OLD 0xA390
|
| 112 |
|
| 113 | #define EM_FRV 0x5441
|
| 114 |
|
| 115 |
|
| 116 | #define DT_NULL 0
|
| 117 | #define DT_NEEDED 1
|
| 118 | #define DT_PLTRELSZ 2
|
| 119 | #define DT_PLTGOT 3
|
| 120 | #define DT_HASH 4
|
| 121 | #define DT_STRTAB 5
|
| 122 | #define DT_SYMTAB 6
|
| 123 | #define DT_RELA 7
|
| 124 | #define DT_RELASZ 8
|
| 125 | #define DT_RELAENT 9
|
| 126 | #define DT_STRSZ 10
|
| 127 | #define DT_SYMENT 11
|
| 128 | #define DT_INIT 12
|
| 129 | #define DT_FINI 13
|
| 130 | #define DT_SONAME 14
|
| 131 | #define DT_RPATH 15
|
| 132 | #define DT_SYMBOLIC 16
|
| 133 | #define DT_REL 17
|
| 134 | #define DT_RELSZ 18
|
| 135 | #define DT_RELENT 19
|
| 136 | #define DT_PLTREL 20
|
| 137 | #define DT_DEBUG 21
|
| 138 | #define DT_TEXTREL 22
|
| 139 | #define DT_JMPREL 23
|
| 140 | #define DT_LOPROC 0x70000000
|
| 141 | #define DT_HIPROC 0x7fffffff
|
| 142 |
|
| 143 |
|
| 144 | #define STB_LOCAL 0
|
| 145 | #define STB_GLOBAL 1
|
| 146 | #define STB_WEAK 2
|
| 147 |
|
| 148 | #define STT_NOTYPE 0
|
| 149 | #define STT_OBJECT 1
|
| 150 | #define STT_FUNC 2
|
| 151 | #define STT_SECTION 3
|
| 152 | #define STT_FILE 4
|
| 153 |
|
| 154 | #define ELF_ST_BIND(x) ((x) >> 4)
|
| 155 | #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
|
| 156 | #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
|
| 157 | #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
|
| 158 | #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
|
| 159 | #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
|
| 160 |
|
| 161 | |
| 162 | put on the initial stack
|
| 163 | #define AT_NULL 0
|
| 164 | #define AT_IGNORE 1
|
| 165 | #define AT_EXECFD 2
|
| 166 | #define AT_PHDR 3
|
| 167 | #define AT_PHENT 4
|
| 168 | #define AT_PHNUM 5
|
| 169 | #define AT_PAGESZ 6
|
| 170 | #define AT_BASE 7
|
| 171 | #define AT_FLAGS 8
|
| 172 | #define AT_ENTRY 9
|
| 173 | #define AT_NOTELF 10
|
| 174 | #define AT_UID 11
|
| 175 | #define AT_EUID 12
|
| 176 | #define AT_GID 13
|
| 177 | #define AT_EGID 14
|
| 178 | #define AT_PLATFORM 15
|
| 179 | #define AT_HWCAP 16
|
| 180 | #define AT_CLKTCK 17
|
| 181 |
|
| 182 | #define AT_SECURE 23
|
| 183 |
|
| 184 | typedef struct dynamic{
|
| 185 | Elf32_Sword d_tag;
|
| 186 | union{
|
| 187 | Elf32_Sword d_val;
|
| 188 | Elf32_Addr d_ptr;
|
| 189 | } d_un;
|
| 190 | } Elf32_Dyn;
|
| 191 |
|
| 192 | typedef struct {
|
| 193 | Elf64_Sxword d_tag;
|
| 194 | union {
|
| 195 | Elf64_Xword d_val;
|
| 196 | Elf64_Addr d_ptr;
|
| 197 | } d_un;
|
| 198 | } Elf64_Dyn;
|
| 199 |
|
| 200 |
|
| 201 | #define ELF32_R_SYM(x) ((x) >> 8)
|
| 202 | #define ELF32_R_TYPE(x) ((x) & 0xff)
|
| 203 |
|
| 204 | #define ELF64_R_SYM(i) ((i) >> 32)
|
| 205 | #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
|
| 206 |
|
| 207 | typedef struct elf32_rel {
|
| 208 | Elf32_Addr r_offset;
|
| 209 | Elf32_Word r_info;
|
| 210 | } Elf32_Rel;
|
| 211 |
|
| 212 | typedef struct elf64_rel {
|
| 213 | Elf64_Addr r_offset;
|
| 214 | Elf64_Xword r_info;
|
| 215 | } Elf64_Rel;
|
| 216 |
|
| 217 | typedef struct elf32_rela{
|
| 218 | Elf32_Addr r_offset;
|
| 219 | Elf32_Word r_info;
|
| 220 | Elf32_Sword r_addend;
|
| 221 | } Elf32_Rela;
|
| 222 |
|
| 223 | typedef struct elf64_rela {
|
| 224 | Elf64_Addr r_offset;
|
| 225 | Elf64_Xword r_info;
|
| 226 | Elf64_Sxword r_addend;
|
| 227 | } Elf64_Rela;
|
| 228 |
|
| 229 | typedef struct elf32_sym{
|
| 230 | Elf32_Word st_name;
|
| 231 | Elf32_Addr st_value;
|
| 232 | Elf32_Word st_size;
|
| 233 | unsigned char st_info;
|
| 234 | unsigned char st_other;
|
| 235 | Elf32_Half st_shndx;
|
| 236 | } Elf32_Sym;
|
| 237 |
|
| 238 | typedef struct elf64_sym {
|
| 239 | Elf64_Word st_name;
|
| 240 | unsigned char st_info;
|
| 241 | unsigned char st_other;
|
| 242 | Elf64_Half st_shndx;
|
| 243 | Elf64_Addr st_value;
|
| 244 | Elf64_Xword st_size;
|
| 245 | } Elf64_Sym;
|
| 246 |
|
| 247 |
|
| 248 | #define EI_NIDENT 16
|
| 249 |
|
| 250 | typedef struct elf32_hdr{
|
| 251 | unsigned char e_ident[EI_NIDENT];
|
| 252 | Elf32_Half e_type;
|
| 253 | Elf32_Half e_machine;
|
| 254 | Elf32_Word e_version;
|
| 255 | Elf32_Addr e_entry;
|
| 256 | Elf32_Off e_phoff;
|
| 257 | Elf32_Off e_shoff;
|
| 258 | Elf32_Word e_flags;
|
| 259 | Elf32_Half e_ehsize;
|
| 260 | Elf32_Half e_phentsize;
|
| 261 | Elf32_Half e_phnum;
|
| 262 | Elf32_Half e_shentsize;
|
| 263 | Elf32_Half e_shnum;
|
| 264 | Elf32_Half e_shstrndx;
|
| 265 | } Elf32_Ehdr;
|
| 266 |
|
| 267 | typedef struct elf64_hdr {
|
| 268 | unsigned char e_ident[16];
|
| 269 | Elf64_Half e_type;
|
| 270 | Elf64_Half e_machine;
|
| 271 | Elf64_Word e_version;
|
| 272 | Elf64_Addr e_entry;
|
| 273 | Elf64_Off e_phoff;
|
| 274 | Elf64_Off e_shoff;
|
| 275 | Elf64_Word e_flags;
|
| 276 | Elf64_Half e_ehsize;
|
| 277 | Elf64_Half e_phentsize;
|
| 278 | Elf64_Half e_phnum;
|
| 279 | Elf64_Half e_shentsize;
|
| 280 | Elf64_Half e_shnum;
|
| 281 | Elf64_Half e_shstrndx;
|
| 282 | } Elf64_Ehdr;
|
| 283 |
|
| 284 | |
| 285 | header, p_flags.
|
| 286 | #define PF_R 0x4
|
| 287 | #define PF_W 0x2
|
| 288 | #define PF_X 0x1
|
| 289 |
|
| 290 | typedef struct elf32_phdr{
|
| 291 | Elf32_Word p_type;
|
| 292 | Elf32_Off p_offset;
|
| 293 | Elf32_Addr p_vaddr;
|
| 294 | Elf32_Addr p_paddr;
|
| 295 | Elf32_Word p_filesz;
|
| 296 | Elf32_Word p_memsz;
|
| 297 | Elf32_Word p_flags;
|
| 298 | Elf32_Word p_align;
|
| 299 | } Elf32_Phdr;
|
| 300 |
|
| 301 | typedef struct elf64_phdr {
|
| 302 | Elf64_Word p_type;
|
| 303 | Elf64_Word p_flags;
|
| 304 | Elf64_Off p_offset;
|
| 305 | Elf64_Addr p_vaddr;
|
| 306 | Elf64_Addr p_paddr;
|
| 307 | Elf64_Xword p_filesz;
|
| 308 | Elf64_Xword p_memsz;
|
| 309 | Elf64_Xword p_align;
|
| 310 | } Elf64_Phdr;
|
| 311 |
|
| 312 |
|
| 313 | #define SHT_NULL 0
|
| 314 | #define SHT_PROGBITS 1
|
| 315 | #define SHT_SYMTAB 2
|
| 316 | #define SHT_STRTAB 3
|
| 317 | #define SHT_RELA 4
|
| 318 | #define SHT_HASH 5
|
| 319 | #define SHT_DYNAMIC 6
|
| 320 | #define SHT_NOTE 7
|
| 321 | #define SHT_NOBITS 8
|
| 322 | #define SHT_REL 9
|
| 323 | #define SHT_SHLIB 10
|
| 324 | #define SHT_DYNSYM 11
|
| 325 | #define SHT_NUM 12
|
| 326 | #define SHT_LOPROC 0x70000000
|
| 327 | #define SHT_HIPROC 0x7fffffff
|
| 328 | #define SHT_LOUSER 0x80000000
|
| 329 | #define SHT_HIUSER 0xffffffff
|
| 330 |
|
| 331 |
|
| 332 | #define SHF_WRITE 0x1
|
| 333 | #define SHF_ALLOC 0x2
|
| 334 | #define SHF_EXECINSTR 0x4
|
| 335 | #define SHF_MASKPROC 0xf0000000
|
| 336 |
|
| 337 |
|
| 338 | #define SHN_UNDEF 0
|
| 339 | #define SHN_LORESERVE 0xff00
|
| 340 | #define SHN_LOPROC 0xff00
|
| 341 | #define SHN_HIPROC 0xff1f
|
| 342 | #define SHN_ABS 0xfff1
|
| 343 | #define SHN_COMMON 0xfff2
|
| 344 | #define SHN_HIRESERVE 0xffff
|
| 345 |
|
| 346 | typedef struct {
|
| 347 | Elf32_Word sh_name;
|
| 348 | Elf32_Word sh_type;
|
| 349 | Elf32_Word sh_flags;
|
| 350 | Elf32_Addr sh_addr;
|
| 351 | Elf32_Off sh_offset;
|
| 352 | Elf32_Word sh_size;
|
| 353 | Elf32_Word sh_link;
|
| 354 | Elf32_Word sh_info;
|
| 355 | Elf32_Word sh_addralign;
|
| 356 | Elf32_Word sh_entsize;
|
| 357 | } Elf32_Shdr;
|
| 358 |
|
| 359 | typedef struct elf64_shdr {
|
| 360 | Elf64_Word sh_name;
|
| 361 | Elf64_Word sh_type;
|
| 362 | Elf64_Xword sh_flags;
|
| 363 | Elf64_Addr sh_addr;
|
| 364 | Elf64_Off sh_offset;
|
| 365 | Elf64_Xword sh_size;
|
| 366 | Elf64_Word sh_link;
|
| 367 | Elf64_Word sh_info;
|
| 368 | Elf64_Xword sh_addralign;
|
| 369 | Elf64_Xword sh_entsize;
|
| 370 | } Elf64_Shdr;
|
| 371 |
|
| 372 | #define EI_MAG0 0
|
| 373 | #define EI_MAG1 1
|
| 374 | #define EI_MAG2 2
|
| 375 | #define EI_MAG3 3
|
| 376 | #define EI_CLASS 4
|
| 377 | #define EI_DATA 5
|
| 378 | #define EI_VERSION 6
|
| 379 | #define EI_OSABI 7
|
| 380 | #define EI_PAD 8
|
| 381 |
|
| 382 | #define ELFMAG0 0x7f
|
| 383 | #define ELFMAG1 'E'
|
| 384 | #define ELFMAG2 'L'
|
| 385 | #define ELFMAG3 'F'
|
| 386 | #define ELFMAG "\177ELF"
|
| 387 | #define SELFMAG 4
|
| 388 |
|
| 389 | #define ELFCLASSNONE 0
|
| 390 | #define ELFCLASS32 1
|
| 391 | #define ELFCLASS64 2
|
| 392 | #define ELFCLASSNUM 3
|
| 393 |
|
| 394 | #define ELFDATANONE 0
|
| 395 | #define ELFDATA2LSB 1
|
| 396 | #define ELFDATA2MSB 2
|
| 397 |
|
| 398 | #define EV_NONE 0
|
| 399 | #define EV_CURRENT 1
|
| 400 | #define EV_NUM 2
|
| 401 |
|
| 402 | #define ELFOSABI_NONE 0
|
| 403 | #define ELFOSABI_LINUX 3
|
| 404 |
|
| 405 | #ifndef ELF_OSABI
|
| 406 | #define ELF_OSABI ELFOSABI_NONE
|
| 407 | #endif
|
| 408 |
|
| 409 |
|
| 410 | #define NT_PRSTATUS 1
|
| 411 | #define NT_PRFPREG 2
|
| 412 | #define NT_PRPSINFO 3
|
| 413 | #define NT_TASKSTRUCT 4
|
| 414 | #define NT_AUXV 6
|
| 415 | #define NT_PRXFPREG 0x46e62b7f
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 | typedef struct elf32_note {
|
| 420 | Elf32_Word n_namesz;
|
| 421 | Elf32_Word n_descsz;
|
| 422 | Elf32_Word n_type;
|
| 423 | } Elf32_Nhdr;
|
| 424 |
|
| 425 |
|
| 426 | typedef struct elf64_note {
|
| 427 | Elf64_Word n_namesz;
|
| 428 | Elf64_Word n_descsz;
|
| 429 | Elf64_Word n_type;
|
| 430 | } Elf64_Nhdr;
|
| 431 |
|
| 432 | #if ELF_CLASS == ELFCLASS32
|
| 433 |
|
| 434 | extern Elf32_Dyn _DYNAMIC [];
|
| 435 | #define elfhdr elf32_hdr
|
| 436 | #define elf_phdr elf32_phdr
|
| 437 | #define elf_note elf32_note
|
| 438 |
|
| 439 | #else
|
| 440 |
|
| 441 | extern Elf64_Dyn _DYNAMIC [];
|
| 442 | #define elfhdr elf64_hdr
|
| 443 | #define elf_phdr elf64_phdr
|
| 444 | #define elf_note elf64_note
|
| 445 |
|
| 446 | #endif
|
| 447 |
|
| 448 |
|
| 449 | #endif
|