FreeBSD/Linux Kernel Cross Reference
sys/sys/exec_elf.h
1 /* $NetBSD: exec_elf.h,v 1.89.2.1 2007/07/09 10:30:55 liamjfoy Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _SYS_EXEC_ELF_H_
40 #define _SYS_EXEC_ELF_H_
41
42 /*
43 * The current ELF ABI specification is available at:
44 * http://www.sco.com/developers/gabi/
45 *
46 * Current header definitions are in:
47 * http://www.sco.com/developers/gabi/latest/ch4.eheader.html
48 */
49
50 #if defined(_KERNEL) || defined(_STANDALONE)
51 #include <sys/types.h>
52 #else
53 #include <inttypes.h>
54 #endif /* _KERNEL || _STANDALONE */
55
56 #if defined(ELFSIZE)
57 #define CONCAT(x,y) __CONCAT(x,y)
58 #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
59 #define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
60 #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
61 #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
62 #endif
63
64 #if HAVE_NBTOOL_CONFIG_H
65 #include <nbinclude/machine/elf_machdep.h>
66 #else
67 #include <machine/elf_machdep.h>
68 #endif
69
70 typedef uint8_t Elf_Byte;
71
72 typedef uint32_t Elf32_Addr;
73 #define ELF32_FSZ_ADDR 4
74 typedef uint32_t Elf32_Off;
75 #define ELF32_FSZ_OFF 4
76 typedef int32_t Elf32_Sword;
77 #define ELF32_FSZ_SWORD 4
78 typedef uint32_t Elf32_Word;
79 #define ELF32_FSZ_WORD 4
80 typedef uint16_t Elf32_Half;
81 #define ELF32_FSZ_HALF 2
82
83 typedef uint64_t Elf64_Addr;
84 #define ELF64_FSZ_ADDR 8
85 typedef uint64_t Elf64_Off;
86 #define ELF64_FSZ_OFF 8
87 typedef int32_t Elf64_Shalf;
88 #define ELF64_FSZ_SHALF 4
89
90 #ifndef ELF64_FSZ_SWORD
91 typedef int32_t Elf64_Sword;
92 #define ELF64_FSZ_SWORD 4
93 #endif /* ELF64_FSZ_SWORD */
94 #ifndef ELF64_FSZ_WORD
95 typedef uint32_t Elf64_Word;
96 #define ELF64_FSZ_WORD 4
97 #endif /* ELF64_FSZ_WORD */
98
99 typedef int64_t Elf64_Sxword;
100 #define ELF64_FSZ_XWORD 8
101 typedef uint64_t Elf64_Xword;
102 #define ELF64_FSZ_XWORD 8
103 typedef uint32_t Elf64_Half;
104 #define ELF64_FSZ_HALF 4
105 typedef uint16_t Elf64_Quarter;
106 #define ELF64_FSZ_QUARTER 2
107
108 /*
109 * ELF Header
110 */
111 #define ELF_NIDENT 16
112
113 typedef struct {
114 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
115 Elf32_Half e_type; /* file type */
116 Elf32_Half e_machine; /* machine type */
117 Elf32_Word e_version; /* version number */
118 Elf32_Addr e_entry; /* entry point */
119 Elf32_Off e_phoff; /* Program hdr offset */
120 Elf32_Off e_shoff; /* Section hdr offset */
121 Elf32_Word e_flags; /* Processor flags */
122 Elf32_Half e_ehsize; /* sizeof ehdr */
123 Elf32_Half e_phentsize; /* Program header entry size */
124 Elf32_Half e_phnum; /* Number of program headers */
125 Elf32_Half e_shentsize; /* Section header entry size */
126 Elf32_Half e_shnum; /* Number of section headers */
127 Elf32_Half e_shstrndx; /* String table index */
128 } Elf32_Ehdr;
129
130 typedef struct {
131 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
132 Elf64_Quarter e_type; /* file type */
133 Elf64_Quarter e_machine; /* machine type */
134 Elf64_Half e_version; /* version number */
135 Elf64_Addr e_entry; /* entry point */
136 Elf64_Off e_phoff; /* Program hdr offset */
137 Elf64_Off e_shoff; /* Section hdr offset */
138 Elf64_Half e_flags; /* Processor flags */
139 Elf64_Quarter e_ehsize; /* sizeof ehdr */
140 Elf64_Quarter e_phentsize; /* Program header entry size */
141 Elf64_Quarter e_phnum; /* Number of program headers */
142 Elf64_Quarter e_shentsize; /* Section header entry size */
143 Elf64_Quarter e_shnum; /* Number of section headers */
144 Elf64_Quarter e_shstrndx; /* String table index */
145 } Elf64_Ehdr;
146
147 /* e_ident offsets */
148 #define EI_MAG0 0 /* '\177' */
149 #define EI_MAG1 1 /* 'E' */
150 #define EI_MAG2 2 /* 'L' */
151 #define EI_MAG3 3 /* 'F' */
152 #define EI_CLASS 4 /* File class */
153 #define EI_DATA 5 /* Data encoding */
154 #define EI_VERSION 6 /* File version */
155 #define EI_OSABI 7 /* Operating system/ABI identification */
156 #define EI_ABIVERSION 8 /* ABI version */
157 #define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
158 #define EI_NIDENT 16 /* First non-ident header byte */
159
160 /* e_ident[EI_MAG0,EI_MAG3] */
161 #define ELFMAG0 0x7f
162 #define ELFMAG1 'E'
163 #define ELFMAG2 'L'
164 #define ELFMAG3 'F'
165 #define ELFMAG "\177ELF"
166 #define SELFMAG 4
167
168 /* e_ident[EI_CLASS] */
169 #define ELFCLASSNONE 0 /* Invalid class */
170 #define ELFCLASS32 1 /* 32-bit objects */
171 #define ELFCLASS64 2 /* 64-bit objects */
172 #define ELFCLASSNUM 3
173
174 /* e_ident[EI_DATA] */
175 #define ELFDATANONE 0 /* Invalid data encoding */
176 #define ELFDATA2LSB 1 /* 2's complement values, LSB first */
177 #define ELFDATA2MSB 2 /* 2's complement values, MSB first */
178
179 /* e_ident[EI_VERSION] */
180 #define EV_NONE 0 /* Invalid version */
181 #define EV_CURRENT 1 /* Current version */
182 #define EV_NUM 2
183
184 /* e_ident[EI_OSABI] */
185 #define ELFOSABI_SYSV 0 /* UNIX System V ABI */
186 #define ELFOSABI_HPUX 1 /* HP-UX operating system */
187 #define ELFOSABI_NETBSD 2 /* NetBSD */
188 #define ELFOSABI_LINUX 3 /* GNU/Linux */
189 #define ELFOSABI_HURD 4 /* GNU/Hurd */
190 #define ELFOSABI_86OPEN 5 /* 86Open */
191 #define ELFOSABI_SOLARIS 6 /* Solaris */
192 #define ELFOSABI_MONTEREY 7 /* Monterey */
193 #define ELFOSABI_IRIX 8 /* IRIX */
194 #define ELFOSABI_FREEBSD 9 /* FreeBSD */
195 #define ELFOSABI_TRU64 10 /* TRU64 UNIX */
196 #define ELFOSABI_MODESTO 11 /* Novell Modesto */
197 #define ELFOSABI_OPENBSD 12 /* OpenBSD */
198 /* Unofficial OSABIs follow */
199 #define ELFOSABI_ARM 97 /* ARM */
200 #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
201
202 /* e_type */
203 #define ET_NONE 0 /* No file type */
204 #define ET_REL 1 /* Relocatable file */
205 #define ET_EXEC 2 /* Executable file */
206 #define ET_DYN 3 /* Shared object file */
207 #define ET_CORE 4 /* Core file */
208 #define ET_NUM 5
209
210 #define ET_LOOS 0xfe00 /* Operating system specific range */
211 #define ET_HIOS 0xfeff
212 #define ET_LOPROC 0xff00 /* Processor-specific range */
213 #define ET_HIPROC 0xffff
214
215 /* e_machine */
216 #define EM_NONE 0 /* No machine */
217 #define EM_M32 1 /* AT&T WE 32100 */
218 #define EM_SPARC 2 /* SPARC */
219 #define EM_386 3 /* Intel 80386 */
220 #define EM_68K 4 /* Motorola 68000 */
221 #define EM_88K 5 /* Motorola 88000 */
222 #define EM_486 6 /* Intel 80486 */
223 #define EM_860 7 /* Intel 80860 */
224 #define EM_MIPS 8 /* MIPS I Architecture */
225 #define EM_S370 9 /* Amdahl UTS on System/370 */
226 #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
227 /* 11-14 - Reserved */
228 #define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
229 #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
230 #define EM_NCUBE 16 /* NCube XXX reserved */
231 #define EM_VPP500 17 /* Fujitsu VPP500 */
232 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
233 #define EM_960 19 /* Intel 80960 */
234 #define EM_PPC 20 /* PowerPC */
235 #define EM_PPC64 21 /* 64-bit PowerPC */
236 /* 22-35 - Reserved */
237 #define EM_V800 36 /* NEC V800 */
238 #define EM_FR20 37 /* Fujitsu FR20 */
239 #define EM_RH32 38 /* TRW RH-32 */
240 #define EM_RCE 39 /* Motorola RCE */
241 #define EM_ARM 40 /* Advanced RISC Machines ARM */
242 #define EM_ALPHA 41 /* DIGITAL Alpha */
243 #define EM_SH 42 /* Hitachi Super-H */
244 #define EM_SPARCV9 43 /* SPARC Version 9 */
245 #define EM_TRICORE 44 /* Siemens Tricore */
246 #define EM_ARC 45 /* Argonaut RISC Core */
247 #define EM_H8_300 46 /* Hitachi H8/300 */
248 #define EM_H8_300H 47 /* Hitachi H8/300H */
249 #define EM_H8S 48 /* Hitachi H8S */
250 #define EM_H8_500 49 /* Hitachi H8/500 */
251 #define EM_IA_64 50 /* Intel Merced Processor */
252 #define EM_MIPS_X 51 /* Stanford MIPS-X */
253 #define EM_COLDFIRE 52 /* Motorola Coldfire */
254 #define EM_68HC12 53 /* Motorola MC68HC12 */
255 #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
256 #define EM_PCP 55 /* Siemens PCP */
257 #define EM_NCPU 56 /* Sony nCPU embedded RISC processor */
258 #define EM_NDR1 57 /* Denso NDR1 microprocessor */
259 #define EM_STARCORE 58 /* Motorola Star*Core processor */
260 #define EM_ME16 59 /* Toyota ME16 processor */
261 #define EM_ST100 60 /* STMicroelectronics ST100 processor */
262 #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded family processor */
263 #define EM_X86_64 62 /* AMD x86-64 architecture */
264 #define EM_PDSP 63 /* Sony DSP Processor */
265 #define EM_PDP10 64 /* Digital Equipment Corp. PDP-10 */
266 #define EM_PDP11 65 /* Digital Equipment Corp. PDP-11 */
267 #define EM_FX66 66 /* Siemens FX66 microcontroller */
268 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */
269 #define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */
270 #define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */
271 #define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */
272 #define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */
273 #define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */
274 #define EM_SVX 73 /* Silicon Graphics SVx */
275 #define EM_ST19 74 /* STMicroelectronics ST19 8-bit CPU */
276 #define EM_VAX 75 /* Digital VAX */
277 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
278 #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded CPU */
279 #define EM_FIREPATH 78 /* Element 14 64-bit DSP processor */
280 #define EM_ZSP 79 /* LSI Logic's 16-bit DSP processor */
281 #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
282 #define EM_HUANY 81 /* Harvard's machine-independent format */
283 #define EM_PRISM 82 /* SiTera Prism */
284 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
285 #define EM_FR30 84 /* Fujitsu FR30 */
286 #define EM_D10V 85 /* Mitsubishi D10V */
287 #define EM_D30V 86 /* Mitsubishi D30V */
288 #define EM_V850 87 /* NEC v850 */
289 #define EM_M32R 88 /* Mitsubishi M32R */
290 #define EM_MN10300 89 /* Matsushita MN10300 */
291 #define EM_MN10200 90 /* Matsushita MN10200 */
292 #define EM_PJ 91 /* picoJava */
293 #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
294 #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
295 #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
296 #define EM_NS32K 97 /* National Semiconductor 32000 series */
297
298 /* Unofficial machine types follow */
299 #define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
300 #define EM_NUM 36903
301
302 /*
303 * Program Header
304 */
305 typedef struct {
306 Elf32_Word p_type; /* entry type */
307 Elf32_Off p_offset; /* offset */
308 Elf32_Addr p_vaddr; /* virtual address */
309 Elf32_Addr p_paddr; /* physical address */
310 Elf32_Word p_filesz; /* file size */
311 Elf32_Word p_memsz; /* memory size */
312 Elf32_Word p_flags; /* flags */
313 Elf32_Word p_align; /* memory & file alignment */
314 } Elf32_Phdr;
315
316 typedef struct {
317 Elf64_Half p_type; /* entry type */
318 Elf64_Half p_flags; /* flags */
319 Elf64_Off p_offset; /* offset */
320 Elf64_Addr p_vaddr; /* virtual address */
321 Elf64_Addr p_paddr; /* physical address */
322 Elf64_Xword p_filesz; /* file size */
323 Elf64_Xword p_memsz; /* memory size */
324 Elf64_Xword p_align; /* memory & file alignment */
325 } Elf64_Phdr;
326
327 /* p_type */
328 #define PT_NULL 0 /* Program header table entry unused */
329 #define PT_LOAD 1 /* Loadable program segment */
330 #define PT_DYNAMIC 2 /* Dynamic linking information */
331 #define PT_INTERP 3 /* Program interpreter */
332 #define PT_NOTE 4 /* Auxiliary information */
333 #define PT_SHLIB 5 /* Reserved, unspecified semantics */
334 #define PT_PHDR 6 /* Entry for header table itself */
335 #define PT_NUM 7
336
337 #define PT_LOOS 0x60000000 /* OS-specific range */
338 #define PT_HIOS 0x6fffffff
339 #define PT_LOPROC 0x70000000 /* Processor-specific range */
340 #define PT_HIPROC 0x7fffffff
341
342 #define PT_MIPS_REGINFO 0x70000000
343
344 /* p_flags */
345 #define PF_R 0x4 /* Segment is readable */
346 #define PF_W 0x2 /* Segment is writable */
347 #define PF_X 0x1 /* Segment is executable */
348
349 #define PF_MASKOS 0x0ff00000 /* Operating system specific values */
350 #define PF_MASKPROC 0xf0000000 /* Processor-specific values */
351
352 /*
353 * Section Headers
354 */
355 typedef struct {
356 Elf32_Word sh_name; /* section name (.shstrtab index) */
357 Elf32_Word sh_type; /* section type */
358 Elf32_Word sh_flags; /* section flags */
359 Elf32_Addr sh_addr; /* virtual address */
360 Elf32_Off sh_offset; /* file offset */
361 Elf32_Word sh_size; /* section size */
362 Elf32_Word sh_link; /* link to another */
363 Elf32_Word sh_info; /* misc info */
364 Elf32_Word sh_addralign; /* memory alignment */
365 Elf32_Word sh_entsize; /* table entry size */
366 } Elf32_Shdr;
367
368 typedef struct {
369 Elf64_Half sh_name; /* section name (.shstrtab index) */
370 Elf64_Half sh_type; /* section type */
371 Elf64_Xword sh_flags; /* section flags */
372 Elf64_Addr sh_addr; /* virtual address */
373 Elf64_Off sh_offset; /* file offset */
374 Elf64_Xword sh_size; /* section size */
375 Elf64_Half sh_link; /* link to another */
376 Elf64_Half sh_info; /* misc info */
377 Elf64_Xword sh_addralign; /* memory alignment */
378 Elf64_Xword sh_entsize; /* table entry size */
379 } Elf64_Shdr;
380
381 /* sh_type */
382 #define SHT_NULL 0 /* Section header table entry unused */
383 #define SHT_PROGBITS 1 /* Program information */
384 #define SHT_SYMTAB 2 /* Symbol table */
385 #define SHT_STRTAB 3 /* String table */
386 #define SHT_RELA 4 /* Relocation information w/ addend */
387 #define SHT_HASH 5 /* Symbol hash table */
388 #define SHT_DYNAMIC 6 /* Dynamic linking information */
389 #define SHT_NOTE 7 /* Auxiliary information */
390 #define SHT_NOBITS 8 /* No space allocated in file image */
391 #define SHT_REL 9 /* Relocation information w/o addend */
392 #define SHT_SHLIB 10 /* Reserved, unspecified semantics */
393 #define SHT_DYNSYM 11 /* Symbol table for dynamic linker */
394 #define SHT_NUM 12
395
396 #define SHT_LOOS 0x60000000 /* Operating system specific range */
397 #define SHT_SUNW_VERDEF 0x6ffffffd /* Versions defined by file */
398 #define SHT_SUNW_VERNEED 0x6ffffffe /* Versions needed by file */
399 #define SHT_SUNW_VERSYM 0x6fffffff /* Symbol versions */
400 #define SHT_HIOS 0x6fffffff
401 #define SHT_LOPROC 0x70000000 /* Processor-specific range */
402 #define SHT_HIPROC 0x7fffffff
403 #define SHT_LOUSER 0x80000000 /* Application-specific range */
404 #define SHT_HIUSER 0xffffffff
405
406 /* sh_flags */
407 #define SHF_WRITE 0x1 /* Section contains writable data */
408 #define SHF_ALLOC 0x2 /* Section occupies memory */
409 #define SHF_EXECINSTR 0x4 /* Section contains executable insns */
410
411 #define SHF_MASKOS 0x0f000000 /* Operating system specific values */
412 #define SHF_MASKPROC 0xf0000000 /* Processor-specific values */
413
414 /*
415 * Symbol Table
416 */
417 typedef struct {
418 Elf32_Word st_name; /* Symbol name (.symtab index) */
419 Elf32_Word st_value; /* value of symbol */
420 Elf32_Word st_size; /* size of symbol */
421 Elf_Byte st_info; /* type / binding attrs */
422 Elf_Byte st_other; /* unused */
423 Elf32_Half st_shndx; /* section index of symbol */
424 } Elf32_Sym;
425
426 typedef struct {
427 Elf64_Half st_name; /* Symbol name (.symtab index) */
428 Elf_Byte st_info; /* type / binding attrs */
429 Elf_Byte st_other; /* unused */
430 Elf64_Quarter st_shndx; /* section index of symbol */
431 Elf64_Addr st_value; /* value of symbol */
432 Elf64_Xword st_size; /* size of symbol */
433 } Elf64_Sym;
434
435 /* Symbol Table index of the undefined symbol */
436 #define ELF_SYM_UNDEFINED 0
437
438 #define STN_UNDEF 0 /* undefined index */
439
440 /* st_info: Symbol Bindings */
441 #define STB_LOCAL 0 /* local symbol */
442 #define STB_GLOBAL 1 /* global symbol */
443 #define STB_WEAK 2 /* weakly defined global symbol */
444 #define STB_NUM 3
445
446 #define STB_LOOS 10 /* Operating system specific range */
447 #define STB_HIOS 12
448 #define STB_LOPROC 13 /* Processor-specific range */
449 #define STB_HIPROC 15
450
451 /* st_info: Symbol Types */
452 #define STT_NOTYPE 0 /* Type not specified */
453 #define STT_OBJECT 1 /* Associated with a data object */
454 #define STT_FUNC 2 /* Associated with a function */
455 #define STT_SECTION 3 /* Associated with a section */
456 #define STT_FILE 4 /* Associated with a file name */
457 #define STT_NUM 5
458
459 #define STT_LOOS 10 /* Operating system specific range */
460 #define STT_HIOS 12
461 #define STT_LOPROC 13 /* Processor-specific range */
462 #define STT_HIPROC 15
463
464 /* st_other: Visibility Types */
465 #define STV_DEFAULT 0 /* use binding type */
466 #define STV_INTERNAL 1 /* not referenced from outside */
467 #define STV_HIDDEN 2 /* not visible, may be used via ptr */
468 #define STV_PROTECTED 3 /* visible, not preemptible */
469
470 /* st_info/st_other utility macros */
471 #define ELF_ST_BIND(info) ((uint32_t)(info) >> 4)
472 #define ELF_ST_TYPE(info) ((uint32_t)(info) & 0xf)
473 #define ELF_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | \
474 ((type) & 0xf)))
475 #define ELF_ST_VISIBILITY(other) ((uint32_t)(other) & 3)
476
477 /*
478 * Special section indexes
479 */
480 #define SHN_UNDEF 0 /* Undefined section */
481
482 #define SHN_LORESERVE 0xff00 /* Reserved range */
483 #define SHN_ABS 0xfff1 /* Absolute symbols */
484 #define SHN_COMMON 0xfff2 /* Common symbols */
485 #define SHN_HIRESERVE 0xffff
486
487 #define SHN_LOPROC 0xff00 /* Processor-specific range */
488 #define SHN_HIPROC 0xff1f
489 #define SHN_LOOS 0xff20 /* Operating system specific range */
490 #define SHN_HIOS 0xff3f
491
492 #define SHN_MIPS_ACOMMON 0xff00
493 #define SHN_MIPS_TEXT 0xff01
494 #define SHN_MIPS_DATA 0xff02
495 #define SHN_MIPS_SCOMMON 0xff03
496
497 /*
498 * Relocation Entries
499 */
500 typedef struct {
501 Elf32_Word r_offset; /* where to do it */
502 Elf32_Word r_info; /* index & type of relocation */
503 } Elf32_Rel;
504
505 typedef struct {
506 Elf32_Word r_offset; /* where to do it */
507 Elf32_Word r_info; /* index & type of relocation */
508 Elf32_Sword r_addend; /* adjustment value */
509 } Elf32_Rela;
510
511 /* r_info utility macros */
512 #define ELF32_R_SYM(info) ((info) >> 8)
513 #define ELF32_R_TYPE(info) ((info) & 0xff)
514 #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
515
516 typedef struct {
517 Elf64_Addr r_offset; /* where to do it */
518 Elf64_Xword r_info; /* index & type of relocation */
519 } Elf64_Rel;
520
521 typedef struct {
522 Elf64_Addr r_offset; /* where to do it */
523 Elf64_Xword r_info; /* index & type of relocation */
524 Elf64_Sxword r_addend; /* adjustment value */
525 } Elf64_Rela;
526
527 /* r_info utility macros */
528 #define ELF64_R_SYM(info) ((info) >> 32)
529 #define ELF64_R_TYPE(info) ((info) & 0xffffffff)
530 #define ELF64_R_INFO(sym,type) (((sym) << 32) + (type))
531
532 /*
533 * Dynamic Section structure array
534 */
535 typedef struct {
536 Elf32_Word d_tag; /* entry tag value */
537 union {
538 Elf32_Addr d_ptr;
539 Elf32_Word d_val;
540 } d_un;
541 } Elf32_Dyn;
542
543 typedef struct {
544 Elf64_Xword d_tag; /* entry tag value */
545 union {
546 Elf64_Addr d_ptr;
547 Elf64_Xword d_val;
548 } d_un;
549 } Elf64_Dyn;
550
551 /* d_tag */
552 #define DT_NULL 0 /* Marks end of dynamic array */
553 #define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
554 #define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
555 #define DT_PLTGOT 3 /* Address of PLT and/or GOT */
556 #define DT_HASH 4 /* Address of symbol hash table */
557 #define DT_STRTAB 5 /* Address of string table */
558 #define DT_SYMTAB 6 /* Address of symbol table */
559 #define DT_RELA 7 /* Address of Rela relocation table */
560 #define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
561 #define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
562 #define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
563 #define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
564 #define DT_INIT 12 /* Address of initialization function */
565 #define DT_FINI 13 /* Address of termination function */
566 #define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
567 #define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
568 #define DT_SYMBOLIC 16 /* Start symbol search within local object */
569 #define DT_REL 17 /* Address of Rel relocation table */
570 #define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
571 #define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
572 #define DT_PLTREL 20 /* Type of PLT relocation entries */
573 #define DT_DEBUG 21 /* Used for debugging; unspecified */
574 #define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
575 #define DT_JMPREL 23 /* Address of relocations associated with PLT */
576 #define DT_BIND_NOW 24 /* Process all relocations at load-time */
577 #define DT_INIT_ARRAY 25 /* Address of initialization function array */
578 #define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
579 #define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
580 #define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
581 #define DT_NUM 29
582
583 #define DT_LOOS 0x60000000 /* Operating system specific range */
584 #define DT_VERSYM 0x6ffffff0 /* Symbol versions */
585 #define DT_VERDEF 0x6ffffffc /* Versions defined by file */
586 #define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
587 #define DT_VERNEED 0x6ffffffe /* Versions needed by file */
588 #define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
589 #define DT_HIOS 0x6fffffff
590 #define DT_LOPROC 0x70000000 /* Processor-specific range */
591 #define DT_HIPROC 0x7fffffff
592
593 /*
594 * Auxiliary Vectors
595 */
596 typedef struct {
597 Elf32_Word a_type; /* 32-bit id */
598 Elf32_Word a_v; /* 32-bit id */
599 } Aux32Info;
600
601 typedef struct {
602 Elf64_Half a_type; /* 32-bit id */
603 Elf64_Xword a_v; /* 64-bit id */
604 } Aux64Info;
605
606 /* a_type */
607 #define AT_NULL 0 /* Marks end of array */
608 #define AT_IGNORE 1 /* No meaning, a_un is undefined */
609 #define AT_EXECFD 2 /* Open file descriptor of object file */
610 #define AT_PHDR 3 /* &phdr[0] */
611 #define AT_PHENT 4 /* sizeof(phdr[0]) */
612 #define AT_PHNUM 5 /* # phdr entries */
613 #define AT_PAGESZ 6 /* PAGESIZE */
614 #define AT_BASE 7 /* Interpreter base addr */
615 #define AT_FLAGS 8 /* Processor flags */
616 #define AT_ENTRY 9 /* Entry address of executable */
617 #define AT_DCACHEBSIZE 10 /* Data cache block size */
618 #define AT_ICACHEBSIZE 11 /* Instruction cache block size */
619 #define AT_UCACHEBSIZE 12 /* Unified cache block size */
620
621 /* Vendor specific */
622 #define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */
623
624 #define AT_EUID 2000 /* euid (solaris compatible numbers) */
625 #define AT_RUID 2001 /* ruid (solaris compatible numbers) */
626 #define AT_EGID 2002 /* egid (solaris compatible numbers) */
627 #define AT_RGID 2003 /* rgid (solaris compatible numbers) */
628
629 /* Solaris kernel specific */
630 #define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */
631 #define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */
632 #define AT_SUN_LDNAME 2006 /* dynamic linker's name */
633 #define AT_SUN_LPGSIZE 2007 /* large pagesize */
634
635 /* Other information */
636 #define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */
637 #define AT_SUN_HWCAP 2009 /* process hardware capabilities */
638 #define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */
639 #define AT_SUN_CPU 2011 /* CPU name */
640 /* ibcs2 emulation band aid */
641 #define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */
642 #define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
643 /* Executable's fully resolved name */
644 #define AT_SUN_EXECNAME 2014
645
646 /*
647 * Note Headers
648 */
649 typedef struct {
650 Elf32_Word n_namesz;
651 Elf32_Word n_descsz;
652 Elf32_Word n_type;
653 } Elf32_Nhdr;
654
655 typedef struct {
656 Elf64_Half n_namesz;
657 Elf64_Half n_descsz;
658 Elf64_Half n_type;
659 } Elf64_Nhdr;
660
661 #define ELF_NOTE_TYPE_ABI_TAG 1
662
663 /* GNU-specific note name and description sizes */
664 #define ELF_NOTE_ABI_NAMESZ 4
665 #define ELF_NOTE_ABI_DESCSZ 16
666 /* GNU-specific note name */
667 #define ELF_NOTE_ABI_NAME "GNU\0"
668
669 /* GNU-specific OS/version value stuff */
670 #define ELF_NOTE_ABI_OS_LINUX 0
671 #define ELF_NOTE_ABI_OS_HURD 1
672 #define ELF_NOTE_ABI_OS_SOLARIS 2
673
674 /* NetBSD-specific note type: Emulation name. desc is emul name string. */
675 #define ELF_NOTE_TYPE_NETBSD_TAG 1
676 /* NetBSD-specific note name and description sizes */
677 #define ELF_NOTE_NETBSD_NAMESZ 7
678 #define ELF_NOTE_NETBSD_DESCSZ 4
679 /* NetBSD-specific note name */
680 #define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
681
682 /* NetBSD-specific note type: Checksum. There should be 1 NOTE per PT_LOAD
683 section. desc is a tuple of <phnum>(16),<chk-type>(16),<chk-value>. */
684 #define ELF_NOTE_TYPE_CHECKSUM_TAG 2
685 #define ELF_NOTE_CHECKSUM_CRC32 1
686 #define ELF_NOTE_CHECKSUM_MD5 2
687 #define ELF_NOTE_CHECKSUM_SHA1 3
688 #define ELF_NOTE_CHECKSUM_SHA256 4
689
690 /* NetBSD-specific note type: PaX. There should be 1 NOTE per executable.
691 section. desc is a 32 bit bitmask */
692 #define ELF_NOTE_TYPE_PAX_TAG 3
693 #define ELF_NOTE_PAX_MPROTECT 0x1 /* Force enable Mprotect */
694 #define ELF_NOTE_PAX_NOMPROTECT 0x2 /* Force disable Mprotect */
695 #define ELF_NOTE_PAX_GUARD 0x4 /* Force enable Segvguard */
696 #define ELF_NOTE_PAX_NOGUARD 0x8 /* Force disable Servguard */
697 #define ELF_NOTE_PAX_NAMESZ 4
698 #define ELF_NOTE_PAX_NAME "PaX\0"
699 #define ELF_NOTE_PAX_DESCSZ 4
700
701 /*
702 * NetBSD-specific core file information.
703 *
704 * NetBSD ELF core files use notes to provide information about
705 * the process's state. The note name is "NetBSD-CORE" for
706 * information that is global to the process, and "NetBSD-CORE@nn",
707 * where "nn" is the lwpid of the LWP that the information belongs
708 * to (such as register state).
709 *
710 * We use the following note identifiers:
711 *
712 * ELF_NOTE_NETBSD_CORE_PROCINFO
713 * Note is a "netbsd_elfcore_procinfo" structure.
714 *
715 * We also use ptrace(2) request numbers (the ones that exist in
716 * machine-dependent space) to identify register info notes. The
717 * info in such notes is in the same format that ptrace(2) would
718 * export that information.
719 *
720 * Please try to keep the members of this structure nicely aligned,
721 * and if you add elements, add them to the end and bump the version.
722 */
723
724 #define ELF_NOTE_NETBSD_CORE_NAME "NetBSD-CORE"
725
726 #define ELF_NOTE_NETBSD_CORE_PROCINFO 1
727
728 #define NETBSD_ELFCORE_PROCINFO_VERSION 1
729
730 struct netbsd_elfcore_procinfo {
731 /* Version 1 fields start here. */
732 uint32_t cpi_version; /* netbsd_elfcore_procinfo version */
733 uint32_t cpi_cpisize; /* sizeof(netbsd_elfcore_procinfo) */
734 uint32_t cpi_signo; /* killing signal */
735 uint32_t cpi_sigcode; /* signal code */
736 uint32_t cpi_sigpend[4]; /* pending signals */
737 uint32_t cpi_sigmask[4]; /* blocked signals */
738 uint32_t cpi_sigignore[4];/* blocked signals */
739 uint32_t cpi_sigcatch[4];/* blocked signals */
740 int32_t cpi_pid; /* process ID */
741 int32_t cpi_ppid; /* parent process ID */
742 int32_t cpi_pgrp; /* process group ID */
743 int32_t cpi_sid; /* session ID */
744 uint32_t cpi_ruid; /* real user ID */
745 uint32_t cpi_euid; /* effective user ID */
746 uint32_t cpi_svuid; /* saved user ID */
747 uint32_t cpi_rgid; /* real group ID */
748 uint32_t cpi_egid; /* effective group ID */
749 uint32_t cpi_svgid; /* saved group ID */
750 uint32_t cpi_nlwps; /* number of LWPs */
751 int8_t cpi_name[32]; /* copy of p->p_comm */
752 /* Add version 2 fields below here. */
753 int32_t cpi_siglwp; /* LWP target of killing signal */
754 };
755
756 #if defined(ELFSIZE) && (ELFSIZE == 32)
757 #define Elf_Ehdr Elf32_Ehdr
758 #define Elf_Phdr Elf32_Phdr
759 #define Elf_Shdr Elf32_Shdr
760 #define Elf_Sym Elf32_Sym
761 #define Elf_Rel Elf32_Rel
762 #define Elf_Rela Elf32_Rela
763 #define Elf_Dyn Elf32_Dyn
764 #define Elf_Word Elf32_Word
765 #define Elf_Sword Elf32_Sword
766 #define Elf_Addr Elf32_Addr
767 #define Elf_Off Elf32_Off
768 #define Elf_Nhdr Elf32_Nhdr
769
770 #define ELF_R_SYM ELF32_R_SYM
771 #define ELF_R_TYPE ELF32_R_TYPE
772 #define ELFCLASS ELFCLASS32
773
774 #define AuxInfo Aux32Info
775 #elif defined(ELFSIZE) && (ELFSIZE == 64)
776 #define Elf_Ehdr Elf64_Ehdr
777 #define Elf_Phdr Elf64_Phdr
778 #define Elf_Shdr Elf64_Shdr
779 #define Elf_Sym Elf64_Sym
780 #define Elf_Rel Elf64_Rel
781 #define Elf_Rela Elf64_Rela
782 #define Elf_Dyn Elf64_Dyn
783 #define Elf_Word Elf64_Word
784 #define Elf_Sword Elf64_Sword
785 #define Elf_Addr Elf64_Addr
786 #define Elf_Off Elf64_Off
787 #define Elf_Nhdr Elf64_Nhdr
788
789 #define ELF_R_SYM ELF64_R_SYM
790 #define ELF_R_TYPE ELF64_R_TYPE
791 #define ELFCLASS ELFCLASS64
792
793 #define AuxInfo Aux64Info
794 #endif
795
796 #define ELF32_ST_BIND(info) ELF_ST_BIND(info)
797 #define ELF32_ST_TYPE(info) ELF_ST_TYPE(info)
798 #define ELF32_ST_INFO(bind,type) ELF_ST_INFO(bind,type)
799 #define ELF32_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other)
800
801 #define ELF64_ST_BIND(info) ELF_ST_BIND(info)
802 #define ELF64_ST_TYPE(info) ELF_ST_TYPE(info)
803 #define ELF64_ST_INFO(bind,type) ELF_ST_INFO(bind,type)
804 #define ELF64_ST_VISIBILITY(other) ELF_ST_VISIBILITY(other)
805
806 #ifdef _KERNEL
807
808 #define ELF_AUX_ENTRIES 12 /* Size of aux array passed to loader */
809 #define ELF32_NO_ADDR (~(Elf32_Addr)0) /* Indicates addr. not yet filled in */
810 #define ELF32_LINK_ADDR ((Elf32_Addr)-2) /* advises to use link address */
811 #define ELF64_NO_ADDR (~(Elf64_Addr)0) /* Indicates addr. not yet filled in */
812 #define ELF64_LINK_ADDR ((Elf64_Addr)-2) /* advises to use link address */
813
814 #if defined(ELFSIZE) && (ELFSIZE == 64)
815 #define ELF_NO_ADDR ELF64_NO_ADDR
816 #define ELF_LINK_ADDR ELF64_LINK_ADDR
817 #elif defined(ELFSIZE) && (ELFSIZE == 32)
818 #define ELF_NO_ADDR ELF32_NO_ADDR
819 #define ELF_LINK_ADDR ELF32_LINK_ADDR
820 #endif
821
822 #ifndef ELF32_EHDR_FLAGS_OK
823 #define ELF32_EHDR_FLAGS_OK(eh) 1
824 #endif
825
826 #ifndef ELF64_EHDR_FLAGS_OK
827 #define ELF64_EHDR_FLAGS_OK(eh) 1
828 #endif
829
830 #if defined(ELFSIZE) && (ELFSIZE == 64)
831 #define ELF_EHDR_FLAGS_OK(eh) ELF64_EHDR_FLAGS_OK(eh)
832 #else
833 #define ELF_EHDR_FLAGS_OK(eh) ELF32_EHDR_FLAGS_OK(eh)
834 #endif
835
836 #if defined(ELFSIZE)
837 struct elf_args {
838 Elf_Addr arg_entry; /* program entry point */
839 Elf_Addr arg_interp; /* Interpreter load address */
840 Elf_Addr arg_phaddr; /* program header address */
841 Elf_Addr arg_phentsize; /* Size of program header */
842 Elf_Addr arg_phnum; /* Number of program headers */
843 };
844 #endif
845
846 /*
847 * These constants are used for Elf32_Verdef struct's version number.
848 */
849 #define VER_DEF_NONE 0
850 #define VER_DEF_CURRENT 1
851
852 /*
853 * These constants are used for Elf32_Verdef struct's vd_flags.
854 */
855 #define VER_FLG_BASE 0x1
856 #define VER_FLG_WEAK 0x2
857
858 /*
859 * These are used in an Elf32_Versym field.
860 */
861 #define VER_NDX_LOCAL 0
862 #define VER_NDX_GLOBAL 1
863
864 /*
865 * These constants are used for Elf32_Verneed struct's version number.
866 */
867 #define VER_NEED_NONE 0
868 #define VER_NEED_CURRENT 1
869
870 /*
871 * GNU Extension hidding symb
872 */
873 #define VERSYM_HIDDEN 0x8000
874 #define VERSYM_VERSION 0x7fff
875
876 #define ELF_VER_CHR '@'
877
878 /*
879 * These are current size independent.
880 */
881
882 typedef struct {
883 Elf32_Half vd_version; /* version number of structure */
884 Elf32_Half vd_flags; /* flags (VER_FLG_*) */
885 Elf32_Half vd_ndx; /* version index */
886 Elf32_Half vd_cnt; /* number of verdaux entries */
887 Elf32_Word vd_hash; /* hash of name */
888 Elf32_Word vd_aux; /* offset to verdaux entries */
889 Elf32_Word vd_next; /* offset to next verdef */
890 } Elf32_Verdef;
891
892 typedef struct {
893 Elf32_Word vda_name; /* string table offset of name */
894 Elf32_Word vda_next; /* offset to verdaux */
895 } Elf32_Verdaux;
896
897 typedef struct {
898 Elf32_Half vn_version; /* version number of structure */
899 Elf32_Half vn_cnt; /* number of vernaux entries */
900 Elf32_Word vn_file; /* string table offset of library name*/
901 Elf32_Word vn_aux; /* offset to vernaux entries */
902 Elf32_Word vn_next; /* offset to next verneed */
903 } Elf32_Verneed;
904
905 typedef struct {
906 Elf32_Word vna_hash; /* Hash of dependency name */
907 Elf32_Half vna_flags; /* flags (VER_FLG_*) */
908 Elf32_Half vna_other; /* unused */
909 Elf32_Word vna_name; /* string table offset to version name*/
910 Elf32_Word vna_next; /* offset to next vernaux */
911 } Elf32_Vernaux;
912
913 typedef struct {
914 Elf32_Half vs_vers;
915 } Elf32_Versym;
916
917 #ifndef _LKM
918 #include "opt_execfmt.h"
919 #endif
920
921 #ifdef EXEC_ELF32
922 int exec_elf32_makecmds(struct lwp *, struct exec_package *);
923 int elf32_copyargs(struct lwp *, struct exec_package *,
924 struct ps_strings *, char **, void *);
925
926 int coredump_elf32(struct lwp *, void *);
927 int coredump_writenote_elf32(struct proc *, void *, Elf32_Nhdr *,
928 const char *, void *);
929
930 int elf32_check_header(Elf32_Ehdr *, int);
931 #endif
932
933 #ifdef EXEC_ELF64
934 int exec_elf64_makecmds(struct lwp *, struct exec_package *);
935 int elf64_copyargs(struct lwp *, struct exec_package *,
936 struct ps_strings *, char **, void *);
937
938 int coredump_elf64(struct lwp *, void *);
939 int coredump_writenote_elf64(struct proc *, void *, Elf64_Nhdr *,
940 const char *, void *);
941
942 int elf64_check_header(Elf64_Ehdr *, int);
943 #endif
944
945 #endif /* _KERNEL */
946
947 #endif /* !_SYS_EXEC_ELF_H_ */
Cache object: 70f2b78f6f2ecbe932862fcaca97eea4
|