FreeBSD/Linux Kernel Cross Reference
sys/sys/exec_elf.h
1 /* $NetBSD: exec_elf.h,v 1.95 2008/04/28 20:24:10 martin 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _SYS_EXEC_ELF_H_
33 #define _SYS_EXEC_ELF_H_
34
35 /*
36 * The current ELF ABI specification is available at:
37 * http://www.sco.com/developers/gabi/
38 *
39 * Current header definitions are in:
40 * http://www.sco.com/developers/gabi/latest/ch4.eheader.html
41 */
42
43 #if defined(_KERNEL) || defined(_STANDALONE)
44 #include <sys/types.h>
45 #else
46 #include <inttypes.h>
47 #endif /* _KERNEL || _STANDALONE */
48
49 #if defined(ELFSIZE)
50 #define CONCAT(x,y) __CONCAT(x,y)
51 #define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
52 #define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
53 #define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE))
54 #define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
55 #endif
56
57 #if HAVE_NBTOOL_CONFIG_H
58 #include <nbinclude/machine/elf_machdep.h>
59 #else
60 #include <machine/elf_machdep.h>
61 #endif
62
63 typedef uint8_t Elf_Byte;
64
65 typedef uint32_t Elf32_Addr;
66 #define ELF32_FSZ_ADDR 4
67 typedef uint32_t Elf32_Off;
68 #define ELF32_FSZ_OFF 4
69 typedef int32_t Elf32_Sword;
70 #define ELF32_FSZ_SWORD 4
71 typedef uint32_t Elf32_Word;
72 #define ELF32_FSZ_WORD 4
73 typedef uint16_t Elf32_Half;
74 #define ELF32_FSZ_HALF 2
75
76 typedef uint64_t Elf64_Addr;
77 #define ELF64_FSZ_ADDR 8
78 typedef uint64_t Elf64_Off;
79 #define ELF64_FSZ_OFF 8
80 typedef int32_t Elf64_Shalf;
81 #define ELF64_FSZ_SHALF 4
82
83 #ifndef ELF64_FSZ_SWORD
84 typedef int32_t Elf64_Sword;
85 #define ELF64_FSZ_SWORD 4
86 #endif /* ELF64_FSZ_SWORD */
87 #ifndef ELF64_FSZ_WORD
88 typedef uint32_t Elf64_Word;
89 #define ELF64_FSZ_WORD 4
90 #endif /* ELF64_FSZ_WORD */
91
92 typedef int64_t Elf64_Sxword;
93 #define ELF64_FSZ_XWORD 8
94 typedef uint64_t Elf64_Xword;
95 #define ELF64_FSZ_XWORD 8
96 typedef uint32_t Elf64_Half;
97 #define ELF64_FSZ_HALF 4
98 typedef uint16_t Elf64_Quarter;
99 #define ELF64_FSZ_QUARTER 2
100
101 /*
102 * ELF Header
103 */
104 #define ELF_NIDENT 16
105
106 typedef struct {
107 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
108 Elf32_Half e_type; /* file type */
109 Elf32_Half e_machine; /* machine type */
110 Elf32_Word e_version; /* version number */
111 Elf32_Addr e_entry; /* entry point */
112 Elf32_Off e_phoff; /* Program hdr offset */
113 Elf32_Off e_shoff; /* Section hdr offset */
114 Elf32_Word e_flags; /* Processor flags */
115 Elf32_Half e_ehsize; /* sizeof ehdr */
116 Elf32_Half e_phentsize; /* Program header entry size */
117 Elf32_Half e_phnum; /* Number of program headers */
118 Elf32_Half e_shentsize; /* Section header entry size */
119 Elf32_Half e_shnum; /* Number of section headers */
120 Elf32_Half e_shstrndx; /* String table index */
121 } Elf32_Ehdr;
122
123 typedef struct {
124 unsigned char e_ident[ELF_NIDENT]; /* Id bytes */
125 Elf64_Quarter e_type; /* file type */
126 Elf64_Quarter e_machine; /* machine type */
127 Elf64_Half e_version; /* version number */
128 Elf64_Addr e_entry; /* entry point */
129 Elf64_Off e_phoff; /* Program hdr offset */
130 Elf64_Off e_shoff; /* Section hdr offset */
131 Elf64_Half e_flags; /* Processor flags */
132 Elf64_Quarter e_ehsize; /* sizeof ehdr */
133 Elf64_Quarter e_phentsize; /* Program header entry size */
134 Elf64_Quarter e_phnum; /* Number of program headers */
135 Elf64_Quarter e_shentsize; /* Section header entry size */
136 Elf64_Quarter e_shnum; /* Number of section headers */
137 Elf64_Quarter e_shstrndx; /* String table index */
138 } Elf64_Ehdr;
139
140 /* e_ident offsets */
141 #define EI_MAG0 0 /* '\177' */
142 #define EI_MAG1 1 /* 'E' */
143 #define EI_MAG2 2 /* 'L' */
144 #define EI_MAG3 3 /* 'F' */
145 #define EI_CLASS 4 /* File class */
146 #define EI_DATA 5 /* Data encoding */
147 #define EI_VERSION 6 /* File version */
148 #define EI_OSABI 7 /* Operating system/ABI identification */
149 #define EI_ABIVERSION 8 /* ABI version */
150 #define EI_PAD 9 /* Start of padding bytes up to EI_NIDENT*/
151 #define EI_NIDENT 16 /* First non-ident header byte */
152
153 /* e_ident[EI_MAG0,EI_MAG3] */
154 #define ELFMAG0 0x7f
155 #define ELFMAG1 'E'
156 #define ELFMAG2 'L'
157 #define ELFMAG3 'F'
158 #define ELFMAG "\177ELF"
159 #define SELFMAG 4
160
161 /* e_ident[EI_CLASS] */
162 #define ELFCLASSNONE 0 /* Invalid class */
163 #define ELFCLASS32 1 /* 32-bit objects */
164 #define ELFCLASS64 2 /* 64-bit objects */
165 #define ELFCLASSNUM 3
166
167 /* e_ident[EI_DATA] */
168 #define ELFDATANONE 0 /* Invalid data encoding */
169 #define ELFDATA2LSB 1 /* 2's complement values, LSB first */
170 #define ELFDATA2MSB 2 /* 2's complement values, MSB first */
171
172 /* e_ident[EI_VERSION] */
173 #define EV_NONE 0 /* Invalid version */
174 #define EV_CURRENT 1 /* Current version */
175 #define EV_NUM 2
176
177 /* e_ident[EI_OSABI] */
178 #define ELFOSABI_SYSV 0 /* UNIX System V ABI */
179 #define ELFOSABI_HPUX 1 /* HP-UX operating system */
180 #define ELFOSABI_NETBSD 2 /* NetBSD */
181 #define ELFOSABI_LINUX 3 /* GNU/Linux */
182 #define ELFOSABI_HURD 4 /* GNU/Hurd */
183 #define ELFOSABI_86OPEN 5 /* 86Open */
184 #define ELFOSABI_SOLARIS 6 /* Solaris */
185 #define ELFOSABI_MONTEREY 7 /* Monterey */
186 #define ELFOSABI_IRIX 8 /* IRIX */
187 #define ELFOSABI_FREEBSD 9 /* FreeBSD */
188 #define ELFOSABI_TRU64 10 /* TRU64 UNIX */
189 #define ELFOSABI_MODESTO 11 /* Novell Modesto */
190 #define ELFOSABI_OPENBSD 12 /* OpenBSD */
191 /* Unofficial OSABIs follow */
192 #define ELFOSABI_ARM 97 /* ARM */
193 #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
194
195 /* e_type */
196 #define ET_NONE 0 /* No file type */
197 #define ET_REL 1 /* Relocatable file */
198 #define ET_EXEC 2 /* Executable file */
199 #define ET_DYN 3 /* Shared object file */
200 #define ET_CORE 4 /* Core file */
201 #define ET_NUM 5
202
203 #define ET_LOOS 0xfe00 /* Operating system specific range */
204 #define ET_HIOS 0xfeff
205 #define ET_LOPROC 0xff00 /* Processor-specific range */
206 #define ET_HIPROC 0xffff
207
208 /* e_machine */
209 #define EM_NONE 0 /* No machine */
210 #define EM_M32 1 /* AT&T WE 32100 */
211 #define EM_SPARC 2 /* SPARC */
212 #define EM_386 3 /* Intel 80386 */
213 #define EM_68K 4 /* Motorola 68000 */
214 #define EM_88K 5 /* Motorola 88000 */
215 #define EM_486 6 /* Intel 80486 */
216 #define EM_860 7 /* Intel 80860 */
217 #define EM_MIPS 8 /* MIPS I Architecture */
218 #define EM_S370 9 /* Amdahl UTS on System/370 */
219 #define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
220 /* 11-14 - Reserved */
221 #define EM_RS6000 11 /* IBM RS/6000 XXX reserved */
222 #define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
223 #define EM_NCUBE 16 /* NCube XXX reserved */
224 #define EM_VPP500 17 /* Fujitsu VPP500 */
225 #define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
226 #define EM_960 19 /* Intel 80960 */
227 #define EM_PPC 20 /* PowerPC */
228 #define EM_PPC64 21 /* 64-bit PowerPC */
229 /* 22-35 - Reserved */
230 #define EM_V800 36 /* NEC V800 */
231 #define EM_FR20 37 /* Fujitsu FR20 */
232 #define EM_RH32 38 /* TRW RH-32 */
233 #define EM_RCE 39 /* Motorola RCE */
234 #define EM_ARM 40 /* Advanced RISC Machines ARM */
235 #define EM_ALPHA 41 /* DIGITAL Alpha */
236 #define EM_SH 42 /* Hitachi Super-H */
237 #define EM_SPARCV9 43 /* SPARC Version 9 */
238 #define EM_TRICORE 44 /* Siemens Tricore */
239 #define EM_ARC 45 /* Argonaut RISC Core */
240 #define EM_H8_300 46 /* Hitachi H8/300 */
241 #define EM_H8_300H 47 /* Hitachi H8/300H */
242 #define EM_H8S 48 /* Hitachi H8S */
243 #define EM_H8_500 49 /* Hitachi H8/500 */
244 #define EM_IA_64 50 /* Intel Merced Processor */
245 #define EM_MIPS_X 51 /* Stanford MIPS-X */
246 #define EM_COLDFIRE 52 /* Motorola Coldfire */
247 #define EM_68HC12 53 /* Motorola MC68HC12 */
248 #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
249 #define EM_PCP 55 /* Siemens PCP */
250 #define EM_NCPU 56 /* Sony nCPU embedded RISC processor */
251 #define EM_NDR1 57 /* Denso NDR1 microprocessor */
252 #define EM_STARCORE 58 /* Motorola Star*Core processor */
253 #define EM_ME16 59 /* Toyota ME16 processor */
254 #define EM_ST100 60 /* STMicroelectronics ST100 processor */
255 #define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded family processor */
256 #define EM_X86_64 62 /* AMD x86-64 architecture */
257 #define EM_PDSP 63 /* Sony DSP Processor */
258 #define EM_PDP10 64 /* Digital Equipment Corp. PDP-10 */
259 #define EM_PDP11 65 /* Digital Equipment Corp. PDP-11 */
260 #define EM_FX66 66 /* Siemens FX66 microcontroller */
261 #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */
262 #define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */
263 #define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */
264 #define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */
265 #define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */
266 #define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */
267 #define EM_SVX 73 /* Silicon Graphics SVx */
268 #define EM_ST19 74 /* STMicroelectronics ST19 8-bit CPU */
269 #define EM_VAX 75 /* Digital VAX */
270 #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
271 #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded CPU */
272 #define EM_FIREPATH 78 /* Element 14 64-bit DSP processor */
273 #define EM_ZSP 79 /* LSI Logic's 16-bit DSP processor */
274 #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
275 #define EM_HUANY 81 /* Harvard's machine-independent format */
276 #define EM_PRISM 82 /* SiTera Prism */
277 #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
278 #define EM_FR30 84 /* Fujitsu FR30 */
279 #define EM_D10V 85 /* Mitsubishi D10V */
280 #define EM_D30V 86 /* Mitsubishi D30V */
281 #define EM_V850 87 /* NEC v850 */
282 #define EM_M32R 88 /* Mitsubishi M32R */
283 #define EM_MN10300 89 /* Matsushita MN10300 */
284 #define EM_MN10200 90 /* Matsushita MN10200 */
285 #define EM_PJ 91 /* picoJava */
286 #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
287 #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
288 #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
289 #define EM_NS32K 97 /* National Semiconductor 32000 series */
290
291 /* Unofficial machine types follow */
292 #define EM_AVR32 6317 /* used by NetBSD/avr32 */
293 #define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */
294 #define EM_NUM 36903
295
296 /*
297 * Program Header
298 */
299 typedef struct {
300 Elf32_Word p_type; /* entry type */
301 Elf32_Off p_offset; /* offset */
302 Elf32_Addr p_vaddr; /* virtual address */
303 Elf32_Addr p_paddr; /* physical address */
304 Elf32_Word p_filesz; /* file size */
305 Elf32_Word p_memsz; /* memory size */
306 Elf32_Word p_flags; /* flags */
307 Elf32_Word p_align; /* memory & file alignment */
308 } Elf32_Phdr;
309
310 typedef struct {
311 Elf64_Half p_type; /* entry type */
312 Elf64_Half p_flags; /* flags */
313 Elf64_Off p_offset; /* offset */
314 Elf64_Addr p_vaddr; /* virtual address */
315 Elf64_Addr p_paddr; /* physical address */
316 Elf64_Xword p_filesz; /* file size */
317 Elf64_Xword p_memsz; /* memory size */
318 Elf64_Xword p_align; /* memory & file alignment */
319 } Elf64_Phdr;
320
321 /* p_type */
322 #define PT_NULL 0 /* Program header table entry unused */
323 #define PT_LOAD 1 /* Loadable program segment */
324 #define PT_DYNAMIC 2 /* Dynamic linking information */
325 #define PT_INTERP 3 /* Program interpreter */
326 #define PT_NOTE 4 /* Auxiliary information */
327 #define PT_SHLIB 5 /* Reserved, unspecified semantics */
328 #define PT_PHDR 6 /* Entry for header table itself */
329 #define PT_NUM 7
330
331 #define PT_LOOS 0x60000000 /* OS-specific range */
332 #define PT_HIOS 0x6fffffff
333 #define PT_LOPROC 0x70000000 /* Processor-specific range */
334 #define PT_HIPROC 0x7fffffff
335
336 #define PT_MIPS_REGINFO 0x70000000
337
338 /* p_flags */
339 #define PF_R 0x4 /* Segment is readable */
340 #define PF_W 0x2 /* Segment is writable */
341 #define PF_X 0x1 /* Segment is executable */
342
343 #define PF_MASKOS 0x0ff00000 /* Operating system specific values */
344 #define PF_MASKPROC 0xf0000000 /* Processor-specific values */
345
346 /*
347 * Section Headers
348 */
349 typedef struct {
350 Elf32_Word sh_name; /* section name (.shstrtab index) */
351 Elf32_Word sh_type; /* section type */
352 Elf32_Word sh_flags; /* section flags */
353 Elf32_Addr sh_addr; /* virtual address */
354 Elf32_Off sh_offset; /* file offset */
355 Elf32_Word sh_size; /* section size */
356 Elf32_Word sh_link; /* link to another */
357 Elf32_Word sh_info; /* misc info */
358 Elf32_Word sh_addralign; /* memory alignment */
359 Elf32_Word sh_entsize; /* table entry size */
360 } Elf32_Shdr;
361
362 typedef struct {
363 Elf64_Half sh_name; /* section name (.shstrtab index) */
364 Elf64_Half sh_type; /* section type */
365 Elf64_Xword sh_flags; /* section flags */
366 Elf64_Addr sh_addr; /* virtual address */
367 Elf64_Off sh_offset; /* file offset */
368 Elf64_Xword sh_size; /* section size */
369 Elf64_Half sh_link; /* link to another */
370 Elf64_Half sh_info; /* misc info */
371 Elf64_Xword sh_addralign; /* memory alignment */
372 Elf64_Xword sh_entsize; /* table entry size */
373 } Elf64_Shdr;
374
375 /* sh_type */
376 #define SHT_NULL 0 /* Section header table entry unused */
377 #define SHT_PROGBITS 1 /* Program information */
378 #define SHT_SYMTAB 2 /* Symbol table */
379 #define SHT_STRTAB 3 /* String table */
380 #define SHT_RELA 4 /* Relocation information w/ addend */
381 #define SHT_HASH 5 /* Symbol hash table */
382 #define SHT_DYNAMIC 6 /* Dynamic linking information */
383 #define SHT_NOTE 7 /* Auxiliary information */
384 #define SHT_NOBITS 8 /* No space allocated in file image */
385 #define SHT_REL 9 /* Relocation information w/o addend */
386 #define SHT_SHLIB 10 /* Reserved, unspecified semantics */
387 #define SHT_DYNSYM 11 /* Symbol table for dynamic linker */
388 #define SHT_NUM 12
389
390 #define SHT_LOOS 0x60000000 /* Operating system specific range */
391 #define SHT_SUNW_VERDEF 0x6ffffffd /* Versions defined by file */
392 #define SHT_SUNW_VERNEED 0x6ffffffe /* Versions needed by file */
393 #define SHT_SUNW_VERSYM 0x6fffffff /* Symbol versions */
394 #define SHT_HIOS 0x6fffffff
395 #define SHT_LOPROC 0x70000000 /* Processor-specific range */
396 #define SHT_HIPROC 0x7fffffff
397 #define SHT_LOUSER 0x80000000 /* Application-specific range */
398 #define SHT_HIUSER 0xffffffff
399
400 /* sh_flags */
401 #define SHF_WRITE 0x1 /* Section contains writable data */
402 #define SHF_ALLOC 0x2 /* Section occupies memory */
403 #define SHF_EXECINSTR 0x4 /* Section contains executable insns */
404
405 #define SHF_MASKOS 0x0f000000 /* Operating system specific values */
406 #define SHF_MASKPROC 0xf0000000 /* Processor-specific values */
407
408 /*
409 * Symbol Table
410 */
411 typedef struct {
412 Elf32_Word st_name; /* Symbol name (.symtab index) */
413 Elf32_Word st_value; /* value of symbol */
414 Elf32_Word st_size; /* size of symbol */
415 Elf_Byte st_info; /* type / binding attrs */
416 Elf_Byte st_other; /* unused */
417 Elf32_Half st_shndx; /* section index of symbol */
418 } Elf32_Sym;
419
420 typedef struct {
421 Elf64_Half st_name; /* Symbol name (.symtab index) */
422 Elf_Byte st_info; /* type / binding attrs */
423 Elf_Byte st_other; /* unused */
424 Elf64_Quarter st_shndx; /* section index of symbol */
425 Elf64_Addr st_value; /* value of symbol */
426 Elf64_Xword st_size; /* size of symbol */
427 } Elf64_Sym;
428
429 /* Symbol Table index of the undefined symbol */
430 #define ELF_SYM_UNDEFINED 0
431
432 #define STN_UNDEF 0 /* undefined index */
433
434 /* st_info: Symbol Bindings */
435 #define STB_LOCAL 0 /* local symbol */
436 #define STB_GLOBAL 1 /* global symbol */
437 #define STB_WEAK 2 /* weakly defined global symbol */
438 #define STB_NUM 3
439
440 #define STB_LOOS 10 /* Operating system specific range */
441 #define STB_HIOS 12
442 #define STB_LOPROC 13 /* Processor-specific range */
443 #define STB_HIPROC 15
444
445 /* st_info: Symbol Types */
446 #define STT_NOTYPE 0 /* Type not specified */
447 #define STT_OBJECT 1 /* Associated with a data object */
448 #define STT_FUNC 2 /* Associated with a function */
449 #define STT_SECTION 3 /* Associated with a section */
450 #define STT_FILE 4 /* Associated with a file name */
451 #define STT_NUM 5
452
453 #define STT_LOOS 10 /* Operating system specific range */
454 #define STT_HIOS 12
455 #define STT_LOPROC 13 /* Processor-specific range */
456 #define STT_HIPROC 15
457
458 /* st_other: Visibility Types */
459 #define STV_DEFAULT 0 /* use binding type */
460 #define STV_INTERNAL 1 /* not referenced from outside */
461 #define STV_HIDDEN 2 /* not visible, may be used via ptr */
462 #define STV_PROTECTED 3 /* visible, not preemptible */
463
464 /* st_info/st_other utility macros */
465 #define ELF_ST_BIND(info) ((uint32_t)(info) >> 4)
466 #define ELF_ST_TYPE(info) ((uint32_t)(info) & 0xf)
467 #define ELF_ST_INFO(bind,type) ((Elf_Byte)(((bind) << 4) | \
468 ((type) & 0xf)))
469 #define ELF_ST_VISIBILITY(other) ((uint32_t)(other) & 3)
470
471 /*
472 * Special section indexes
473 */
474 #define SHN_UNDEF 0 /* Undefined section */
475
476 #define SHN_LORESERVE 0xff00 /* Reserved range */
477 #define SHN_ABS 0xfff1 /* Absolute symbols */
478 #define SHN_COMMON 0xfff2 /* Common symbols */
479 #define SHN_HIRESERVE 0xffff
480
481 #define SHN_LOPROC 0xff00 /* Processor-specific range */
482 #define SHN_HIPROC 0xff1f
483 #define SHN_LOOS 0xff20 /* Operating system specific range */
484 #define SHN_HIOS 0xff3f
485
486 #define SHN_MIPS_ACOMMON 0xff00
487 #define SHN_MIPS_TEXT 0xff01
488 #define SHN_MIPS_DATA 0xff02
489 #define SHN_MIPS_SCOMMON 0xff03
490
491 /*
492 * Relocation Entries
493 */
494 typedef struct {
495 Elf32_Word r_offset; /* where to do it */
496 Elf32_Word r_info; /* index & type of relocation */
497 } Elf32_Rel;
498
499 typedef struct {
500 Elf32_Word r_offset; /* where to do it */
501 Elf32_Word r_info; /* index & type of relocation */
502 Elf32_Sword r_addend; /* adjustment value */
503 } Elf32_Rela;
504
505 /* r_info utility macros */
506 #define ELF32_R_SYM(info) ((info) >> 8)
507 #define ELF32_R_TYPE(info) ((info) & 0xff)
508 #define ELF32_R_INFO(sym, type) (((sym) << 8) + (unsigned char)(type))
509
510 typedef struct {
511 Elf64_Addr r_offset; /* where to do it */
512 Elf64_Xword r_info; /* index & type of relocation */
513 } Elf64_Rel;
514
515 typedef struct {
516 Elf64_Addr r_offset; /* where to do it */
517 Elf64_Xword r_info; /* index & type of relocation */
518 Elf64_Sxword r_addend; /* adjustment value */
519 } Elf64_Rela;
520
521 /* r_info utility macros */
522 #define ELF64_R_SYM(info) ((info) >> 32)
523 #define ELF64_R_TYPE(info) ((info) & 0xffffffff)
524 #define ELF64_R_INFO(sym,type) (((sym) << 32) + (type))
525
526 /*
527 * Dynamic Section structure array
528 */
529 typedef struct {
530 Elf32_Word d_tag; /* entry tag value */
531 union {
532 Elf32_Addr d_ptr;
533 Elf32_Word d_val;
534 } d_un;
535 } Elf32_Dyn;
536
537 typedef struct {
538 Elf64_Xword d_tag; /* entry tag value */
539 union {
540 Elf64_Addr d_ptr;
541 Elf64_Xword d_val;
542 } d_un;
543 } Elf64_Dyn;
544
545 /* d_tag */
546 #define DT_NULL 0 /* Marks end of dynamic array */
547 #define DT_NEEDED 1 /* Name of needed library (DT_STRTAB offset) */
548 #define DT_PLTRELSZ 2 /* Size, in bytes, of relocations in PLT */
549 #define DT_PLTGOT 3 /* Address of PLT and/or GOT */
550 #define DT_HASH 4 /* Address of symbol hash table */
551 #define DT_STRTAB 5 /* Address of string table */
552 #define DT_SYMTAB 6 /* Address of symbol table */
553 #define DT_RELA 7 /* Address of Rela relocation table */
554 #define DT_RELASZ 8 /* Size, in bytes, of DT_RELA table */
555 #define DT_RELAENT 9 /* Size, in bytes, of one DT_RELA entry */
556 #define DT_STRSZ 10 /* Size, in bytes, of DT_STRTAB table */
557 #define DT_SYMENT 11 /* Size, in bytes, of one DT_SYMTAB entry */
558 #define DT_INIT 12 /* Address of initialization function */
559 #define DT_FINI 13 /* Address of termination function */
560 #define DT_SONAME 14 /* Shared object name (DT_STRTAB offset) */
561 #define DT_RPATH 15 /* Library search path (DT_STRTAB offset) */
562 #define DT_SYMBOLIC 16 /* Start symbol search within local object */
563 #define DT_REL 17 /* Address of Rel relocation table */
564 #define DT_RELSZ 18 /* Size, in bytes, of DT_REL table */
565 #define DT_RELENT 19 /* Size, in bytes, of one DT_REL entry */
566 #define DT_PLTREL 20 /* Type of PLT relocation entries */
567 #define DT_DEBUG 21 /* Used for debugging; unspecified */
568 #define DT_TEXTREL 22 /* Relocations might modify non-writable seg */
569 #define DT_JMPREL 23 /* Address of relocations associated with PLT */
570 #define DT_BIND_NOW 24 /* Process all relocations at load-time */
571 #define DT_INIT_ARRAY 25 /* Address of initialization function array */
572 #define DT_FINI_ARRAY 26 /* Size, in bytes, of DT_INIT_ARRAY array */
573 #define DT_INIT_ARRAYSZ 27 /* Address of termination function array */
574 #define DT_FINI_ARRAYSZ 28 /* Size, in bytes, of DT_FINI_ARRAY array*/
575 #define DT_NUM 29
576
577 #define DT_LOOS 0x60000000 /* Operating system specific range */
578 #define DT_VERSYM 0x6ffffff0 /* Symbol versions */
579 #define DT_FLAGS_1 0x6ffffffb /* ELF dynamic flags */
580 #define DT_VERDEF 0x6ffffffc /* Versions defined by file */
581 #define DT_VERDEFNUM 0x6ffffffd /* Number of versions defined by file */
582 #define DT_VERNEED 0x6ffffffe /* Versions needed by file */
583 #define DT_VERNEEDNUM 0x6fffffff /* Number of versions needed by file */
584 #define DT_HIOS 0x6fffffff
585 #define DT_LOPROC 0x70000000 /* Processor-specific range */
586 #define DT_HIPROC 0x7fffffff
587
588 /* Flag values for DT_FLAGS_1 (incomplete) */
589 #define DF_1_INITFIRST 0x00000020 /* Object's init/fini take priority */
590
591 /*
592 * Auxiliary Vectors
593 */
594 typedef struct {
595 Elf32_Word a_type; /* 32-bit id */
596 Elf32_Word a_v; /* 32-bit id */
597 } Aux32Info;
598
599 typedef struct {
600 Elf64_Half a_type; /* 32-bit id */
601 Elf64_Xword a_v; /* 64-bit id */
602 } Aux64Info;
603
604 /* a_type */
605 #define AT_NULL 0 /* Marks end of array */
606 #define AT_IGNORE 1 /* No meaning, a_un is undefined */
607 #define AT_EXECFD 2 /* Open file descriptor of object file */
608 #define AT_PHDR 3 /* &phdr[0] */
609 #define AT_PHENT 4 /* sizeof(phdr[0]) */
610 #define AT_PHNUM 5 /* # phdr entries */
611 #define AT_PAGESZ 6 /* PAGESIZE */
612 #define AT_BASE 7 /* Interpreter base addr */
613 #define AT_FLAGS 8 /* Processor flags */
614 #define AT_ENTRY 9 /* Entry address of executable */
615 #define AT_DCACHEBSIZE 10 /* Data cache block size */
616 #define AT_ICACHEBSIZE 11 /* Instruction cache block size */
617 #define AT_UCACHEBSIZE 12 /* Unified cache block size */
618
619 /* Vendor specific */
620 #define AT_MIPS_NOTELF 10 /* XXX a_val != 0 -> MIPS XCOFF executable */
621
622 #define AT_EUID 2000 /* euid (solaris compatible numbers) */
623 #define AT_RUID 2001 /* ruid (solaris compatible numbers) */
624 #define AT_EGID 2002 /* egid (solaris compatible numbers) */
625 #define AT_RGID 2003 /* rgid (solaris compatible numbers) */
626
627 /* Solaris kernel specific */
628 #define AT_SUN_LDELF 2004 /* dynamic linker's ELF header */
629 #define AT_SUN_LDSHDR 2005 /* dynamic linker's section header */
630 #define AT_SUN_LDNAME 2006 /* dynamic linker's name */
631 #define AT_SUN_LPGSIZE 2007 /* large pagesize */
632
633 /* Other information */
634 #define AT_SUN_PLATFORM 2008 /* sysinfo(SI_PLATFORM) */
635 #define AT_SUN_HWCAP 2009 /* process hardware capabilities */
636 #define AT_SUN_IFLUSH 2010 /* do we need to flush the instruction cache? */
637 #define AT_SUN_CPU 2011 /* CPU name */
638 /* ibcs2 emulation band aid */
639 #define AT_SUN_EMUL_ENTRY 2012 /* coff entry point */
640 #define AT_SUN_EMUL_EXECFD 2013 /* coff file descriptor */
641 /* Executable's fully resolved name */
642 #define AT_SUN_EXECNAME 2014
643
644 /*
645 * Note Headers
646 */
647 typedef struct {
648 Elf32_Word n_namesz;
649 Elf32_Word n_descsz;
650 Elf32_Word n_type;
651 } Elf32_Nhdr;
652
653 typedef struct {
654 Elf64_Half n_namesz;
655 Elf64_Half n_descsz;
656 Elf64_Half n_type;
657 } Elf64_Nhdr;
658
659 #define ELF_NOTE_TYPE_ABI_TAG 1
660
661 /* GNU-specific note name and description sizes */
662 #define ELF_NOTE_ABI_NAMESZ 4
663 #define ELF_NOTE_ABI_DESCSZ 16
664 /* GNU-specific note name */
665 #define ELF_NOTE_ABI_NAME "GNU\0"
666
667 /* GNU-specific OS/version value stuff */
668 #define ELF_NOTE_ABI_OS_LINUX 0
669 #define ELF_NOTE_ABI_OS_HURD 1
670 #define ELF_NOTE_ABI_OS_SOLARIS 2
671
672 /* NetBSD-specific note type: Emulation name. desc is emul name string. */
673 #define ELF_NOTE_TYPE_NETBSD_TAG 1
674 /* NetBSD-specific note name and description sizes */
675 #define ELF_NOTE_NETBSD_NAMESZ 7
676 #define ELF_NOTE_NETBSD_DESCSZ 4
677 /* NetBSD-specific note name */
678 #define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
679
680 /* NetBSD-specific note type: Checksum. There should be 1 NOTE per PT_LOAD
681 section. desc is a tuple of <phnum>(16),<chk-type>(16),<chk-value>. */
682 #define ELF_NOTE_TYPE_CHECKSUM_TAG 2
683 #define ELF_NOTE_CHECKSUM_CRC32 1
684 #define ELF_NOTE_CHECKSUM_MD5 2
685 #define ELF_NOTE_CHECKSUM_SHA1 3
686 #define ELF_NOTE_CHECKSUM_SHA256 4
687
688 /* NetBSD-specific note type: PaX. There should be 1 NOTE per executable.
689 section. desc is a 32 bit bitmask */
690 #define ELF_NOTE_TYPE_PAX_TAG 3
691 #define ELF_NOTE_PAX_MPROTECT 0x01 /* Force enable Mprotect */
692 #define ELF_NOTE_PAX_NOMPROTECT 0x02 /* Force disable Mprotect */
693 #define ELF_NOTE_PAX_GUARD 0x04 /* Force enable Segvguard */
694 #define ELF_NOTE_PAX_NOGUARD 0x08 /* Force disable Servguard */
695 #define ELF_NOTE_PAX_ASLR 0x10 /* Force enable ASLR */
696 #define ELF_NOTE_PAX_NOASLR 0x20 /* Force disable ASLR */
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 14 /* Max 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: 73f3d3d4e88d0cca60a472d54ac75e0f
|