xref: /titanic_53/usr/src/head/libelf.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  *	Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  *	Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _LIBELF_H
32*7c478bd9Sstevel@tonic-gate #define	_LIBELF_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9	*/
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/elf.h>
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
41*7c478bd9Sstevel@tonic-gate extern "C" {
42*7c478bd9Sstevel@tonic-gate #endif
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
46*7c478bd9Sstevel@tonic-gate #error "large files are not supported by libelf"
47*7c478bd9Sstevel@tonic-gate #endif
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #undef _
51*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
52*7c478bd9Sstevel@tonic-gate typedef void		Elf_Void;
53*7c478bd9Sstevel@tonic-gate #define	_(a)		a
54*7c478bd9Sstevel@tonic-gate #else
55*7c478bd9Sstevel@tonic-gate typedef char		Elf_Void;
56*7c478bd9Sstevel@tonic-gate #define	_(a)		()
57*7c478bd9Sstevel@tonic-gate #undef const
58*7c478bd9Sstevel@tonic-gate #define	const
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate 
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate /*
63*7c478bd9Sstevel@tonic-gate  * Commands
64*7c478bd9Sstevel@tonic-gate  */
65*7c478bd9Sstevel@tonic-gate typedef enum {
66*7c478bd9Sstevel@tonic-gate 	ELF_C_NULL = 0,	/* must be first, 0 */
67*7c478bd9Sstevel@tonic-gate 	ELF_C_READ,
68*7c478bd9Sstevel@tonic-gate 	ELF_C_WRITE,
69*7c478bd9Sstevel@tonic-gate 	ELF_C_CLR,
70*7c478bd9Sstevel@tonic-gate 	ELF_C_SET,
71*7c478bd9Sstevel@tonic-gate 	ELF_C_FDDONE,
72*7c478bd9Sstevel@tonic-gate 	ELF_C_FDREAD,
73*7c478bd9Sstevel@tonic-gate 	ELF_C_RDWR,
74*7c478bd9Sstevel@tonic-gate 	ELF_C_WRIMAGE,
75*7c478bd9Sstevel@tonic-gate 	ELF_C_IMAGE,
76*7c478bd9Sstevel@tonic-gate 	ELF_C_NUM	/* must be last */
77*7c478bd9Sstevel@tonic-gate } Elf_Cmd;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate /*
81*7c478bd9Sstevel@tonic-gate  * Flags
82*7c478bd9Sstevel@tonic-gate  */
83*7c478bd9Sstevel@tonic-gate #define	ELF_F_DIRTY	0x1
84*7c478bd9Sstevel@tonic-gate #define	ELF_F_LAYOUT	0x4
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /*
88*7c478bd9Sstevel@tonic-gate  * File types
89*7c478bd9Sstevel@tonic-gate  */
90*7c478bd9Sstevel@tonic-gate typedef enum {
91*7c478bd9Sstevel@tonic-gate 	ELF_K_NONE = 0,	/* must be first, 0 */
92*7c478bd9Sstevel@tonic-gate 	ELF_K_AR,
93*7c478bd9Sstevel@tonic-gate 	ELF_K_COFF,
94*7c478bd9Sstevel@tonic-gate 	ELF_K_ELF,
95*7c478bd9Sstevel@tonic-gate 	ELF_K_NUM	/* must be last */
96*7c478bd9Sstevel@tonic-gate } Elf_Kind;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate /*
100*7c478bd9Sstevel@tonic-gate  * Translation types
101*7c478bd9Sstevel@tonic-gate  */
102*7c478bd9Sstevel@tonic-gate typedef enum {
103*7c478bd9Sstevel@tonic-gate 	ELF_T_BYTE = 0,	/* must be first, 0 */
104*7c478bd9Sstevel@tonic-gate 	ELF_T_ADDR,
105*7c478bd9Sstevel@tonic-gate 	ELF_T_DYN,
106*7c478bd9Sstevel@tonic-gate 	ELF_T_EHDR,
107*7c478bd9Sstevel@tonic-gate 	ELF_T_HALF,
108*7c478bd9Sstevel@tonic-gate 	ELF_T_OFF,
109*7c478bd9Sstevel@tonic-gate 	ELF_T_PHDR,
110*7c478bd9Sstevel@tonic-gate 	ELF_T_RELA,
111*7c478bd9Sstevel@tonic-gate 	ELF_T_REL,
112*7c478bd9Sstevel@tonic-gate 	ELF_T_SHDR,
113*7c478bd9Sstevel@tonic-gate 	ELF_T_SWORD,
114*7c478bd9Sstevel@tonic-gate 	ELF_T_SYM,
115*7c478bd9Sstevel@tonic-gate 	ELF_T_WORD,
116*7c478bd9Sstevel@tonic-gate 	ELF_T_VDEF,
117*7c478bd9Sstevel@tonic-gate 	ELF_T_VNEED,
118*7c478bd9Sstevel@tonic-gate 	ELF_T_SXWORD,
119*7c478bd9Sstevel@tonic-gate 	ELF_T_XWORD,
120*7c478bd9Sstevel@tonic-gate 	ELF_T_SYMINFO,
121*7c478bd9Sstevel@tonic-gate 	ELF_T_NOTE,
122*7c478bd9Sstevel@tonic-gate 	ELF_T_MOVE,
123*7c478bd9Sstevel@tonic-gate 	ELF_T_MOVEP,
124*7c478bd9Sstevel@tonic-gate 	ELF_T_CAP,
125*7c478bd9Sstevel@tonic-gate 	ELF_T_NUM	/* must be last */
126*7c478bd9Sstevel@tonic-gate } Elf_Type;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate typedef struct Elf	Elf;
130*7c478bd9Sstevel@tonic-gate typedef struct Elf_Scn	Elf_Scn;
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  * Archive member header
135*7c478bd9Sstevel@tonic-gate  */
136*7c478bd9Sstevel@tonic-gate typedef struct {
137*7c478bd9Sstevel@tonic-gate 	char		*ar_name;
138*7c478bd9Sstevel@tonic-gate 	time_t		ar_date;
139*7c478bd9Sstevel@tonic-gate 	uid_t		ar_uid;
140*7c478bd9Sstevel@tonic-gate 	gid_t 		ar_gid;
141*7c478bd9Sstevel@tonic-gate 	mode_t		ar_mode;
142*7c478bd9Sstevel@tonic-gate 	off_t		ar_size;
143*7c478bd9Sstevel@tonic-gate 	char 		*ar_rawname;
144*7c478bd9Sstevel@tonic-gate } Elf_Arhdr;
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate /*
148*7c478bd9Sstevel@tonic-gate  * Archive symbol table
149*7c478bd9Sstevel@tonic-gate  */
150*7c478bd9Sstevel@tonic-gate typedef struct {
151*7c478bd9Sstevel@tonic-gate 	char		*as_name;
152*7c478bd9Sstevel@tonic-gate 	size_t		as_off;
153*7c478bd9Sstevel@tonic-gate 	unsigned long	as_hash;
154*7c478bd9Sstevel@tonic-gate } Elf_Arsym;
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate  * Data descriptor
159*7c478bd9Sstevel@tonic-gate  */
160*7c478bd9Sstevel@tonic-gate typedef struct {
161*7c478bd9Sstevel@tonic-gate 	Elf_Void	*d_buf;
162*7c478bd9Sstevel@tonic-gate 	Elf_Type	d_type;
163*7c478bd9Sstevel@tonic-gate 	size_t		d_size;
164*7c478bd9Sstevel@tonic-gate 	off_t		d_off;		/* offset into section */
165*7c478bd9Sstevel@tonic-gate 	size_t		d_align;	/* alignment in section */
166*7c478bd9Sstevel@tonic-gate 	unsigned	d_version;	/* elf version */
167*7c478bd9Sstevel@tonic-gate } Elf_Data;
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * Function declarations
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate Elf		*elf_begin	_((int, Elf_Cmd, Elf *));
174*7c478bd9Sstevel@tonic-gate int		elf_cntl	_((Elf *, Elf_Cmd));
175*7c478bd9Sstevel@tonic-gate int		elf_end		_((Elf *));
176*7c478bd9Sstevel@tonic-gate const char	*elf_errmsg	_((int));
177*7c478bd9Sstevel@tonic-gate int		elf_errno	_((void));
178*7c478bd9Sstevel@tonic-gate void		elf_fill	_((int));
179*7c478bd9Sstevel@tonic-gate unsigned	elf_flagdata	_((Elf_Data *, Elf_Cmd, unsigned));
180*7c478bd9Sstevel@tonic-gate unsigned	elf_flagehdr	_((Elf *, Elf_Cmd,  unsigned));
181*7c478bd9Sstevel@tonic-gate unsigned	elf_flagelf	_((Elf *, Elf_Cmd, unsigned));
182*7c478bd9Sstevel@tonic-gate unsigned	elf_flagphdr	_((Elf *, Elf_Cmd, unsigned));
183*7c478bd9Sstevel@tonic-gate unsigned	elf_flagscn	_((Elf_Scn *, Elf_Cmd, unsigned));
184*7c478bd9Sstevel@tonic-gate unsigned	elf_flagshdr	_((Elf_Scn *, Elf_Cmd, unsigned));
185*7c478bd9Sstevel@tonic-gate size_t		elf32_fsize	_((Elf_Type, size_t, unsigned));
186*7c478bd9Sstevel@tonic-gate Elf_Arhdr	*elf_getarhdr	_((Elf *));
187*7c478bd9Sstevel@tonic-gate Elf_Arsym	*elf_getarsym	_((Elf *, size_t *));
188*7c478bd9Sstevel@tonic-gate off_t		elf_getbase	_((Elf *));
189*7c478bd9Sstevel@tonic-gate Elf_Data	*elf_getdata	_((Elf_Scn *, Elf_Data *));
190*7c478bd9Sstevel@tonic-gate Elf32_Ehdr	*elf32_getehdr	_((Elf *));
191*7c478bd9Sstevel@tonic-gate char		*elf_getident	_((Elf *, size_t *));
192*7c478bd9Sstevel@tonic-gate Elf32_Phdr	*elf32_getphdr	_((Elf *));
193*7c478bd9Sstevel@tonic-gate Elf_Scn		*elf_getscn	_((Elf *elf, size_t));
194*7c478bd9Sstevel@tonic-gate Elf32_Shdr	*elf32_getshdr	_((Elf_Scn *));
195*7c478bd9Sstevel@tonic-gate int		elf_getshnum	_((Elf *, size_t *));
196*7c478bd9Sstevel@tonic-gate int		elf_getshstrndx	_((Elf *, size_t *));
197*7c478bd9Sstevel@tonic-gate unsigned long	elf_hash	_((const char *));
198*7c478bd9Sstevel@tonic-gate long		elf32_checksum	_((Elf *));
199*7c478bd9Sstevel@tonic-gate Elf_Kind	elf_kind	_((Elf *));
200*7c478bd9Sstevel@tonic-gate Elf		*elf_memory	_((char *, size_t));
201*7c478bd9Sstevel@tonic-gate size_t		elf_ndxscn	_((Elf_Scn *));
202*7c478bd9Sstevel@tonic-gate Elf_Data	*elf_newdata	_((Elf_Scn *));
203*7c478bd9Sstevel@tonic-gate Elf32_Ehdr	*elf32_newehdr	_((Elf *));
204*7c478bd9Sstevel@tonic-gate Elf32_Phdr	*elf32_newphdr	_((Elf *, size_t));
205*7c478bd9Sstevel@tonic-gate Elf_Scn		*elf_newscn	_((Elf *));
206*7c478bd9Sstevel@tonic-gate Elf_Scn		*elf_nextscn	_((Elf *, Elf_Scn *));
207*7c478bd9Sstevel@tonic-gate Elf_Cmd		elf_next	_((Elf *));
208*7c478bd9Sstevel@tonic-gate size_t		elf_rand	_((Elf *, size_t));
209*7c478bd9Sstevel@tonic-gate Elf_Data	*elf_rawdata	_((Elf_Scn *, Elf_Data *));
210*7c478bd9Sstevel@tonic-gate char		*elf_rawfile	_((Elf *, size_t *));
211*7c478bd9Sstevel@tonic-gate char		*elf_strptr	_((Elf *, size_t, size_t));
212*7c478bd9Sstevel@tonic-gate off_t		elf_update	_((Elf *, Elf_Cmd));
213*7c478bd9Sstevel@tonic-gate unsigned	elf_version	_((unsigned));
214*7c478bd9Sstevel@tonic-gate Elf_Data	*elf32_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
215*7c478bd9Sstevel@tonic-gate Elf_Data	*elf32_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(_LONGLONG_TYPE)
218*7c478bd9Sstevel@tonic-gate size_t		elf64_fsize	_((Elf_Type, size_t, unsigned));
219*7c478bd9Sstevel@tonic-gate Elf64_Ehdr	*elf64_getehdr	_((Elf *));
220*7c478bd9Sstevel@tonic-gate Elf64_Phdr	*elf64_getphdr	_((Elf *));
221*7c478bd9Sstevel@tonic-gate Elf64_Shdr	*elf64_getshdr	_((Elf_Scn *));
222*7c478bd9Sstevel@tonic-gate long		elf64_checksum	_((Elf *));
223*7c478bd9Sstevel@tonic-gate Elf64_Ehdr	*elf64_newehdr	_((Elf *));
224*7c478bd9Sstevel@tonic-gate Elf64_Phdr	*elf64_newphdr	_((Elf *, size_t));
225*7c478bd9Sstevel@tonic-gate Elf_Data	*elf64_xlatetof	_((Elf_Data *, const Elf_Data *, unsigned));
226*7c478bd9Sstevel@tonic-gate Elf_Data	*elf64_xlatetom	_((Elf_Data *, const Elf_Data *, unsigned));
227*7c478bd9Sstevel@tonic-gate #endif /* (defined(_LP64) || defined(_LONGLONG_TYPE) */
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate #undef	_
230*7c478bd9Sstevel@tonic-gate 
231*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
232*7c478bd9Sstevel@tonic-gate }
233*7c478bd9Sstevel@tonic-gate #endif
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate #endif	/* _LIBELF_H */
236