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