|
1 /* |
|
2 * libelf.h - public header file for libelf. |
|
3 * Copyright (C) 1995 - 2006 Michael Riepe |
|
4 * |
|
5 * This library is free software; you can redistribute it and/or |
|
6 * modify it under the terms of the GNU Library General Public |
|
7 * License as published by the Free Software Foundation; either |
|
8 * version 2 of the License, or (at your option) any later version. |
|
9 * |
|
10 * This library is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 * Library General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU Library General Public |
|
16 * License along with this library; if not, write to the Free Software |
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 */ |
|
19 |
|
20 /* @(#) $Id: libelf.h,v 1.26 2006/09/02 14:11:48 michael Exp $ */ |
|
21 |
|
22 #ifndef _LIBELF_H |
|
23 #define _LIBELF_H |
|
24 |
|
25 #include <stddef.h> /* for size_t */ |
|
26 #include <sys/types.h> |
|
27 |
|
28 #if __LIBELF_INTERNAL__ |
|
29 #include <sys_elf.h> |
|
30 #else /* __LIBELF_INTERNAL__ */ |
|
31 #include <libelf/sys_elf.h> |
|
32 #endif /* __LIBELF_INTERNAL__ */ |
|
33 |
|
34 #ifdef __cplusplus |
|
35 extern "C" { |
|
36 #endif /* __cplusplus */ |
|
37 |
|
38 #ifndef __P |
|
39 # if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32) |
|
40 # define __P(args) args |
|
41 # else /* __STDC__ || defined(__cplusplus) */ |
|
42 # define __P(args) () |
|
43 # endif /* __STDC__ || defined(__cplusplus) */ |
|
44 #endif /* __P */ |
|
45 |
|
46 /* |
|
47 * Commands |
|
48 */ |
|
49 typedef enum { |
|
50 ELF_C_NULL = 0, /* must be first, 0 */ |
|
51 ELF_C_READ, |
|
52 ELF_C_WRITE, |
|
53 ELF_C_CLR, |
|
54 ELF_C_SET, |
|
55 ELF_C_FDDONE, |
|
56 ELF_C_FDREAD, |
|
57 ELF_C_RDWR, |
|
58 ELF_C_NUM /* must be last */ |
|
59 } Elf_Cmd; |
|
60 |
|
61 /* |
|
62 * Flags |
|
63 */ |
|
64 #define ELF_F_DIRTY 0x1 |
|
65 #define ELF_F_LAYOUT 0x4 |
|
66 |
|
67 /* |
|
68 * File types |
|
69 */ |
|
70 typedef enum { |
|
71 ELF_K_NONE = 0, /* must be first, 0 */ |
|
72 ELF_K_AR, |
|
73 ELF_K_COFF, |
|
74 ELF_K_ELF, |
|
75 ELF_K_NUM /* must be last */ |
|
76 } Elf_Kind; |
|
77 |
|
78 /* |
|
79 * Data types |
|
80 */ |
|
81 typedef enum { |
|
82 ELF_T_BYTE = 0, /* must be first, 0 */ |
|
83 ELF_T_ADDR, |
|
84 ELF_T_DYN, |
|
85 ELF_T_EHDR, |
|
86 ELF_T_HALF, |
|
87 ELF_T_OFF, |
|
88 ELF_T_PHDR, |
|
89 ELF_T_RELA, |
|
90 ELF_T_REL, |
|
91 ELF_T_SHDR, |
|
92 ELF_T_SWORD, |
|
93 ELF_T_SYM, |
|
94 ELF_T_WORD, |
|
95 /* |
|
96 * New stuff for 64-bit. |
|
97 * |
|
98 * Most implementations add ELF_T_SXWORD after ELF_T_SWORD |
|
99 * which breaks binary compatibility with earlier versions. |
|
100 * If this causes problems for you, contact me. |
|
101 */ |
|
102 ELF_T_SXWORD, |
|
103 ELF_T_XWORD, |
|
104 /* |
|
105 * Symbol versioning. Sun broke binary compatibility (again!), |
|
106 * but I won't. |
|
107 */ |
|
108 ELF_T_VDEF, |
|
109 ELF_T_VNEED, |
|
110 ELF_T_NUM /* must be last */ |
|
111 } Elf_Type; |
|
112 |
|
113 /* |
|
114 * Elf descriptor |
|
115 */ |
|
116 typedef struct Elf Elf; |
|
117 |
|
118 /* |
|
119 * Section descriptor |
|
120 */ |
|
121 typedef struct Elf_Scn Elf_Scn; |
|
122 |
|
123 /* |
|
124 * Archive member header |
|
125 */ |
|
126 typedef struct { |
|
127 char* ar_name; |
|
128 time_t ar_date; |
|
129 long ar_uid; |
|
130 long ar_gid; |
|
131 unsigned long ar_mode; |
|
132 off_t ar_size; |
|
133 char* ar_rawname; |
|
134 } Elf_Arhdr; |
|
135 |
|
136 /* |
|
137 * Archive symbol table |
|
138 */ |
|
139 typedef struct { |
|
140 char* as_name; |
|
141 size_t as_off; |
|
142 unsigned long as_hash; |
|
143 } Elf_Arsym; |
|
144 |
|
145 /* |
|
146 * Data descriptor |
|
147 */ |
|
148 typedef struct { |
|
149 void* d_buf; |
|
150 Elf_Type d_type; |
|
151 size_t d_size; |
|
152 off_t d_off; |
|
153 size_t d_align; |
|
154 unsigned d_version; |
|
155 } Elf_Data; |
|
156 |
|
157 /* |
|
158 * Function declarations |
|
159 */ |
|
160 extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref)); |
|
161 extern Elf *elf_memory __P((char *__image, size_t __size)); |
|
162 extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd)); |
|
163 extern int elf_end __P((Elf *__elf)); |
|
164 extern const char *elf_errmsg __P((int __err)); |
|
165 extern int elf_errno __P((void)); |
|
166 extern void elf_fill __P((int __fill)); |
|
167 extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd, |
|
168 unsigned __flags)); |
|
169 extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd, |
|
170 unsigned __flags)); |
|
171 extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd, |
|
172 unsigned __flags)); |
|
173 extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd, |
|
174 unsigned __flags)); |
|
175 extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd, |
|
176 unsigned __flags)); |
|
177 extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd, |
|
178 unsigned __flags)); |
|
179 extern size_t elf32_fsize __P((Elf_Type __type, size_t __count, |
|
180 unsigned __ver)); |
|
181 extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf)); |
|
182 extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr)); |
|
183 extern off_t elf_getbase __P((Elf *__elf)); |
|
184 extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data)); |
|
185 extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf)); |
|
186 extern char *elf_getident __P((Elf *__elf, size_t *__ptr)); |
|
187 extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf)); |
|
188 extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index)); |
|
189 extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn)); |
|
190 extern unsigned long elf_hash __P((const unsigned char *__name)); |
|
191 extern Elf_Kind elf_kind __P((Elf *__elf)); |
|
192 extern size_t elf_ndxscn __P((Elf_Scn *__scn)); |
|
193 extern Elf_Data *elf_newdata __P((Elf_Scn *__scn)); |
|
194 extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf)); |
|
195 extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count)); |
|
196 extern Elf_Scn *elf_newscn __P((Elf *__elf)); |
|
197 extern Elf_Cmd elf_next __P((Elf *__elf)); |
|
198 extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn)); |
|
199 extern size_t elf_rand __P((Elf *__elf, size_t __offset)); |
|
200 extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data)); |
|
201 extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr)); |
|
202 extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset)); |
|
203 extern off_t elf_update __P((Elf *__elf, Elf_Cmd __cmd)); |
|
204 extern unsigned elf_version __P((unsigned __ver)); |
|
205 extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, |
|
206 unsigned __encode)); |
|
207 extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, |
|
208 unsigned __encode)); |
|
209 |
|
210 /* |
|
211 * Additional functions found on Solaris |
|
212 */ |
|
213 extern long elf32_checksum __P((Elf *__elf)); |
|
214 |
|
215 #if __LIBELF64 |
|
216 /* |
|
217 * 64-bit ELF functions |
|
218 * Not available on all platforms |
|
219 */ |
|
220 extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf)); |
|
221 extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf)); |
|
222 extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf)); |
|
223 extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count)); |
|
224 extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn)); |
|
225 extern size_t elf64_fsize __P((Elf_Type __type, size_t __count, |
|
226 unsigned __ver)); |
|
227 extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src, |
|
228 unsigned __encode)); |
|
229 extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src, |
|
230 unsigned __encode)); |
|
231 |
|
232 /* |
|
233 * Additional functions found on Solaris |
|
234 */ |
|
235 extern long elf64_checksum __P((Elf *__elf)); |
|
236 |
|
237 #endif /* __LIBELF64 */ |
|
238 |
|
239 /* |
|
240 * ELF format extensions |
|
241 * |
|
242 * These functions return 0 on failure, 1 on success. |
|
243 */ |
|
244 extern int elf_getphnum __P((Elf *__elf, size_t *__resultp)); |
|
245 extern int elf_getshnum __P((Elf *__elf, size_t *__resultp)); |
|
246 extern int elf_getshstrndx __P((Elf *__elf, size_t *__resultp)); |
|
247 |
|
248 /* |
|
249 * Convenience functions |
|
250 * |
|
251 * elfx_update_shstrndx is elf_getshstrndx's counterpart. |
|
252 * It should be used to set the e_shstrndx member. |
|
253 * There is no update function for e_shnum or e_phnum |
|
254 * because libelf handles them internally. |
|
255 */ |
|
256 extern int elfx_update_shstrndx __P((Elf *__elf, size_t __index)); |
|
257 |
|
258 /* |
|
259 * Experimental extensions: |
|
260 * |
|
261 * elfx_movscn() moves section `__scn' directly after section `__after'. |
|
262 * elfx_remscn() removes section `__scn'. Both functions update |
|
263 * the section indices; elfx_remscn() also adjusts the ELF header's |
|
264 * e_shnum member. The application is responsible for updating other |
|
265 * data (in particular, e_shstrndx and the section headers' sh_link and |
|
266 * sh_info members). |
|
267 * |
|
268 * elfx_movscn() returns the new index of the moved section. |
|
269 * elfx_remscn() returns the original index of the removed section. |
|
270 * A return value of zero indicates an error. |
|
271 */ |
|
272 extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after)); |
|
273 extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn)); |
|
274 |
|
275 /* |
|
276 * elf_delscn() is obsolete. Please use elfx_remscn() instead. |
|
277 */ |
|
278 extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn)); |
|
279 |
|
280 #ifdef __cplusplus |
|
281 } |
|
282 #endif /* __cplusplus */ |
|
283 |
|
284 #endif /* _LIBELF_H */ |