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