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