25 #include "elf/common.h" 26 #include "elf/internal.h" 37 #include "filenames.h" 75 #define SYMBOL_GOT_PLT_SUFFIX "@got.plt" 82 Elf_Internal_Phdr *phdrs, **segments;
88 phdrs_size = bfd_get_elf_phdr_upper_bound (abfd);
92 phdrs = (Elf_Internal_Phdr *) alloca (phdrs_size);
93 num_phdrs = bfd_get_elf_phdrs (abfd, phdrs);
98 segments = XALLOCAVEC (Elf_Internal_Phdr *, num_phdrs);
99 for (i = 0; i < num_phdrs; i++)
100 if (phdrs[i].p_type == PT_LOAD)
117 num_sections = bfd_count_sections (abfd);
120 for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
125 if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
128 vma = bfd_get_section_vma (abfd, sect);
131 if (segments[j]->p_memsz > 0
132 && vma >= segments[j]->p_vaddr
133 && (vma - segments[j]->p_vaddr) < segments[j]->p_memsz)
148 if (bfd_get_section_size (sect) > 0 && j ==
num_segments 149 && (bfd_get_section_flags (abfd, sect) & SEC_LOAD) != 0)
150 warning (
_(
"Loadable section \"%s\" outside of ELF segments"),
151 bfd_section_name (abfd, sect));
182 if (strcmp (sectp->name,
".stab") == 0)
186 else if (strcmp (sectp->name,
".mdebug") == 0)
225 #define ST_SYNTHETIC 2 230 long number_of_symbols, asymbol **symbol_table,
240 const char *filesymname =
"";
241 int stripped = (bfd_get_symcount (
objfile->
obfd) == 0);
242 int elf_make_msymbol_special_p
245 for (i = 0; i < number_of_symbols; i++)
247 sym = symbol_table[i];
248 if (sym->name == NULL || *sym->name ==
'\0')
258 if (bfd_is_target_special_symbol (
objfile->
obfd, sym))
266 && sym->section == bfd_und_section_ptr
267 && (sym->flags & BSF_FUNCTION))
281 symaddr = sym->value;
289 for (sect = abfd->sections; sect != NULL; sect = sect->next)
291 if ((bfd_get_section_flags (abfd, sect) & SEC_ALLOC) == 0)
294 if (symaddr >= bfd_get_section_vma (abfd, sect)
295 && symaddr < bfd_get_section_vma (abfd, sect)
296 + bfd_get_section_size (sect))
316 && bfd_get_section_by_name (abfd,
".plt") != NULL)
320 (reader, sym->name, strlen (sym->name), copy_names,
325 if (elf_make_msymbol_special_p)
336 if (sym->flags & BSF_FILE)
339 = (
const char *)
bcache (sym->name, strlen (sym->name) + 1,
342 else if (sym->flags & BSF_SECTION_SYM)
344 else if (sym->flags & (BSF_GLOBAL | BSF_LOCAL | BSF_WEAK
353 symaddr = sym->value + sym->section->vma;
357 if (sym->section == bfd_abs_section_ptr)
366 ((elf_symbol_type *) sym)->internal_elf_sym.st_shndx;
376 case SHN_MIPS_ACOMMON:
387 if (sym->name[0] ==
'.')
391 else if (sym->section->flags & SEC_CODE)
393 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
395 if (sym->flags & BSF_GNU_INDIRECT_FUNCTION)
403 else if ((sym->name[0] ==
'.' && sym->name[1] ==
'L' 404 && (sym->flags & BSF_SYNTHETIC) == 0)
405 || ((sym->flags & BSF_LOCAL)
406 && sym->name[0] ==
'$' 407 && sym->name[1] ==
'L'))
421 else if (sym->section->flags & SEC_ALLOC)
423 if (sym->flags & (BSF_GLOBAL | BSF_WEAK | BSF_GNU_UNIQUE))
425 if (sym->section->flags & SEC_LOAD)
434 else if (sym->flags & BSF_LOCAL)
436 if (sym->section->flags & SEC_LOAD)
460 (reader, sym->name, strlen (sym->name), copy_names, symaddr,
461 ms_type, sym->section,
objfile);
470 elf_symbol_type *elf_sym = (elf_symbol_type *) sym;
475 if (elf_make_msymbol_special_p)
483 const char *atsign = strchr (sym->name,
'@');
485 if (atsign != NULL && atsign[1] ==
'@' && atsign > sym->name)
487 int len = atsign - sym->name;
490 ms_type, sym->section,
objfile);
500 int len = strlen (sym->name);
502 if (len > 4 && strcmp (sym->name + len - 4,
"@plt") == 0)
515 if (elf_make_msymbol_special_p)
537 const struct elf_backend_data *bed = get_elf_backend_data (obfd);
538 asection *plt, *relplt, *got_plt;
540 bfd_size_type reloc_count, reloc;
548 plt = bfd_get_section_by_name (obfd,
".plt");
551 plt_elf_idx = elf_section_data (plt)->this_idx;
553 got_plt = bfd_get_section_by_name (obfd,
".got.plt");
557 got_plt = bfd_get_section_by_name (obfd,
".got");
563 for (relplt = obfd->sections; relplt != NULL; relplt = relplt->next)
564 if (elf_section_data (relplt)->this_hdr.sh_info == plt_elf_idx
565 && (elf_section_data (relplt)->this_hdr.sh_type == SHT_REL
566 || elf_section_data (relplt)->this_hdr.sh_type == SHT_RELA))
571 if (! bed->s->slurp_reloc_table (obfd, relplt, dyn_symbol_table, TRUE))
576 reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
577 for (reloc = 0; reloc < reloc_count; reloc++)
585 name = bfd_asymbol_name (*relplt->relocation[reloc].sym_ptr_ptr);
586 address = relplt->relocation[reloc].address;
589 if (!(bfd_get_section_vma (obfd, got_plt) <= address
590 && address < bfd_get_section_vma (obfd, got_plt)
591 + bfd_get_section_size (got_plt)))
598 string_buffer.assign (
name);
599 string_buffer.append (got_suffix, got_suffix + got_suffix_len);
602 string_buffer.size (),
632 return htab_hash_string (a->
name);
645 return strcmp (a->
name, b->
name) == 0;
678 if (strcmp (bfd_get_section_name (
objfile->
obfd, sect),
".plt") == 0)
699 slot = htab_find_slot (htab, entry_p, INSERT);
706 if (entry_found_p->
addr != addr)
711 warning (
_(
"gnu-indirect-function \"%s\" has changed its resolved " 712 "function_address from %s to %s"),
747 alloca (
sizeof (*entry_p) + strlen (
name)));
750 slot = htab_find_slot (htab, entry_p, NO_INSERT);
757 *addr_p = entry_p->
addr;
779 name_got_plt = (
char *) alloca (strlen (
name) + got_suffix_len + 1);
794 if (msym.minsym == NULL)
800 plt = bfd_get_section_by_name (obfd,
".plt");
849 const char *name_at_pc;
852 struct value *
function, *address_val;
854 struct value *hwcap_val;
859 && start_at_pc == pc)
877 ->builtin_unsigned_long, hwcap);
910 if (b_return->
thread == thread_id
950 struct value *func_func;
969 _(
"handle_inferior_event: Invalid " 970 "gnu-indirect-function breakpoint type %d"),
1008 long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
1009 asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
1016 "Reading minimal symbols of objfile %s ...\n",
1031 "... minimal symbols previously read\n");
1043 storage_needed = bfd_get_symtab_upper_bound (
objfile->
obfd);
1044 if (storage_needed < 0)
1045 error (
_(
"Can't read symbols from %s: %s"),
1047 bfd_errmsg (bfd_get_error ()));
1049 if (storage_needed > 0)
1054 symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1058 error (
_(
"Can't read symbols from %s: %s"),
1060 bfd_errmsg (bfd_get_error ()));
1068 storage_needed = bfd_get_dynamic_symtab_upper_bound (
objfile->
obfd);
1070 if (storage_needed > 0)
1079 dyn_symbol_table = (asymbol **) bfd_alloc (abfd, storage_needed);
1080 dynsymcount = bfd_canonicalize_dynamic_symtab (
objfile->
obfd,
1083 if (dynsymcount < 0)
1084 error (
_(
"Can't read symbols from %s: %s"),
1086 bfd_errmsg (bfd_get_error ()));
1089 dyn_symbol_table,
false);
1113 synthcount = bfd_get_synthetic_symtab (synth_abfd,
symcount, symbol_table,
1114 dynsymcount, dyn_symbol_table,
1120 std::unique_ptr<asymbol *[]>
1121 synth_symbol_table (
new asymbol *[synthcount]);
1122 for (i = 0; i < synthcount; i++)
1123 synth_symbol_table[i] = synthsyms + i;
1125 synth_symbol_table.get (),
true);
1173 memset ((
char *) &ei, 0,
sizeof (ei));
1193 const struct ecoff_debug_swap *swap;
1197 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
1207 str_sect = bfd_get_section_by_name (abfd,
".stabstr");
1214 bfd_section_size (abfd, str_sect));
1265 if (debugfile == NULL)
1268 if (debugfile != NULL)
1325 static const std::vector<probe *> &
1328 std::vector<probe *> *probes_per_bfd;
1333 if (probes_per_bfd == NULL)
1335 probes_per_bfd =
new std::vector<probe *>;
1340 ops->get_probes (probes_per_bfd,
objfile);
1345 return *probes_per_bfd;
1354 std::vector<probe *> *probes = (std::vector<probe *> *) d;
1356 for (
probe *p : *probes)
int frame_id_p(struct frame_id l)
bool dwarf2_initialize_objfile(struct objfile *objfile, dw_index_kind *index_kind)
void stabsread_new_init(void)
CORE_ADDR extract_typed_address(const gdb_byte *buf, struct type *type)
int dwarf2_has_info(struct objfile *objfile, const struct dwarf2_debug_sections *names)
void objfile_set_sym_fns(struct objfile *objfile, const struct sym_fns *sf)
static const struct sym_fns elf_sym_fns
CORE_ADDR get_frame_pc(struct frame_info *frame)
struct frame_info * get_current_frame(void)
static struct symfile_segment_data * elf_symfile_segments(bfd *abfd)
char * find_separate_debug_file_by_buildid(struct objfile *objfile)
struct regcache * get_thread_regcache(ptid_t ptid)
int gdb_bfd_section_index(bfd *abfd, asection *section)
struct objfile * separate_debug_objfile_backlink
void dummy_obstack_deallocate(void *object, void *data)
struct frame_info * get_prev_frame(struct frame_info *this_frame)
#define BMSYMBOL_VALUE_ADDRESS(symbol)
void warning(const char *fmt,...)
CORE_ADDR * segment_bases
static const struct bfd_data * probe_key
const struct builtin_type * builtin_type(struct gdbarch *gdbarch)
static int elf_gnu_ifunc_record_cache(const char *name, CORE_ADDR addr)
struct frame_id get_stack_frame_id(struct frame_info *next_frame)
static const struct sym_probe_fns elf_probe_fns
void * memset(T *s, int c, size_t n)=delete
void internal_error(const char *file, int line, const char *fmt,...)
void add_symtab_fns(enum bfd_flavour flavour, const struct sym_fns *sf)
struct type * builtin_func_func
const struct gnu_ifunc_fns * gnu_ifunc_fns_p
CORE_ADDR requested_address
static void probe_key_free(bfd *abfd, void *d)
static int elf_gnu_ifunc_resolve_by_cache(const char *name, CORE_ADDR *addr_p)
#define SYMBOL_GOT_PLT_SUFFIX
gdb_bfd_ref_ptr symfile_bfd_open(const char *name)
void dwarf2_build_psymtabs(struct objfile *objfile)
struct obj_section * section
static const struct gnu_ifunc_fns elf_gnu_ifunc_fns
breakpoint * related_breakpoint
struct objfile_per_bfd_storage * per_bfd
struct value * allocate_value(struct type *type)
void gdbarch_elf_make_msymbol_special(struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
static int elf_gnu_ifunc_cache_eq(const void *a_voidp, const void *b_voidp)
struct minimal_symbol * record_full(const char *name, int name_len, bool copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, int section)
struct obj_section * find_pc_overlay(CORE_ADDR pc)
void set_value_address(struct value *value, CORE_ADDR addr)
struct program_space * pspace
#define MSYMBOL_OBJ_SECTION(objfile, symbol)
int frame_id_eq(struct frame_id l, struct frame_id r)
int objfile_has_partial_symbols(struct objfile *objfile)
static void elf_read_minimal_symbols(struct objfile *objfile, int symfile_flags, const struct elfinfo *ei)
unsigned int created_by_gdb
bfd_byte * default_symfile_relocate(struct objfile *objfile, asection *sectp, bfd_byte *buf)
int gdbarch_record_special_symbol_p(struct gdbarch *gdbarch)
static void read_psyms(struct objfile *objfile)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
void dwarf2_free_objfile(struct objfile *objfile)
struct target_ops current_target
CORE_ADDR gdbarch_addr_bits_remove(struct gdbarch *gdbarch, CORE_ADDR addr)
struct symtab_and_line find_pc_line(CORE_ADDR pc, int notcurrent)
static void elf_symfile_finish(struct objfile *objfile)
objfile(bfd *, const char *, objfile_flags)
static void elf_locate_sections(bfd *ignore_abfd, asection *sectp, void *eip)
static void elf_gnu_ifunc_resolver_stop(struct breakpoint *b)
CORE_ADDR gdbarch_convert_from_func_ptr_addr(struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
static void elf_rel_plt_read(minimal_symbol_reader &reader, struct objfile *objfile, asymbol **dyn_symbol_table)
int target_auxv_search(struct target_ops *ops, CORE_ADDR match, CORE_ADDR *valp)
#define MSYMBOL_SIZE(msymbol)
static int elf_gnu_ifunc_resolve_name(const char *name, CORE_ADDR *addr_p)
void buildsym_new_init(void)
static void elf_gnu_ifunc_resolver_return_stop(struct breakpoint *b)
struct gdbarch * get_objfile_arch(const struct objfile *objfile)
int ptid_to_global_thread_id(ptid_t ptid)
void update_breakpoint_locations(struct breakpoint *b, struct program_space *filter_pspace, gdb::array_view< const symtab_and_line > sals, gdb::array_view< const symtab_and_line > sals_end)
static void elf_symfile_init(struct objfile *objfile)
int find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr)
const struct sym_fns elf_sym_fns_debug_names
struct objfile * separate_debug_objfile
static const struct objfile_data * elf_objfile_gnu_ifunc_cache_data
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)
char * find_separate_debug_file_by_debuglink(struct objfile *objfile)
void _initialize_elfread(void)
const struct sym_fns elf_sym_fns_lazy_psyms
struct value * value_from_longest(struct type *type, LONGEST num)
static int startswith(const char *string, const char *pattern)
#define SET_MSYMBOL_SIZE(msymbol, sz)
const char * event_location_to_string(struct event_location *location)
void elfmdebug_build_psymtabs(struct objfile *objfile, const struct ecoff_debug_swap *swap, asection *sec)
const char * objfile_name(const struct objfile *objfile)
const struct quick_symbol_functions dwarf2_debug_names_functions
void gdbarch_record_special_symbol(struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym)
void * hashtab_obstack_allocate(void *data, size_t size, size_t count)
std::vector< const static_probe_ops * > all_static_probe_ops
static struct minimal_symbol * record_minimal_symbol(minimal_symbol_reader &reader, const char *name, int name_len, bool copy_name, CORE_ADDR address, enum minimal_symbol_type ms_type, asection *bfd_section, struct objfile *objfile)
const struct sym_fns elf_sym_fns_gdb_index
#define MSYMBOL_TYPE(msymbol)
static CORE_ADDR elf_gnu_ifunc_resolve_addr(struct gdbarch *gdbarch, CORE_ADDR pc)
breakpoint_up set_momentary_breakpoint(struct gdbarch *gdbarch, struct symtab_and_line sal, struct frame_id frame_id, enum bptype type)
#define TYPE_TARGET_TYPE(thistype)
static void elf_symfile_read(struct objfile *objfile, symfile_add_flags symfile_flags)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
event_location_up location
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
struct type * builtin_data_ptr
struct minimal_symbol * minsym
const struct quick_symbol_functions psym_functions
struct program_space * pspace
const struct quick_symbol_functions dwarf2_gdb_index_functions
CORE_ADDR related_address
int gdbarch_elf_make_msymbol_special_p(struct gdbarch *gdbarch)
static const std::vector< probe * > & elf_get_probes(struct objfile *objfile)
void default_symfile_offsets(struct objfile *objfile, const struct section_addr_info *addrs)
struct inferior * current_inferior(void)
static int elf_gnu_ifunc_resolve_by_got(const char *name, CORE_ADDR *addr_p)
struct program_space * current_program_space
unsigned int symtab_create_debug
static int ignore(struct target_ops *ops, struct gdbarch *gdbarch, struct bp_target_info *bp_tgt)
struct value * call_function_by_hand(struct value *function, type *default_return_type, int nargs, struct value **args)
#define obstack_grow_str0(OBSTACK, STRING)
struct type * value_type(const struct value *value)
void elfstab_build_psymtabs(struct objfile *objfile, asection *stabsect, file_ptr stabstroffset, unsigned int stabstrsize)
const struct objfile_data * dbx_objfile_data_key
static void elf_new_init(struct objfile *ignore)
CORE_ADDR value_as_address(struct value *val)
gdb_byte * value_contents_raw(struct value *value)
#define TYPE_LENGTH(thistype)
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 hashval_t elf_gnu_ifunc_cache_hash(const void *a_voidp)
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
CORE_ADDR * segment_sizes
#define ALL_PSPACE_OBJFILES(ss, obj)
void delete_breakpoint(struct breakpoint *bpt)
void error(const char *fmt,...)
struct gdbarch * get_frame_arch(struct frame_info *this_frame)
char * copy_name(struct stoken token)
void symbol_file_add_separate(bfd *bfd, const char *name, symfile_add_flags symfile_flags, struct objfile *objfile)