xref: /freebsd/contrib/elftoolchain/libelftc/libelftc.h (revision 44e86fbdcf5a3e625095652a3d0ab99532e54eea)
1a85fe12eSEd Maste /*-
2a85fe12eSEd Maste  * Copyright (c) 2009 Kai Wang
3a85fe12eSEd Maste  * All rights reserved.
4a85fe12eSEd Maste  *
5a85fe12eSEd Maste  * Redistribution and use in source and binary forms, with or without
6a85fe12eSEd Maste  * modification, are permitted provided that the following conditions
7a85fe12eSEd Maste  * are met:
8a85fe12eSEd Maste  * 1. Redistributions of source code must retain the above copyright
9a85fe12eSEd Maste  *    notice, this list of conditions and the following disclaimer
10a85fe12eSEd Maste  *    in this position and unchanged.
11a85fe12eSEd Maste  * 2. Redistributions in binary form must reproduce the above copyright
12a85fe12eSEd Maste  *    notice, this list of conditions and the following disclaimer in the
13a85fe12eSEd Maste  *    documentation and/or other materials provided with the distribution.
14a85fe12eSEd Maste  *
15a85fe12eSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16a85fe12eSEd Maste  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17a85fe12eSEd Maste  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18a85fe12eSEd Maste  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19a85fe12eSEd Maste  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20a85fe12eSEd Maste  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21a85fe12eSEd Maste  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22a85fe12eSEd Maste  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23a85fe12eSEd Maste  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24a85fe12eSEd Maste  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25a85fe12eSEd Maste  *
26a85fe12eSEd Maste  * $FreeBSD: users/kaiwang27/elftc/libelftc.h 392 2009-05-31 19:17:46Z kaiwang27 $
27d003e0d7SEd Maste  * $Id: libelftc.h 3744 2019-06-28 00:41:47Z emaste $
28a85fe12eSEd Maste  */
29a85fe12eSEd Maste 
30a85fe12eSEd Maste #ifndef	_LIBELFTC_H_
31a85fe12eSEd Maste #define	_LIBELFTC_H_
32a85fe12eSEd Maste 
33a85fe12eSEd Maste #include <sys/stat.h>
34a85fe12eSEd Maste 
35a85fe12eSEd Maste #include <libelf.h>
36a85fe12eSEd Maste 
37cf781b2eSEd Maste /*
38cf781b2eSEd Maste  * Types meant to be opaque to the consumers of these APIs.
39cf781b2eSEd Maste  */
40a85fe12eSEd Maste typedef struct _Elftc_Bfd_Target Elftc_Bfd_Target;
41a85fe12eSEd Maste typedef struct _Elftc_String_Table Elftc_String_Table;
42a85fe12eSEd Maste 
43a85fe12eSEd Maste /* Target types. */
44a85fe12eSEd Maste typedef enum {
45a85fe12eSEd Maste 	ETF_NONE,
46a85fe12eSEd Maste 	ETF_ELF,
47a85fe12eSEd Maste 	ETF_BINARY,
48a85fe12eSEd Maste 	ETF_SREC,
49839529caSEd Maste 	ETF_IHEX,
50839529caSEd Maste 	ETF_PE,
51839529caSEd Maste 	ETF_EFI,
52a85fe12eSEd Maste } Elftc_Bfd_Target_Flavor;
53a85fe12eSEd Maste 
54a85fe12eSEd Maste /*
55a85fe12eSEd Maste  * Demangler flags.
56a85fe12eSEd Maste  */
57a85fe12eSEd Maste 
58a85fe12eSEd Maste /* Name mangling style. */
59a85fe12eSEd Maste #define	ELFTC_DEM_UNKNOWN	0x00000000U /* Not specified. */
60a85fe12eSEd Maste #define	ELFTC_DEM_ARM		0x00000001U /* C++ Ann. Ref. Manual. */
61a85fe12eSEd Maste #define	ELFTC_DEM_GNU2		0x00000002U /* GNU version 2. */
62a85fe12eSEd Maste #define	ELFTC_DEM_GNU3		0x00000004U /* GNU version 3. */
63a85fe12eSEd Maste 
64a85fe12eSEd Maste /* Demangling behaviour control. */
65a85fe12eSEd Maste #define ELFTC_DEM_NOPARAM	0x00010000U
66a85fe12eSEd Maste 
6767d97fe7SEd Maste #ifdef __cplusplus
6867d97fe7SEd Maste extern "C" {
6967d97fe7SEd Maste #endif
70a85fe12eSEd Maste Elftc_Bfd_Target	*elftc_bfd_find_target(const char *_tgt_name);
71a85fe12eSEd Maste Elftc_Bfd_Target_Flavor	 elftc_bfd_target_flavor(Elftc_Bfd_Target *_tgt);
72a85fe12eSEd Maste unsigned int	elftc_bfd_target_byteorder(Elftc_Bfd_Target *_tgt);
73a85fe12eSEd Maste unsigned int	elftc_bfd_target_class(Elftc_Bfd_Target *_tgt);
74a85fe12eSEd Maste unsigned int	elftc_bfd_target_machine(Elftc_Bfd_Target *_tgt);
75*57d7e4ccSEd Maste unsigned int	elftc_bfd_target_osabi(Elftc_Bfd_Target *_tgt);
76a85fe12eSEd Maste int		elftc_copyfile(int _srcfd,  int _dstfd);
77a85fe12eSEd Maste int		elftc_demangle(const char *_mangledname, char *_buffer,
78a85fe12eSEd Maste     size_t _bufsize, unsigned int _flags);
79b6b6f9ccSEd Maste const char	*elftc_reloc_type_str(unsigned int mach, unsigned int type);
80a85fe12eSEd Maste int		elftc_set_timestamps(const char *_filename, struct stat *_sb);
81b90eaf94SMark Johnston Elftc_String_Table	*elftc_string_table_create(size_t _sizehint);
82a85fe12eSEd Maste void		elftc_string_table_destroy(Elftc_String_Table *_table);
83a85fe12eSEd Maste Elftc_String_Table	*elftc_string_table_from_section(Elf_Scn *_scn,
84b90eaf94SMark Johnston     size_t _sizehint);
85a85fe12eSEd Maste const char	*elftc_string_table_image(Elftc_String_Table *_table,
86a85fe12eSEd Maste     size_t *_sz);
87a85fe12eSEd Maste size_t		elftc_string_table_insert(Elftc_String_Table *_table,
88a85fe12eSEd Maste     const char *_string);
89a85fe12eSEd Maste size_t		elftc_string_table_lookup(Elftc_String_Table *_table,
90a85fe12eSEd Maste     const char *_string);
91a85fe12eSEd Maste int		elftc_string_table_remove(Elftc_String_Table *_table,
92a85fe12eSEd Maste     const char *_string);
93a85fe12eSEd Maste const char	*elftc_string_table_to_string(Elftc_String_Table *_table,
94a85fe12eSEd Maste     size_t offset);
95b6d812d2SEd Maste int		elftc_timestamp(time_t *_timestamp);
96a85fe12eSEd Maste const char	*elftc_version(void);
9767d97fe7SEd Maste #ifdef __cplusplus
9867d97fe7SEd Maste }
9967d97fe7SEd Maste #endif
100a85fe12eSEd Maste 
101a85fe12eSEd Maste #endif	/* _LIBELFTC_H_ */
102