Add some patches from the disasm-branch branch.
[platform/upstream/elfutils.git] / libebl / libebl.h
1 /* Interface for libebl.
2    Copyright (C) 2000, 2001, 2002, 2004, 2005 Red Hat, Inc.
3
4    This program is Open Source software; you can redistribute it and/or
5    modify it under the terms of the Open Software License version 1.0 as
6    published by the Open Source Initiative.
7
8    You should have received a copy of the Open Software License along
9    with this program; if not, you may obtain a copy of the Open Software
10    License version 1.0 from http://www.opensource.org/licenses/osl.php or
11    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
12    3001 King Ranch Road, Ukiah, CA 95482.   */
13
14 #ifndef _LIBEBL_H
15 #define _LIBEBL_H 1
16
17 #include <gelf.h>
18 #include <stdbool.h>
19 #include <stddef.h>
20 #include <stdint.h>
21
22 #include <elf-knowledge.h>
23
24
25 /* Opaque type for the handle.  */
26 typedef struct ebl Ebl;
27
28
29 /* Get backend handle for object associated with ELF handle.  */
30 extern Ebl *ebl_openbackend (Elf *elf);
31 /* Similar but without underlying ELF file.  */
32 extern Ebl *ebl_openbackend_machine (GElf_Half machine);
33 /* Similar but with emulation name given.  */
34 extern Ebl *ebl_openbackend_emulation (const char *emulation);
35
36 /* Free resources allocated for backend handle.  */
37 extern void ebl_closebackend (Ebl *bh);
38
39
40 /* Information about the descriptor.  */
41
42 /* Get ELF machine.  */
43 extern int ebl_get_elfmachine (Ebl *ebl) __attribute__ ((__pure__));
44
45 /* Get ELF class.  */
46 extern int ebl_get_elfclass (Ebl *ebl) __attribute__ ((__pure__));
47
48 /* Get ELF data encoding.  */
49 extern int ebl_get_elfdata (Ebl *ebl) __attribute__ ((__pure__));
50
51
52 /* Function to call the callback functions including default ELF
53    handling.  */
54
55 /* Return backend name.  */
56 extern const char *ebl_backend_name (Ebl *ebl);
57
58 /* Return relocation type name.  */
59 extern const char *ebl_object_type_name (Ebl *ebl, int object,
60                                          char *buf, size_t len);
61
62 /* Return relocation type name.  */
63 extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
64                                         char *buf, size_t len);
65
66 /* Check relocation type.  */
67 extern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
68
69 /* Check relocation type use.  */
70 extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
71
72 /* Check if relocation type is for simple absolute relocations.
73    Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM.  */
74 extern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc);
75
76 /* Return true if the symbol type is that referencing the GOT.  E.g.,
77    R_386_GOTPC.  */
78 extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
79
80 /* Return segment type name.  */
81 extern const char *ebl_segment_type_name (Ebl *ebl, int segment,
82                                           char *buf, size_t len);
83
84 /* Return section type name.  */
85 extern const char *ebl_section_type_name (Ebl *ebl, int section,
86                                           char *buf, size_t len);
87
88 /* Return section name.  */
89 extern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
90                                      char *buf, size_t len,
91                                      const char *scnnames[], size_t shnum);
92
93 /* Return machine flag names.  */
94 extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
95                                           char *buf, size_t len);
96
97 /* Check whether machine flag is valid.  */
98 extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
99
100 /* Return symbol type name.  */
101 extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
102                                          char *buf, size_t len);
103
104 /* Return symbol binding name.  */
105 extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
106                                             char *buf, size_t len);
107
108 /* Return dynamic tag name.  */
109 extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
110                                          char *buf, size_t len);
111
112 /* Check dynamic tag.  */
113 extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
114
115 /* Return combined section header flags value.  */
116 extern GElf_Word ebl_sh_flags_combine (Ebl *ebl, GElf_Word flags1,
117                                        GElf_Word flags2);
118
119 /* Return symbolic representation of OS ABI.  */
120 extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
121
122
123 /* Return name of the note section type for a core file.  */
124 extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
125                                             size_t len);
126
127 /* Return name of the note section type for an object file.  */
128 extern const char *ebl_object_note_type_name (Ebl *ebl, uint32_t type,
129                                               char *buf, size_t len);
130
131 /* Print information about core note if available.  */
132 extern void ebl_core_note (Ebl *ebl, const char *name, uint32_t type,
133                            uint32_t descsz, const char *desc);
134
135 /* Print information about object note if available.  */
136 extern void ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
137                              uint32_t descsz, const char *desc);
138
139 /* Check section name for being that of a debug informatino section.  */
140 extern bool ebl_debugscn_p (Ebl *ebl, const char *name);
141
142 /* Check whether given relocation is a copy relocation.  */
143 extern bool ebl_copy_reloc_p (Ebl *ebl, int reloc);
144
145
146 /* CHeck whether section should be stripped.  */
147 extern bool ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr,
148                                  const GElf_Shdr *shdr, const char *name,
149                                  bool remove_comment, bool only_remove_debug);
150
151
152 /* ELF string table handling.  */
153 struct Ebl_Strtab;
154 struct Ebl_Strent;
155
156 /* Create new ELF string table object in memory.  */
157 extern struct Ebl_Strtab *ebl_strtabinit (bool nullstr);
158
159 /* Free resources allocated for ELF string table ST.  */
160 extern void ebl_strtabfree (struct Ebl_Strtab *st);
161
162 /* Add string STR (length LEN is != 0) to ELF string table ST.  */
163 extern struct Ebl_Strent *ebl_strtabadd (struct Ebl_Strtab *st,
164                                          const char *str, size_t len);
165
166 /* Finalize string table ST and store size and memory location information
167    in DATA.  */
168 extern void ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data);
169
170 /* Get offset in string table for string associated with SE.  */
171 extern size_t ebl_strtaboffset (struct Ebl_Strent *se);
172
173 /* Return the string associated with SE.  */
174 extern const char *ebl_string (struct Ebl_Strent *se);
175
176
177 /* ELF wide char string table handling.  */
178 struct Ebl_WStrtab;
179 struct Ebl_WStrent;
180
181 /* Create new ELF wide char string table object in memory.  */
182 extern struct Ebl_WStrtab *ebl_wstrtabinit (bool nullstr);
183
184 /* Free resources allocated for ELF wide char string table ST.  */
185 extern void ebl_wstrtabfree (struct Ebl_WStrtab *st);
186
187 /* Add string STR (length LEN is != 0) to ELF string table ST.  */
188 extern struct Ebl_WStrent *ebl_wstrtabadd (struct Ebl_WStrtab *st,
189                                            const wchar_t *str, size_t len);
190
191 /* Finalize string table ST and store size and memory location information
192    in DATA.  */
193 extern void ebl_wstrtabfinalize (struct Ebl_WStrtab *st, Elf_Data *data);
194
195 /* Get offset in wide char string table for string associated with SE.  */
196 extern size_t ebl_wstrtaboffset (struct Ebl_WStrent *se);
197
198
199 /* Generic string table handling.  */
200 struct Ebl_GStrtab;
201 struct Ebl_GStrent;
202
203 /* Create new string table object in memory.  */
204 extern struct Ebl_GStrtab *ebl_gstrtabinit (unsigned int width, bool nullstr);
205
206 /* Free resources allocated for string table ST.  */
207 extern void ebl_gstrtabfree (struct Ebl_GStrtab *st);
208
209 /* Add string STR (length LEN is != 0) to string table ST.  */
210 extern struct Ebl_GStrent *ebl_gstrtabadd (struct Ebl_GStrtab *st,
211                                            const char *str, size_t len);
212
213 /* Finalize string table ST and store size and memory location information
214    in DATA.  */
215 extern void ebl_gstrtabfinalize (struct Ebl_GStrtab *st, Elf_Data *data);
216
217 /* Get offset in wide char string table for string associated with SE.  */
218 extern size_t ebl_gstrtaboffset (struct Ebl_GStrent *se);
219
220 #endif  /* libebl.h */