Automatic date update in version.in
[binutils-gdb.git] / gdb / elfread.c
blob9bfe12712db788c3f8f3a3cfa65df72623d49c7d
1 /* Read ELF (Executable and Linking Format) object files for GDB.
3 Copyright (C) 1991-2024 Free Software Foundation, Inc.
5 Written by Fred Fish at Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "bfd.h"
23 #include "elf-bfd.h"
24 #include "elf/common.h"
25 #include "elf/internal.h"
26 #include "elf/mips.h"
27 #include "symtab.h"
28 #include "symfile.h"
29 #include "objfiles.h"
30 #include "stabsread.h"
31 #include "demangle.h"
32 #include "filenames.h"
33 #include "probe.h"
34 #include "arch-utils.h"
35 #include "gdbtypes.h"
36 #include "value.h"
37 #include "infcall.h"
38 #include "gdbthread.h"
39 #include "inferior.h"
40 #include "regcache.h"
41 #include "bcache.h"
42 #include "gdb_bfd.h"
43 #include "location.h"
44 #include "auxv.h"
45 #include "mdebugread.h"
46 #include "ctfread.h"
47 #include <string_view>
48 #include "gdbsupport/scoped_fd.h"
49 #include "dwarf2/public.h"
50 #include "cli/cli-cmds.h"
52 /* Whether ctf should always be read, or only if no dwarf is present. */
53 static bool always_read_ctf;
55 /* The struct elfinfo is available only during ELF symbol table and
56 psymtab reading. It is destroyed at the completion of psymtab-reading.
57 It's local to elf_symfile_read. */
59 struct elfinfo
61 asection *stabsect; /* Section pointer for .stab section */
62 asection *mdebugsect; /* Section pointer for .mdebug section */
63 asection *ctfsect; /* Section pointer for .ctf section */
66 /* Type for per-BFD data. */
68 typedef std::vector<std::unique_ptr<probe>> elfread_data;
70 /* Per-BFD data for probe info. */
72 static const registry<bfd>::key<elfread_data> probe_key;
74 /* Minimal symbols located at the GOT entries for .plt - that is the real
75 pointer where the given entry will jump to. It gets updated by the real
76 function address during lazy ld.so resolving in the inferior. These
77 minimal symbols are indexed for <tab>-completion. */
79 #define SYMBOL_GOT_PLT_SUFFIX "@got.plt"
81 /* Locate the segments in ABFD. */
83 static symfile_segment_data_up
84 elf_symfile_segments (bfd *abfd)
86 Elf_Internal_Phdr *phdrs, **segments;
87 long phdrs_size;
88 int num_phdrs, num_segments, num_sections, i;
89 asection *sect;
91 phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
92 if (phdrs_size == -1)
93 return NULL;
95 phdrs = (Elf_Internal_Phdr *) alloca (phdrs_size);
96 num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
97 if (num_phdrs == -1)
98 return NULL;
100 num_segments = 0;
101 segments = XALLOCAVEC (Elf_Internal_Phdr *, num_phdrs);
102 for (i = 0; i < num_phdrs; i++)
103 if (phdrs[i].p_type == PT_LOAD)
104 segments[num_segments++] = &phdrs[i];
106 if (num_segments == 0)
107 return NULL;
109 symfile_segment_data_up data (new symfile_segment_data);
110 data->segments.reserve (num_segments);
112 for (i = 0; i < num_segments; i++)
113 data->segments.emplace_back (segments[i]->p_vaddr, segments[i]->p_memsz);
115 num_sections = bfd_count_sections (abfd);
117 /* All elements are initialized to 0 (map to no segment). */
118 data->segment_info.resize (num_sections);
120 for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
122 int j;
124 if ((bfd_section_flags (sect) & SEC_ALLOC) == 0)
125 continue;
127 Elf_Internal_Shdr *this_hdr = &elf_section_data (sect)->this_hdr;
129 for (j = 0; j < num_segments; j++)
130 if (ELF_SECTION_IN_SEGMENT (this_hdr, segments[j]))
132 data->segment_info[i] = j + 1;
133 break;
136 /* We should have found a segment for every non-empty section.
137 If we haven't, we will not relocate this section by any
138 offsets we apply to the segments. As an exception, do not
139 warn about SHT_NOBITS sections; in normal ELF execution
140 environments, SHT_NOBITS means zero-initialized and belongs
141 in a segment, but in no-OS environments some tools (e.g. ARM
142 RealView) use SHT_NOBITS for uninitialized data. Since it is
143 uninitialized, it doesn't need a program header. Such
144 binaries are not relocatable. */
146 /* Exclude debuginfo files from this warning, too, since those
147 are often not strictly compliant with the standard. See, e.g.,
148 ld/24717 for more discussion. */
149 if (!is_debuginfo_file (abfd)
150 && bfd_section_size (sect) > 0 && j == num_segments
151 && (bfd_section_flags (sect) & SEC_LOAD) != 0)
152 warning (_("Loadable section \"%s\" outside of ELF segments\n in %s"),
153 bfd_section_name (sect), bfd_get_filename (abfd));
156 return data;
159 /* We are called once per section from elf_symfile_read. We
160 need to examine each section we are passed, check to see
161 if it is something we are interested in processing, and
162 if so, stash away some access information for the section.
164 For now we recognize the dwarf debug information sections and
165 line number sections from matching their section names. The
166 ELF definition is no real help here since it has no direct
167 knowledge of DWARF (by design, so any debugging format can be
168 used).
170 We also recognize the ".stab" sections used by the Sun compilers
171 released with Solaris 2.
173 FIXME: The section names should not be hardwired strings (what
174 should they be? I don't think most object file formats have enough
175 section flags to specify what kind of debug section it is.
176 -kingdon). */
178 static void
179 elf_locate_sections (asection *sectp, struct elfinfo *ei)
181 if (strcmp (sectp->name, ".stab") == 0)
183 ei->stabsect = sectp;
185 else if (strcmp (sectp->name, ".mdebug") == 0)
187 ei->mdebugsect = sectp;
189 else if (strcmp (sectp->name, ".ctf") == 0)
191 ei->ctfsect = sectp;
195 static struct minimal_symbol *
196 record_minimal_symbol (minimal_symbol_reader &reader,
197 std::string_view name, bool copy_name,
198 unrelocated_addr address,
199 enum minimal_symbol_type ms_type,
200 asection *bfd_section, struct objfile *objfile)
202 struct gdbarch *gdbarch = objfile->arch ();
204 if (ms_type == mst_text || ms_type == mst_file_text
205 || ms_type == mst_text_gnu_ifunc)
206 address
207 = unrelocated_addr (gdbarch_addr_bits_remove (gdbarch,
208 CORE_ADDR (address)));
210 /* We only setup section information for allocatable sections. Usually
211 we'd only expect to find msymbols for allocatable sections, but if the
212 ELF is malformed then this might not be the case. In that case don't
213 create an msymbol that references an uninitialised section object. */
214 int section_index = 0;
215 if ((bfd_section_flags (bfd_section) & SEC_ALLOC) == SEC_ALLOC
216 || bfd_section == bfd_abs_section_ptr)
217 section_index = gdb_bfd_section_index (objfile->obfd.get (), bfd_section);
219 return reader.record_full (name, copy_name, address, ms_type, section_index);
222 /* Read the symbol table of an ELF file.
224 Given an objfile, a symbol table, and a flag indicating whether the
225 symbol table contains regular, dynamic, or synthetic symbols, add all
226 the global function and data symbols to the minimal symbol table.
228 In stabs-in-ELF, as implemented by Sun, there are some local symbols
229 defined in the ELF symbol table, which can be used to locate
230 the beginnings of sections from each ".o" file that was linked to
231 form the executable objfile. We gather any such info and record it
232 in data structures hung off the objfile's private data. */
234 #define ST_REGULAR 0
235 #define ST_DYNAMIC 1
236 #define ST_SYNTHETIC 2
238 static void
239 elf_symtab_read (minimal_symbol_reader &reader,
240 struct objfile *objfile, int type,
241 long number_of_symbols, asymbol **symbol_table,
242 bool copy_names)
244 struct gdbarch *gdbarch = objfile->arch ();
245 asymbol *sym;
246 long i;
247 CORE_ADDR symaddr;
248 enum minimal_symbol_type ms_type;
249 /* Name of the last file symbol. This is either a constant string or is
250 saved on the objfile's filename cache. */
251 const char *filesymname = "";
252 int stripped = (bfd_get_symcount (objfile->obfd.get ()) == 0);
253 int elf_make_msymbol_special_p
254 = gdbarch_elf_make_msymbol_special_p (gdbarch);
256 for (i = 0; i < number_of_symbols; i++)
258 sym = symbol_table[i];
259 if (sym->name == NULL || *sym->name == '\0')
261 /* Skip names that don't exist (shouldn't happen), or names
262 that are null strings (may happen). */
263 continue;
266 elf_symbol_type *elf_sym = (elf_symbol_type *) sym;
268 /* Skip "special" symbols, e.g. ARM mapping symbols. These are
269 symbols which do not correspond to objects in the symbol table,
270 but have some other target-specific meaning. */
271 if (bfd_is_target_special_symbol (objfile->obfd.get (), sym))
273 if (gdbarch_record_special_symbol_p (gdbarch))
274 gdbarch_record_special_symbol (gdbarch, objfile, sym);
275 continue;
278 if (type == ST_DYNAMIC
279 && sym->section == bfd_und_section_ptr
280 && (sym->flags & BSF_FUNCTION))
282 struct minimal_symbol *msym;
283 bfd *abfd = objfile->obfd.get ();
284 asection *sect;
286 /* Symbol is a reference to a function defined in
287 a shared library.
288 If its value is non zero then it is usually the address
289 of the corresponding entry in the procedure linkage table,
290 plus the desired section offset.
291 If its value is zero then the dynamic linker has to resolve
292 the symbol. We are unable to find any meaningful address
293 for this symbol in the executable file, so we skip it. */
294 symaddr = sym->value;
295 if (symaddr == 0)
296 continue;
298 /* sym->section is the undefined section. However, we want to
299 record the section where the PLT stub resides with the
300 minimal symbol. Search the section table for the one that
301 covers the stub's address. */
302 for (sect = abfd->sections; sect != NULL; sect = sect->next)
304 if ((bfd_section_flags (sect) & SEC_ALLOC) == 0)
305 continue;
307 if (symaddr >= bfd_section_vma (sect)
308 && symaddr < bfd_section_vma (sect)
309 + bfd_section_size (sect))
310 break;
312 if (!sect)
313 continue;
315 /* On ia64-hpux, we have discovered that the system linker
316 adds undefined symbols with nonzero addresses that cannot
317 be right (their address points inside the code of another
318 function in the .text section). This creates problems
319 when trying to determine which symbol corresponds to
320 a given address.
322 We try to detect those buggy symbols by checking which
323 section we think they correspond to. Normally, PLT symbols
324 are stored inside their own section, and the typical name
325 for that section is ".plt". So, if there is a ".plt"
326 section, and yet the section name of our symbol does not
327 start with ".plt", we ignore that symbol. */
328 if (!startswith (sect->name, ".plt")
329 && bfd_get_section_by_name (abfd, ".plt") != NULL)
330 continue;
332 msym = record_minimal_symbol
333 (reader, sym->name, copy_names,
334 unrelocated_addr (symaddr),
335 mst_solib_trampoline, sect, objfile);
336 if (msym != NULL)
338 msym->filename = filesymname;
339 if (elf_make_msymbol_special_p)
340 gdbarch_elf_make_msymbol_special (gdbarch, sym, msym);
342 continue;
345 /* If it is a nonstripped executable, do not enter dynamic
346 symbols, as the dynamic symbol table is usually a subset
347 of the main symbol table. */
348 if (type == ST_DYNAMIC && !stripped)
349 continue;
350 if (sym->flags & BSF_FILE)
351 filesymname = objfile->intern (sym->name);
352 else if (sym->flags & BSF_SECTION_SYM)
353 continue;
354 else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK
355 | BSF_GNU_UNIQUE))
357 struct minimal_symbol *msym;
359 /* Select global/local/weak symbols. Note that bfd puts abs
360 symbols in their own section, so all symbols we are
361 interested in will have a section. */
362 /* Bfd symbols are section relative. */
363 symaddr = sym->value + sym->section->vma;
364 /* For non-absolute symbols, use the type of the section
365 they are relative to, to intuit text/data. Bfd provides
366 no way of figuring this out for absolute symbols. */
367 if (sym->section == bfd_abs_section_ptr)
369 /* This is a hack to get the minimal symbol type
370 right for Irix 5, which has absolute addresses
371 with special section indices for dynamic symbols.
373 NOTE: uweigand-20071112: Synthetic symbols do not
374 have an ELF-private part, so do not touch those. */
375 unsigned int shndx = type == ST_SYNTHETIC ? 0 :
376 elf_sym->internal_elf_sym.st_shndx;
378 switch (shndx)
380 case SHN_MIPS_TEXT:
381 ms_type = mst_text;
382 break;
383 case SHN_MIPS_DATA:
384 ms_type = mst_data;
385 break;
386 case SHN_MIPS_ACOMMON:
387 ms_type = mst_bss;
388 break;
389 default:
390 ms_type = mst_abs;
393 /* If it is an Irix dynamic symbol, skip section name
394 symbols, relocate all others by section offset. */
395 if (ms_type != mst_abs)
397 if (sym->name[0] == '.')
398 continue;
401 else if (sym->section->flags & SEC_CODE)
403 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
405 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
406 ms_type = mst_text_gnu_ifunc;
407 else
408 ms_type = mst_text;
410 /* The BSF_SYNTHETIC check is there to omit ppc64 function
411 descriptors mistaken for static functions starting with 'L'.
413 else if ((sym->name[0] == '.' && sym->name[1] == 'L'
414 && (sym->flags & BSF_SYNTHETIC) == 0)
415 || ((sym->flags & BSF_LOCAL)
416 && sym->name[0] == '$'
417 && sym->name[1] == 'L'))
418 /* Looks like a compiler-generated label. Skip
419 it. The assembler should be skipping these (to
420 keep executables small), but apparently with
421 gcc on the (deleted) delta m88k SVR4, it loses.
422 So to have us check too should be harmless (but
423 I encourage people to fix this in the assembler
424 instead of adding checks here). */
425 continue;
426 else
428 ms_type = mst_file_text;
431 else if (sym->section->flags & SEC_ALLOC)
433 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
435 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
437 ms_type = mst_data_gnu_ifunc;
439 else if (sym->section->flags & SEC_LOAD)
441 ms_type = mst_data;
443 else
445 ms_type = mst_bss;
448 else if (sym->flags & BSF_LOCAL)
450 if (sym->section->flags & SEC_LOAD)
452 ms_type = mst_file_data;
454 else
456 ms_type = mst_file_bss;
459 else
461 ms_type = mst_unknown;
464 else
466 /* FIXME: Solaris2 shared libraries include lots of
467 odd "absolute" and "undefined" symbols, that play
468 hob with actions like finding what function the PC
469 is in. Ignore them if they aren't text, data, or bss. */
470 /* ms_type = mst_unknown; */
471 continue; /* Skip this symbol. */
473 msym = record_minimal_symbol
474 (reader, sym->name, copy_names, unrelocated_addr (symaddr),
475 ms_type, sym->section, objfile);
477 if (msym)
479 /* NOTE: uweigand-20071112: A synthetic symbol does not have an
480 ELF-private part. */
481 if (type != ST_SYNTHETIC)
483 /* Pass symbol size field in via BFD. FIXME!!! */
484 msym->set_size (elf_sym->internal_elf_sym.st_size);
487 msym->filename = filesymname;
488 if (elf_make_msymbol_special_p)
489 gdbarch_elf_make_msymbol_special (gdbarch, sym, msym);
492 /* If we see a default versioned symbol, install it under
493 its version-less name. */
494 if (msym != NULL)
496 const char *atsign = strchr (sym->name, '@');
497 bool is_at_symbol = atsign != nullptr && atsign > sym->name;
498 bool is_plt = is_at_symbol && strcmp (atsign, "@plt") == 0;
499 int len = is_at_symbol ? atsign - sym->name : 0;
501 if (is_at_symbol
502 && !is_plt
503 && (elf_sym->version & VERSYM_HIDDEN) == 0)
504 record_minimal_symbol (reader,
505 std::string_view (sym->name, len),
506 true, unrelocated_addr (symaddr),
507 ms_type, sym->section, objfile);
508 else if (is_plt)
510 /* For @plt symbols, also record a trampoline to the
511 destination symbol. The @plt symbol will be used
512 in disassembly, and the trampoline will be used
513 when we are trying to find the target. */
514 if (ms_type == mst_text && type == ST_SYNTHETIC)
516 struct minimal_symbol *mtramp;
518 mtramp = record_minimal_symbol
519 (reader, std::string_view (sym->name, len), true,
520 unrelocated_addr (symaddr),
521 mst_solib_trampoline, sym->section, objfile);
522 if (mtramp)
524 mtramp->set_size (msym->size());
525 mtramp->created_by_gdb = 1;
526 mtramp->filename = filesymname;
527 if (elf_make_msymbol_special_p)
528 gdbarch_elf_make_msymbol_special (gdbarch,
529 sym, mtramp);
538 /* Build minimal symbols named `function@got.plt' (see SYMBOL_GOT_PLT_SUFFIX)
539 for later look ups of which function to call when user requests
540 a STT_GNU_IFUNC function. As the STT_GNU_IFUNC type is found at the target
541 library defining `function' we cannot yet know while reading OBJFILE which
542 of the SYMBOL_GOT_PLT_SUFFIX entries will be needed and later
543 DYN_SYMBOL_TABLE is no longer easily available for OBJFILE. */
545 static void
546 elf_rel_plt_read (minimal_symbol_reader &reader,
547 struct objfile *objfile, asymbol **dyn_symbol_table)
549 bfd *obfd = objfile->obfd.get ();
550 const struct elf_backend_data *bed = get_elf_backend_data (obfd);
551 asection *relplt, *got_plt;
552 bfd_size_type reloc_count, reloc;
553 struct gdbarch *gdbarch = objfile->arch ();
554 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
555 size_t ptr_size = ptr_type->length ();
557 if (objfile->separate_debug_objfile_backlink)
558 return;
560 got_plt = bfd_get_section_by_name (obfd, ".got.plt");
561 if (got_plt == NULL)
563 /* For platforms where there is no separate .got.plt. */
564 got_plt = bfd_get_section_by_name (obfd, ".got");
565 if (got_plt == NULL)
566 return;
569 /* Depending on system, we may find jump slots in a relocation
570 section for either .got.plt or .plt. */
571 asection *plt = bfd_get_section_by_name (obfd, ".plt");
572 int plt_elf_idx = (plt != NULL) ? elf_section_data (plt)->this_idx : -1;
574 int got_plt_elf_idx = elf_section_data (got_plt)->this_idx;
576 /* This search algorithm is from _bfd_elf_canonicalize_dynamic_reloc. */
577 for (relplt = obfd->sections; relplt != NULL; relplt = relplt->next)
579 const auto &this_hdr = elf_section_data (relplt)->this_hdr;
581 if (this_hdr.sh_type == SHT_REL || this_hdr.sh_type == SHT_RELA)
583 if (this_hdr.sh_info == plt_elf_idx
584 || this_hdr.sh_info == got_plt_elf_idx)
585 break;
588 if (relplt == NULL)
589 return;
591 if (! bed->s->slurp_reloc_table (obfd, relplt, dyn_symbol_table, TRUE))
592 return;
594 std::string string_buffer;
596 /* Does ADDRESS reside in SECTION of OBFD? */
597 auto within_section = [obfd] (asection *section, CORE_ADDR address)
599 if (section == NULL)
600 return false;
602 return (bfd_section_vma (section) <= address
603 && (address < bfd_section_vma (section)
604 + bfd_section_size (section)));
607 reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
608 for (reloc = 0; reloc < reloc_count; reloc++)
610 const char *name;
611 struct minimal_symbol *msym;
612 CORE_ADDR address;
613 const char *got_suffix = SYMBOL_GOT_PLT_SUFFIX;
614 const size_t got_suffix_len = strlen (SYMBOL_GOT_PLT_SUFFIX);
616 name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
617 address = relplt->relocation[reloc].address;
619 asection *msym_section;
621 /* Does the pointer reside in either the .got.plt or .plt
622 sections? */
623 if (within_section (got_plt, address))
624 msym_section = got_plt;
625 else if (within_section (plt, address))
626 msym_section = plt;
627 else
628 continue;
630 /* We cannot check if NAME is a reference to
631 mst_text_gnu_ifunc/mst_data_gnu_ifunc as in OBJFILE the
632 symbol is undefined and the objfile having NAME defined may
633 not yet have been loaded. */
635 string_buffer.assign (name);
636 string_buffer.append (got_suffix, got_suffix + got_suffix_len);
638 msym = record_minimal_symbol (reader, string_buffer,
639 true, unrelocated_addr (address),
640 mst_slot_got_plt, msym_section, objfile);
641 if (msym)
642 msym->set_size (ptr_size);
646 /* The data pointer is htab_t for gnu_ifunc_record_cache_unchecked. */
648 static const registry<objfile>::key<htab, htab_deleter>
649 elf_objfile_gnu_ifunc_cache_data;
651 /* Map function names to CORE_ADDR in elf_objfile_gnu_ifunc_cache_data. */
653 struct elf_gnu_ifunc_cache
655 /* This is always a function entry address, not a function descriptor. */
656 CORE_ADDR addr;
658 char name[1];
661 /* htab_hash for elf_objfile_gnu_ifunc_cache_data. */
663 static hashval_t
664 elf_gnu_ifunc_cache_hash (const void *a_voidp)
666 const struct elf_gnu_ifunc_cache *a
667 = (const struct elf_gnu_ifunc_cache *) a_voidp;
669 return htab_hash_string (a->name);
672 /* htab_eq for elf_objfile_gnu_ifunc_cache_data. */
674 static int
675 elf_gnu_ifunc_cache_eq (const void *a_voidp, const void *b_voidp)
677 const struct elf_gnu_ifunc_cache *a
678 = (const struct elf_gnu_ifunc_cache *) a_voidp;
679 const struct elf_gnu_ifunc_cache *b
680 = (const struct elf_gnu_ifunc_cache *) b_voidp;
682 return strcmp (a->name, b->name) == 0;
685 /* Record the target function address of a STT_GNU_IFUNC function NAME is the
686 function entry address ADDR. Return 1 if NAME and ADDR are considered as
687 valid and therefore they were successfully recorded, return 0 otherwise.
689 Function does not expect a duplicate entry. Use
690 elf_gnu_ifunc_resolve_by_cache first to check if the entry for NAME already
691 exists. */
693 static int
694 elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
696 struct bound_minimal_symbol msym;
697 struct objfile *objfile;
698 htab_t htab;
699 struct elf_gnu_ifunc_cache entry_local, *entry_p;
700 void **slot;
702 msym = lookup_minimal_symbol_by_pc (addr);
703 if (msym.minsym == NULL)
704 return 0;
705 if (msym.value_address () != addr)
706 return 0;
707 objfile = msym.objfile;
709 /* If .plt jumps back to .plt the symbol is still deferred for later
710 resolution and it has no use for GDB. */
711 const char *target_name = msym.minsym->linkage_name ();
712 size_t len = strlen (target_name);
714 /* Note we check the symbol's name instead of checking whether the
715 symbol is in the .plt section because some systems have @plt
716 symbols in the .text section. */
717 if (len > 4 && strcmp (target_name + len - 4, "@plt") == 0)
718 return 0;
720 if (strcmp (target_name, "_PROCEDURE_LINKAGE_TABLE_") == 0)
721 return 0;
723 htab = elf_objfile_gnu_ifunc_cache_data.get (objfile);
724 if (htab == NULL)
726 htab = htab_create_alloc (1, elf_gnu_ifunc_cache_hash,
727 elf_gnu_ifunc_cache_eq,
728 NULL, xcalloc, xfree);
729 elf_objfile_gnu_ifunc_cache_data.set (objfile, htab);
732 entry_local.addr = addr;
733 obstack_grow (&objfile->objfile_obstack, &entry_local,
734 offsetof (struct elf_gnu_ifunc_cache, name));
735 obstack_grow_str0 (&objfile->objfile_obstack, name);
736 entry_p
737 = (struct elf_gnu_ifunc_cache *) obstack_finish (&objfile->objfile_obstack);
739 slot = htab_find_slot (htab, entry_p, INSERT);
740 if (*slot != NULL)
742 struct elf_gnu_ifunc_cache *entry_found_p
743 = (struct elf_gnu_ifunc_cache *) *slot;
744 struct gdbarch *gdbarch = objfile->arch ();
746 if (entry_found_p->addr != addr)
748 /* This case indicates buggy inferior program, the resolved address
749 should never change. */
751 warning (_("gnu-indirect-function \"%s\" has changed its resolved "
752 "function_address from %s to %s"),
753 name, paddress (gdbarch, entry_found_p->addr),
754 paddress (gdbarch, addr));
757 /* New ENTRY_P is here leaked/duplicate in the OBJFILE obstack. */
759 *slot = entry_p;
761 return 1;
764 /* Try to find the target resolved function entry address of a STT_GNU_IFUNC
765 function NAME. If the address is found it is stored to *ADDR_P (if ADDR_P
766 is not NULL) and the function returns 1. It returns 0 otherwise.
768 Only the elf_objfile_gnu_ifunc_cache_data hash table is searched by this
769 function. */
771 static int
772 elf_gnu_ifunc_resolve_by_cache (const char *name, CORE_ADDR *addr_p)
774 int found = 0;
776 /* FIXME: we only search the initial namespace.
778 To search other namespaces, we would need to provide context, e.g. in
779 form of an objfile in that namespace. */
780 gdbarch_iterate_over_objfiles_in_search_order
781 (current_inferior ()->arch (),
782 [name, &addr_p, &found] (struct objfile *objfile)
784 htab_t htab;
785 elf_gnu_ifunc_cache *entry_p;
786 void **slot;
788 htab = elf_objfile_gnu_ifunc_cache_data.get (objfile);
789 if (htab == NULL)
790 return 0;
792 entry_p = ((elf_gnu_ifunc_cache *)
793 alloca (sizeof (*entry_p) + strlen (name)));
794 strcpy (entry_p->name, name);
796 slot = htab_find_slot (htab, entry_p, NO_INSERT);
797 if (slot == NULL)
798 return 0;
799 entry_p = (elf_gnu_ifunc_cache *) *slot;
800 gdb_assert (entry_p != NULL);
802 if (addr_p)
803 *addr_p = entry_p->addr;
805 found = 1;
806 return 1;
807 }, nullptr);
809 return found;
812 /* Try to find the target resolved function entry address of a STT_GNU_IFUNC
813 function NAME. If the address is found it is stored to *ADDR_P (if ADDR_P
814 is not NULL) and the function returns 1. It returns 0 otherwise.
816 Only the SYMBOL_GOT_PLT_SUFFIX locations are searched by this function.
817 elf_gnu_ifunc_resolve_by_cache must have been already called for NAME to
818 prevent cache entries duplicates. */
820 static int
821 elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
823 char *name_got_plt;
824 const size_t got_suffix_len = strlen (SYMBOL_GOT_PLT_SUFFIX);
825 int found = 0;
827 name_got_plt = (char *) alloca (strlen (name) + got_suffix_len + 1);
828 sprintf (name_got_plt, "%s" SYMBOL_GOT_PLT_SUFFIX, name);
830 /* FIXME: we only search the initial namespace.
832 To search other namespaces, we would need to provide context, e.g. in
833 form of an objfile in that namespace. */
834 gdbarch_iterate_over_objfiles_in_search_order
835 (current_inferior ()->arch (),
836 [name, name_got_plt, &addr_p, &found] (struct objfile *objfile)
838 bfd *obfd = objfile->obfd.get ();
839 struct gdbarch *gdbarch = objfile->arch ();
840 type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
841 size_t ptr_size = ptr_type->length ();
842 CORE_ADDR pointer_address, addr;
843 asection *plt;
844 gdb_byte *buf = (gdb_byte *) alloca (ptr_size);
845 bound_minimal_symbol msym;
847 msym = lookup_minimal_symbol (name_got_plt, NULL, objfile);
848 if (msym.minsym == NULL)
849 return 0;
850 if (msym.minsym->type () != mst_slot_got_plt)
851 return 0;
852 pointer_address = msym.value_address ();
854 plt = bfd_get_section_by_name (obfd, ".plt");
855 if (plt == NULL)
856 return 0;
858 if (msym.minsym->size () != ptr_size)
859 return 0;
860 if (target_read_memory (pointer_address, buf, ptr_size) != 0)
861 return 0;
862 addr = extract_typed_address (buf, ptr_type);
863 addr = gdbarch_convert_from_func_ptr_addr
864 (gdbarch, addr, current_inferior ()->top_target ());
865 addr = gdbarch_addr_bits_remove (gdbarch, addr);
867 if (elf_gnu_ifunc_record_cache (name, addr))
869 if (addr_p != NULL)
870 *addr_p = addr;
872 found = 1;
873 return 1;
876 return 0;
877 }, nullptr);
879 return found;
882 /* Try to find the target resolved function entry address of a STT_GNU_IFUNC
883 function NAME. If the address is found it is stored to *ADDR_P (if ADDR_P
884 is not NULL) and the function returns true. It returns false otherwise.
886 Both the elf_objfile_gnu_ifunc_cache_data hash table and
887 SYMBOL_GOT_PLT_SUFFIX locations are searched by this function. */
889 static bool
890 elf_gnu_ifunc_resolve_name (const char *name, CORE_ADDR *addr_p)
892 if (elf_gnu_ifunc_resolve_by_cache (name, addr_p))
893 return true;
895 if (elf_gnu_ifunc_resolve_by_got (name, addr_p))
896 return true;
898 return false;
901 /* Call STT_GNU_IFUNC - a function returning addresss of a real function to
902 call. PC is theSTT_GNU_IFUNC resolving function entry. The value returned
903 is the entry point of the resolved STT_GNU_IFUNC target function to call.
906 static CORE_ADDR
907 elf_gnu_ifunc_resolve_addr (struct gdbarch *gdbarch, CORE_ADDR pc)
909 const char *name_at_pc;
910 CORE_ADDR start_at_pc, address;
911 struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
912 struct value *function, *address_val;
913 CORE_ADDR hwcap = 0;
914 struct value *hwcap_val;
916 /* Try first any non-intrusive methods without an inferior call. */
918 if (find_pc_partial_function (pc, &name_at_pc, &start_at_pc, NULL)
919 && start_at_pc == pc)
921 if (elf_gnu_ifunc_resolve_name (name_at_pc, &address))
922 return address;
924 else
925 name_at_pc = NULL;
927 function = value::allocate (func_func_type);
928 function->set_lval (lval_memory);
929 function->set_address (pc);
931 /* STT_GNU_IFUNC resolver functions usually receive the HWCAP vector as
932 parameter. FUNCTION is the function entry address. ADDRESS may be a
933 function descriptor. */
935 target_auxv_search (AT_HWCAP, &hwcap);
936 hwcap_val = value_from_longest (builtin_type (gdbarch)
937 ->builtin_unsigned_long, hwcap);
938 address_val = call_function_by_hand (function, NULL, hwcap_val);
939 address = value_as_address (address_val);
940 address = gdbarch_convert_from_func_ptr_addr
941 (gdbarch, address, current_inferior ()->top_target ());
942 address = gdbarch_addr_bits_remove (gdbarch, address);
944 if (name_at_pc)
945 elf_gnu_ifunc_record_cache (name_at_pc, address);
947 return address;
950 /* Handle inferior hit of bp_gnu_ifunc_resolver, see its definition. */
952 static void
953 elf_gnu_ifunc_resolver_stop (code_breakpoint *b)
955 struct breakpoint *b_return;
956 frame_info_ptr prev_frame = get_prev_frame (get_current_frame ());
957 struct frame_id prev_frame_id = get_stack_frame_id (prev_frame);
958 CORE_ADDR prev_pc = get_frame_pc (prev_frame);
959 int thread_id = inferior_thread ()->global_num;
961 gdb_assert (b->type == bp_gnu_ifunc_resolver);
963 for (b_return = b->related_breakpoint; b_return != b;
964 b_return = b_return->related_breakpoint)
966 gdb_assert (b_return->type == bp_gnu_ifunc_resolver_return);
967 gdb_assert (b_return->has_single_location ());
968 gdb_assert (frame_id_p (b_return->frame_id));
970 if (b_return->thread == thread_id
971 && b_return->first_loc ().requested_address == prev_pc
972 && b_return->frame_id == prev_frame_id)
973 break;
976 if (b_return == b)
978 /* No need to call find_pc_line for symbols resolving as this is only
979 a helper breakpointer never shown to the user. */
981 symtab_and_line sal;
982 sal.pspace = current_inferior ()->pspace;
983 sal.pc = prev_pc;
984 sal.section = find_pc_overlay (sal.pc);
985 sal.explicit_pc = 1;
986 b_return
987 = set_momentary_breakpoint (get_frame_arch (prev_frame), sal,
988 prev_frame_id,
989 bp_gnu_ifunc_resolver_return).release ();
992 /* Add new b_return to the ring list b->related_breakpoint. */
993 gdb_assert (b_return->related_breakpoint == b_return);
994 b_return->related_breakpoint = b->related_breakpoint;
995 b->related_breakpoint = b_return;
999 /* Handle inferior hit of bp_gnu_ifunc_resolver_return, see its definition. */
1001 static void
1002 elf_gnu_ifunc_resolver_return_stop (code_breakpoint *b)
1004 thread_info *thread = inferior_thread ();
1005 struct gdbarch *gdbarch = get_frame_arch (get_current_frame ());
1006 struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
1007 struct type *value_type = func_func_type->target_type ();
1008 struct regcache *regcache = get_thread_regcache (thread);
1009 struct value *func_func;
1010 struct value *value;
1011 CORE_ADDR resolved_address, resolved_pc;
1013 gdb_assert (b->type == bp_gnu_ifunc_resolver_return);
1015 while (b->related_breakpoint != b)
1017 struct breakpoint *b_next = b->related_breakpoint;
1019 switch (b->type)
1021 case bp_gnu_ifunc_resolver:
1022 break;
1023 case bp_gnu_ifunc_resolver_return:
1024 delete_breakpoint (b);
1025 break;
1026 default:
1027 internal_error (_("handle_inferior_event: Invalid "
1028 "gnu-indirect-function breakpoint type %d"),
1029 (int) b->type);
1031 b = gdb::checked_static_cast<code_breakpoint *> (b_next);
1033 gdb_assert (b->type == bp_gnu_ifunc_resolver);
1034 gdb_assert (b->has_single_location ());
1036 func_func = value::allocate (func_func_type);
1037 func_func->set_lval (lval_memory);
1038 func_func->set_address (b->first_loc ().related_address);
1040 value = value::allocate (value_type);
1041 gdbarch_return_value_as_value (gdbarch, func_func, value_type, regcache,
1042 &value, NULL);
1043 resolved_address = value_as_address (value);
1044 resolved_pc = gdbarch_convert_from_func_ptr_addr
1045 (gdbarch, resolved_address, current_inferior ()->top_target ());
1046 resolved_pc = gdbarch_addr_bits_remove (gdbarch, resolved_pc);
1048 gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
1049 elf_gnu_ifunc_record_cache (b->locspec->to_string (), resolved_pc);
1051 b->type = bp_breakpoint;
1052 update_breakpoint_locations (b, current_program_space,
1053 find_function_start_sal (resolved_pc, NULL, true),
1054 {});
1057 /* A helper function for elf_symfile_read that reads the minimal
1058 symbols. */
1060 static void
1061 elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
1062 const struct elfinfo *ei)
1064 bfd *synth_abfd, *abfd = objfile->obfd.get ();
1065 long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
1066 asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
1067 asymbol *synthsyms;
1069 symtab_create_debug_printf ("reading minimal symbols of objfile %s",
1070 objfile_name (objfile));
1072 /* If we already have minsyms, then we can skip some work here.
1073 However, if there were stabs or mdebug sections, we go ahead and
1074 redo all the work anyway, because the psym readers for those
1075 kinds of debuginfo need extra information found here. This can
1076 go away once all types of symbols are in the per-BFD object. */
1077 if (objfile->per_bfd->minsyms_read
1078 && ei->stabsect == NULL
1079 && ei->mdebugsect == NULL
1080 && ei->ctfsect == NULL)
1082 symtab_create_debug_printf ("minimal symbols were previously read");
1083 return;
1086 minimal_symbol_reader reader (objfile);
1088 /* Process the normal ELF symbol table first. */
1090 storage_needed = bfd_get_symtab_upper_bound (objfile->obfd.get ());
1091 if (storage_needed < 0)
1092 error (_("Can't read symbols from %s: %s"),
1093 bfd_get_filename (objfile->obfd.get ()),
1094 bfd_errmsg (bfd_get_error ()));
1096 if (storage_needed > 0)
1098 /* Memory gets permanently referenced from ABFD after
1099 bfd_canonicalize_symtab so it must not get freed before ABFD gets. */
1101 symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1102 symcount = bfd_canonicalize_symtab (objfile->obfd.get (), symbol_table);
1104 if (symcount < 0)
1105 error (_("Can't read symbols from %s: %s"),
1106 bfd_get_filename (objfile->obfd.get ()),
1107 bfd_errmsg (bfd_get_error ()));
1109 elf_symtab_read (reader, objfile, ST_REGULAR, symcount, symbol_table,
1110 false);
1113 /* Add the dynamic symbols. */
1115 storage_needed = bfd_get_dynamic_symtab_upper_bound (objfile->obfd.get ());
1117 if (storage_needed > 0)
1119 /* Memory gets permanently referenced from ABFD after
1120 bfd_get_synthetic_symtab so it must not get freed before ABFD gets.
1121 It happens only in the case when elf_slurp_reloc_table sees
1122 asection->relocation NULL. Determining which section is asection is
1123 done by _bfd_elf_get_synthetic_symtab which is all a bfd
1124 implementation detail, though. */
1126 dyn_symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1127 dynsymcount = bfd_canonicalize_dynamic_symtab (objfile->obfd.get (),
1128 dyn_symbol_table);
1130 if (dynsymcount < 0)
1131 error (_("Can't read symbols from %s: %s"),
1132 bfd_get_filename (objfile->obfd.get ()),
1133 bfd_errmsg (bfd_get_error ()));
1135 elf_symtab_read (reader, objfile, ST_DYNAMIC, dynsymcount,
1136 dyn_symbol_table, false);
1138 elf_rel_plt_read (reader, objfile, dyn_symbol_table);
1141 /* Contrary to binutils --strip-debug/--only-keep-debug the strip command from
1142 elfutils (eu-strip) moves even the .symtab section into the .debug file.
1144 bfd_get_synthetic_symtab on ppc64 for each function descriptor ELF symbol
1145 'name' creates a new BSF_SYNTHETIC ELF symbol '.name' with its code
1146 address. But with eu-strip files bfd_get_synthetic_symtab would fail to
1147 read the code address from .opd while it reads the .symtab section from
1148 a separate debug info file as the .opd section is SHT_NOBITS there.
1150 With SYNTH_ABFD the .opd section will be read from the original
1151 backlinked binary where it is valid. */
1153 if (objfile->separate_debug_objfile_backlink)
1154 synth_abfd = objfile->separate_debug_objfile_backlink->obfd.get ();
1155 else
1156 synth_abfd = abfd;
1158 /* Add synthetic symbols - for instance, names for any PLT entries. */
1160 synthcount = bfd_get_synthetic_symtab (synth_abfd, symcount, symbol_table,
1161 dynsymcount, dyn_symbol_table,
1162 &synthsyms);
1163 if (synthcount > 0)
1165 long i;
1167 std::unique_ptr<asymbol *[]>
1168 synth_symbol_table (new asymbol *[synthcount]);
1169 for (i = 0; i < synthcount; i++)
1170 synth_symbol_table[i] = synthsyms + i;
1171 elf_symtab_read (reader, objfile, ST_SYNTHETIC, synthcount,
1172 synth_symbol_table.get (), true);
1174 xfree (synthsyms);
1175 synthsyms = NULL;
1178 /* Install any minimal symbols that have been collected as the current
1179 minimal symbols for this objfile. The debug readers below this point
1180 should not generate new minimal symbols; if they do it's their
1181 responsibility to install them. "mdebug" appears to be the only one
1182 which will do this. */
1184 reader.install ();
1186 symtab_create_debug_printf ("done reading minimal symbols");
1189 /* Dwarf-specific helper for elf_symfile_read. Return true if we managed to
1190 load dwarf debug info. */
1192 static bool
1193 elf_symfile_read_dwarf2 (struct objfile *objfile,
1194 symfile_add_flags symfile_flags)
1196 bool has_dwarf2 = true;
1198 if (dwarf2_initialize_objfile (objfile, nullptr, true))
1200 /* Nothing. */
1202 /* If the file has its own symbol tables it has no separate debug
1203 info. `.dynsym'/`.symtab' go to MSYMBOLS, `.debug_info' goes to
1204 SYMTABS/PSYMTABS. `.gnu_debuglink' may no longer be present with
1205 `.note.gnu.build-id'.
1207 .gnu_debugdata is !objfile::has_partial_symbols because it contains only
1208 .symtab, not .debug_* section. But if we already added .gnu_debugdata as
1209 an objfile via find_separate_debug_file_in_section there was no separate
1210 debug info available. Therefore do not attempt to search for another one,
1211 objfile->separate_debug_objfile->separate_debug_objfile GDB guarantees to
1212 be NULL and we would possibly violate it. */
1214 else if (!objfile->has_partial_symbols ()
1215 && objfile->separate_debug_objfile == NULL
1216 && objfile->separate_debug_objfile_backlink == NULL)
1218 if (objfile->find_and_add_separate_symbol_file (symfile_flags))
1219 gdb_assert (objfile->separate_debug_objfile != nullptr);
1220 else
1221 has_dwarf2 = false;
1224 return has_dwarf2;
1227 /* Scan and build partial symbols for a symbol file.
1228 We have been initialized by a call to elf_symfile_init, which
1229 currently does nothing.
1231 This function only does the minimum work necessary for letting the
1232 user "name" things symbolically; it does not read the entire symtab.
1233 Instead, it reads the external and static symbols and puts them in partial
1234 symbol tables. When more extensive information is requested of a
1235 file, the corresponding partial symbol table is mutated into a full
1236 fledged symbol table by going back and reading the symbols
1237 for real.
1239 We look for sections with specific names, to tell us what debug
1240 format to look for: FIXME!!!
1242 elfstab_build_psymtabs() handles STABS symbols;
1243 mdebug_build_psymtabs() handles ECOFF debugging information.
1245 Note that ELF files have a "minimal" symbol table, which looks a lot
1246 like a COFF symbol table, but has only the minimal information necessary
1247 for linking. We process this also, and use the information to
1248 build gdb's minimal symbol table. This gives us some minimal debugging
1249 capability even for files compiled without -g. */
1251 static void
1252 elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
1254 bfd *abfd = objfile->obfd.get ();
1255 struct elfinfo ei;
1257 memset ((char *) &ei, 0, sizeof (ei));
1258 if (!(objfile->flags & OBJF_READNEVER))
1260 for (asection *sect : gdb_bfd_sections (abfd))
1261 elf_locate_sections (sect, &ei);
1264 elf_read_minimal_symbols (objfile, symfile_flags, &ei);
1266 /* ELF debugging information is inserted into the psymtab in the
1267 order of least informative first - most informative last. Since
1268 the psymtab table is searched `most recent insertion first' this
1269 increases the probability that more detailed debug information
1270 for a section is found.
1272 For instance, an object file might contain both .mdebug (XCOFF)
1273 and .debug_info (DWARF2) sections then .mdebug is inserted first
1274 (searched last) and DWARF2 is inserted last (searched first). If
1275 we don't do this then the XCOFF info is found first - for code in
1276 an included file XCOFF info is useless. */
1278 if (ei.mdebugsect)
1280 const struct ecoff_debug_swap *swap;
1282 /* .mdebug section, presumably holding ECOFF debugging
1283 information. */
1284 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1285 if (swap)
1286 elfmdebug_build_psymtabs (objfile, swap, ei.mdebugsect);
1288 if (ei.stabsect)
1290 asection *str_sect;
1292 /* Stab sections have an associated string table that looks like
1293 a separate section. */
1294 str_sect = bfd_get_section_by_name (abfd, ".stabstr");
1296 /* FIXME should probably warn about a stab section without a stabstr. */
1297 if (str_sect)
1298 elfstab_build_psymtabs (objfile,
1299 ei.stabsect,
1300 str_sect->filepos,
1301 bfd_section_size (str_sect));
1304 /* Read the CTF section only if there is no DWARF info. */
1305 if (always_read_ctf && ei.ctfsect)
1307 elfctf_build_psymtabs (objfile);
1310 bool has_dwarf2 = elf_symfile_read_dwarf2 (objfile, symfile_flags);
1312 /* Read the CTF section only if there is no DWARF info. */
1313 if (!always_read_ctf && !has_dwarf2 && ei.ctfsect)
1315 elfctf_build_psymtabs (objfile);
1318 /* Copy relocations are used by some ABIs using the ELF format, so
1319 set the objfile flag indicating this fact. */
1320 objfile->object_format_has_copy_relocs = true;
1323 /* Initialize anything that needs initializing when a completely new symbol
1324 file is specified (not just adding some symbols from another file, e.g. a
1325 shared library). */
1327 static void
1328 elf_new_init (struct objfile *ignore)
1332 /* Perform any local cleanups required when we are done with a particular
1333 objfile. I.E, we are in the process of discarding all symbol information
1334 for an objfile, freeing up all memory held for it, and unlinking the
1335 objfile struct from the global list of known objfiles. */
1337 static void
1338 elf_symfile_finish (struct objfile *objfile)
1342 /* ELF specific initialization routine for reading symbols. */
1344 static void
1345 elf_symfile_init (struct objfile *objfile)
1349 /* Implementation of `sym_get_probes', as documented in symfile.h. */
1351 static const elfread_data &
1352 elf_get_probes (struct objfile *objfile)
1354 elfread_data *probes_per_bfd = probe_key.get (objfile->obfd.get ());
1356 if (probes_per_bfd == NULL)
1358 probes_per_bfd = probe_key.emplace (objfile->obfd.get ());
1360 /* Here we try to gather information about all types of probes from the
1361 objfile. */
1362 for (const static_probe_ops *ops : all_static_probe_ops)
1363 ops->get_probes (probes_per_bfd, objfile);
1366 return *probes_per_bfd;
1371 /* Implementation `sym_probe_fns', as documented in symfile.h. */
1373 static const struct sym_probe_fns elf_probe_fns =
1375 elf_get_probes, /* sym_get_probes */
1378 /* Register that we are able to handle ELF object file formats. */
1380 static const struct sym_fns elf_sym_fns =
1382 elf_new_init, /* init anything gbl to entire symtab */
1383 elf_symfile_init, /* read initial info, setup for sym_read() */
1384 elf_symfile_read, /* read a symbol file into symtab */
1385 elf_symfile_finish, /* finished with file, cleanup */
1386 default_symfile_offsets, /* Translate ext. to int. relocation */
1387 elf_symfile_segments, /* Get segment information from a file. */
1388 NULL,
1389 default_symfile_relocate, /* Relocate a debug section. */
1390 &elf_probe_fns, /* sym_probe_fns */
1393 /* STT_GNU_IFUNC resolver vector to be installed to gnu_ifunc_fns_p. */
1395 static const struct gnu_ifunc_fns elf_gnu_ifunc_fns =
1397 elf_gnu_ifunc_resolve_addr,
1398 elf_gnu_ifunc_resolve_name,
1399 elf_gnu_ifunc_resolver_stop,
1400 elf_gnu_ifunc_resolver_return_stop
1403 void _initialize_elfread ();
1404 void
1405 _initialize_elfread ()
1407 add_symtab_fns (bfd_target_elf_flavour, &elf_sym_fns);
1409 gnu_ifunc_fns_p = &elf_gnu_ifunc_fns;
1411 /* Add "set always-read-ctf on/off". */
1412 add_setshow_boolean_cmd ("always-read-ctf", class_support, &always_read_ctf,
1413 _("\
1414 Set whether CTF is always read."),
1415 _("\
1416 Show whether CTF is always read."),
1417 _("\
1418 When off, CTF is only read if DWARF is not present. When on, CTF is read\
1419 regardless of whether DWARF is present."),
1420 nullptr /* set_func */, nullptr /* show_func */,
1421 &setlist, &showlist);