xref: /illumos-gate/usr/src/uts/common/sys/elf.h (revision 34bdffbf)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
23  */
24 /*
25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 
33 #ifndef _SYS_ELF_H
34 #define	_SYS_ELF_H
35 
36 #include <sys/elftypes.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #define	ELF32_FSZ_ADDR	4
43 #define	ELF32_FSZ_HALF	2
44 #define	ELF32_FSZ_OFF	4
45 #define	ELF32_FSZ_SWORD	4
46 #define	ELF32_FSZ_WORD	4
47 
48 #define	ELF64_FSZ_ADDR	8
49 #define	ELF64_FSZ_HALF	2
50 #define	ELF64_FSZ_OFF	8
51 #define	ELF64_FSZ_SWORD	4
52 #define	ELF64_FSZ_WORD	4
53 #define	ELF64_FSZ_SXWORD 8
54 #define	ELF64_FSZ_XWORD	8
55 
56 /*
57  *	"Enumerations" below use ...NUM as the number of
58  *	values in the list.  It should be 1 greater than the
59  *	highest "real" value.
60  */
61 
62 /*
63  *	ELF header
64  */
65 
66 #define	EI_NIDENT	16
67 
68 typedef struct {
69 	unsigned char	e_ident[EI_NIDENT];	/* ident bytes */
70 	Elf32_Half	e_type;			/* file type */
71 	Elf32_Half	e_machine;		/* target machine */
72 	Elf32_Word	e_version;		/* file version */
73 	Elf32_Addr	e_entry;		/* start address */
74 	Elf32_Off	e_phoff;		/* phdr file offset */
75 	Elf32_Off	e_shoff;		/* shdr file offset */
76 	Elf32_Word	e_flags;		/* file flags */
77 	Elf32_Half	e_ehsize;		/* sizeof ehdr */
78 	Elf32_Half	e_phentsize;		/* sizeof phdr */
79 	Elf32_Half	e_phnum;		/* number phdrs */
80 	Elf32_Half	e_shentsize;		/* sizeof shdr */
81 	Elf32_Half	e_shnum;		/* number shdrs */
82 	Elf32_Half	e_shstrndx;		/* shdr string index */
83 } Elf32_Ehdr;
84 
85 #if defined(_LP64) || defined(_LONGLONG_TYPE)
86 typedef struct {
87 	unsigned char	e_ident[EI_NIDENT];	/* ident bytes */
88 	Elf64_Half	e_type;			/* file type */
89 	Elf64_Half	e_machine;		/* target machine */
90 	Elf64_Word	e_version;		/* file version */
91 	Elf64_Addr	e_entry;		/* start address */
92 	Elf64_Off	e_phoff;		/* phdr file offset */
93 	Elf64_Off	e_shoff;		/* shdr file offset */
94 	Elf64_Word	e_flags;		/* file flags */
95 	Elf64_Half	e_ehsize;		/* sizeof ehdr */
96 	Elf64_Half	e_phentsize;		/* sizeof phdr */
97 	Elf64_Half	e_phnum;		/* number phdrs */
98 	Elf64_Half	e_shentsize;		/* sizeof shdr */
99 	Elf64_Half	e_shnum;		/* number shdrs */
100 	Elf64_Half	e_shstrndx;		/* shdr string index */
101 } Elf64_Ehdr;
102 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
103 
104 
105 #define	EI_MAG0		0	/* e_ident[] indexes */
106 #define	EI_MAG1		1
107 #define	EI_MAG2		2
108 #define	EI_MAG3		3
109 #define	EI_CLASS	4	/* File class */
110 #define	EI_DATA		5	/* Data encoding */
111 #define	EI_VERSION	6	/* File version */
112 #define	EI_OSABI	7	/* Operating system/ABI identification */
113 #define	EI_ABIVERSION	8	/* ABI version */
114 #define	EI_PAD		9	/* Start of padding bytes */
115 
116 #define	ELFMAG0		0x7f		/* EI_MAG */
117 #define	ELFMAG1		'E'
118 #define	ELFMAG2		'L'
119 #define	ELFMAG3		'F'
120 #define	ELFMAG		"\177ELF"
121 #define	SELFMAG		4
122 
123 #define	ELFCLASSNONE	0		/* EI_CLASS */
124 #define	ELFCLASS32	1
125 #define	ELFCLASS64	2
126 #define	ELFCLASSNUM	3
127 
128 #define	ELFDATANONE	0		/* EI_DATA */
129 #define	ELFDATA2LSB	1
130 #define	ELFDATA2MSB	2
131 #define	ELFDATANUM	3
132 
133 #define	ET_NONE		0		/* e_type */
134 #define	ET_REL		1
135 #define	ET_EXEC		2
136 #define	ET_DYN		3
137 #define	ET_CORE		4
138 #define	ET_NUM		5
139 #define	ET_LOOS		0xfe00		/* OS specific range */
140 #define	ET_LOSUNW	0xfeff
141 #define	ET_SUNWPSEUDO	0xfeff
142 #define	ET_HISUNW	0xfeff
143 #define	ET_HIOS		0xfeff
144 #define	ET_LOPROC	0xff00		/* processor specific range */
145 #define	ET_HIPROC	0xffff
146 
147 #define	ET_LOPROC	0xff00		/* processor specific range */
148 #define	ET_HIPROC	0xffff
149 
150 #define	EM_NONE		0		/* e_machine */
151 #define	EM_M32		1		/* AT&T WE 32100 */
152 #define	EM_SPARC	2		/* Sun SPARC */
153 #define	EM_386		3		/* Intel 80386 */
154 #define	EM_68K		4		/* Motorola 68000 */
155 #define	EM_88K		5		/* Motorola 88000 */
156 #define	EM_486		6		/* Intel 80486 */
157 #define	EM_860		7		/* Intel i860 */
158 #define	EM_MIPS		8		/* MIPS RS3000 Big-Endian */
159 #define	EM_S370		9		/* IBM System/370 Processor */
160 #define	EM_MIPS_RS3_LE	10		/* MIPS RS3000 Little-Endian */
161 #define	EM_RS6000	11		/* RS6000 */
162 #define	EM_UNKNOWN12	12
163 #define	EM_UNKNOWN13	13
164 #define	EM_UNKNOWN14	14
165 #define	EM_PA_RISC	15		/* PA-RISC */
166 #define	EM_PARISC	EM_PA_RISC	/* Alias: GNU compatibility */
167 #define	EM_nCUBE	16		/* nCUBE */
168 #define	EM_VPP500	17		/* Fujitsu VPP500 */
169 #define	EM_SPARC32PLUS	18		/* Sun SPARC 32+ */
170 #define	EM_960		19		/* Intel 80960 */
171 #define	EM_PPC		20		/* PowerPC */
172 #define	EM_PPC64	21		/* 64-bit PowerPC */
173 #define	EM_S390		22		/* IBM System/390 Processor */
174 #define	EM_UNKNOWN22	EM_S390		/* Alias: Older published name */
175 #define	EM_UNKNOWN23	23
176 #define	EM_UNKNOWN24	24
177 #define	EM_UNKNOWN25	25
178 #define	EM_UNKNOWN26	26
179 #define	EM_UNKNOWN27	27
180 #define	EM_UNKNOWN28	28
181 #define	EM_UNKNOWN29	29
182 #define	EM_UNKNOWN30	30
183 #define	EM_UNKNOWN31	31
184 #define	EM_UNKNOWN32	32
185 #define	EM_UNKNOWN33	33
186 #define	EM_UNKNOWN34	34
187 #define	EM_UNKNOWN35	35
188 #define	EM_V800		36		/* NEX V800 */
189 #define	EM_FR20		37		/* Fujitsu FR20 */
190 #define	EM_RH32		38		/* TRW RH-32 */
191 #define	EM_RCE		39		/* Motorola RCE */
192 #define	EM_ARM		40		/* Advanced RISC Marchines ARM */
193 #define	EM_ALPHA	41		/* Digital Alpha */
194 #define	EM_SH		42		/* Hitachi SH */
195 #define	EM_SPARCV9	43		/* Sun SPARC V9 (64-bit) */
196 #define	EM_TRICORE	44		/* Siemens Tricore embedded processor */
197 #define	EM_ARC		45		/* Argonaut RISC Core, */
198 					/*	Argonaut Technologies Inc. */
199 #define	EM_H8_300	46		/* Hitachi H8/300 */
200 #define	EM_H8_300H	47		/* Hitachi H8/300H */
201 #define	EM_H8S		48		/* Hitachi H8S */
202 #define	EM_H8_500	49		/* Hitachi H8/500 */
203 #define	EM_IA_64	50		/* Intel IA64 */
204 #define	EM_MIPS_X	51		/* Stanford MIPS-X */
205 #define	EM_COLDFIRE	52		/* Motorola ColdFire */
206 #define	EM_68HC12	53		/* Motorola M68HC12 */
207 #define	EM_MMA		54		/* Fujitsu MMA Mulimedia Accelerator */
208 #define	EM_PCP		55		/* Siemens PCP */
209 #define	EM_NCPU		56		/* Sony nCPU embedded RISC processor */
210 #define	EM_NDR1		57		/* Denso NDR1 microprocessor */
211 #define	EM_STARCORE	58		/* Motorola Star*Core processor */
212 #define	EM_ME16		59		/* Toyota ME16 processor */
213 #define	EM_ST100	60		/* STMicroelectronics ST100 processor */
214 #define	EM_TINYJ	61		/* Advanced Logic Corp. TinyJ */
215 					/*	embedded processor family */
216 #define	EM_AMD64	62		/* AMDs x86-64 architecture */
217 #define	EM_X86_64	EM_AMD64	/* (compatibility) */
218 
219 #define	EM_PDSP		63		/* Sony DSP Processor */
220 #define	EM_UNKNOWN64	64
221 #define	EM_UNKNOWN65	65
222 #define	EM_FX66		66		/* Siemens FX66 microcontroller */
223 #define	EM_ST9PLUS	67		/* STMicroelectronics ST9+8/16 bit */
224 					/*	microcontroller */
225 #define	EM_ST7		68		/* STMicroelectronics ST7 8-bit */
226 					/*	microcontroller */
227 #define	EM_68HC16	69		/* Motorola MC68HC16 Microcontroller */
228 #define	EM_68HC11	70		/* Motorola MC68HC11 Microcontroller */
229 #define	EM_68HC08	71		/* Motorola MC68HC08 Microcontroller */
230 #define	EM_68HC05	72		/* Motorola MC68HC05 Microcontroller */
231 #define	EM_SVX		73		/* Silicon Graphics SVx */
232 #define	EM_ST19		74		/* STMicroelectronics ST19 8-bit */
233 					/*	microcontroller */
234 #define	EM_VAX		75		/* Digital VAX */
235 #define	EM_CRIS		76		/* Axis Communications 32-bit */
236 					/*	embedded processor */
237 #define	EM_JAVELIN	77		/* Infineon Technologies 32-bit */
238 					/*	embedded processor */
239 #define	EM_FIREPATH	78		/* Element 14 64-bit DSP Processor */
240 #define	EM_ZSP		79		/* LSI Logic 16-bit DSP Processor */
241 #define	EM_MMIX		80		/* Donald Knuth's educational */
242 					/*	64-bit processor */
243 #define	EM_HUANY	81		/* Harvard University */
244 					/*	machine-independent */
245 					/*	object files */
246 #define	EM_PRISM	82		/* SiTera Prism */
247 #define	EM_AVR		83		/* Atmel AVR 8-bit microcontroller */
248 #define	EM_FR30		84		/* Fujitsu FR30 */
249 #define	EM_D10V		85		/* Mitsubishi D10V */
250 #define	EM_D30V		86		/* Mitsubishi D30V */
251 #define	EM_V850		87		/* NEC v850 */
252 #define	EM_M32R		88		/* Mitsubishi M32R */
253 #define	EM_MN10300	89		/* Matsushita MN10300 */
254 #define	EM_MN10200	90		/* Matsushita MN10200 */
255 #define	EM_PJ		91		/* picoJava */
256 #define	EM_OPENRISC	92		/* OpenRISC 32-bit embedded processor */
257 #define	EM_ARC_A5	93		/* ARC Cores Tangent-A5 */
258 #define	EM_XTENSA	94		/* Tensilica Xtensa architecture */
259 #define	EM_NUM		95
260 
261 #define	EV_NONE		0		/* e_version, EI_VERSION */
262 #define	EV_CURRENT	1
263 #define	EV_NUM		2
264 
265 
266 #define	ELFOSABI_NONE		0	/* No extensions or unspecified */
267 #define	ELFOSABI_SYSV		ELFOSABI_NONE
268 #define	ELFOSABI_HPUX		1	/* Hewlett-Packard HP-UX */
269 #define	ELFOSABI_NETBSD		2	/* NetBSD */
270 #define	ELFOSABI_LINUX		3	/* Linux */
271 #define	ELFOSABI_UNKNOWN4	4
272 #define	ELFOSABI_UNKNOWN5	5
273 #define	ELFOSABI_SOLARIS	6	/* Sun Solaris */
274 #define	ELFOSABI_AIX		7	/* AIX */
275 #define	ELFOSABI_IRIX		8	/* IRIX */
276 #define	ELFOSABI_FREEBSD	9	/* FreeBSD */
277 #define	ELFOSABI_TRU64		10	/* Compaq TRU64 UNIX */
278 #define	ELFOSABI_MODESTO	11	/* Novell Modesto */
279 #define	ELFOSABI_OPENBSD	12	/* Open BSD */
280 #define	ELFOSABI_OPENVMS	13	/* Open VMS */
281 #define	ELFOSABI_NSK		14	/* Hewlett-Packard Non-Stop Kernel */
282 #define	ELFOSABI_AROS		15	/* Amiga Research OS */
283 #define	ELFOSABI_ARM		97	/* ARM */
284 #define	ELFOSABI_STANDALONE	255	/* standalone (embedded) application */
285 
286 #define	EAV_SUNW_NONE		0	/* EI_ABIVERSION */
287 #define	EAV_SUNW_CURRENT	1
288 #define	EAV_SUNW_NUM		2
289 
290 
291 /*
292  *	Program header
293  */
294 
295 typedef struct {
296 	Elf32_Word	p_type;		/* entry type */
297 	Elf32_Off	p_offset;	/* file offset */
298 	Elf32_Addr	p_vaddr;	/* virtual address */
299 	Elf32_Addr	p_paddr;	/* physical address */
300 	Elf32_Word	p_filesz;	/* file size */
301 	Elf32_Word	p_memsz;	/* memory size */
302 	Elf32_Word	p_flags;	/* entry flags */
303 	Elf32_Word	p_align;	/* memory/file alignment */
304 } Elf32_Phdr;
305 
306 #if defined(_LP64) || defined(_LONGLONG_TYPE)
307 typedef struct {
308 	Elf64_Word	p_type;		/* entry type */
309 	Elf64_Word	p_flags;	/* entry flags */
310 	Elf64_Off	p_offset;	/* file offset */
311 	Elf64_Addr	p_vaddr;	/* virtual address */
312 	Elf64_Addr	p_paddr;	/* physical address */
313 	Elf64_Xword	p_filesz;	/* file size */
314 	Elf64_Xword	p_memsz;	/* memory size */
315 	Elf64_Xword	p_align;	/* memory/file alignment */
316 } Elf64_Phdr;
317 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
318 
319 
320 #define	PT_NULL		0		/* p_type */
321 #define	PT_LOAD		1
322 #define	PT_DYNAMIC	2
323 #define	PT_INTERP	3
324 #define	PT_NOTE		4
325 #define	PT_SHLIB	5
326 #define	PT_PHDR		6
327 #define	PT_TLS		7
328 #define	PT_NUM		8
329 
330 #define	PT_LOOS		0x60000000	/* OS specific range */
331 
332 /*
333  * PT_SUNW_UNWIND and PT_SUNW_EH_FRAME perform the same function,
334  * providing access to the .eh_frame_hdr section of the object.
335  * PT_SUNW_UNWIND is the original value, while PT_SUNW_EH_FRAME is
336  * required by the amd64 psABI. The Solaris link-editor (ld) tags output
337  * objects with PT_SUNW_UNWIND, but the Solaris runtime linker (ld.so.1)
338  * will accept and use either value.
339  */
340 #define	PT_SUNW_UNWIND		0x6464e550
341 #define	PT_SUNW_EH_FRAME	0x6474e550
342 #define	PT_GNU_EH_FRAME		PT_SUNW_EH_FRAME
343 
344 /*
345  * Linux specific program headers not currently used by Solaris
346  */
347 #define	PT_GNU_STACK	0x6474e551	/* Indicates stack executability */
348 #define	PT_GNU_RELRO	0x6474e552	/* Read-only after relocation */
349 
350 #define	PT_LOSUNW	0x6ffffffa
351 #define	PT_SUNWBSS	0x6ffffffa	/* Sun Specific segment (unused) */
352 #define	PT_SUNWSTACK	0x6ffffffb	/* describes the stack segment */
353 #define	PT_SUNWDTRACE	0x6ffffffc	/* private */
354 #define	PT_SUNWCAP	0x6ffffffd	/* hard/soft capabilities segment */
355 #define	PT_HISUNW	0x6fffffff
356 #define	PT_HIOS		0x6fffffff
357 
358 #define	PT_LOPROC	0x70000000	/* processor specific range */
359 #define	PT_HIPROC	0x7fffffff
360 
361 #define	PF_R		0x4		/* p_flags */
362 #define	PF_W		0x2
363 #define	PF_X		0x1
364 
365 #define	PF_MASKOS	0x0ff00000	/* OS specific values */
366 #define	PF_MASKPROC	0xf0000000	/* processor specific values */
367 
368 #define	PF_SUNW_FAILURE	0x00100000	/* mapping absent due to failure */
369 
370 #define	PN_XNUM		0xffff		/* extended program header index */
371 
372 /*
373  *	Section header
374  */
375 
376 typedef struct {
377 	Elf32_Word	sh_name;	/* section name */
378 	Elf32_Word	sh_type;	/* SHT_... */
379 	Elf32_Word	sh_flags;	/* SHF_... */
380 	Elf32_Addr	sh_addr;	/* virtual address */
381 	Elf32_Off	sh_offset;	/* file offset */
382 	Elf32_Word	sh_size;	/* section size */
383 	Elf32_Word	sh_link;	/* misc info */
384 	Elf32_Word	sh_info;	/* misc info */
385 	Elf32_Word	sh_addralign;	/* memory alignment */
386 	Elf32_Word	sh_entsize;	/* entry size if table */
387 } Elf32_Shdr;
388 
389 #if defined(_LP64) || defined(_LONGLONG_TYPE)
390 typedef struct {
391 	Elf64_Word	sh_name;	/* section name */
392 	Elf64_Word	sh_type;	/* SHT_... */
393 	Elf64_Xword	sh_flags;	/* SHF_... */
394 	Elf64_Addr	sh_addr;	/* virtual address */
395 	Elf64_Off	sh_offset;	/* file offset */
396 	Elf64_Xword	sh_size;	/* section size */
397 	Elf64_Word	sh_link;	/* misc info */
398 	Elf64_Word	sh_info;	/* misc info */
399 	Elf64_Xword	sh_addralign;	/* memory alignment */
400 	Elf64_Xword	sh_entsize;	/* entry size if table */
401 } Elf64_Shdr;
402 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
403 
404 #define	SHT_NULL		0		/* sh_type */
405 #define	SHT_PROGBITS		1
406 #define	SHT_SYMTAB		2
407 #define	SHT_STRTAB		3
408 #define	SHT_RELA		4
409 #define	SHT_HASH		5
410 #define	SHT_DYNAMIC		6
411 #define	SHT_NOTE		7
412 #define	SHT_NOBITS		8
413 #define	SHT_REL			9
414 #define	SHT_SHLIB		10
415 #define	SHT_DYNSYM		11
416 #define	SHT_UNKNOWN12		12
417 #define	SHT_UNKNOWN13		13
418 #define	SHT_INIT_ARRAY		14
419 #define	SHT_FINI_ARRAY		15
420 #define	SHT_PREINIT_ARRAY	16
421 #define	SHT_GROUP		17
422 #define	SHT_SYMTAB_SHNDX	18
423 #define	SHT_NUM			19
424 
425 /* Solaris ABI specific values */
426 #define	SHT_LOOS		0x60000000	/* OS specific range */
427 #define	SHT_LOSUNW		0x6fffffef
428 #define	SHT_SUNW_capchain	0x6fffffef
429 #define	SHT_SUNW_capinfo	0x6ffffff0
430 #define	SHT_SUNW_symsort	0x6ffffff1
431 #define	SHT_SUNW_tlssort	0x6ffffff2
432 #define	SHT_SUNW_LDYNSYM	0x6ffffff3
433 #define	SHT_SUNW_dof		0x6ffffff4
434 #define	SHT_SUNW_cap		0x6ffffff5
435 #define	SHT_SUNW_SIGNATURE	0x6ffffff6
436 #define	SHT_SUNW_ANNOTATE	0x6ffffff7
437 #define	SHT_SUNW_DEBUGSTR	0x6ffffff8
438 #define	SHT_SUNW_DEBUG		0x6ffffff9
439 #define	SHT_SUNW_move		0x6ffffffa
440 #define	SHT_SUNW_COMDAT		0x6ffffffb
441 #define	SHT_SUNW_syminfo	0x6ffffffc
442 #define	SHT_SUNW_verdef		0x6ffffffd
443 #define	SHT_GNU_verdef		SHT_SUNW_verdef
444 #define	SHT_SUNW_verneed	0x6ffffffe
445 #define	SHT_GNU_verneed		SHT_SUNW_verneed
446 #define	SHT_SUNW_versym		0x6fffffff
447 #define	SHT_GNU_versym		SHT_SUNW_versym
448 #define	SHT_HISUNW		0x6fffffff
449 #define	SHT_HIOS		0x6fffffff
450 
451 /*
452  * GNU/Linux OSABI specific values with different meanings than under Solaris.
453  * Due to the overlap in assigned values with the Solaris OSABI, correct
454  * interpretation of these values requires knowledge of the OSABI used by
455  * the object.
456  */
457 #define	SHT_GNU_ATTRIBUTES	0x6ffffff5	/* Object attributes */
458 #define	SHT_GNU_HASH		0x6ffffff6	/* GNU-style hash table */
459 #define	SHT_GNU_LIBLIST		0x6ffffff7	/* Prelink library list */
460 #define	SHT_CHECKSUM		0x6ffffff8	/* Checksum for DSO content */
461 
462 #define	SHT_LOPROC	0x70000000	/* processor specific range */
463 #define	SHT_HIPROC	0x7fffffff
464 
465 #define	SHT_LOUSER	0x80000000
466 #define	SHT_HIUSER	0xffffffff
467 
468 #define	SHF_WRITE		0x01		/* sh_flags */
469 #define	SHF_ALLOC		0x02
470 #define	SHF_EXECINSTR		0x04
471 #define	SHF_MERGE		0x10
472 #define	SHF_STRINGS		0x20
473 #define	SHF_INFO_LINK		0x40
474 #define	SHF_LINK_ORDER		0x80
475 #define	SHF_OS_NONCONFORMING	0x100
476 #define	SHF_GROUP		0x200
477 #define	SHF_TLS			0x400
478 
479 #define	SHF_MASKOS	0x0ff00000	/* OS specific values */
480 
481 
482 #define	SHF_MASKPROC	0xf0000000	/* processor specific values */
483 
484 #define	SHN_UNDEF	0		/* special section numbers */
485 #define	SHN_LORESERVE	0xff00
486 #define	SHN_LOPROC	0xff00		/* processor specific range */
487 #define	SHN_HIPROC	0xff1f
488 #define	SHN_LOOS	0xff20		/* OS specific range */
489 #define	SHN_LOSUNW	0xff3f
490 #define	SHN_SUNW_IGNORE	0xff3f
491 #define	SHN_HISUNW	0xff3f
492 #define	SHN_HIOS	0xff3f
493 #define	SHN_ABS		0xfff1
494 #define	SHN_COMMON	0xfff2
495 #define	SHN_XINDEX	0xffff		/* extended sect index */
496 #define	SHN_HIRESERVE	0xffff
497 
498 
499 
500 /*
501  *	Symbol table
502  */
503 
504 typedef struct {
505 	Elf32_Word	st_name;
506 	Elf32_Addr	st_value;
507 	Elf32_Word	st_size;
508 	unsigned char	st_info;	/* bind, type: ELF_32_ST_... */
509 	unsigned char	st_other;
510 	Elf32_Half	st_shndx;	/* SHN_... */
511 } Elf32_Sym;
512 
513 #if defined(_LP64) || defined(_LONGLONG_TYPE)
514 typedef struct {
515 	Elf64_Word	st_name;
516 	unsigned char	st_info;	/* bind, type: ELF_64_ST_... */
517 	unsigned char	st_other;
518 	Elf64_Half	st_shndx;	/* SHN_... */
519 	Elf64_Addr	st_value;
520 	Elf64_Xword	st_size;
521 } Elf64_Sym;
522 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
523 
524 #define	STN_UNDEF	0
525 
526 /*
527  *	Macros to compose and decompose values for S.st_info
528  *
529  *	bind = ELF32_ST_BIND(S.st_info)
530  *	type = ELF32_ST_TYPE(S.st_info)
531  *	S.st_info = ELF32_ST_INFO(bind, type)
532  */
533 
534 #define	ELF32_ST_BIND(info)		((info) >> 4)
535 #define	ELF32_ST_TYPE(info)		((info) & 0xf)
536 #define	ELF32_ST_INFO(bind, type)	(((bind)<<4)+((type)&0xf))
537 
538 #define	ELF64_ST_BIND(info)		((info) >> 4)
539 #define	ELF64_ST_TYPE(info)		((info) & 0xf)
540 #define	ELF64_ST_INFO(bind, type)	(((bind)<<4)+((type)&0xf))
541 
542 
543 #define	STB_LOCAL	0		/* BIND */
544 #define	STB_GLOBAL	1
545 #define	STB_WEAK	2
546 #define	STB_NUM		3
547 
548 #define	STB_LOPROC	13		/* processor specific range */
549 #define	STB_HIPROC	15
550 
551 #define	STT_NOTYPE	0		/* symbol type is unspecified */
552 #define	STT_OBJECT	1		/* data object */
553 #define	STT_FUNC	2		/* code object */
554 #define	STT_SECTION	3		/* symbol identifies an ELF section */
555 #define	STT_FILE	4		/* symbol's name is file name */
556 #define	STT_COMMON	5		/* common data object */
557 #define	STT_TLS		6		/* thread-local data object */
558 #define	STT_NUM		7		/* # defined types in generic range */
559 #define	STT_LOOS	10		/* OS specific range */
560 #define	STT_HIOS	12
561 #define	STT_LOPROC	13		/* processor specific range */
562 #define	STT_HIPROC	15
563 
564 /*
565  *	Macros to decompose values for S.st_other
566  *
567  *	visibility = ELF32_ST_VISIBILITY(S.st_other)
568  */
569 #define	ELF32_ST_VISIBILITY(other)	((other)&0x7)
570 #define	ELF64_ST_VISIBILITY(other)	((other)&0x7)
571 
572 #define	STV_DEFAULT	0
573 #define	STV_INTERNAL	1
574 #define	STV_HIDDEN	2
575 #define	STV_PROTECTED	3
576 #define	STV_EXPORTED	4
577 #define	STV_SINGLETON	5
578 #define	STV_ELIMINATE	6
579 
580 #define	STV_NUM		7
581 
582 /*
583  *	Relocation
584  */
585 
586 typedef struct {
587 	Elf32_Addr	r_offset;
588 	Elf32_Word	r_info;		/* sym, type: ELF32_R_... */
589 } Elf32_Rel;
590 
591 typedef struct {
592 	Elf32_Addr	r_offset;
593 	Elf32_Word	r_info;		/* sym, type: ELF32_R_... */
594 	Elf32_Sword	r_addend;
595 } Elf32_Rela;
596 
597 #if defined(_LP64) || defined(_LONGLONG_TYPE)
598 typedef struct {
599 	Elf64_Addr	r_offset;
600 	Elf64_Xword	r_info;		/* sym, type: ELF64_R_... */
601 } Elf64_Rel;
602 
603 typedef struct {
604 	Elf64_Addr	r_offset;
605 	Elf64_Xword	r_info;		/* sym, type: ELF64_R_... */
606 	Elf64_Sxword	r_addend;
607 } Elf64_Rela;
608 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
609 
610 
611 /*
612  *	Macros to compose and decompose values for Rel.r_info, Rela.f_info
613  *
614  *	sym = ELF32_R_SYM(R.r_info)
615  *	type = ELF32_R_TYPE(R.r_info)
616  *	R.r_info = ELF32_R_INFO(sym, type)
617  */
618 
619 #define	ELF32_R_SYM(info)	((info)>>8)
620 #define	ELF32_R_TYPE(info)	((unsigned char)(info))
621 #define	ELF32_R_INFO(sym, type)	(((sym)<<8)+(unsigned char)(type))
622 
623 #define	ELF64_R_SYM(info)	((info)>>32)
624 #define	ELF64_R_TYPE(info)    	((Elf64_Word)(info))
625 #define	ELF64_R_INFO(sym, type)	(((Elf64_Xword)(sym)<<32)+(Elf64_Xword)(type))
626 
627 
628 /*
629  * The r_info field is composed of two 32-bit components: the symbol
630  * table index and the relocation type.  The relocation type for SPARC V9
631  * is further decomposed into an 8-bit type identifier and a 24-bit type
632  * dependent data field.  For the existing Elf32 relocation types,
633  * that data field is zero.
634  */
635 #define	ELF64_R_TYPE_DATA(info)	(((Elf64_Xword)(info)<<32)>>40)
636 #define	ELF64_R_TYPE_ID(info)	(((Elf64_Xword)(info)<<56)>>56)
637 #define	ELF64_R_TYPE_INFO(data, type)	\
638 		(((Elf64_Xword)(data)<<8)+(Elf64_Xword)(type))
639 
640 
641 /*
642  * Section Group Flags (SHT_GROUP)
643  */
644 #define	GRP_COMDAT	0x01
645 
646 
647 /*
648  *	Note entry header
649  */
650 
651 typedef struct {
652 	Elf32_Word	n_namesz;	/* length of note's name */
653 	Elf32_Word	n_descsz;	/* length of note's "desc" */
654 	Elf32_Word	n_type;		/* type of note */
655 } Elf32_Nhdr;
656 
657 #if defined(_LP64) || defined(_LONGLONG_TYPE)
658 typedef struct {
659 	Elf64_Word	n_namesz;	/* length of note's name */
660 	Elf64_Word	n_descsz;	/* length of note's "desc" */
661 	Elf64_Word	n_type;		/* type of note */
662 } Elf64_Nhdr;
663 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
664 
665 /*
666  *	Move entry
667  */
668 #if defined(_LP64) || defined(_LONGLONG_TYPE)
669 typedef struct {
670 	Elf32_Lword	m_value;	/* symbol value */
671 	Elf32_Word 	m_info;		/* size + index */
672 	Elf32_Word	m_poffset;	/* symbol offset */
673 	Elf32_Half	m_repeat;	/* repeat count */
674 	Elf32_Half	m_stride;	/* stride info */
675 } Elf32_Move;
676 
677 /*
678  *	Macros to compose and decompose values for Move.r_info
679  *
680  *	sym = ELF32_M_SYM(M.m_info)
681  *	size = ELF32_M_SIZE(M.m_info)
682  *	M.m_info = ELF32_M_INFO(sym, size)
683  */
684 #define	ELF32_M_SYM(info)	((info)>>8)
685 #define	ELF32_M_SIZE(info)	((unsigned char)(info))
686 #define	ELF32_M_INFO(sym, size)	(((sym)<<8)+(unsigned char)(size))
687 
688 typedef struct {
689 	Elf64_Lword	m_value;	/* symbol value */
690 	Elf64_Xword 	m_info;		/* size + index */
691 	Elf64_Xword	m_poffset;	/* symbol offset */
692 	Elf64_Half	m_repeat;	/* repeat count */
693 	Elf64_Half	m_stride;	/* stride info */
694 } Elf64_Move;
695 #define	ELF64_M_SYM(info)	((info)>>8)
696 #define	ELF64_M_SIZE(info)	((unsigned char)(info))
697 #define	ELF64_M_INFO(sym, size)	(((sym)<<8)+(unsigned char)(size))
698 
699 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
700 
701 
702 /*
703  *	Capabilities entry, Capabilities info and Capabilities chain.
704  */
705 #ifndef	_ASM
706 typedef struct {
707 	Elf32_Word	c_tag;		/* how to interpret value */
708 	union {
709 		Elf32_Word	c_val;
710 		Elf32_Addr	c_ptr;
711 	} c_un;
712 } Elf32_Cap;
713 
714 typedef	Elf32_Word	Elf32_Capinfo;
715 typedef	Elf32_Word	Elf32_Capchain;
716 
717 /*
718  *	Macros to compose and decompose values for capabilities info.
719  *
720  *	sym = ELF32_C_SYM(info)
721  *	grp = ELF32_C_GROUP(info)
722  *	info = ELF32_C_INFO(sym, grp)
723  */
724 #define	ELF32_C_SYM(info)	((info)>>8)
725 #define	ELF32_C_GROUP(info)	((unsigned char)(info))
726 #define	ELF32_C_INFO(sym, grp)	(((sym)<<8)+(unsigned char)(grp))
727 
728 
729 #if defined(_LP64) || defined(_LONGLONG_TYPE)
730 typedef struct {
731 	Elf64_Xword	c_tag;		/* how to interpret value */
732 	union {
733 		Elf64_Xword	c_val;
734 		Elf64_Addr	c_ptr;
735 	} c_un;
736 } Elf64_Cap;
737 
738 typedef	Elf64_Xword	Elf64_Capinfo;
739 typedef	Elf64_Word	Elf64_Capchain;
740 
741 /*
742  *	Macros to compose and decompose values for capabilities info.
743  *
744  *	sym = ELF64_C_SYM(info)
745  *	grp = ELF64_C_GROUP(info)
746  *	info = ELF64_C_INFO(sym, grp)
747  */
748 #define	ELF64_C_SYM(info)	((info)>>32)
749 #define	ELF64_C_GROUP(info)    	((Elf64_Word)(info))
750 #define	ELF64_C_INFO(sym, grp)	(((Elf64_Xword)(sym)<<32)+(Elf64_Xword)(grp))
751 
752 #endif	/* defined(_LP64) || defined(_LONGLONG_TYPE) */
753 #endif
754 
755 /*
756  * Version numbers for SHT_SUNW_capinfo and SHT_SUNW_capchain.
757  */
758 #define	CAPINFO_NONE		0
759 #define	CAPINFO_CURRENT		1
760 #define	CAPINFO_NUM		2
761 
762 #define	CAPCHAIN_NONE		0
763 #define	CAPCHAIN_CURRENT	1
764 #define	CAPCHAIN_NUM		2
765 
766 /*
767  * A SHT_SUNW_capinfo table mirrors a symbol table.  A capabilities symbol has
768  * a SHT_SUNW_capinfo table entry that provides an index into the associated
769  * SHT_SUNW_cap capabilities group, and the symbol index of the associated lead
770  * symbol.  A capabilities symbol is a local symbol.  A global lead capabilities
771  * symbol is tagged with a group CAPINFO_SUNW_GLOB.
772  */
773 #define	CAPINFO_SUNW_GLOB	0xff
774 
775 /*
776  * Capabilities values.
777  */
778 #define	CA_SUNW_NULL	0
779 #define	CA_SUNW_HW_1	1		/* first hardware capabilities entry */
780 #define	CA_SUNW_SF_1	2		/* first software capabilities entry */
781 #define	CA_SUNW_HW_2	3		/* second hardware capabilities entry */
782 #define	CA_SUNW_PLAT	4		/* platform capability entry */
783 #define	CA_SUNW_MACH	5		/* machine capability entry */
784 #define	CA_SUNW_ID	6		/* capability identifier */
785 #define	CA_SUNW_NUM	7
786 
787 /*
788  * Define software capabilities (CA_SUNW_SF_1 values).  Note, hardware
789  * capabilities (CA_SUNW_HW_1 values) are taken directly from sys/auxv_$MACH.h.
790  */
791 #define	SF1_SUNW_FPKNWN	0x001		/* frame pointer usage is known */
792 #define	SF1_SUNW_FPUSED	0x002		/* frame pointer is in use */
793 #define	SF1_SUNW_ADDR32	0x004		/* 32-bit address space requirement */
794 #define	SF1_SUNW_MASK	0x007		/* known software capabilities mask */
795 
796 /*
797  *	Known values for note entry types (e_type == ET_CORE)
798  */
799 #define	NT_PRSTATUS	1	/* prstatus_t	<sys/old_procfs.h>	*/
800 #define	NT_PRFPREG	2	/* prfpregset_t	<sys/old_procfs.h>	*/
801 #define	NT_PRPSINFO	3	/* prpsinfo_t	<sys/old_procfs.h>	*/
802 #define	NT_PRXREG	4	/* prxregset_t	<sys/procfs.h>		*/
803 #define	NT_PLATFORM	5	/* string from sysinfo(SI_PLATFORM)	*/
804 #define	NT_AUXV		6	/* auxv_t array	<sys/auxv.h>		*/
805 #define	NT_GWINDOWS	7	/* gwindows_t	SPARC only		*/
806 #define	NT_ASRS		8	/* asrset_t	SPARC V9 only		*/
807 #define	NT_LDT		9	/* ssd array	<sys/sysi86.h> IA32 only */
808 #define	NT_PSTATUS	10	/* pstatus_t	<sys/procfs.h>		*/
809 #define	NT_PSINFO	13	/* psinfo_t	<sys/procfs.h>		*/
810 #define	NT_PRCRED	14	/* prcred_t	<sys/procfs.h>		*/
811 #define	NT_UTSNAME	15	/* struct utsname <sys/utsname.h>	*/
812 #define	NT_LWPSTATUS	16	/* lwpstatus_t	<sys/procfs.h>		*/
813 #define	NT_LWPSINFO	17	/* lwpsinfo_t	<sys/procfs.h>		*/
814 #define	NT_PRPRIV	18	/* prpriv_t	<sys/procfs.h>		*/
815 #define	NT_PRPRIVINFO	19	/* priv_impl_info_t <sys/priv.h>	*/
816 #define	NT_CONTENT	20	/* core_content_t <sys/corectl.h>	*/
817 #define	NT_ZONENAME	21	/* string from getzonenamebyid(3C)	*/
818 #define	NT_FDINFO	22	/* open fd info 			*/
819 #define	NT_NUM		22
820 
821 
822 #ifdef _KERNEL
823 /*
824  * The following routine checks the processor-specific
825  * fields of an ELF header.
826  */
827 int	elfheadcheck(unsigned char, Elf32_Half, Elf32_Word);
828 #endif
829 
830 #ifdef	__cplusplus
831 }
832 #endif
833 
834 #if defined(ELF_TARGET_ALL) || defined(ELF_TARGET_SPARC)
835 #include <sys/elf_SPARC.h>
836 #endif
837 
838 #if defined(ELF_TARGET_ALL) || defined(ELF_TARGET_386)
839 #include <sys/elf_386.h>
840 #endif
841 
842 #if defined(ELF_TARGET_ALL) || defined(ELF_TARGET_AMD64)
843 #include <sys/elf_amd64.h>
844 #endif
845 
846 #endif	/* _SYS_ELF_H */
847