25#include "elf/common.h"
26#include "elf/internal.h"
50#include "gdbsupport/gdb_string_view.h"
51#include "gdbsupport/scoped_fd.h"
79#define SYMBOL_GOT_PLT_SUFFIX "@got.plt"
86 Elf_Internal_Phdr *phdrs, **segments;
88 int num_phdrs, num_segments, num_sections, i;
91 phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
95 phdrs = (Elf_Internal_Phdr *) alloca (phdrs_size);
96 num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
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)
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);
118 data->segment_info.resize (num_sections);
120 for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
124 if ((bfd_section_flags (sect) & SEC_ALLOC) == 0)
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;
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));
181 if (strcmp (sectp->name,
".stab") == 0)
185 else if (strcmp (sectp->name,
".mdebug") == 0)
189 else if (strcmp (sectp->name,
".ctf") == 0)
212 int section_index = 0;
213 if ((bfd_section_flags (bfd_section) & SEC_ALLOC) == SEC_ALLOC)
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,
341 if (elf_make_msymbol_special_p)
352 if (sym->flags & BSF_FILE)
354 else if (sym->flags & BSF_SECTION_SYM)
356 else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK
365 symaddr = sym->value + sym->section->vma;
369 if (sym->section == bfd_abs_section_ptr)
378 elf_sym->internal_elf_sym.st_shndx;
388 case SHN_MIPS_ACOMMON:
399 if (sym->name[0] ==
'.')
403 else if (sym->section->flags & SEC_CODE)
405 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
407 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
415 else if ((sym->name[0] ==
'.' && sym->name[1] ==
'L'
416 && (sym->flags & BSF_SYNTHETIC) == 0)
417 || ((sym->flags & BSF_LOCAL)
418 && sym->name[0] ==
'$'
419 && sym->name[1] ==
'L'))
433 else if (sym->section->flags & SEC_ALLOC)
435 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
437 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
441 else if (sym->section->flags & SEC_LOAD)
450 else if (sym->flags & BSF_LOCAL)
452 if (sym->section->flags & SEC_LOAD)
476 (reader, sym->name, copy_names, symaddr,
477 ms_type, sym->section,
objfile);
486 msym->
set_size (elf_sym->internal_elf_sym.st_size);
490 if (elf_make_msymbol_special_p)
498 const char *atsign = strchr (sym->name,
'@');
499 bool is_at_symbol = atsign !=
nullptr && atsign > sym->name;
500 bool is_plt = is_at_symbol && strcmp (atsign,
"@plt") == 0;
501 int len = is_at_symbol ? atsign - sym->name : 0;
505 && (elf_sym->version & VERSYM_HIDDEN) == 0)
507 gdb::string_view (sym->name, len),
508 true, symaddr, ms_type, sym->section,
521 (reader, gdb::string_view (sym->name, len),
true,
528 if (elf_make_msymbol_special_p)
551 const struct elf_backend_data *bed = get_elf_backend_data (
obfd);
552 asection *relplt, *got_plt;
553 bfd_size_type reloc_count, reloc;
556 size_t ptr_size = ptr_type->
length ();
561 got_plt = bfd_get_section_by_name (
obfd,
".got.plt");
565 got_plt = bfd_get_section_by_name (
obfd,
".got");
572 asection *plt = bfd_get_section_by_name (
obfd,
".plt");
573 int plt_elf_idx = (plt != NULL) ? elf_section_data (plt)->this_idx : -1;
575 int got_plt_elf_idx = elf_section_data (got_plt)->this_idx;
578 for (relplt =
obfd->sections; relplt != NULL; relplt = relplt->next)
580 const auto &this_hdr = elf_section_data (relplt)->this_hdr;
582 if (this_hdr.sh_type == SHT_REL || this_hdr.sh_type == SHT_RELA)
584 if (this_hdr.sh_info == plt_elf_idx
585 || this_hdr.sh_info == got_plt_elf_idx)
592 if (! bed->s->slurp_reloc_table (
obfd, relplt, dyn_symbol_table, TRUE))
595 std::string string_buffer;
598 auto within_section = [
obfd] (asection *section, CORE_ADDR address)
603 return (bfd_section_vma (section) <= address
604 && (address < bfd_section_vma (section)
605 + bfd_section_size (section)));
608 reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
609 for (reloc = 0; reloc < reloc_count; reloc++)
617 name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
618 address = relplt->relocation[reloc].address;
620 asection *msym_section;
624 if (within_section (got_plt,
address))
625 msym_section = got_plt;
626 else if (within_section (plt,
address))
636 string_buffer.assign (
name);
637 string_buffer.append (got_suffix, got_suffix + got_suffix_len);
670 return htab_hash_string (a->
name);
683 return strcmp (a->
name, b->
name) == 0;
718 if (len > 4 && strcmp (
target_name + len - 4,
"@plt") == 0)
737 slot = htab_find_slot (htab, entry_p, INSERT);
744 if (entry_found_p->
addr != addr)
749 warning (_(
"gnu-indirect-function \"%s\" has changed its resolved "
750 "function_address from %s to %s"),
791 alloca (
sizeof (*entry_p) + strlen (
name)));
794 slot = htab_find_slot (htab, entry_p, NO_INSERT);
798 gdb_assert (entry_p != NULL);
801 *addr_p = entry_p->
addr;
825 name_got_plt = (
char *) alloca (strlen (
name) + got_suffix_len + 1);
839 size_t ptr_size = ptr_type->
length ();
840 CORE_ADDR pointer_address, addr;
842 gdb_byte *buf = (gdb_byte *) alloca (ptr_size);
852 plt = bfd_get_section_by_name (
obfd,
".plt");
907 const char *name_at_pc;
908 CORE_ADDR start_at_pc, address;
910 struct value *function, *address_val;
912 struct value *hwcap_val;
917 && start_at_pc == pc)
935 ->builtin_unsigned_long, hwcap);
965 gdb_assert (b_return->
loc != NULL && b_return->
loc->
next == NULL);
968 if (b_return->
thread == thread_id
970 && b_return->
frame_id == prev_frame_id)
1009 struct value *func_func;
1011 CORE_ADDR resolved_address, resolved_pc;
1027 internal_error (_(
"handle_inferior_event: Invalid "
1028 "gnu-indirect-function breakpoint type %d"),
1034 gdb_assert (b->
loc->
next == NULL);
1065 long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
1066 asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
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"),
1094 bfd_errmsg (bfd_get_error ()));
1096 if (storage_needed > 0)
1101 symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1102 symcount = bfd_canonicalize_symtab (
objfile->
obfd.get (), symbol_table);
1105 error (_(
"Can't read symbols from %s: %s"),
1107 bfd_errmsg (bfd_get_error ()));
1115 storage_needed = bfd_get_dynamic_symtab_upper_bound (
objfile->
obfd.get ());
1117 if (storage_needed > 0)
1126 dyn_symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1127 dynsymcount = bfd_canonicalize_dynamic_symtab (
objfile->
obfd.get (),
1130 if (dynsymcount < 0)
1131 error (_(
"Can't read symbols from %s: %s"),
1133 bfd_errmsg (bfd_get_error ()));
1136 dyn_symbol_table,
false);
1160 synthcount = bfd_get_synthetic_symtab (synth_abfd, symcount, symbol_table,
1161 dynsymcount, dyn_symbol_table,
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;
1172 synth_symbol_table.get (),
true);
1194 symfile_add_flags symfile_flags)
1196 bool has_dwarf2 =
true;
1218 if (debugfile.empty ())
1221 if (!debugfile.empty ())
1231 const struct bfd_build_id *build_id
1233 const char *filename = bfd_get_filename (
objfile->
obfd.get ());
1235 if (build_id !=
nullptr)
1237 gdb::unique_xmalloc_ptr<char> symfile_path;
1248 if (debug_bfd ==
nullptr)
1249 warning (_(
"File \"%s\" from debuginfod cannot be opened as bfd"),
1296 memset ((
char *) &ei, 0,
sizeof (ei));
1319 const struct ecoff_debug_swap *swap;
1323 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1333 str_sect = bfd_get_section_by_name (abfd,
".stabstr");
1340 bfd_section_size (str_sect));
1346 if (!has_dwarf2 && ei.
ctfsect)
1389 if (probes_per_bfd == NULL)
1396 ops->get_probes (probes_per_bfd,
objfile);
1399 return *probes_per_bfd;
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
int build_id_verify(bfd *abfd, size_t check_len, const bfd_byte *check)
std::string find_separate_debug_file_by_buildid(struct objfile *objfile)
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, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
void set(unsigned key, void *datum)
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 struct minimal_symbol * record_minimal_symbol(minimal_symbol_reader &reader, gdb::string_view name, bool copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, asection *bfd_section, struct objfile *objfile)
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
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(struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, 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)
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
void dwarf2_initialize_objfile(struct objfile *objfile)
int dwarf2_has_info(struct objfile *, const struct dwarf2_debug_sections *, bool=false)
struct regcache * get_thread_regcache(process_stratum_target *target, ptid_t ptid)
CORE_ADDR value_address() const
struct minimal_symbol * minsym
breakpoint * related_breakpoint
struct type * builtin_data_ptr
struct type * builtin_func_func
short section_index() const
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
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
gdb_bfd_ref_ptr symfile_bfd_open(const char *name)
struct obj_section * find_pc_overlay(CORE_ADDR pc)
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *sf)
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)
std::string find_separate_debug_file_by_debuglink(struct objfile *objfile)
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)
struct type * value_type(const struct value *value)
struct value * allocate_value(struct type *type)
CORE_ADDR value_as_address(struct value *val)
void set_value_address(struct value *value, CORE_ADDR addr)
struct value * value_from_longest(struct type *type, LONGEST num)
gdb::array_view< gdb_byte > value_contents_raw(struct value *value)