Imported Upstream version 0.155
[platform/upstream/elfutils.git] / libebl / eblopenbackend.c
1 /* Generate ELF backend handle.
2    Copyright (C) 2000-2011 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 <error.h>
36 #include <libelfP.h>
37 #include <dwarf.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <stdio.h>
41
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, 0, 0 },
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 };
135 #define nmachines (sizeof (machines) / sizeof (machines[0]))
136
137
138 /* Default callbacks.  Mostly they just return the error value.  */
139 static const char *default_object_type_name (int ignore, char *buf,
140                                              size_t len);
141 static const char *default_reloc_type_name (int ignore, char *buf, size_t len);
142 static bool default_reloc_type_check (int ignore);
143 static bool default_reloc_valid_use (Elf *elf, int ignore);
144 static Elf_Type default_reloc_simple_type (Ebl *ebl, int ignore);
145 static bool default_gotpc_reloc_check (Elf *elf, int ignore);
146 static const char *default_segment_type_name (int ignore, char *buf,
147                                               size_t len);
148 static const char *default_section_type_name (int ignore, char *buf,
149                                               size_t len);
150 static const char *default_section_name (int ignore, int ignore2, char *buf,
151                                          size_t len);
152 static const char *default_machine_flag_name (Elf64_Word *ignore);
153 static bool default_machine_flag_check (Elf64_Word flags);
154 static bool default_machine_section_flag_check (GElf_Xword flags);
155 static const char *default_symbol_type_name (int ignore, char *buf,
156                                              size_t len);
157 static const char *default_symbol_binding_name (int ignore, char *buf,
158                                                 size_t len);
159 static const char *default_dynamic_tag_name (int64_t ignore, char *buf,
160                                              size_t len);
161 static bool default_dynamic_tag_check (int64_t ignore);
162 static GElf_Word default_sh_flags_combine (GElf_Word flags1, GElf_Word flags2);
163 static const char *default_osabi_name (int ignore, char *buf, size_t len);
164 static void default_destr (struct ebl *ignore);
165 static const char *default_core_note_type_name (uint32_t, char *buf,
166                                                 size_t len);
167 static const char *default_object_note_type_name (const char *name, uint32_t,
168                                                   char *buf, size_t len);
169 static int default_core_note (const GElf_Nhdr *nhdr, const char *name,
170                               GElf_Word *regs_offset, size_t *nregloc,
171                               const Ebl_Register_Location **reglocs,
172                               size_t *nitems, const Ebl_Core_Item **);
173 static int default_auxv_info (GElf_Xword a_type,
174                               const char **name, const char **format);
175 static bool default_object_note (const char *name, uint32_t type,
176                                  uint32_t descsz, const char *desc);
177 static bool default_debugscn_p (const char *name);
178 static bool default_copy_reloc_p (int reloc);
179 static bool default_none_reloc_p (int reloc);
180 static bool default_relative_reloc_p (int reloc);
181 static bool default_check_special_symbol (Elf *elf, GElf_Ehdr *ehdr,
182                                           const GElf_Sym *sym,
183                                           const char *name,
184                                           const GElf_Shdr *destshdr);
185 static bool default_check_st_other_bits (unsigned char st_other);
186 static bool default_check_special_section (Ebl *, int,
187                                            const GElf_Shdr *, const char *);
188 static bool default_bss_plt_p (Elf *elf, GElf_Ehdr *ehdr);
189 static int default_return_value_location (Dwarf_Die *functypedie,
190                                           const Dwarf_Op **locops);
191 static ssize_t default_register_info (Ebl *ebl,
192                                       int regno, char *name, size_t namelen,
193                                       const char **prefix,
194                                       const char **setname,
195                                       int *bits, int *type);
196 static int default_syscall_abi (Ebl *ebl, int *sp, int *pc,
197                                 int *callno, int args[6]);
198 static bool default_check_object_attribute (Ebl *ebl, const char *vendor,
199                                             int tag, uint64_t value,
200                                             const char **tag_name,
201                                             const char **value_name);
202 static int default_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info);
203
204
205 static void
206 fill_defaults (Ebl *result)
207 {
208   result->object_type_name = default_object_type_name;
209   result->reloc_type_name = default_reloc_type_name;
210   result->reloc_type_check = default_reloc_type_check;
211   result->reloc_valid_use = default_reloc_valid_use;
212   result->reloc_simple_type = default_reloc_simple_type;
213   result->gotpc_reloc_check = default_gotpc_reloc_check;
214   result->segment_type_name = default_segment_type_name;
215   result->section_type_name = default_section_type_name;
216   result->section_name = default_section_name;
217   result->machine_flag_name = default_machine_flag_name;
218   result->machine_flag_check = default_machine_flag_check;
219   result->machine_section_flag_check = default_machine_section_flag_check;
220   result->check_special_section = default_check_special_section;
221   result->symbol_type_name = default_symbol_type_name;
222   result->symbol_binding_name = default_symbol_binding_name;
223   result->dynamic_tag_name = default_dynamic_tag_name;
224   result->dynamic_tag_check = default_dynamic_tag_check;
225   result->sh_flags_combine = default_sh_flags_combine;
226   result->osabi_name = default_osabi_name;
227   result->core_note_type_name = default_core_note_type_name;
228   result->object_note_type_name = default_object_note_type_name;
229   result->core_note = default_core_note;
230   result->auxv_info = default_auxv_info;
231   result->object_note = default_object_note;
232   result->debugscn_p = default_debugscn_p;
233   result->copy_reloc_p = default_copy_reloc_p;
234   result->none_reloc_p = default_none_reloc_p;
235   result->relative_reloc_p = default_relative_reloc_p;
236   result->check_special_symbol = default_check_special_symbol;
237   result->check_st_other_bits = default_check_st_other_bits;
238   result->bss_plt_p = default_bss_plt_p;
239   result->return_value_location = default_return_value_location;
240   result->register_info = default_register_info;
241   result->syscall_abi = default_syscall_abi;
242   result->check_object_attribute = default_check_object_attribute;
243   result->disasm = NULL;
244   result->abi_cfi = default_abi_cfi;
245   result->destr = default_destr;
246   result->sysvhash_entrysize = sizeof (Elf32_Word);
247 }
248
249
250 /* Find an appropriate backend for the file associated with ELF.  */
251 static Ebl *
252 openbackend (elf, emulation, machine)
253      Elf *elf;
254      const char *emulation;
255      GElf_Half machine;
256 {
257   Ebl *result;
258   size_t cnt;
259
260   /* First allocate the data structure for the result.  We do this
261      here since this assures that the structure is always large
262      enough.  */
263   result = (Ebl *) calloc (1, sizeof (Ebl));
264   if (result == NULL)
265     {
266       // XXX uncomment
267       // __libebl_seterror (ELF_E_NOMEM);
268       return NULL;
269     }
270
271   /* Fill in the default callbacks.  The initializer for the machine
272      specific module can overwrite the values.  */
273   fill_defaults (result);
274
275   /* XXX Currently all we do is to look at 'e_machine' value in the
276      ELF header.  With an internal mapping table from EM_* value to
277      DSO name we try to load the appropriate module to handle this
278      binary type.
279
280      Multiple modules for the same machine type are possible and they
281      will be tried in sequence.  The lookup process will only stop
282      when a module which can handle the machine type is found or all
283      available matching modules are tried.  */
284   for (cnt = 0; cnt < nmachines; ++cnt)
285     if ((emulation != NULL && strcmp (emulation, machines[cnt].emulation) == 0)
286         || (emulation == NULL && machines[cnt].em == machine))
287       {
288         /* Well, we know the emulation name now.  */
289         result->emulation = machines[cnt].emulation;
290
291         /* We access some data structures directly.  Make sure the 32 and
292            64 bit variants are laid out the same.  */
293         assert (offsetof (Elf32_Ehdr, e_machine)
294                 == offsetof (Elf64_Ehdr, e_machine));
295         assert (sizeof (((Elf32_Ehdr *) 0)->e_machine)
296                 == sizeof (((Elf64_Ehdr *) 0)->e_machine));
297         assert (offsetof (Elf, state.elf32.ehdr)
298                 == offsetof (Elf, state.elf64.ehdr));
299
300         /* Prefer taking the information from the ELF file.  */
301         if (elf == NULL)
302           {
303             result->machine = machines[cnt].em;
304             result->class = machines[cnt].class;
305             result->data = machines[cnt].data;
306           }
307         else
308           {
309             result->machine = elf->state.elf32.ehdr->e_machine;
310             result->class = elf->state.elf32.ehdr->e_ident[EI_CLASS];
311             result->data = elf->state.elf32.ehdr->e_ident[EI_DATA];
312           }
313
314 #ifndef LIBEBL_SUBDIR
315 # define LIBEBL_SUBDIR PACKAGE
316 #endif
317 #define ORIGINDIR "$ORIGIN/../$LIB/" LIBEBL_SUBDIR "/"
318
319         /* Give it a try.  At least the machine type matches.  First
320            try to load the module.  */
321         char dsoname[100];
322         strcpy (stpcpy (stpcpy (dsoname, ORIGINDIR "libebl_"),
323                         machines[cnt].dsoname),
324                 ".so");
325
326         void *h = dlopen (dsoname, RTLD_LAZY);
327         if (h == NULL)
328           {
329             strcpy (stpcpy (stpcpy (dsoname, "libebl_"),
330                             machines[cnt].dsoname),
331                     ".so");
332             h = dlopen (dsoname, RTLD_LAZY);
333           }
334
335           /* Try without an explicit path.  */
336         if (h != NULL)
337           {
338             /* We managed to load the object.  Now see whether the
339                initialization function likes our file.  */
340             static const char version[] = MODVERSION;
341             const char *modversion;
342             ebl_bhinit_t initp;
343             char symname[machines[cnt].prefix_len + sizeof "_init"];
344
345             strcpy (mempcpy (symname, machines[cnt].prefix,
346                              machines[cnt].prefix_len), "_init");
347
348             initp = (ebl_bhinit_t) dlsym (h, symname);
349             if (initp != NULL
350                 && (modversion = initp (elf, machine, result, sizeof (Ebl)))
351                 && strcmp (version, modversion) == 0)
352               {
353                 /* We found a module to handle our file.  */
354                 result->dlhandle = h;
355                 result->elf = elf;
356
357                 /* A few entries are mandatory.  */
358                 assert (result->name != NULL);
359                 assert (result->destr != NULL);
360
361                 return result;
362               }
363
364             /* Not the module we need.  */
365             (void) dlclose (h);
366           }
367
368         /* We cannot find a DSO but the emulation/machine ID matches.
369            Return that information.  */
370         result->dlhandle = NULL;
371         result->elf = elf;
372         result->name = machines[cnt].prefix;
373         fill_defaults (result);
374
375         return result;
376       }
377
378   /* Nothing matched.  We use only the default callbacks.   */
379   result->dlhandle = NULL;
380   result->elf = elf;
381   result->emulation = "<unknown>";
382   result->name = "<unknown>";
383   fill_defaults (result);
384
385   return result;
386 }
387
388
389 /* Find an appropriate backend for the file associated with ELF.  */
390 Ebl *
391 ebl_openbackend (elf)
392      Elf *elf;
393 {
394   GElf_Ehdr ehdr_mem;
395   GElf_Ehdr *ehdr;
396
397   /* Get the ELF header of the object.  */
398   ehdr = gelf_getehdr (elf, &ehdr_mem);
399   if (ehdr == NULL)
400     {
401       // XXX uncomment
402       // __libebl_seterror (elf_errno ());
403       return NULL;
404     }
405
406   return openbackend (elf, NULL, ehdr->e_machine);
407 }
408
409
410 /* Find backend without underlying ELF file.  */
411 Ebl *
412 ebl_openbackend_machine (machine)
413      GElf_Half machine;
414 {
415   return openbackend (NULL, NULL, machine);
416 }
417
418
419 /* Find backend with given emulation name.  */
420 Ebl *
421 ebl_openbackend_emulation (const char *emulation)
422 {
423   return openbackend (NULL, emulation, EM_NONE);
424 }
425
426
427 /* Default callbacks.  Mostly they just return the error value.  */
428 static const char *
429 default_object_type_name (int ignore __attribute__ ((unused)),
430                           char *buf __attribute__ ((unused)),
431                           size_t len __attribute__ ((unused)))
432 {
433   return NULL;
434 }
435
436 static const char *
437 default_reloc_type_name (int ignore __attribute__ ((unused)),
438                          char *buf __attribute__ ((unused)),
439                          size_t len __attribute__ ((unused)))
440 {
441   return NULL;
442 }
443
444 static bool
445 default_reloc_type_check (int ignore __attribute__ ((unused)))
446 {
447   return false;
448 }
449
450 static bool
451 default_reloc_valid_use (Elf *elf __attribute__ ((unused)),
452                          int ignore __attribute__ ((unused)))
453 {
454   return false;
455 }
456
457 static Elf_Type
458 default_reloc_simple_type (Ebl *eh __attribute__ ((unused)),
459                            int ignore __attribute__ ((unused)))
460 {
461   return ELF_T_NUM;
462 }
463
464 static bool
465 default_gotpc_reloc_check (Elf *elf __attribute__ ((unused)),
466                            int ignore __attribute__ ((unused)))
467 {
468   return false;
469 }
470
471 static const char *
472 default_segment_type_name (int ignore __attribute__ ((unused)),
473                            char *buf __attribute__ ((unused)),
474                            size_t len __attribute__ ((unused)))
475 {
476   return NULL;
477 }
478
479 static const char *
480 default_section_type_name (int ignore __attribute__ ((unused)),
481                            char *buf __attribute__ ((unused)),
482                            size_t len __attribute__ ((unused)))
483 {
484   return NULL;
485 }
486
487 static const char *
488 default_section_name (int ignore __attribute__ ((unused)),
489                       int ignore2 __attribute__ ((unused)),
490                       char *buf __attribute__ ((unused)),
491                       size_t len __attribute__ ((unused)))
492 {
493   return NULL;
494 }
495
496 static const char *
497 default_machine_flag_name (Elf64_Word *ignore __attribute__ ((unused)))
498 {
499   return NULL;
500 }
501
502 static bool
503 default_machine_flag_check (Elf64_Word flags __attribute__ ((unused)))
504 {
505   return flags == 0;
506 }
507
508 static bool
509 default_machine_section_flag_check (GElf_Xword flags)
510 {
511   return flags == 0;
512 }
513
514 static bool
515 default_check_special_section (Ebl *ebl __attribute__ ((unused)),
516                                int ndx __attribute__ ((unused)),
517                                const GElf_Shdr *shdr __attribute__ ((unused)),
518                                const char *sname __attribute__ ((unused)))
519 {
520   return false;
521 }
522
523 static const char *
524 default_symbol_type_name (int ignore __attribute__ ((unused)),
525                           char *buf __attribute__ ((unused)),
526                           size_t len __attribute__ ((unused)))
527 {
528   return NULL;
529 }
530
531 static const char *
532 default_symbol_binding_name (int ignore __attribute__ ((unused)),
533                              char *buf __attribute__ ((unused)),
534                              size_t len __attribute__ ((unused)))
535 {
536   return NULL;
537 }
538
539 static const char *
540 default_dynamic_tag_name (int64_t ignore __attribute__ ((unused)),
541                           char *buf __attribute__ ((unused)),
542                           size_t len __attribute__ ((unused)))
543 {
544   return NULL;
545 }
546
547 static bool
548 default_dynamic_tag_check (int64_t ignore __attribute__ ((unused)))
549 {
550   return false;
551 }
552
553 static GElf_Word
554 default_sh_flags_combine (GElf_Word flags1, GElf_Word flags2)
555 {
556   return SH_FLAGS_COMBINE (flags1, flags2);
557 }
558
559 static void
560 default_destr (struct ebl *ignore __attribute__ ((unused)))
561 {
562 }
563
564 static const char *
565 default_osabi_name (int ignore __attribute__ ((unused)),
566                     char *buf __attribute__ ((unused)),
567                     size_t len __attribute__ ((unused)))
568 {
569   return NULL;
570 }
571
572 static const char *
573 default_core_note_type_name (uint32_t ignore __attribute__ ((unused)),
574                              char *buf __attribute__ ((unused)),
575                              size_t len __attribute__ ((unused)))
576 {
577   return NULL;
578 }
579
580 static int
581 default_auxv_info (GElf_Xword a_type __attribute__ ((unused)),
582                    const char **name __attribute__ ((unused)),
583                    const char **format __attribute__ ((unused)))
584 {
585   return 0;
586 }
587
588 static int
589 default_core_note (const GElf_Nhdr *nhdr __attribute__ ((unused)),
590                    const char *name __attribute__ ((unused)),
591                    GElf_Word *ro __attribute__ ((unused)),
592                    size_t *nregloc  __attribute__ ((unused)),
593                    const Ebl_Register_Location **reglocs
594                    __attribute__ ((unused)),
595                    size_t *nitems __attribute__ ((unused)),
596                    const Ebl_Core_Item **items __attribute__ ((unused)))
597 {
598   return 0;
599 }
600
601 static const char *
602 default_object_note_type_name (const char *name __attribute__ ((unused)),
603                                uint32_t ignore __attribute__ ((unused)),
604                                char *buf __attribute__ ((unused)),
605                                size_t len __attribute__ ((unused)))
606 {
607   return NULL;
608 }
609
610 static bool
611 default_object_note (const char *name __attribute__ ((unused)),
612                      uint32_t type __attribute__ ((unused)),
613                      uint32_t descsz __attribute__ ((unused)),
614                      const char *desc __attribute__ ((unused)))
615 {
616   return NULL;
617 }
618
619 static bool
620 default_debugscn_p (const char *name)
621 {
622   /* We know by default only about the DWARF debug sections which have
623      fixed names.  */
624   static const char *dwarf_scn_names[] =
625     {
626       /* DWARF 1 */
627       ".debug",
628       ".line",
629       /* GNU DWARF 1 extensions */
630       ".debug_srcinfo",
631       ".debug_sfnames",
632       /* DWARF 1.1 and DWARF 2 */
633       ".debug_aranges",
634       ".debug_pubnames",
635       /* DWARF 2 */
636       ".debug_info",
637       ".debug_abbrev",
638       ".debug_line",
639       ".debug_frame",
640       ".debug_str",
641       ".debug_loc",
642       ".debug_macinfo",
643       /* DWARF 3 */
644       ".debug_ranges",
645       ".debug_pubtypes",
646       /* DWARF 4 */
647       ".debug_types",
648       /* GDB DWARF 4 extension */
649       ".gdb_index",
650       /* GNU/DWARF 5 extension/proposal */
651       ".debug_macro",
652       /* SGI/MIPS DWARF 2 extensions */
653       ".debug_weaknames",
654       ".debug_funcnames",
655       ".debug_typenames",
656       ".debug_varnames"
657     };
658   const size_t ndwarf_scn_names = (sizeof (dwarf_scn_names)
659                                    / sizeof (dwarf_scn_names[0]));
660   for (size_t cnt = 0; cnt < ndwarf_scn_names; ++cnt)
661     if (strcmp (name, dwarf_scn_names[cnt]) == 0)
662       return true;
663
664   return false;
665 }
666
667 static bool
668 default_copy_reloc_p (int reloc __attribute__ ((unused)))
669 {
670   return false;
671 }
672 strong_alias (default_copy_reloc_p, default_none_reloc_p)
673 strong_alias (default_copy_reloc_p, default_relative_reloc_p)
674
675 static bool
676 default_check_special_symbol (Elf *elf __attribute__ ((unused)),
677                               GElf_Ehdr *ehdr __attribute__ ((unused)),
678                               const GElf_Sym *sym __attribute__ ((unused)),
679                               const char *name __attribute__ ((unused)),
680                               const GElf_Shdr *destshdr __attribute__ ((unused)))
681 {
682   return false;
683 }
684
685 static bool
686 default_check_st_other_bits (unsigned char st_other __attribute__ ((unused)))
687 {
688   return false;
689 }
690
691
692 static bool
693 default_bss_plt_p (Elf *elf __attribute__ ((unused)),
694                    GElf_Ehdr *ehdr __attribute__ ((unused)))
695 {
696   return false;
697 }
698
699 static int
700 default_return_value_location (Dwarf_Die *functypedie __attribute__ ((unused)),
701                                const Dwarf_Op **locops __attribute__ ((unused)))
702 {
703   return -2;
704 }
705
706 static ssize_t
707 default_register_info (Ebl *ebl __attribute__ ((unused)),
708                        int regno, char *name, size_t namelen,
709                        const char **prefix,
710                        const char **setname,
711                        int *bits, int *type)
712 {
713   if (name == NULL)
714     return 0;
715
716   *setname = "???";
717   *prefix = "";
718   *bits = -1;
719   *type = DW_ATE_void;
720   return snprintf (name, namelen, "reg%d", regno);
721 }
722
723 static int
724 default_syscall_abi (Ebl *ebl __attribute__ ((unused)),
725                      int *sp, int *pc, int *callno, int args[6])
726 {
727   *sp = *pc = *callno = -1;
728   args[0] = -1;
729   args[1] = -1;
730   args[2] = -1;
731   args[3] = -1;
732   args[4] = -1;
733   args[5] = -1;
734   return -1;
735 }
736
737 static bool
738 default_check_object_attribute (Ebl *ebl __attribute__ ((unused)),
739                                 const char *vendor  __attribute__ ((unused)),
740                                 int tag __attribute__ ((unused)),
741                                 uint64_t value __attribute__ ((unused)),
742                                 const char **tag_name, const char **value_name)
743 {
744   *tag_name = NULL;
745   *value_name = NULL;
746   return false;
747 }
748
749 static int
750 default_abi_cfi (Ebl *ebl __attribute__ ((unused)),
751                  Dwarf_CIE *abi_info __attribute__ ((unused)))
752 {
753   return 0;
754 }