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