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