2 * libelf.h - public header file for libelf.
3 * Copyright (C) 1995 - 2008 Michael Riepe
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 /* @(#) $Id: libelf.h,v 1.29 2009/07/07 17:57:43 michael Exp $ */
25 #include <stddef.h> /* for size_t */
27 #include <sys/types.h>
29 #if __LIBELF_INTERNAL__
31 #else /* __LIBELF_INTERNAL__ */
32 #include <libelf/sys_elf.h>
33 #endif /* __LIBELF_INTERNAL__ */
35 #if defined __GNUC__ && !defined __cplusplus
36 #define DEPRECATED __attribute__((deprecated))
38 #define DEPRECATED /* nothing */
43 #endif /* __cplusplus */
46 # if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32)
47 # define __P(args) args
48 # else /* __STDC__ || defined(__cplusplus) */
50 # endif /* __STDC__ || defined(__cplusplus) */
57 ELF_C_NULL = 0, /* must be first, 0 */
65 ELF_C_NUM /* must be last */
71 #define ELF_F_DIRTY 0x1
72 #define ELF_F_LAYOUT 0x4
74 * Allow sections to overlap when ELF_F_LAYOUT is in effect.
75 * Note that this flag ist NOT portable, and that it may render
76 * the output file unusable. Use with extreme caution!
78 #define ELF_F_LAYOUT_OVERLAP 0x10000000
84 ELF_K_NONE = 0, /* must be first, 0 */
88 ELF_K_NUM /* must be last */
95 ELF_T_BYTE = 0, /* must be first, 0 */
109 * New stuff for 64-bit.
111 * Most implementations add ELF_T_SXWORD after ELF_T_SWORD
112 * which breaks binary compatibility with earlier versions.
113 * If this causes problems for you, contact me.
118 * Symbol versioning. Sun broke binary compatibility (again!),
123 ELF_T_NUM /* must be last */
129 typedef struct Elf Elf;
134 typedef struct Elf_Scn Elf_Scn;
137 * Archive member header
144 unsigned long ar_mode;
150 * Archive symbol table
155 unsigned long as_hash;
171 * Function declarations
173 extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref));
174 extern Elf *elf_memory __P((char *__image, size_t __size));
175 extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd));
176 extern int elf_end __P((Elf *__elf));
177 extern const char *elf_errmsg __P((int __err));
178 extern int elf_errno __P((void));
179 extern void elf_fill __P((int __fill));
180 extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd,
182 extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd,
184 extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd,
186 extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd,
188 extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd,
190 extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd,
192 extern size_t elf32_fsize __P((Elf_Type __type, size_t __count,
194 extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf));
195 extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr));
196 extern int64_t elf_getbase __P((Elf *__elf));
197 extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data));
198 extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf));
199 extern char *elf_getident __P((Elf *__elf, size_t *__ptr));
200 extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf));
201 extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index));
202 extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn));
203 extern unsigned long elf_hash __P((const unsigned char *__name));
204 extern Elf_Kind elf_kind __P((Elf *__elf));
205 extern size_t elf_ndxscn __P((Elf_Scn *__scn));
206 extern Elf_Data *elf_newdata __P((Elf_Scn *__scn));
207 extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf));
208 extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count));
209 extern Elf_Scn *elf_newscn __P((Elf *__elf));
210 extern Elf_Cmd elf_next __P((Elf *__elf));
211 extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn));
212 extern size_t elf_rand __P((Elf *__elf, size_t __offset));
213 extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data));
214 extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr));
215 extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset));
216 extern int64_t elf_update __P((Elf *__elf, Elf_Cmd __cmd));
217 extern unsigned elf_version __P((unsigned __ver));
218 extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src,
220 extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src,
224 * Additional functions found on Solaris
226 extern long elf32_checksum __P((Elf *__elf));
230 * 64-bit ELF functions
231 * Not available on all platforms
233 extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf));
234 extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf));
235 extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf));
236 extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count));
237 extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn));
238 extern size_t elf64_fsize __P((Elf_Type __type, size_t __count,
240 extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src,
242 extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src,
246 * Additional functions found on Solaris
248 extern long elf64_checksum __P((Elf *__elf));
250 #endif /* __LIBELF64 */
253 * ELF format extensions
255 * These functions return 0 on failure, 1 on success. Since other
256 * implementations of libelf may behave differently (there was quite
257 * some confusion about the correct values), they are now officially
258 * deprecated and should be replaced with the three new functions below.
260 DEPRECATED extern int elf_getphnum __P((Elf *__elf, size_t *__resultp));
261 DEPRECATED extern int elf_getshnum __P((Elf *__elf, size_t *__resultp));
262 DEPRECATED extern int elf_getshstrndx __P((Elf *__elf, size_t *__resultp));
264 * Replacement functions (return -1 on failure, 0 on success).
266 extern int elf_getphdrnum __P((Elf *__elf, size_t *__resultp));
267 extern int elf_getshdrnum __P((Elf *__elf, size_t *__resultp));
268 extern int elf_getshdrstrndx __P((Elf *__elf, size_t *__resultp));
271 * Convenience functions
273 * elfx_update_shstrndx is elf_getshstrndx's counterpart.
274 * It should be used to set the e_shstrndx member.
275 * There is no update function for e_shnum or e_phnum
276 * because libelf handles them internally.
278 extern int elfx_update_shstrndx __P((Elf *__elf, size_t __index));
281 * Experimental extensions:
283 * elfx_movscn() moves section `__scn' directly after section `__after'.
284 * elfx_remscn() removes section `__scn'. Both functions update
285 * the section indices; elfx_remscn() also adjusts the ELF header's
286 * e_shnum member. The application is responsible for updating other
287 * data (in particular, e_shstrndx and the section headers' sh_link and
290 * elfx_movscn() returns the new index of the moved section.
291 * elfx_remscn() returns the original index of the removed section.
292 * A return value of zero indicates an error.
294 extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after));
295 extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn));
298 * elf_delscn() is obsolete. Please use elfx_remscn() instead.
300 extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn));
304 #endif /* __cplusplus */
306 #endif /* _LIBELF_H */