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 */
26 #include <sys/types.h>
28 #if __LIBELF_INTERNAL__
30 #else /* __LIBELF_INTERNAL__ */
31 #include <libelf/sys_elf.h>
32 #endif /* __LIBELF_INTERNAL__ */
34 #if defined __GNUC__ && !defined __cplusplus
35 #define DEPRECATED __attribute__((deprecated))
37 #define DEPRECATED /* nothing */
42 #endif /* __cplusplus */
45 # if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32)
46 # define __P(args) args
47 # else /* __STDC__ || defined(__cplusplus) */
49 # endif /* __STDC__ || defined(__cplusplus) */
56 ELF_C_NULL = 0, /* must be first, 0 */
64 ELF_C_NUM /* must be last */
70 #define ELF_F_DIRTY 0x1
71 #define ELF_F_LAYOUT 0x4
73 * Allow sections to overlap when ELF_F_LAYOUT is in effect.
74 * Note that this flag ist NOT portable, and that it may render
75 * the output file unusable. Use with extreme caution!
77 #define ELF_F_LAYOUT_OVERLAP 0x10000000
83 ELF_K_NONE = 0, /* must be first, 0 */
87 ELF_K_NUM /* must be last */
94 ELF_T_BYTE = 0, /* must be first, 0 */
108 * New stuff for 64-bit.
110 * Most implementations add ELF_T_SXWORD after ELF_T_SWORD
111 * which breaks binary compatibility with earlier versions.
112 * If this causes problems for you, contact me.
117 * Symbol versioning. Sun broke binary compatibility (again!),
122 ELF_T_NUM /* must be last */
128 typedef struct Elf Elf;
133 typedef struct Elf_Scn Elf_Scn;
136 * Archive member header
143 unsigned long ar_mode;
149 * Archive symbol table
154 unsigned long as_hash;
170 * Function declarations
172 extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref));
173 extern Elf *elf_memory __P((char *__image, size_t __size));
174 extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd));
175 extern int elf_end __P((Elf *__elf));
176 extern const char *elf_errmsg __P((int __err));
177 extern int elf_errno __P((void));
178 extern void elf_fill __P((int __fill));
179 extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd,
181 extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd,
183 extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd,
185 extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd,
187 extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd,
189 extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd,
191 extern size_t elf32_fsize __P((Elf_Type __type, size_t __count,
193 extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf));
194 extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr));
195 extern off_t elf_getbase __P((Elf *__elf));
196 extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data));
197 extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf));
198 extern char *elf_getident __P((Elf *__elf, size_t *__ptr));
199 extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf));
200 extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index));
201 extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn));
202 extern unsigned long elf_hash __P((const unsigned char *__name));
203 extern Elf_Kind elf_kind __P((Elf *__elf));
204 extern size_t elf_ndxscn __P((Elf_Scn *__scn));
205 extern Elf_Data *elf_newdata __P((Elf_Scn *__scn));
206 extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf));
207 extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count));
208 extern Elf_Scn *elf_newscn __P((Elf *__elf));
209 extern Elf_Cmd elf_next __P((Elf *__elf));
210 extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn));
211 extern size_t elf_rand __P((Elf *__elf, size_t __offset));
212 extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data));
213 extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr));
214 extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset));
215 extern off_t elf_update __P((Elf *__elf, Elf_Cmd __cmd));
216 extern unsigned elf_version __P((unsigned __ver));
217 extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src,
219 extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src,
223 * Additional functions found on Solaris
225 extern long elf32_checksum __P((Elf *__elf));
229 * 64-bit ELF functions
230 * Not available on all platforms
232 extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf));
233 extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf));
234 extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf));
235 extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count));
236 extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn));
237 extern size_t elf64_fsize __P((Elf_Type __type, size_t __count,
239 extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src,
241 extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src,
245 * Additional functions found on Solaris
247 extern long elf64_checksum __P((Elf *__elf));
249 #endif /* __LIBELF64 */
252 * ELF format extensions
254 * These functions return 0 on failure, 1 on success. Since other
255 * implementations of libelf may behave differently (there was quite
256 * some confusion about the correct values), they are now officially
257 * deprecated and should be replaced with the three new functions below.
259 DEPRECATED extern int elf_getphnum __P((Elf *__elf, size_t *__resultp));
260 DEPRECATED extern int elf_getshnum __P((Elf *__elf, size_t *__resultp));
261 DEPRECATED extern int elf_getshstrndx __P((Elf *__elf, size_t *__resultp));
263 * Replacement functions (return -1 on failure, 0 on success).
265 extern int elf_getphdrnum __P((Elf *__elf, size_t *__resultp));
266 extern int elf_getshdrnum __P((Elf *__elf, size_t *__resultp));
267 extern int elf_getshdrstrndx __P((Elf *__elf, size_t *__resultp));
270 * Convenience functions
272 * elfx_update_shstrndx is elf_getshstrndx's counterpart.
273 * It should be used to set the e_shstrndx member.
274 * There is no update function for e_shnum or e_phnum
275 * because libelf handles them internally.
277 extern int elfx_update_shstrndx __P((Elf *__elf, size_t __index));
280 * Experimental extensions:
282 * elfx_movscn() moves section `__scn' directly after section `__after'.
283 * elfx_remscn() removes section `__scn'. Both functions update
284 * the section indices; elfx_remscn() also adjusts the ELF header's
285 * e_shnum member. The application is responsible for updating other
286 * data (in particular, e_shstrndx and the section headers' sh_link and
289 * elfx_movscn() returns the new index of the moved section.
290 * elfx_remscn() returns the original index of the removed section.
291 * A return value of zero indicates an error.
293 extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after));
294 extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn));
297 * elf_delscn() is obsolete. Please use elfx_remscn() instead.
299 extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn));
303 #endif /* __cplusplus */
305 #endif /* _LIBELF_H */