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