• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Interface for libebl.
2    Copyright (C) 2000, 2001, 2002, 2004 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 /* Backend handle.  */
26 typedef struct ebl
27 {
28   /* Machine name.  */
29   const char *name;
30 
31   /* Emulation name.  */
32   const char *emulation;
33 
34   /* The libelf handle (if known).  */
35   Elf *elf;
36 
37   /* Return symbol representaton of object file type.  */
38   const char *(*object_type_name) (int, char *, size_t);
39 
40   /* Return symbolic representation of relocation type.  */
41   const char *(*reloc_type_name) (int, char *, size_t);
42 
43   /* Check relocation type.  */
44   bool (*reloc_type_check) (int);
45 
46   /* Check relocation type use.  */
47   bool (*reloc_valid_use) (Elf *, int);
48 
49   /* Return true if the symbol type is that referencing the GOT.  */
50   bool (*gotpc_reloc_check) (Elf *, int);
51 
52   /* Return symbolic representation of segment type.  */
53   const char *(*segment_type_name) (int, char *, size_t);
54 
55   /* Return symbolic representation of section type.  */
56   const char *(*section_type_name) (int, char *, size_t);
57 
58   /* Return section name.  */
59   const char *(*section_name) (int, int, char *, size_t);
60 
61   /* Return next machine flag name.  */
62   const char *(*machine_flag_name) (GElf_Word *);
63 
64   /* Check whether machine flags are valid.  */
65   bool (*machine_flag_check) (GElf_Word);
66 
67   /* Return symbolic representation of symbol type.  */
68   const char *(*symbol_type_name) (int, char *, size_t);
69 
70   /* Return symbolic representation of symbol binding.  */
71   const char *(*symbol_binding_name) (int, char *, size_t);
72 
73   /* Return symbolic representation of dynamic tag.  */
74   const char *(*dynamic_tag_name) (int64_t, char *, size_t);
75 
76   /* Check dynamic tag.  */
77   bool (*dynamic_tag_check) (int64_t);
78 
79   /* Combine section header flags values.  */
80   GElf_Word (*sh_flags_combine) (GElf_Word, GElf_Word);
81 
82   /* Return symbolic representation of OS ABI.  */
83   const char *(*osabi_name) (int, char *, size_t);
84 
85   /* Name of a note entry type for core files.  */
86   const char *(*core_note_type_name) (uint32_t, char *, size_t);
87 
88   /* Name of a note entry type for object files.  */
89   const char *(*object_note_type_name) (uint32_t, char *, size_t);
90 
91   /* Handle core note.  */
92   bool (*core_note) (const char *, uint32_t, uint32_t, const char *);
93 
94   /* Handle object file note.  */
95   bool (*object_note) (const char *, uint32_t, uint32_t, const char *);
96 
97   /* Check section name for being that of a debug informatino section.  */
98   bool (*debugscn_p) (const char *);
99 
100   /* Destructor for ELF backend handle.  */
101   void (*destr) (struct ebl *);
102 
103   /* Internal data.  */
104   void *dlhandle;
105 } Ebl;
106 
107 
108 /* Get backend handle for object associated with ELF handle.  */
109 extern Ebl *ebl_openbackend (Elf *elf);
110 /* Similar but without underlying ELF file.  */
111 extern Ebl *ebl_openbackend_machine (GElf_Half machine);
112 /* Similar but with emulation name given.  */
113 extern Ebl *ebl_openbackend_emulation (const char *emulation);
114 
115 /* Free resources allocated for backend handle.  */
116 extern void ebl_closebackend (Ebl *bh);
117 
118 
119 /* Function to call the callback functions including default ELF
120    handling.  */
121 
122 /* Return backend name.  */
123 extern const char *ebl_backend_name (Ebl *ebl);
124 
125 /* Return relocation type name.  */
126 extern const char *ebl_object_type_name (Ebl *ebl, int object,
127 					 char *buf, size_t len);
128 
129 /* Return relocation type name.  */
130 extern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
131 					char *buf, size_t len);
132 
133 /* Check relocation type.  */
134 extern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
135 
136 /* Check relocation type use.  */
137 extern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
138 
139 /* Return true if the symbol type is that referencing the GOT.  E.g.,
140    R_386_GOTPC.  */
141 extern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
142 
143 /* Return segment type name.  */
144 extern const char *ebl_segment_type_name (Ebl *ebl, int segment,
145 					  char *buf, size_t len);
146 
147 /* Return section type name.  */
148 extern const char *ebl_section_type_name (Ebl *ebl, int section,
149 					  char *buf, size_t len);
150 
151 /* Return section name.  */
152 extern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
153 				     char *buf, size_t len,
154 				     const char *scnnames[], size_t shnum);
155 
156 /* Return machine flag names.  */
157 extern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
158 					  char *buf, size_t len);
159 
160 /* Check whether machine flag is valid.  */
161 extern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
162 
163 /* Return symbol type name.  */
164 extern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
165 					 char *buf, size_t len);
166 
167 /* Return symbol binding name.  */
168 extern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
169 					    char *buf, size_t len);
170 
171 /* Return dynamic tag name.  */
172 extern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
173 					 char *buf, size_t len);
174 
175 /* Check dynamic tag.  */
176 extern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
177 
178 /* Return combined section header flags value.  */
179 extern GElf_Word ebl_sh_flags_combine (Ebl *ebl, GElf_Word flags1,
180 				       GElf_Word flags2);
181 
182 /* Return symbolic representation of OS ABI.  */
183 extern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
184 
185 
186 /* Return name of the note section type for a core file.  */
187 extern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
188 					    size_t len);
189 
190 /* Return name of the note section type for an object file.  */
191 extern const char *ebl_object_note_type_name (Ebl *ebl, uint32_t type,
192 					      char *buf, size_t len);
193 
194 /* Print information about core note if available.  */
195 extern void ebl_core_note (Ebl *ebl, const char *name, uint32_t type,
196 			   uint32_t descsz, const char *desc);
197 
198 /* Print information about object note if available.  */
199 extern void ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
200 			     uint32_t descsz, const char *desc);
201 
202 /* Check section name for being that of a debug informatino section.  */
203 extern bool ebl_debugscn_p (Ebl *ebl, const char *name);
204 
205 
206 /* ELF string table handling.  */
207 struct Ebl_Strtab;
208 struct Ebl_Strent;
209 
210 /* Create new ELF string table object in memory.  */
211 extern struct Ebl_Strtab *ebl_strtabinit (bool nullstr);
212 
213 /* Free resources allocated for ELF string table ST.  */
214 extern void ebl_strtabfree (struct Ebl_Strtab *st);
215 
216 /* Add string STR (length LEN is != 0) to ELF string table ST.  */
217 extern struct Ebl_Strent *ebl_strtabadd (struct Ebl_Strtab *st,
218 					 const char *str, size_t len);
219 
220 /* Finalize string table ST and store size and memory location information
221    in DATA.  */
222 extern void ebl_strtabfinalize (struct Ebl_Strtab *st, Elf_Data *data);
223 
224 /* Get offset in string table for string associated with SE.  */
225 extern size_t ebl_strtaboffset (struct Ebl_Strent *se);
226 
227 /* Return the string associated with SE.  */
228 extern const char *ebl_string (struct Ebl_Strent *se);
229 
230 
231 /* ELF wide char string table handling.  */
232 struct Ebl_WStrtab;
233 struct Ebl_WStrent;
234 
235 /* Create new ELF wide char string table object in memory.  */
236 extern struct Ebl_WStrtab *ebl_wstrtabinit (bool nullstr);
237 
238 /* Free resources allocated for ELF wide char string table ST.  */
239 extern void ebl_wstrtabfree (struct Ebl_WStrtab *st);
240 
241 /* Add string STR (length LEN is != 0) to ELF string table ST.  */
242 extern struct Ebl_WStrent *ebl_wstrtabadd (struct Ebl_WStrtab *st,
243 					   const wchar_t *str, size_t len);
244 
245 /* Finalize string table ST and store size and memory location information
246    in DATA.  */
247 extern void ebl_wstrtabfinalize (struct Ebl_WStrtab *st, Elf_Data *data);
248 
249 /* Get offset in wide char string table for string associated with SE.  */
250 extern size_t ebl_wstrtaboffset (struct Ebl_WStrent *se);
251 
252 
253 /* Generic string table handling.  */
254 struct Ebl_GStrtab;
255 struct Ebl_GStrent;
256 
257 /* Create new string table object in memory.  */
258 extern struct Ebl_GStrtab *ebl_gstrtabinit (unsigned int width, bool nullstr);
259 
260 /* Free resources allocated for string table ST.  */
261 extern void ebl_gstrtabfree (struct Ebl_GStrtab *st);
262 
263 /* Add string STR (length LEN is != 0) to string table ST.  */
264 extern struct Ebl_GStrent *ebl_gstrtabadd (struct Ebl_GStrtab *st,
265 					   const char *str, size_t len);
266 
267 /* Finalize string table ST and store size and memory location information
268    in DATA.  */
269 extern void ebl_gstrtabfinalize (struct Ebl_GStrtab *st, Elf_Data *data);
270 
271 /* Get offset in wide char string table for string associated with SE.  */
272 extern size_t ebl_gstrtaboffset (struct Ebl_GStrent *se);
273 
274 #endif	/* libebl.h */
275