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
33 /* These constants define the different elf file types */
42 /* These constants define the various ELF target machines */
49 #define EM_486 6 /* Perhaps disused */
52 #define EM_MIPS 8 /* MIPS R3000 (officially, big-endian only) */
54 #define EM_MIPS_RS4_BE 10 /* MIPS R4000 big-endian */
56 #define EM_PARISC 15 /* HPPA */
58 #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
60 #define EM_PPC 20 /* PowerPC */
62 #define EM_SPARCV9 43 /* SPARC v9 64-bit */
65 * This is an interim value that we will use until the committee comes
66 * up with a final number.
68 #define EM_ALPHA 0x9026
71 /* This is the info that is needed to parse the dynamic section of the file */
88 #define DT_SYMBOLIC 16
96 #define DT_LOPROC 0x70000000
97 #define DT_HIPROC 0x7fffffff
99 /* This info is needed when parsing the symbol table */
107 #define STT_SECTION 3
110 #define ELF32_ST_BIND(x) ((x) >> 4)
111 #define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
113 /* Symbolic values for the entries in the auxiliary table
114 put on the initial stack */
115 #define AT_NULL 0 /* end of vector */
116 #define AT_IGNORE 1 /* entry should be ignored */
117 #define AT_EXECFD 2 /* file descriptor of program */
118 #define AT_PHDR 3 /* program headers for program */
119 #define AT_PHENT 4 /* size of program header entry */
120 #define AT_PHNUM 5 /* number of program headers */
121 #define AT_PAGESZ 6 /* system page size */
122 #define AT_BASE 7 /* base address of interpreter */
123 #define AT_FLAGS 8 /* flags */
124 #define AT_ENTRY 9 /* entry point of program */
125 #define AT_NOTELF 10 /* program is not ELF */
126 #define AT_UID 11 /* real uid */
127 #define AT_EUID 12 /* effective uid */
128 #define AT_GID 13 /* real gid */
129 #define AT_EGID 14 /* effective gid */
130 #define AT_PLATFORM 15 /* string identifying CPU for optimizations */
131 #define AT_HWCAP 16 /* arch dependent hints at CPU capabilities */
133 typedef struct dynamic
{
142 Elf64_Word d_tag
; /* entry tag value */
149 /* The following are used with relocations */
150 #define ELF32_R_SYM(x) ((x) >> 8)
151 #define ELF32_R_TYPE(x) ((x) & 0xff)
156 #define R_386_GOT32 3
157 #define R_386_PLT32 4
159 #define R_386_GLOB_DAT 6
160 #define R_386_JMP_SLOT 7
161 #define R_386_RELATIVE 8
162 #define R_386_GOTOFF 9
163 #define R_386_GOTPC 10
167 * Sparc ELF relocation types
169 #define R_SPARC_NONE 0
173 #define R_SPARC_DISP8 4
174 #define R_SPARC_DISP16 5
175 #define R_SPARC_DISP32 6
176 #define R_SPARC_WDISP30 7
177 #define R_SPARC_WDISP22 8
178 #define R_SPARC_HI22 9
179 #define R_SPARC_22 10
180 #define R_SPARC_13 11
181 #define R_SPARC_LO10 12
182 #define R_SPARC_GOT10 13
183 #define R_SPARC_GOT13 14
184 #define R_SPARC_GOT22 15
185 #define R_SPARC_PC10 16
186 #define R_SPARC_PC22 17
187 #define R_SPARC_WPLT30 18
188 #define R_SPARC_COPY 19
189 #define R_SPARC_GLOB_DAT 20
190 #define R_SPARC_JMP_SLOT 21
191 #define R_SPARC_RELATIVE 22
192 #define R_SPARC_UA32 23
193 #define R_SPARC_PLT32 24
194 #define R_SPARC_HIPLT22 25
195 #define R_SPARC_LOPLT10 26
196 #define R_SPARC_PCPLT32 27
197 #define R_SPARC_PCPLT22 28
198 #define R_SPARC_PCPLT10 29
199 #define R_SPARC_10 30
200 #define R_SPARC_11 31
201 #define R_SPARC_WDISP16 40
202 #define R_SPARC_WDISP19 41
207 /* Bits present in AT_HWCAP, primarily for Sparc32. */
209 #define HWCAP_SPARC_FLUSH 1 /* CPU supports flush instruction. */
210 #define HWCAP_SPARC_STBAR 2
211 #define HWCAP_SPARC_SWAP 4
212 #define HWCAP_SPARC_MULDIV 8
213 #define HWCAP_SPARC_V9 16
217 * 68k ELF relocation types
226 #define R_68K_GOT32 7
227 #define R_68K_GOT16 8
229 #define R_68K_GOT32O 10
230 #define R_68K_GOT16O 11
231 #define R_68K_GOT8O 12
232 #define R_68K_PLT32 13
233 #define R_68K_PLT16 14
234 #define R_68K_PLT8 15
235 #define R_68K_PLT32O 16
236 #define R_68K_PLT16O 17
237 #define R_68K_PLT8O 18
238 #define R_68K_COPY 19
239 #define R_68K_GLOB_DAT 20
240 #define R_68K_JMP_SLOT 21
241 #define R_68K_RELATIVE 22
244 * Alpha ELF relocation types
246 #define R_ALPHA_NONE 0 /* No reloc */
247 #define R_ALPHA_REFLONG 1 /* Direct 32 bit */
248 #define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
249 #define R_ALPHA_GPREL32 3 /* GP relative 32 bit */
250 #define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */
251 #define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */
252 #define R_ALPHA_GPDISP 6 /* Add displacement to GP */
253 #define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */
254 #define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */
255 #define R_ALPHA_SREL16 9 /* PC relative 16 bit */
256 #define R_ALPHA_SREL32 10 /* PC relative 32 bit */
257 #define R_ALPHA_SREL64 11 /* PC relative 64 bit */
258 #define R_ALPHA_OP_PUSH 12 /* OP stack push */
259 #define R_ALPHA_OP_STORE 13 /* OP stack pop and store */
260 #define R_ALPHA_OP_PSUB 14 /* OP stack subtract */
261 #define R_ALPHA_OP_PRSHIFT 15 /* OP stack right shift */
262 #define R_ALPHA_GPVALUE 16
263 #define R_ALPHA_GPRELHIGH 17
264 #define R_ALPHA_GPRELLOW 18
265 #define R_ALPHA_IMMED_GP_16 19
266 #define R_ALPHA_IMMED_GP_HI32 20
267 #define R_ALPHA_IMMED_SCN_HI32 21
268 #define R_ALPHA_IMMED_BR_HI32 22
269 #define R_ALPHA_IMMED_LO32 23
270 #define R_ALPHA_COPY 24 /* Copy symbol at runtime */
271 #define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
272 #define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
273 #define R_ALPHA_RELATIVE 27 /* Adjust by program base */
275 /* Legal values for e_flags field of Elf64_Ehdr. */
277 #define EF_ALPHA_32BIT 1 /* All addresses are below 2GB */
280 typedef struct elf32_rel
{
285 typedef struct elf64_rel
{
286 Elf64_Addr r_offset
; /* Location at which to apply the action */
287 Elf64_Word r_info
; /* index and type of relocation */
290 typedef struct elf32_rela
{
293 Elf32_Sword r_addend
;
296 typedef struct elf64_rela
{
297 Elf64_Addr r_offset
; /* Location at which to apply the action */
298 Elf64_Word r_info
; /* index and type of relocation */
299 Elf64_Word r_addend
; /* Constant addend used to compute value */
302 typedef struct elf32_sym
{
306 unsigned char st_info
;
307 unsigned char st_other
;
311 typedef struct elf64_sym
{
312 Elf32_Word st_name
; /* Symbol name, index in string tbl (yes, Elf32) */
313 unsigned char st_info
; /* Type and binding attributes */
314 unsigned char st_other
; /* No defined meaning, 0 */
315 Elf64_Half st_shndx
; /* Associated section index */
316 Elf64_Addr st_value
; /* Value of the symbol */
317 Elf64_Word st_size
; /* Associated symbol size */
323 typedef struct elf32_hdr
{
324 unsigned char e_ident
[EI_NIDENT
];
326 Elf32_Half e_machine
;
327 Elf32_Word e_version
;
328 Elf32_Addr e_entry
; /* Entry point */
333 Elf32_Half e_phentsize
;
335 Elf32_Half e_shentsize
;
337 Elf32_Half e_shstrndx
;
340 typedef struct elf64_hdr
{
341 unsigned char e_ident
[16]; /* ELF "magic number" */
343 Elf64_Half e_machine
;
345 Elf64_Addr e_entry
; /* Entry point virtual address */
346 Elf64_Off e_phoff
; /* Program header table file offset */
347 Elf64_Off e_shoff
; /* Section header table file offset */
349 Elf64_SHalf e_ehsize
;
350 Elf64_SHalf e_phentsize
;
352 Elf64_SHalf e_shentsize
;
354 Elf64_SHalf e_shstrndx
;
357 /* These constants define the permissions on sections in the program
363 typedef struct elf32_phdr
{
374 typedef struct elf64_phdr
{
377 Elf64_Off p_offset
; /* Segment file offset */
378 Elf64_Addr p_vaddr
; /* Segment virtual address */
379 Elf64_Addr p_paddr
; /* Segment physical address */
380 Elf64_Word p_filesz
; /* Segment size in file */
381 Elf64_Word p_memsz
; /* Segment size in memory */
382 Elf64_Word p_align
; /* Segment alignment, file & memory */
387 #define SHT_PROGBITS 1
392 #define SHT_DYNAMIC 6
397 #define SHT_DYNSYM 11
399 #define SHT_LOPROC 0x70000000
400 #define SHT_HIPROC 0x7fffffff
401 #define SHT_LOUSER 0x80000000
402 #define SHT_HIUSER 0xffffffff
405 #define SHF_WRITE 0x1
406 #define SHF_ALLOC 0x2
407 #define SHF_EXECINSTR 0x4
408 #define SHF_MASKPROC 0xf0000000
410 /* special section indexes */
412 #define SHN_LORESERVE 0xff00
413 #define SHN_LOPROC 0xff00
414 #define SHN_HIPROC 0xff1f
415 #define SHN_ABS 0xfff1
416 #define SHN_COMMON 0xfff2
417 #define SHN_HIRESERVE 0xffff
428 Elf32_Word sh_addralign
;
429 Elf32_Word sh_entsize
;
432 typedef struct elf64_shdr
{
433 Elf32_Word sh_name
; /* Section name, index in string tbl (yes Elf32) */
434 Elf32_Word sh_type
; /* Type of section (yes Elf32) */
435 Elf64_Word sh_flags
; /* Miscellaneous section attributes */
436 Elf64_Addr sh_addr
; /* Section virtual addr at execution */
437 Elf64_Off sh_offset
; /* Section file offset */
438 Elf64_Word sh_size
; /* Size of section in bytes */
439 Elf32_Word sh_link
; /* Index of another section (yes Elf32) */
440 Elf32_Word sh_info
; /* Additional section information (yes Elf32) */
441 Elf64_Word sh_addralign
; /* Section alignment */
442 Elf64_Word sh_entsize
; /* Entry size if section holds table */
445 #define EI_MAG0 0 /* e_ident[] indexes */
454 #define ELFMAG0 0x7f /* EI_MAG */
458 #define ELFMAG "\177ELF"
461 #define ELFCLASSNONE 0 /* EI_CLASS */
464 #define ELFCLASSNUM 3
466 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
467 #define ELFDATA2LSB 1
468 #define ELFDATA2MSB 2
470 #define EV_NONE 0 /* e_version, EI_VERSION */
474 /* Notes used in ET_CORE */
475 #define NT_PRSTATUS 1
477 #define NT_PRPSINFO 3
478 #define NT_TASKSTRUCT 4
480 /* Note header in a PT_NOTE section */
481 typedef struct elf32_note
{
482 Elf32_Word n_namesz
; /* Name size */
483 Elf32_Word n_descsz
; /* Content size */
484 Elf32_Word n_type
; /* Content type */
487 /* Note header in a PT_NOTE section */
489 * For now we use the 32 bit version of the structure until we figure
490 * out whether we need anything better. Note - on the Alpha, "unsigned int"
493 typedef struct elf64_note
{
494 Elf32_Word n_namesz
; /* Name size */
495 Elf32_Word n_descsz
; /* Content size */
496 Elf32_Word n_type
; /* Content type */
499 #if ELF_CLASS == ELFCLASS32
501 extern Elf32_Dyn _DYNAMIC
[];
502 #define elfhdr elf32_hdr
503 #define elf_phdr elf32_phdr
504 #define elf_note elf32_note
508 extern Elf64_Dyn _DYNAMIC
[];
509 #define elfhdr elf64_hdr
510 #define elf_phdr elf64_phdr
511 #define elf_note elf64_note
516 #endif /* _LINUX_ELF_H */