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