Line data Source code
1 : /* Generate ELF backend handle.
2 : Copyright (C) 2000-2017 Red Hat, Inc.
3 : This file is part of elfutils.
4 :
5 : This file is free software; you can redistribute it and/or modify
6 : it under the terms of either
7 :
8 : * the GNU Lesser General Public License as published by the Free
9 : Software Foundation; either version 3 of the License, or (at
10 : your option) any later version
11 :
12 : or
13 :
14 : * the GNU General Public License as published by the Free
15 : Software Foundation; either version 2 of the License, or (at
16 : your option) any later version
17 :
18 : or both in parallel, as here.
19 :
20 : elfutils is distributed in the hope that it will be useful, but
21 : WITHOUT ANY WARRANTY; without even the implied warranty of
22 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 : General Public License for more details.
24 :
25 : You should have received copies of the GNU General Public License and
26 : the GNU Lesser General Public License along with this program. If
27 : not, see <http://www.gnu.org/licenses/>. */
28 :
29 : #ifdef HAVE_CONFIG_H
30 : # include <config.h>
31 : #endif
32 :
33 : #include <assert.h>
34 : #include <dlfcn.h>
35 : #include <libelfP.h>
36 : #include <dwarf.h>
37 : #include <stdlib.h>
38 : #include <string.h>
39 : #include <stdio.h>
40 :
41 : #include <system.h>
42 : #include <libeblP.h>
43 :
44 :
45 : /* This table should contain the complete list of architectures as far
46 : as the ELF specification is concerned. */
47 : /* XXX When things are stable replace the string pointers with char
48 : arrays to avoid relocations. */
49 : static const struct
50 : {
51 : const char *dsoname;
52 : const char *emulation;
53 : const char *prefix;
54 : int prefix_len;
55 : int em;
56 : int class;
57 : int data;
58 : } machines[] =
59 : {
60 : { "i386", "elf_i386", "i386", 4, EM_386, ELFCLASS32, ELFDATA2LSB },
61 : { "ia64", "elf_ia64", "ia64", 4, EM_IA_64, ELFCLASS64, ELFDATA2LSB },
62 : { "alpha", "elf_alpha", "alpha", 5, EM_ALPHA, ELFCLASS64, ELFDATA2LSB },
63 : { "x86_64", "elf_x86_64", "x86_64", 6, EM_X86_64, ELFCLASS64, ELFDATA2LSB },
64 : { "ppc", "elf_ppc", "ppc", 3, EM_PPC, ELFCLASS32, ELFDATA2MSB },
65 : { "ppc64", "elf_ppc64", "ppc64", 5, EM_PPC64, ELFCLASS64, ELFDATA2MSB },
66 : { "tilegx", "elf_tilegx", "tilegx", 6, EM_TILEGX, ELFCLASS64, ELFDATA2LSB },
67 : // XXX class and machine fields need to be filled in for all archs.
68 : { "sh", "elf_sh", "sh", 2, EM_SH, 0, 0 },
69 : { "arm", "ebl_arm", "arm", 3, EM_ARM, 0, 0 },
70 : { "sparc", "elf_sparcv9", "sparc", 5, EM_SPARCV9, 0, 0 },
71 : { "sparc", "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
72 : { "sparc", "elf_sparcv8plus", "sparc", 5, EM_SPARC32PLUS, 0, 0 },
73 : { "s390", "ebl_s390", "s390", 4, EM_S390, 0, 0 },
74 :
75 : { "m32", "elf_m32", "m32", 3, EM_M32, 0, 0 },
76 : { "m68k", "elf_m68k", "m68k", 4, EM_68K, ELFCLASS32, ELFDATA2MSB },
77 : { "m88k", "elf_m88k", "m88k", 4, EM_88K, 0, 0 },
78 : { "i860", "elf_i860", "i860", 4, EM_860, 0, 0 },
79 : { "s370", "ebl_s370", "s370", 4, EM_S370, 0, 0 },
80 : { "parisc", "elf_parisc", "parisc", 6, EM_PARISC, 0, 0 },
81 : { "vpp500", "elf_vpp500", "vpp500", 5, EM_VPP500, 0, 0 },
82 : { "sparc", "elf_v8plus", "v8plus", 6, EM_SPARC32PLUS, 0, 0 },
83 : { "i960", "elf_i960", "i960", 4, EM_960, 0, 0 },
84 : { "v800", "ebl_v800", "v800", 4, EM_V800, 0, 0 },
85 : { "fr20", "ebl_fr20", "fr20", 4, EM_FR20, 0, 0 },
86 : { "rh32", "ebl_rh32", "rh32", 4, EM_RH32, 0, 0 },
87 : { "rce", "ebl_rce", "rce", 3, EM_RCE, 0, 0 },
88 : { "tricore", "elf_tricore", "tricore", 7, EM_TRICORE, 0, 0 },
89 : { "arc", "elf_arc", "arc", 3, EM_ARC, 0, 0 },
90 : { "h8", "elf_h8_300", "h8_300", 6, EM_H8_300, 0, 0 },
91 : { "h8", "elf_h8_300h", "h8_300h", 6, EM_H8_300H, 0, 0 },
92 : { "h8", "elf_h8s", "h8s", 6, EM_H8S, 0, 0 },
93 : { "h8", "elf_h8_500", "h8_500", 6, EM_H8_500, 0, 0 },
94 : { "coldfire", "elf_coldfire", "coldfire", 8, EM_COLDFIRE, 0, 0 },
95 : { "m68k", "elf_68hc12", "68hc12", 6, EM_68HC12, 0, 0 },
96 : { "mma", "elf_mma", "mma", 3, EM_MMA, 0, 0 },
97 : { "pcp", "elf_pcp", "pcp", 3, EM_PCP, 0, 0 },
98 : { "ncpu", "elf_ncpu", "ncpu", 4, EM_NCPU, 0, 0 },
99 : { "ndr1", "elf_ndr1", "ndr1", 4, EM_NDR1, 0, 0 },
100 : { "starcore", "elf_starcore", "starcore", 8, EM_STARCORE, 0, 0 },
101 : { "me16", "elf_me16", "em16", 4, EM_ME16, 0, 0 },
102 : { "st100", "elf_st100", "st100", 5, EM_ST100, 0, 0 },
103 : { "tinyj", "elf_tinyj", "tinyj", 5, EM_TINYJ, 0, 0 },
104 : { "pdsp", "elf_pdsp", "pdsp", 4, EM_PDSP, 0, 0 },
105 : { "fx66", "elf_fx66", "fx66", 4, EM_FX66, 0, 0 },
106 : { "st9plus", "elf_st9plus", "st9plus", 7, EM_ST9PLUS, 0, 0 },
107 : { "st7", "elf_st7", "st7", 3, EM_ST7, 0, 0 },
108 : { "m68k", "elf_68hc16", "68hc16", 6, EM_68HC16, 0, 0 },
109 : { "m68k", "elf_68hc11", "68hc11", 6, EM_68HC11, 0, 0 },
110 : { "m68k", "elf_68hc08", "68hc08", 6, EM_68HC08, 0, 0 },
111 : { "m68k", "elf_68hc05", "68hc05", 6, EM_68HC05, 0, 0 },
112 : { "svx", "elf_svx", "svx", 3, EM_SVX, 0, 0 },
113 : { "st19", "elf_st19", "st19", 4, EM_ST19, 0, 0 },
114 : { "vax", "elf_vax", "vax", 3, EM_VAX, 0, 0 },
115 : { "cris", "elf_cris", "cris", 4, EM_CRIS, 0, 0 },
116 : { "javelin", "elf_javelin", "javelin", 7, EM_JAVELIN, 0, 0 },
117 : { "firepath", "elf_firepath", "firepath", 8, EM_FIREPATH, 0, 0 },
118 : { "zsp", "elf_zsp", "zsp", 3, EM_ZSP, 0, 0 },
119 : { "mmix", "elf_mmix", "mmix", 4, EM_MMIX, 0, 0 },
120 : { "hunay", "elf_huany", "huany", 5, EM_HUANY, 0, 0 },
121 : { "prism", "elf_prism", "prism", 5, EM_PRISM, 0, 0 },
122 : { "avr", "elf_avr", "avr", 3, EM_AVR, 0, 0 },
123 : { "fr30", "elf_fr30", "fr30", 4, EM_FR30, 0, 0 },
124 : { "dv10", "elf_dv10", "dv10", 4, EM_D10V, 0, 0 },
125 : { "dv30", "elf_dv30", "dv30", 4, EM_D30V, 0, 0 },
126 : { "v850", "elf_v850", "v850", 4, EM_V850, 0, 0 },
127 : { "m32r", "elf_m32r", "m32r", 4, EM_M32R, 0, 0 },
128 : { "mn10300", "elf_mn10300", "mn10300", 7, EM_MN10300, 0, 0 },
129 : { "mn10200", "elf_mn10200", "mn10200", 7, EM_MN10200, 0, 0 },
130 : { "pj", "elf_pj", "pj", 2, EM_PJ, 0, 0 },
131 : { "openrisc", "elf_openrisc", "openrisc", 8, EM_OPENRISC, 0, 0 },
132 : { "arc", "elf_arc_a5", "arc_a5", 6, EM_ARC_A5, 0, 0 },
133 : { "xtensa", "elf_xtensa", "xtensa", 6, EM_XTENSA, 0, 0 },
134 : { "aarch64", "elf_aarch64", "aarch64", 7, EM_AARCH64, ELFCLASS64, 0 },
135 : { "bpf", "elf_bpf", "bpf", 3, EM_BPF, 0, 0 },
136 : { "riscv", "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS64, ELFDATA2LSB },
137 : { "riscv", "elf_riscv", "riscv", 5, EM_RISCV, ELFCLASS32, ELFDATA2LSB },
138 : };
139 : #define nmachines (sizeof (machines) / sizeof (machines[0]))
140 :
141 : /* No machine prefix should be larger than this. */
142 : #define MAX_PREFIX_LEN 16
143 :
144 : /* Default callbacks. Mostly they just return the error value. */
145 : static const char *default_reloc_type_name (int ignore, char *buf, size_t len);
146 : static bool default_reloc_type_check (int ignore);
147 : static bool default_reloc_valid_use (Elf *elf, int ignore);
148 : static Elf_Type default_reloc_simple_type (Ebl *ebl, int ignore);
149 : static bool default_gotpc_reloc_check (Elf *elf, int ignore);
150 : static const char *default_segment_type_name (int ignore, char *buf,
151 : size_t len);
152 : static const char *default_section_type_name (int ignore, char *buf,
153 : size_t len);
154 : static const char *default_section_name (int ignore, int ignore2, char *buf,
155 : size_t len);
156 : static const char *default_machine_flag_name (Elf64_Word *ignore);
157 : static bool default_machine_flag_check (Elf64_Word flags);
158 : static bool default_machine_section_flag_check (GElf_Xword flags);
159 : static const char *default_symbol_type_name (int ignore, char *buf,
160 : size_t len);
161 : static const char *default_symbol_binding_name (int ignore, char *buf,
162 : size_t len);
163 : static const char *default_dynamic_tag_name (int64_t ignore, char *buf,
164 : size_t len);
165 : static bool default_dynamic_tag_check (int64_t ignore);
166 : static const char *default_osabi_name (int ignore, char *buf, size_t len);
167 : static void default_destr (struct ebl *ignore);
168 : static const char *default_core_note_type_name (uint32_t, char *buf,
169 : size_t len);
170 : static const char *default_object_note_type_name (const char *name, uint32_t,
171 : char *buf, size_t len);
172 : static int default_core_note (const GElf_Nhdr *nhdr, const char *name,
173 : GElf_Word *regs_offset, size_t *nregloc,
174 : const Ebl_Register_Location **reglocs,
175 : size_t *nitems, const Ebl_Core_Item **);
176 : static int default_auxv_info (GElf_Xword a_type,
177 : const char **name, const char **format);
178 : static bool default_object_note (const char *name, uint32_t type,
179 : uint32_t descsz, const char *desc);
180 : static bool default_debugscn_p (const char *name);
181 : static bool default_copy_reloc_p (int reloc);
182 : static bool default_none_reloc_p (int reloc);
183 : static bool default_relative_reloc_p (int reloc);
184 : static bool default_check_special_symbol (Elf *elf,
185 : const GElf_Sym *sym,
186 : const char *name,
187 : const GElf_Shdr *destshdr);
188 : static bool default_data_marker_symbol (const GElf_Sym *sym, const char *sname);
189 : static bool default_check_st_other_bits (unsigned char st_other);
190 : static bool default_check_special_section (Ebl *, int,
191 : const GElf_Shdr *, const char *);
192 : static bool default_bss_plt_p (Elf *elf);
193 : static int default_return_value_location (Dwarf_Die *functypedie,
194 : const Dwarf_Op **locops);
195 : static ssize_t default_register_info (Ebl *ebl,
196 : int regno, char *name, size_t namelen,
197 : const char **prefix,
198 : const char **setname,
199 : int *bits, int *type);
200 : static int default_syscall_abi (Ebl *ebl, int *sp, int *pc,
201 : int *callno, int args[6]);
202 : static bool default_check_object_attribute (Ebl *ebl, const char *vendor,
203 : int tag, uint64_t value,
204 : const char **tag_name,
205 : const char **value_name);
206 : static bool default_check_reloc_target_type (Ebl *ebl, Elf64_Word sh_type);
207 : static int default_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info);
208 :
209 :
210 : static void
211 1289 : fill_defaults (Ebl *result)
212 : {
213 1289 : result->reloc_type_name = default_reloc_type_name;
214 1289 : result->reloc_type_check = default_reloc_type_check;
215 1289 : result->reloc_valid_use = default_reloc_valid_use;
216 1289 : result->reloc_simple_type = default_reloc_simple_type;
217 1289 : result->gotpc_reloc_check = default_gotpc_reloc_check;
218 1289 : result->segment_type_name = default_segment_type_name;
219 1289 : result->section_type_name = default_section_type_name;
220 1289 : result->section_name = default_section_name;
221 1289 : result->machine_flag_name = default_machine_flag_name;
222 1289 : result->machine_flag_check = default_machine_flag_check;
223 1289 : result->machine_section_flag_check = default_machine_section_flag_check;
224 1289 : result->check_special_section = default_check_special_section;
225 1289 : result->symbol_type_name = default_symbol_type_name;
226 1289 : result->symbol_binding_name = default_symbol_binding_name;
227 1289 : result->dynamic_tag_name = default_dynamic_tag_name;
228 1289 : result->dynamic_tag_check = default_dynamic_tag_check;
229 1289 : result->osabi_name = default_osabi_name;
230 1289 : result->core_note_type_name = default_core_note_type_name;
231 1289 : result->object_note_type_name = default_object_note_type_name;
232 1289 : result->core_note = default_core_note;
233 1289 : result->auxv_info = default_auxv_info;
234 1289 : result->object_note = default_object_note;
235 1289 : result->debugscn_p = default_debugscn_p;
236 1289 : result->copy_reloc_p = default_copy_reloc_p;
237 1289 : result->none_reloc_p = default_none_reloc_p;
238 1289 : result->relative_reloc_p = default_relative_reloc_p;
239 1289 : result->check_special_symbol = default_check_special_symbol;
240 1289 : result->data_marker_symbol = default_data_marker_symbol;
241 1289 : result->check_st_other_bits = default_check_st_other_bits;
242 1289 : result->bss_plt_p = default_bss_plt_p;
243 1289 : result->return_value_location = default_return_value_location;
244 1289 : result->register_info = default_register_info;
245 1289 : result->syscall_abi = default_syscall_abi;
246 1289 : result->check_object_attribute = default_check_object_attribute;
247 1289 : result->check_reloc_target_type = default_check_reloc_target_type;
248 1289 : result->disasm = NULL;
249 1289 : result->abi_cfi = default_abi_cfi;
250 1289 : result->destr = default_destr;
251 1289 : result->sysvhash_entrysize = sizeof (Elf32_Word);
252 1289 : }
253 :
254 :
255 : /* Find an appropriate backend for the file associated with ELF. */
256 : static Ebl *
257 1289 : openbackend (Elf *elf, const char *emulation, GElf_Half machine)
258 : {
259 : Ebl *result;
260 : size_t cnt;
261 :
262 : /* First allocate the data structure for the result. We do this
263 : here since this assures that the structure is always large
264 : enough. */
265 1289 : result = (Ebl *) calloc (1, sizeof (Ebl));
266 1289 : if (result == NULL)
267 : {
268 : // XXX uncomment
269 : // __libebl_seterror (ELF_E_NOMEM);
270 : return NULL;
271 : }
272 :
273 : /* Fill in the default callbacks. The initializer for the machine
274 : specific module can overwrite the values. */
275 1289 : fill_defaults (result);
276 :
277 : /* XXX Currently all we do is to look at 'e_machine' value in the
278 : ELF header. With an internal mapping table from EM_* value to
279 : DSO name we try to load the appropriate module to handle this
280 : binary type.
281 :
282 : Multiple modules for the same machine type are possible and they
283 : will be tried in sequence. The lookup process will only stop
284 : when a module which can handle the machine type is found or all
285 : available matching modules are tried. */
286 9033 : for (cnt = 0; cnt < nmachines; ++cnt)
287 9033 : if ((emulation != NULL && strcmp (emulation, machines[cnt].emulation) == 0)
288 9033 : || (emulation == NULL && machines[cnt].em == machine))
289 : {
290 : /* Well, we know the emulation name now. */
291 1289 : result->emulation = machines[cnt].emulation;
292 :
293 : /* We access some data structures directly. Make sure the 32 and
294 : 64 bit variants are laid out the same. */
295 : assert (offsetof (Elf32_Ehdr, e_machine)
296 : == offsetof (Elf64_Ehdr, e_machine));
297 : assert (sizeof (((Elf32_Ehdr *) 0)->e_machine)
298 : == sizeof (((Elf64_Ehdr *) 0)->e_machine));
299 : assert (offsetof (Elf, state.elf32.ehdr)
300 : == offsetof (Elf, state.elf64.ehdr));
301 :
302 : /* Prefer taking the information from the ELF file. */
303 1289 : if (elf == NULL)
304 : {
305 9 : result->machine = machines[cnt].em;
306 9 : result->class = machines[cnt].class;
307 9 : result->data = machines[cnt].data;
308 : }
309 : else
310 : {
311 1280 : result->machine = elf->state.elf32.ehdr->e_machine;
312 1280 : result->class = elf->state.elf32.ehdr->e_ident[EI_CLASS];
313 1280 : result->data = elf->state.elf32.ehdr->e_ident[EI_DATA];
314 : }
315 :
316 : #ifndef LIBEBL_SUBDIR
317 : # define LIBEBL_SUBDIR PACKAGE
318 : #endif
319 : #define ORIGINDIR "$ORIGIN/../$LIB/" LIBEBL_SUBDIR "/"
320 :
321 : /* Give it a try. At least the machine type matches. First
322 : try to load the module. */
323 : char dsoname[100];
324 3867 : strcpy (stpcpy (stpcpy (dsoname, ORIGINDIR "libebl_"),
325 : machines[cnt].dsoname),
326 : ".so");
327 :
328 1289 : void *h = dlopen (dsoname, RTLD_LAZY);
329 1289 : if (h == NULL)
330 : {
331 3867 : strcpy (stpcpy (stpcpy (dsoname, "libebl_"),
332 : machines[cnt].dsoname),
333 : ".so");
334 1289 : h = dlopen (dsoname, RTLD_LAZY);
335 : }
336 :
337 : /* Try without an explicit path. */
338 1289 : if (h != NULL)
339 : {
340 : /* We managed to load the object. Now see whether the
341 : initialization function likes our file. */
342 : static const char version[] = MODVERSION;
343 : const char *modversion;
344 : ebl_bhinit_t initp;
345 :
346 : // We use a static number to help the compiler see we don't
347 : // overflow the stack with an arbitrary number.
348 1289 : assert (machines[cnt].prefix_len <= MAX_PREFIX_LEN);
349 : char symname[MAX_PREFIX_LEN + sizeof "_init"];
350 :
351 3867 : strcpy (mempcpy (symname, machines[cnt].prefix,
352 : machines[cnt].prefix_len), "_init");
353 :
354 1289 : initp = (ebl_bhinit_t) dlsym (h, symname);
355 1289 : if (initp != NULL
356 1289 : && (modversion = initp (elf, machine, result, sizeof (Ebl)))
357 1289 : && strcmp (version, modversion) == 0)
358 : {
359 : /* We found a module to handle our file. */
360 1289 : result->dlhandle = h;
361 1289 : result->elf = elf;
362 :
363 : /* A few entries are mandatory. */
364 1289 : assert (result->name != NULL);
365 1289 : assert (result->destr != NULL);
366 :
367 1289 : return result;
368 : }
369 :
370 : /* Not the module we need. */
371 0 : (void) dlclose (h);
372 : }
373 :
374 : /* We cannot find a DSO but the emulation/machine ID matches.
375 : Return that information. */
376 0 : result->dlhandle = NULL;
377 0 : result->elf = elf;
378 0 : result->name = machines[cnt].prefix;
379 0 : fill_defaults (result);
380 :
381 0 : return result;
382 : }
383 :
384 : /* Nothing matched. We use only the default callbacks. */
385 0 : result->dlhandle = NULL;
386 0 : result->elf = elf;
387 0 : result->emulation = "<unknown>";
388 0 : result->name = "<unknown>";
389 0 : fill_defaults (result);
390 :
391 0 : return result;
392 : }
393 :
394 :
395 : /* Find an appropriate backend for the file associated with ELF. */
396 : Ebl *
397 1280 : ebl_openbackend (Elf *elf)
398 : {
399 : GElf_Ehdr ehdr_mem;
400 : GElf_Ehdr *ehdr;
401 :
402 : /* Get the ELF header of the object. */
403 1280 : ehdr = gelf_getehdr (elf, &ehdr_mem);
404 1280 : if (ehdr == NULL)
405 : {
406 : // XXX uncomment
407 : // __libebl_seterror (elf_errno ());
408 : return NULL;
409 : }
410 :
411 1280 : return openbackend (elf, NULL, ehdr->e_machine);
412 : }
413 :
414 :
415 : /* Find backend without underlying ELF file. */
416 : Ebl *
417 9 : ebl_openbackend_machine (GElf_Half machine)
418 : {
419 9 : return openbackend (NULL, NULL, machine);
420 : }
421 :
422 :
423 : /* Find backend with given emulation name. */
424 : Ebl *
425 0 : ebl_openbackend_emulation (const char *emulation)
426 : {
427 0 : return openbackend (NULL, emulation, EM_NONE);
428 : }
429 :
430 :
431 : /* Default callbacks. Mostly they just return the error value. */
432 : static const char *
433 0 : default_reloc_type_name (int ignore __attribute__ ((unused)),
434 : char *buf __attribute__ ((unused)),
435 : size_t len __attribute__ ((unused)))
436 : {
437 0 : return NULL;
438 : }
439 :
440 : static bool
441 0 : default_reloc_type_check (int ignore __attribute__ ((unused)))
442 : {
443 0 : return false;
444 : }
445 :
446 : static bool
447 0 : default_reloc_valid_use (Elf *elf __attribute__ ((unused)),
448 : int ignore __attribute__ ((unused)))
449 : {
450 0 : return false;
451 : }
452 :
453 : static Elf_Type
454 0 : default_reloc_simple_type (Ebl *eh __attribute__ ((unused)),
455 : int ignore __attribute__ ((unused)))
456 : {
457 0 : return ELF_T_NUM;
458 : }
459 :
460 : static bool
461 57247 : default_gotpc_reloc_check (Elf *elf __attribute__ ((unused)),
462 : int ignore __attribute__ ((unused)))
463 : {
464 57247 : return false;
465 : }
466 :
467 : static const char *
468 110 : default_segment_type_name (int ignore __attribute__ ((unused)),
469 : char *buf __attribute__ ((unused)),
470 : size_t len __attribute__ ((unused)))
471 : {
472 110 : return NULL;
473 : }
474 :
475 : static const char *
476 1575900 : default_section_type_name (int ignore __attribute__ ((unused)),
477 : char *buf __attribute__ ((unused)),
478 : size_t len __attribute__ ((unused)))
479 : {
480 1575900 : return NULL;
481 : }
482 :
483 : static const char *
484 35305 : default_section_name (int ignore __attribute__ ((unused)),
485 : int ignore2 __attribute__ ((unused)),
486 : char *buf __attribute__ ((unused)),
487 : size_t len __attribute__ ((unused)))
488 : {
489 35305 : return NULL;
490 : }
491 :
492 : static const char *
493 2 : default_machine_flag_name (Elf64_Word *ignore __attribute__ ((unused)))
494 : {
495 2 : return NULL;
496 : }
497 :
498 : static bool
499 115 : default_machine_flag_check (Elf64_Word flags __attribute__ ((unused)))
500 : {
501 115 : return flags == 0;
502 : }
503 :
504 : static bool
505 0 : default_machine_section_flag_check (GElf_Xword flags)
506 : {
507 0 : return flags == 0;
508 : }
509 :
510 : static bool
511 0 : default_check_special_section (Ebl *ebl __attribute__ ((unused)),
512 : int ndx __attribute__ ((unused)),
513 : const GElf_Shdr *shdr __attribute__ ((unused)),
514 : const char *sname __attribute__ ((unused)))
515 : {
516 0 : return false;
517 : }
518 :
519 : static const char *
520 70611 : default_symbol_type_name (int ignore __attribute__ ((unused)),
521 : char *buf __attribute__ ((unused)),
522 : size_t len __attribute__ ((unused)))
523 : {
524 70611 : return NULL;
525 : }
526 :
527 : static const char *
528 0 : default_symbol_binding_name (int ignore __attribute__ ((unused)),
529 : char *buf __attribute__ ((unused)),
530 : size_t len __attribute__ ((unused)))
531 : {
532 0 : return NULL;
533 : }
534 :
535 : static const char *
536 448 : default_dynamic_tag_name (int64_t ignore __attribute__ ((unused)),
537 : char *buf __attribute__ ((unused)),
538 : size_t len __attribute__ ((unused)))
539 : {
540 448 : return NULL;
541 : }
542 :
543 : static bool
544 1589 : default_dynamic_tag_check (int64_t ignore __attribute__ ((unused)))
545 : {
546 1589 : return false;
547 : }
548 :
549 : static void
550 1283 : default_destr (struct ebl *ignore __attribute__ ((unused)))
551 : {
552 1283 : }
553 :
554 : static const char *
555 32 : default_osabi_name (int ignore __attribute__ ((unused)),
556 : char *buf __attribute__ ((unused)),
557 : size_t len __attribute__ ((unused)))
558 : {
559 32 : return NULL;
560 : }
561 :
562 : static const char *
563 59 : default_core_note_type_name (uint32_t ignore __attribute__ ((unused)),
564 : char *buf __attribute__ ((unused)),
565 : size_t len __attribute__ ((unused)))
566 : {
567 59 : return NULL;
568 : }
569 :
570 : static int
571 92 : default_auxv_info (GElf_Xword a_type __attribute__ ((unused)),
572 : const char **name __attribute__ ((unused)),
573 : const char **format __attribute__ ((unused)))
574 : {
575 92 : return 0;
576 : }
577 :
578 : static int
579 0 : default_core_note (const GElf_Nhdr *nhdr __attribute__ ((unused)),
580 : const char *name __attribute__ ((unused)),
581 : GElf_Word *ro __attribute__ ((unused)),
582 : size_t *nregloc __attribute__ ((unused)),
583 : const Ebl_Register_Location **reglocs
584 : __attribute__ ((unused)),
585 : size_t *nitems __attribute__ ((unused)),
586 : const Ebl_Core_Item **items __attribute__ ((unused)))
587 : {
588 0 : return 0;
589 : }
590 :
591 : static const char *
592 32 : default_object_note_type_name (const char *name __attribute__ ((unused)),
593 : uint32_t ignore __attribute__ ((unused)),
594 : char *buf __attribute__ ((unused)),
595 : size_t len __attribute__ ((unused)))
596 : {
597 32 : return NULL;
598 : }
599 :
600 : static bool
601 32 : default_object_note (const char *name __attribute__ ((unused)),
602 : uint32_t type __attribute__ ((unused)),
603 : uint32_t descsz __attribute__ ((unused)),
604 : const char *desc __attribute__ ((unused)))
605 : {
606 32 : return NULL;
607 : }
608 :
609 : static bool
610 101454 : default_debugscn_p (const char *name)
611 : {
612 : /* We know by default only about the DWARF debug sections which have
613 : fixed names. */
614 : static const char *dwarf_scn_names[] =
615 : {
616 : /* DWARF 1 */
617 : ".debug",
618 : ".line",
619 : /* GNU DWARF 1 extensions */
620 : ".debug_srcinfo",
621 : ".debug_sfnames",
622 : /* DWARF 1.1 and DWARF 2 */
623 : ".debug_aranges",
624 : ".debug_pubnames",
625 : /* DWARF 2 */
626 : ".debug_info",
627 : ".debug_abbrev",
628 : ".debug_line",
629 : ".debug_frame",
630 : ".debug_str",
631 : ".debug_loc",
632 : ".debug_macinfo",
633 : /* DWARF 3 */
634 : ".debug_ranges",
635 : ".debug_pubtypes",
636 : /* DWARF 4 */
637 : ".debug_types",
638 : /* GDB DWARF 4 extension */
639 : ".gdb_index",
640 : /* GNU/DWARF 5 extension/proposal */
641 : ".debug_macro",
642 : /* DWARF 5 */
643 : ".debug_addr",
644 : ".debug_line_str",
645 : ".debug_loclists",
646 : ".debug_names",
647 : ".debug_rnglists",
648 : ".debug_str_offsets",
649 : /* SGI/MIPS DWARF 2 extensions */
650 : ".debug_weaknames",
651 : ".debug_funcnames",
652 : ".debug_typenames",
653 : ".debug_varnames"
654 : };
655 101454 : const size_t ndwarf_scn_names = (sizeof (dwarf_scn_names)
656 : / sizeof (dwarf_scn_names[0]));
657 2503537 : for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
658 2426495 : if (strcmp (name, dwarf_scn_names[cnt]) == 0
659 2402083 : || (strncmp (name, ".zdebug", strlen (".zdebug")) == 0
660 0 : && strcmp (&name[2], &dwarf_scn_names[cnt][1]) == 0))
661 : return true;
662 :
663 : return false;
664 : }
665 :
666 : static bool
667 0 : default_copy_reloc_p (int reloc __attribute__ ((unused)))
668 : {
669 0 : return false;
670 : }
671 : strong_alias (default_copy_reloc_p, default_none_reloc_p)
672 : strong_alias (default_copy_reloc_p, default_relative_reloc_p)
673 :
674 : static bool
675 115893 : default_check_special_symbol (Elf *elf __attribute__ ((unused)),
676 : const GElf_Sym *sym __attribute__ ((unused)),
677 : const char *name __attribute__ ((unused)),
678 : const GElf_Shdr *destshdr __attribute__ ((unused)))
679 : {
680 115893 : return false;
681 : }
682 :
683 : static bool
684 0 : default_data_marker_symbol (const GElf_Sym *sym __attribute__ ((unused)),
685 : const char *sname __attribute__ ((unused)))
686 : {
687 0 : return false;
688 : }
689 :
690 : static bool
691 0 : default_check_st_other_bits (unsigned char st_other __attribute__ ((unused)))
692 : {
693 0 : return false;
694 : }
695 :
696 :
697 : static bool
698 75 : default_bss_plt_p (Elf *elf __attribute__ ((unused)))
699 : {
700 75 : return false;
701 : }
702 :
703 : static int
704 0 : default_return_value_location (Dwarf_Die *functypedie __attribute__ ((unused)),
705 : const Dwarf_Op **locops __attribute__ ((unused)))
706 : {
707 0 : return -2;
708 : }
709 :
710 : static ssize_t
711 0 : default_register_info (Ebl *ebl __attribute__ ((unused)),
712 : int regno, char *name, size_t namelen,
713 : const char **prefix,
714 : const char **setname,
715 : int *bits, int *type)
716 : {
717 0 : if (name == NULL)
718 : return 0;
719 :
720 0 : *setname = "???";
721 0 : *prefix = "";
722 0 : *bits = -1;
723 0 : *type = DW_ATE_void;
724 0 : return snprintf (name, namelen, "reg%d", regno);
725 : }
726 :
727 : static int
728 0 : default_syscall_abi (Ebl *ebl __attribute__ ((unused)),
729 : int *sp, int *pc, int *callno, int args[6])
730 : {
731 0 : *sp = *pc = *callno = -1;
732 0 : args[0] = -1;
733 0 : args[1] = -1;
734 0 : args[2] = -1;
735 0 : args[3] = -1;
736 0 : args[4] = -1;
737 0 : args[5] = -1;
738 0 : return -1;
739 : }
740 :
741 : static bool
742 0 : default_check_object_attribute (Ebl *ebl __attribute__ ((unused)),
743 : const char *vendor __attribute__ ((unused)),
744 : int tag __attribute__ ((unused)),
745 : uint64_t value __attribute__ ((unused)),
746 : const char **tag_name, const char **value_name)
747 : {
748 0 : *tag_name = NULL;
749 0 : *value_name = NULL;
750 0 : return false;
751 : }
752 :
753 : static bool
754 242 : default_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)),
755 : Elf64_Word sh_type __attribute__ ((unused)))
756 : {
757 242 : return false;
758 : }
759 :
760 : static int
761 0 : default_abi_cfi (Ebl *ebl __attribute__ ((unused)),
762 : Dwarf_CIE *abi_info __attribute__ ((unused)))
763 : {
764 0 : return -1;
765 : }
|