25#include "elf/common.h"
26#include "elf/internal.h"
49#include "gdbsupport/gdb_string_view.h"
50#include "gdbsupport/scoped_fd.h"
82#define SYMBOL_GOT_PLT_SUFFIX "@got.plt"
89 Elf_Internal_Phdr *phdrs, **segments;
91 int num_phdrs, num_segments, num_sections, i;
94 phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
98 phdrs = (Elf_Internal_Phdr *) alloca (phdrs_size);
99 num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
104 segments = XALLOCAVEC (Elf_Internal_Phdr *, num_phdrs);
105 for (i = 0; i < num_phdrs; i++)
106 if (phdrs[i].p_type == PT_LOAD)
107 segments[num_segments++] = &phdrs[i];
109 if (num_segments == 0)
113 data->segments.reserve (num_segments);
115 for (i = 0; i < num_segments; i++)
116 data->segments.emplace_back (segments[i]->p_vaddr, segments[i]->p_memsz);
118 num_sections = bfd_count_sections (abfd);
121 data->segment_info.resize (num_sections);
123 for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
127 if ((bfd_section_flags (sect) & SEC_ALLOC) == 0)
130 Elf_Internal_Shdr *this_hdr = &elf_section_data (sect)->this_hdr;
132 for (j = 0; j < num_segments; j++)
133 if (ELF_SECTION_IN_SEGMENT (this_hdr, segments[j]))
135 data->segment_info[i] = j + 1;
152 if (!is_debuginfo_file (abfd)
153 && bfd_section_size (sect) > 0 && j == num_segments
154 && (bfd_section_flags (sect) & SEC_LOAD) != 0)
155 warning (_(
"Loadable section \"%s\" outside of ELF segments\n in %s"),
156 bfd_section_name (sect), bfd_get_filename (abfd));
184 if (strcmp (sectp->name,
".stab") == 0)
188 else if (strcmp (sectp->name,
".mdebug") == 0)
192 else if (strcmp (sectp->name,
".ctf") == 0)
211 CORE_ADDR (address)));
217 int section_index = 0;
218 if ((bfd_section_flags (bfd_section) & SEC_ALLOC) == SEC_ALLOC
219 || bfd_section == bfd_abs_section_ptr)
239#define ST_SYNTHETIC 2
244 long number_of_symbols, asymbol **symbol_table,
254 const char *filesymname =
"";
255 int stripped = (bfd_get_symcount (
objfile->
obfd.get ()) == 0);
256 int elf_make_msymbol_special_p
259 for (i = 0; i < number_of_symbols; i++)
261 sym = symbol_table[i];
262 if (sym->name == NULL || *sym->name ==
'\0')
269 elf_symbol_type *elf_sym = (elf_symbol_type *) sym;
274 if (bfd_is_target_special_symbol (
objfile->
obfd.get (), sym))
282 && sym->section == bfd_und_section_ptr
283 && (sym->flags & BSF_FUNCTION))
297 symaddr = sym->value;
305 for (sect = abfd->sections; sect != NULL; sect = sect->next)
307 if ((bfd_section_flags (sect) & SEC_ALLOC) == 0)
310 if (symaddr >= bfd_section_vma (sect)
311 && symaddr < bfd_section_vma (sect)
312 + bfd_section_size (sect))
331 if (!startswith (sect->name,
".plt")
332 && bfd_get_section_by_name (abfd,
".plt") != NULL)
336 (reader, sym->name, copy_names,
337 unrelocated_addr (symaddr),
342 if (elf_make_msymbol_special_p)
353 if (sym->flags & BSF_FILE)
355 else if (sym->flags & BSF_SECTION_SYM)
357 else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK
366 symaddr = sym->value + sym->section->vma;
370 if (sym->section == bfd_abs_section_ptr)
379 elf_sym->internal_elf_sym.st_shndx;
389 case SHN_MIPS_ACOMMON:
400 if (sym->name[0] ==
'.')
404 else if (sym->section->flags & SEC_CODE)
406 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
408 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
416 else if ((sym->name[0] ==
'.' && sym->name[1] ==
'L'
417 && (sym->flags & BSF_SYNTHETIC) == 0)
418 || ((sym->flags & BSF_LOCAL)
419 && sym->name[0] ==
'$'
420 && sym->name[1] ==
'L'))
434 else if (sym->section->flags & SEC_ALLOC)
436 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
438 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
442 else if (sym->section->flags & SEC_LOAD)
451 else if (sym->flags & BSF_LOCAL)
453 if (sym->section->flags & SEC_LOAD)
477 (reader, sym->name, copy_names, unrelocated_addr (symaddr),
478 ms_type, sym->section,
objfile);
487 msym->
set_size (elf_sym->internal_elf_sym.st_size);
491 if (elf_make_msymbol_special_p)
499 const char *atsign = strchr (sym->name,
'@');
500 bool is_at_symbol = atsign !=
nullptr && atsign > sym->name;
501 bool is_plt = is_at_symbol && strcmp (atsign,
"@plt") == 0;
502 int len = is_at_symbol ? atsign - sym->name : 0;
506 && (elf_sym->version & VERSYM_HIDDEN) == 0)
508 gdb::string_view (sym->name, len),
509 true, unrelocated_addr (symaddr),
510 ms_type, sym->section,
objfile);
522 (reader, gdb::string_view (sym->name, len),
true,
523 unrelocated_addr (symaddr),
530 if (elf_make_msymbol_special_p)
553 const struct elf_backend_data *bed = get_elf_backend_data (
obfd);
554 asection *relplt, *got_plt;
555 bfd_size_type reloc_count, reloc;
558 size_t ptr_size = ptr_type->
length ();
563 got_plt = bfd_get_section_by_name (
obfd,
".got.plt");
567 got_plt = bfd_get_section_by_name (
obfd,
".got");
574 asection *plt = bfd_get_section_by_name (
obfd,
".plt");
575 int plt_elf_idx = (plt != NULL) ? elf_section_data (plt)->this_idx : -1;
577 int got_plt_elf_idx = elf_section_data (got_plt)->this_idx;
580 for (relplt =
obfd->sections; relplt != NULL; relplt = relplt->next)
582 const auto &this_hdr = elf_section_data (relplt)->this_hdr;
584 if (this_hdr.sh_type == SHT_REL || this_hdr.sh_type == SHT_RELA)
586 if (this_hdr.sh_info == plt_elf_idx
587 || this_hdr.sh_info == got_plt_elf_idx)
594 if (! bed->s->slurp_reloc_table (
obfd, relplt, dyn_symbol_table, TRUE))
597 std::string string_buffer;
600 auto within_section = [
obfd] (asection *section, CORE_ADDR address)
605 return (bfd_section_vma (section) <= address
606 && (address < bfd_section_vma (section)
607 + bfd_section_size (section)));
610 reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
611 for (reloc = 0; reloc < reloc_count; reloc++)
619 name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
620 address = relplt->relocation[reloc].address;
622 asection *msym_section;
626 if (within_section (got_plt,
address))
627 msym_section = got_plt;
628 else if (within_section (plt,
address))
638 string_buffer.assign (
name);
639 string_buffer.append (got_suffix, got_suffix + got_suffix_len);
642 true, unrelocated_addr (
address),
672 return htab_hash_string (a->
name);
685 return strcmp (a->
name, b->
name) == 0;
720 if (len > 4 && strcmp (
target_name + len - 4,
"@plt") == 0)
723 if (strcmp (
target_name,
"_PROCEDURE_LINKAGE_TABLE_") == 0)
742 slot = htab_find_slot (htab, entry_p, INSERT);
749 if (entry_found_p->
addr != addr)
754 warning (_(
"gnu-indirect-function \"%s\" has changed its resolved "
755 "function_address from %s to %s"),
796 alloca (
sizeof (*entry_p) + strlen (
name)));
799 slot = htab_find_slot (htab, entry_p, NO_INSERT);
803 gdb_assert (entry_p != NULL);
806 *addr_p = entry_p->
addr;
830 name_got_plt = (
char *) alloca (strlen (
name) + got_suffix_len + 1);
844 size_t ptr_size = ptr_type->
length ();
845 CORE_ADDR pointer_address, addr;
847 gdb_byte *buf = (gdb_byte *) alloca (ptr_size);
857 plt = bfd_get_section_by_name (
obfd,
".plt");
912 const char *name_at_pc;
913 CORE_ADDR start_at_pc, address;
915 struct value *function, *address_val;
917 struct value *hwcap_val;
922 && start_at_pc == pc)
940 ->builtin_unsigned_long, hwcap);
973 if (b_return->
thread == thread_id
975 && b_return->
frame_id == prev_frame_id)
1014 struct value *func_func;
1016 CORE_ADDR resolved_address, resolved_pc;
1032 internal_error (_(
"handle_inferior_event: Invalid "
1033 "gnu-indirect-function breakpoint type %d"),
1036 b = gdb::checked_static_cast<code_breakpoint *> (b_next);
1070 long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
1071 asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
1095 storage_needed = bfd_get_symtab_upper_bound (
objfile->
obfd.get ());
1096 if (storage_needed < 0)
1097 error (_(
"Can't read symbols from %s: %s"),
1099 bfd_errmsg (bfd_get_error ()));
1101 if (storage_needed > 0)
1106 symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1107 symcount = bfd_canonicalize_symtab (
objfile->
obfd.get (), symbol_table);
1110 error (_(
"Can't read symbols from %s: %s"),
1112 bfd_errmsg (bfd_get_error ()));
1120 storage_needed = bfd_get_dynamic_symtab_upper_bound (
objfile->
obfd.get ());
1122 if (storage_needed > 0)
1131 dyn_symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1132 dynsymcount = bfd_canonicalize_dynamic_symtab (
objfile->
obfd.get (),
1135 if (dynsymcount < 0)
1136 error (_(
"Can't read symbols from %s: %s"),
1138 bfd_errmsg (bfd_get_error ()));
1141 dyn_symbol_table,
false);
1165 synthcount = bfd_get_synthetic_symtab (synth_abfd, symcount, symbol_table,
1166 dynsymcount, dyn_symbol_table,
1172 std::unique_ptr<asymbol *[]>
1173 synth_symbol_table (
new asymbol *[synthcount]);
1174 for (i = 0; i < synthcount; i++)
1175 synth_symbol_table[i] = synthsyms + i;
1177 synth_symbol_table.get (),
true);
1199 symfile_add_flags symfile_flags)
1201 bool has_dwarf2 =
true;
1223 std::string debugfile
1226 if (debugfile.empty ())
1229 if (!debugfile.empty ())
1234 if (debug_bfd !=
nullptr)
1241 const struct bfd_build_id *build_id
1243 const char *filename = bfd_get_filename (
objfile->
obfd.get ());
1245 if (build_id !=
nullptr)
1247 gdb::unique_xmalloc_ptr<char> symfile_path;
1259 if (debug_bfd !=
nullptr
1272 if (debugfile.empty () && !has_dwarf2)
1309 memset ((
char *) &ei, 0,
sizeof (ei));
1332 const struct ecoff_debug_swap *swap;
1336 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1346 str_sect = bfd_get_section_by_name (abfd,
".stabstr");
1353 bfd_section_size (str_sect));
1408 if (probes_per_bfd == NULL)
1415 ops->get_probes (probes_per_bfd,
objfile);
1418 return *probes_per_bfd;
1466Set whether CTF is always read."),
1468Show whether CTF is always read."),
1470When off, CTF is only read if DWARF is not present. When on, CTF is read\
1471 regardless of whether DWARF is present."),
void * xcalloc(size_t number, size_t size)
struct gdbarch * target_gdbarch(void)
int target_auxv_search(const gdb::byte_vector &auxv, target_ops *ops, gdbarch *gdbarch, CORE_ADDR match, CORE_ADDR *valp)
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
void delete_breakpoint(struct breakpoint *bpt)
breakpoint_up set_momentary_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line sal, struct frame_id frame_id, enum bptype type)
void update_breakpoint_locations(code_breakpoint *b, struct program_space *filter_pspace, gdb::array_view< const symtab_and_line > sals, gdb::array_view< const symtab_and_line > sals_end)
@ bp_gnu_ifunc_resolver_return
std::string find_separate_debug_file_by_buildid(struct objfile *objfile, deferred_warnings *warnings)
int build_id_verify(bfd *abfd, size_t check_len, const bfd_byte *check)
const struct bfd_build_id * build_id_bfd_get(bfd *abfd)
CORE_ADDR requested_address
CORE_ADDR related_address
struct program_space * pspace
struct minimal_symbol * record_full(gdb::string_view name, bool copy_name, unrelocated_addr address, enum minimal_symbol_type ms_type, int section)
void set(unsigned key, void *datum)
struct cmd_list_element * showlist
struct cmd_list_element * setlist
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void elfctf_build_psymtabs(struct objfile *of)
void elfstab_build_psymtabs(struct objfile *objfile, asection *stabsect, file_ptr stabstroffset, unsigned int stabstrsize)
scoped_fd debuginfod_debuginfo_query(const unsigned char *build_id, int build_id_len, const char *filename, gdb::unique_xmalloc_ptr< char > *destname)
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
std::vector< std::unique_ptr< probe > > elfread_data
static void elf_gnu_ifunc_resolver_stop(code_breakpoint *b)
static const registry< bfd >::key< elfread_data > probe_key
static void elf_new_init(struct objfile *ignore)
static void elf_symfile_init(struct objfile *objfile)
static void elf_read_minimal_symbols(struct objfile *objfile, int symfile_flags, const struct elfinfo *ei)
static bool always_read_ctf
static int elf_gnu_ifunc_cache_eq(const void *a_voidp, const void *b_voidp)
static const struct sym_fns elf_sym_fns
static CORE_ADDR elf_gnu_ifunc_resolve_addr(struct gdbarch *gdbarch, CORE_ADDR pc)
static const registry< objfile >::key< htab, htab_deleter > elf_objfile_gnu_ifunc_cache_data
static symfile_segment_data_up elf_symfile_segments(bfd *abfd)
#define SYMBOL_GOT_PLT_SUFFIX
static struct minimal_symbol * record_minimal_symbol(minimal_symbol_reader &reader, gdb::string_view name, bool copy_name, unrelocated_addr address, enum minimal_symbol_type ms_type, asection *bfd_section, struct objfile *objfile)
void _initialize_elfread()
static int elf_gnu_ifunc_record_cache(const char *name, CORE_ADDR addr)
static int elf_gnu_ifunc_resolve_by_cache(const char *name, CORE_ADDR *addr_p)
static void elf_symfile_finish(struct objfile *objfile)
static void elf_symtab_read(minimal_symbol_reader &reader, struct objfile *objfile, int type, long number_of_symbols, asymbol **symbol_table, bool copy_names)
static void elf_gnu_ifunc_resolver_return_stop(code_breakpoint *b)
static const elfread_data & elf_get_probes(struct objfile *objfile)
static bool elf_symfile_read_dwarf2(struct objfile *objfile, symfile_add_flags symfile_flags)
static hashval_t elf_gnu_ifunc_cache_hash(const void *a_voidp)
static void elf_symfile_read(struct objfile *objfile, symfile_add_flags symfile_flags)
static bool elf_gnu_ifunc_resolve_name(const char *name, CORE_ADDR *addr_p)
static const struct sym_probe_fns elf_probe_fns
static void elf_rel_plt_read(minimal_symbol_reader &reader, struct objfile *objfile, asymbol **dyn_symbol_table)
static void elf_locate_sections(asection *sectp, struct elfinfo *ei)
static int elf_gnu_ifunc_resolve_by_got(const char *name, CORE_ADDR *addr_p)
static const struct gnu_ifunc_fns elf_gnu_ifunc_fns
CORE_ADDR get_frame_pc(frame_info_ptr frame)
struct frame_id get_stack_frame_id(frame_info_ptr next_frame)
bool frame_id_p(frame_id l)
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
frame_info_ptr get_current_frame(void)
frame_info_ptr get_prev_frame(frame_info_ptr this_frame)
int gdb_bfd_section_index(bfd *abfd, asection *section)
gdb::ref_ptr< struct bfd, gdb_bfd_ref_policy > gdb_bfd_ref_ptr
static gdb_bfd_section_range gdb_bfd_sections(bfd *abfd)
bool gdbarch_record_special_symbol_p(struct gdbarch *gdbarch)
enum return_value_convention gdbarch_return_value_as_value(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, struct value **read_value, const gdb_byte *writebuf)
void gdbarch_iterate_over_objfiles_in_search_order(struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struct objfile *current_objfile)
void gdbarch_elf_make_msymbol_special(struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym)
bool gdbarch_elf_make_msymbol_special_p(struct gdbarch *gdbarch)
void gdbarch_record_special_symbol(struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym)
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
struct thread_info * inferior_thread(void)
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
struct value * call_function_by_hand(struct value *function, type *default_return_type, gdb::array_view< value * > args)
struct inferior * current_inferior(void)
void elfmdebug_build_psymtabs(struct objfile *objfile, const struct ecoff_debug_swap *swap, asection *sec)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
const struct gnu_ifunc_fns * gnu_ifunc_fns_p
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
const char * objfile_name(const struct objfile *objfile)
std::string copy_name(struct stoken token)
std::vector< const static_probe_ops * > all_static_probe_ops
struct program_space * current_program_space
bool dwarf2_has_info(struct objfile *, const struct dwarf2_debug_sections *, bool=false)
void dwarf2_initialize_objfile(struct objfile *objfile)
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
CORE_ADDR value_address() const
struct minimal_symbol * minsym
breakpoint * related_breakpoint
bp_location & first_loc()
bool has_single_location() const
struct type * builtin_data_ptr
struct type * builtin_func_func
const char * linkage_name() const
unsigned int created_by_gdb
unsigned long size() const
void set_size(unsigned long size)
minimal_symbol_type type() const
struct objfile * separate_debug_objfile_backlink
struct objfile * separate_debug_objfile
struct gdbarch * arch() const
struct objfile_per_bfd_storage * per_bfd
bool object_format_has_copy_relocs
objfile(gdb_bfd_ref_ptr, const char *, objfile_flags)
const char * intern(const char *str)
auto_obstack objfile_obstack
bool has_partial_symbols()
struct obj_section * section
struct program_space * pspace
struct type * target_type() const
static struct value * allocate(struct type *type)
void set_lval(lval_type val)
void set_address(CORE_ADDR)
struct obj_section * find_pc_overlay(CORE_ADDR pc)
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *sf)
std::string find_separate_debug_file_by_debuglink(struct objfile *objfile, deferred_warnings *warnings)
void default_symfile_offsets(struct objfile *objfile, const section_addr_info &addrs)
void symbol_file_add_separate(const gdb_bfd_ref_ptr &bfd, const char *name, symfile_add_flags symfile_flags, struct objfile *objfile)
gdb_bfd_ref_ptr symfile_bfd_open_no_error(const char *name) noexcept
bfd_byte * default_symfile_relocate(struct objfile *objfile, asection *sectp, bfd_byte *buf)
std::unique_ptr< symfile_segment_data > symfile_segment_data_up
symtab_and_line find_function_start_sal(CORE_ADDR func_addr, obj_section *section, bool funfirstline)
#define symtab_create_debug_printf(fmt,...)
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
CORE_ADDR value_as_address(struct value *val)
struct value * value_from_longest(struct type *type, LONGEST num)