4 #include <linux/types.h>
7 /* 32-bit ELF base types. */
8 typedef __u32 Elf32_Addr
;
9 typedef __u16 Elf32_Half
;
10 typedef __u32 Elf32_Off
;
11 typedef __s32 Elf32_Sword
;
12 typedef __u32 Elf32_Word
;
14 /* 64-bit ELF base types. */
15 typedef __u64 Elf64_Addr
;
16 typedef __u16 Elf64_Half
;
17 typedef __s16 Elf64_SHalf
;
18 typedef __u64 Elf64_Off
;
19 typedef __s64 Elf64_Sword
;
20 typedef __u64 Elf64_Word
;
22 /* These constants are for the segment types stored in the image headers */
30 #define PT_LOPROC 0x70000000
31 #define PT_HIPROC 0x7fffffff
32 #define PT_MIPS_REGINFO 0x70000000
34 /* Flags in the e_flags field of the header */
35 #define EF_MIPS_NOREORDER 0x00000001
36 #define EF_MIPS_PIC 0x00000002
37 #define EF_MIPS_CPIC 0x00000004
38 #define EF_MIPS_ARCH 0xf0000000
40 /* These constants define the different elf file types */
46 #define ET_LOPROC 0xff00
47 #define ET_HIPROC 0xffff
49 /* These constants define the various ELF target machines */
56 #define EM_486 6 /* Perhaps disused */
59 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
61 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
63 #define EM_PARISC 15 /* HPPA */
65 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
67 #define EM_PPC 20 /* PowerPC */
69 #define EM_SH 42 /* SuperH */
71 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
73 #define EM_IA_64 50 /* HP/Intel IA-64 */
76 * This is an interim value that we will use until the committee comes
77 * up with a final number.
79 #define EM_ALPHA 0x9026
82 /* This is the info that is needed to parse the dynamic section of the file */
99 #define DT_SYMBOLIC 16
105 #define DT_TEXTREL 22
107 #define DT_LOPROC 0x70000000
108 #define DT_HIPROC 0x7fffffff
109 #define DT_MIPS_RLD_VERSION 0x70000001
110 #define DT_MIPS_TIME_STAMP 0x70000002
111 #define DT_MIPS_ICHECKSUM 0x70000003
112 #define DT_MIPS_IVERSION 0x70000004
113 #define DT_MIPS_FLAGS 0x70000005
115 #define RHF_HARDWAY 1
117 #define DT_MIPS_BASE_ADDRESS 0x70000006
118 #define DT_MIPS_CONFLICT 0x70000008
119 #define DT_MIPS_LIBLIST 0x70000009
120 #define DT_MIPS_LOCAL_GOTNO 0x7000000a
121 #define DT_MIPS_CONFLICTNO 0x7000000b
122 #define DT_MIPS_LIBLISTNO 0x70000010
123 #define DT_MIPS_SYMTABNO 0x70000011
124 #define DT_MIPS_UNREFEXTNO 0x70000012
125 #define DT_MIPS_GOTSYM 0x70000013
126 #define DT_MIPS_HIPAGENO 0x70000014
127 #define DT_MIPS_RLD_MAP 0x70000016
129 /* This info is needed when parsing the symbol table */
137 #define STT_SECTION 3
140 #define ELF32_ST_BIND(x) ((x) >> 4)
141 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
143 /* Symbolic values for the entries in the auxiliary table
144 put on the initial stack */
145 #define AT_NULL 0 /* end of vector */
146 #define AT_IGNORE 1 /* entry should be ignored */
147 #define AT_EXECFD 2 /* file descriptor of program */
148 #define AT_PHDR 3 /* program headers for program */
149 #define AT_PHENT 4 /* size of program header entry */
150 #define AT_PHNUM 5 /* number of program headers */
151 #define AT_PAGESZ 6 /* system page size */
152 #define AT_BASE 7 /* base address of interpreter */
153 #define AT_FLAGS 8 /* flags */
154 #define AT_ENTRY 9 /* entry point of program */
155 #define AT_NOTELF 10 /* program is not ELF */
156 #define AT_UID 11 /* real uid */
157 #define AT_EUID 12 /* effective uid */
158 #define AT_GID 13 /* real gid */
159 #define AT_EGID 14 /* effective gid */
160 #define AT_PLATFORM 15 /* string identifying CPU for optimizations */
161 #define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
163 typedef struct dynamic
{
172 Elf64_Word d_tag
; /* entry tag value */
179 /* The following are used with relocations */
180 #define ELF32_R_SYM(x) ((x) >> 8)
181 #define ELF32_R_TYPE(x) ((x) & 0xff)
186 #define R_386_GOT32 3
187 #define R_386_PLT32 4
189 #define R_386_GLOB_DAT 6
190 #define R_386_JMP_SLOT 7
191 #define R_386_RELATIVE 8
192 #define R_386_GOTOFF 9
193 #define R_386_GOTPC 10
196 #define R_MIPS_NONE 0
199 #define R_MIPS_REL32 3
201 #define R_MIPS_HI16 5
202 #define R_MIPS_LO16 6
203 #define R_MIPS_GPREL16 7
204 #define R_MIPS_LITERAL 8
205 #define R_MIPS_GOT16 9
206 #define R_MIPS_PC16 10
207 #define R_MIPS_CALL16 11
208 #define R_MIPS_GPREL32 12
209 /* The remaining relocs are defined on Irix, although they are not
210 in the MIPS ELF ABI. */
211 #define R_MIPS_UNUSED1 13
212 #define R_MIPS_UNUSED2 14
213 #define R_MIPS_UNUSED3 15
214 #define R_MIPS_SHIFT5 16
215 #define R_MIPS_SHIFT6 17
217 #define R_MIPS_GOT_DISP 19
218 #define R_MIPS_GOT_PAGE 20
219 #define R_MIPS_GOT_OFST 21
221 * The following two relocation types are specified in the the MIPS ABI
222 * conformance guide version 1.2 but not yet in the psABI.
224 #define R_MIPS_GOTHI16 22
225 #define R_MIPS_GOTLO16 23
226 #define R_MIPS_SUB 24
227 #define R_MIPS_INSERT_A 25
228 #define R_MIPS_INSERT_B 26
229 #define R_MIPS_DELETE 27
230 #define R_MIPS_HIGHER 28
231 #define R_MIPS_HIGHEST 29
233 * The following two relocation types are specified in the the MIPS ABI
234 * conformance guide version 1.2 but not yet in the psABI.
236 #define R_MIPS_CALLHI16 30
237 #define R_MIPS_CALLLO16 31
239 * This range is reserved for vendor specific relocations.
241 #define R_MIPS_LOVENDOR 100
242 #define R_MIPS_HIVENDOR 127
246 * Sparc ELF relocation types
248 #define R_SPARC_NONE 0
252 #define R_SPARC_DISP8 4
253 #define R_SPARC_DISP16 5
254 #define R_SPARC_DISP32 6
255 #define R_SPARC_WDISP30 7
256 #define R_SPARC_WDISP22 8
257 #define R_SPARC_HI22 9
258 #define R_SPARC_22 10
259 #define R_SPARC_13 11
260 #define R_SPARC_LO10 12
261 #define R_SPARC_GOT10 13
262 #define R_SPARC_GOT13 14
263 #define R_SPARC_GOT22 15
264 #define R_SPARC_PC10 16
265 #define R_SPARC_PC22 17
266 #define R_SPARC_WPLT30 18
267 #define R_SPARC_COPY 19
268 #define R_SPARC_GLOB_DAT 20
269 #define R_SPARC_JMP_SLOT 21
270 #define R_SPARC_RELATIVE 22
271 #define R_SPARC_UA32 23
272 #define R_SPARC_PLT32 24
273 #define R_SPARC_HIPLT22 25
274 #define R_SPARC_LOPLT10 26
275 #define R_SPARC_PCPLT32 27
276 #define R_SPARC_PCPLT22 28
277 #define R_SPARC_PCPLT10 29
278 #define R_SPARC_10 30
279 #define R_SPARC_11 31
280 #define R_SPARC_WDISP16 40
281 #define R_SPARC_WDISP19 41
286 /* Bits present in AT_HWCAP, primarily for Sparc32. */
288 #define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
289 #define HWCAP_SPARC_STBAR 2
290 #define HWCAP_SPARC_SWAP 4
291 #define HWCAP_SPARC_MULDIV 8
292 #define HWCAP_SPARC_V9 16
296 * 68k ELF relocation types
305 #define R_68K_GOT32 7
306 #define R_68K_GOT16 8
308 #define R_68K_GOT32O 10
309 #define R_68K_GOT16O 11
310 #define R_68K_GOT8O 12
311 #define R_68K_PLT32 13
312 #define R_68K_PLT16 14
313 #define R_68K_PLT8 15
314 #define R_68K_PLT32O 16
315 #define R_68K_PLT16O 17
316 #define R_68K_PLT8O 18
317 #define R_68K_COPY 19
318 #define R_68K_GLOB_DAT 20
319 #define R_68K_JMP_SLOT 21
320 #define R_68K_RELATIVE 22
323 * Alpha ELF relocation types
325 #define R_ALPHA_NONE 0 /* No reloc */
326 #define R_ALPHA_REFLONG 1 /* Direct 32 bit */
327 #define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
328 #define R_ALPHA_GPREL32 3 /* GP relative 32 bit */
329 #define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */
330 #define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */
331 #define R_ALPHA_GPDISP 6 /* Add displacement to GP */
332 #define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */
333 #define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */
334 #define R_ALPHA_SREL16 9 /* PC relative 16 bit */
335 #define R_ALPHA_SREL32 10 /* PC relative 32 bit */
336 #define R_ALPHA_SREL64 11 /* PC relative 64 bit */
337 #define R_ALPHA_OP_PUSH 12 /* OP stack push */
338 #define R_ALPHA_OP_STORE 13 /* OP stack pop and store */
339 #define R_ALPHA_OP_PSUB 14 /* OP stack subtract */
340 #define R_ALPHA_OP_PRSHIFT 15 /* OP stack right shift */
341 #define R_ALPHA_GPVALUE 16
342 #define R_ALPHA_GPRELHIGH 17
343 #define R_ALPHA_GPRELLOW 18
344 #define R_ALPHA_IMMED_GP_16 19
345 #define R_ALPHA_IMMED_GP_HI32 20
346 #define R_ALPHA_IMMED_SCN_HI32 21
347 #define R_ALPHA_IMMED_BR_HI32 22
348 #define R_ALPHA_IMMED_LO32 23
349 #define R_ALPHA_COPY 24 /* Copy symbol at runtime */
350 #define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
351 #define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
352 #define R_ALPHA_RELATIVE 27 /* Adjust by program base */
354 /* Legal values for e_flags field of Elf64_Ehdr. */
356 #define EF_ALPHA_32BIT 1 /* All addresses are below 2GB */
359 typedef struct elf32_rel
{
364 typedef struct elf64_rel
{
365 Elf64_Addr r_offset
; /* Location at which to apply the action */
366 Elf64_Word r_info
; /* index and type of relocation */
369 typedef struct elf32_rela
{
372 Elf32_Sword r_addend
;
375 typedef struct elf64_rela
{
376 Elf64_Addr r_offset
; /* Location at which to apply the action */
377 Elf64_Word r_info
; /* index and type of relocation */
378 Elf64_Word r_addend
; /* Constant addend used to compute value */
381 typedef struct elf32_sym
{
385 unsigned char st_info
;
386 unsigned char st_other
;
390 typedef struct elf64_sym
{
391 Elf32_Word st_name
; /* Symbol name, index in string tbl (yes, Elf32) */
392 unsigned char st_info
; /* Type and binding attributes */
393 unsigned char st_other
; /* No defined meaning, 0 */
394 Elf64_Half st_shndx
; /* Associated section index */
395 Elf64_Addr st_value
; /* Value of the symbol */
396 Elf64_Word st_size
; /* Associated symbol size */
402 typedef struct elf32_hdr
{
403 unsigned char e_ident
[EI_NIDENT
];
405 Elf32_Half e_machine
;
406 Elf32_Word e_version
;
407 Elf32_Addr e_entry
; /* Entry point */
412 Elf32_Half e_phentsize
;
414 Elf32_Half e_shentsize
;
416 Elf32_Half e_shstrndx
;
419 typedef struct elf64_hdr
{
420 unsigned char e_ident
[16]; /* ELF "magic number" */
422 Elf64_Half e_machine
;
424 Elf64_Addr e_entry
; /* Entry point virtual address */
425 Elf64_Off e_phoff
; /* Program header table file offset */
426 Elf64_Off e_shoff
; /* Section header table file offset */
428 Elf64_SHalf e_ehsize
;
429 Elf64_SHalf e_phentsize
;
431 Elf64_SHalf e_shentsize
;
433 Elf64_SHalf e_shstrndx
;
436 /* These constants define the permissions on sections in the program
442 typedef struct elf32_phdr
{
453 typedef struct elf64_phdr
{
456 Elf64_Off p_offset
; /* Segment file offset */
457 Elf64_Addr p_vaddr
; /* Segment virtual address */
458 Elf64_Addr p_paddr
; /* Segment physical address */
459 Elf64_Word p_filesz
; /* Segment size in file */
460 Elf64_Word p_memsz
; /* Segment size in memory */
461 Elf64_Word p_align
; /* Segment alignment, file & memory */
466 #define SHT_PROGBITS 1
471 #define SHT_DYNAMIC 6
476 #define SHT_DYNSYM 11
478 #define SHT_LOPROC 0x70000000
479 #define SHT_HIPROC 0x7fffffff
480 #define SHT_LOUSER 0x80000000
481 #define SHT_HIUSER 0xffffffff
482 #define SHT_MIPS_LIST 0x70000000
483 #define SHT_MIPS_CONFLICT 0x70000002
484 #define SHT_MIPS_GPTAB 0x70000003
485 #define SHT_MIPS_UCODE 0x70000004
488 #define SHF_WRITE 0x1
489 #define SHF_ALLOC 0x2
490 #define SHF_EXECINSTR 0x4
491 #define SHF_MASKPROC 0xf0000000
492 #define SHF_MIPS_GPREL 0x10000000
494 /* special section indexes */
496 #define SHN_LORESERVE 0xff00
497 #define SHN_LOPROC 0xff00
498 #define SHN_HIPROC 0xff1f
499 #define SHN_ABS 0xfff1
500 #define SHN_COMMON 0xfff2
501 #define SHN_HIRESERVE 0xffff
502 #define SHN_MIPS_ACCOMON 0xff00
513 Elf32_Word sh_addralign
;
514 Elf32_Word sh_entsize
;
517 typedef struct elf64_shdr
{
518 Elf32_Word sh_name
; /* Section name, index in string tbl (yes Elf32) */
519 Elf32_Word sh_type
; /* Type of section (yes Elf32) */
520 Elf64_Word sh_flags
; /* Miscellaneous section attributes */
521 Elf64_Addr sh_addr
; /* Section virtual addr at execution */
522 Elf64_Off sh_offset
; /* Section file offset */
523 Elf64_Word sh_size
; /* Size of section in bytes */
524 Elf32_Word sh_link
; /* Index of another section (yes Elf32) */
525 Elf32_Word sh_info
; /* Additional section information (yes Elf32) */
526 Elf64_Word sh_addralign
; /* Section alignment */
527 Elf64_Word sh_entsize
; /* Entry size if section holds table */
530 #define EI_MAG0 0 /* e_ident[] indexes */
539 #define ELFMAG0 0x7f /* EI_MAG */
543 #define ELFMAG "\177ELF"
546 #define ELFCLASSNONE 0 /* EI_CLASS */
549 #define ELFCLASSNUM 3
551 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
552 #define ELFDATA2LSB 1
553 #define ELFDATA2MSB 2
555 #define EV_NONE 0 /* e_version, EI_VERSION */
559 /* Notes used in ET_CORE */
560 #define NT_PRSTATUS 1
562 #define NT_PRPSINFO 3
563 #define NT_TASKSTRUCT 4
565 /* Note header in a PT_NOTE section */
566 typedef struct elf32_note
{
567 Elf32_Word n_namesz
; /* Name size */
568 Elf32_Word n_descsz
; /* Content size */
569 Elf32_Word n_type
; /* Content type */
572 /* Note header in a PT_NOTE section */
574 * For now we use the 32 bit version of the structure until we figure
575 * out whether we need anything better. Note - on the Alpha, "unsigned int"
578 typedef struct elf64_note
{
579 Elf32_Word n_namesz
; /* Name size */
580 Elf32_Word n_descsz
; /* Content size */
581 Elf32_Word n_type
; /* Content type */
584 #if ELF_CLASS == ELFCLASS32
586 extern Elf32_Dyn _DYNAMIC
[];
587 #define elfhdr elf32_hdr
588 #define elf_phdr elf32_phdr
589 #define elf_note elf32_note
593 extern Elf64_Dyn _DYNAMIC
[];
594 #define elfhdr elf64_hdr
595 #define elf_phdr elf64_phdr
596 #define elf_note elf64_note
601 #endif /* _LINUX_ELF_H */