gdb/
[binutils-gdb.git] / gdb / elfread.c
index d825d9a6e9a969f66cf923020f51f6dab4c0844f..84efc594dcfc1ec525bce0cce7350f2cd67ec3e1 100644 (file)
@@ -44,6 +44,7 @@
 #include "gdbthread.h"
 #include "regcache.h"
 #include "bcache.h"
+#include "gdb_bfd.h"
 
 extern void _initialize_elfread (void);
 
@@ -204,7 +205,7 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
 
   if (ms_type == mst_text || ms_type == mst_file_text
       || ms_type == mst_text_gnu_ifunc)
-    address = gdbarch_smash_text_address (gdbarch, address);
+    address = gdbarch_addr_bits_remove (gdbarch, address);
 
   return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
                                          ms_type, bfd_section->index,
@@ -272,7 +273,7 @@ elf_symtab_read (struct objfile *objfile, int type,
 
       offset = ANOFFSET (objfile->section_offsets, sym->section->index);
       if (type == ST_DYNAMIC
-         && sym->section == &bfd_und_section
+         && sym->section == bfd_und_section_ptr
          && (sym->flags & BSF_FUNCTION))
        {
          struct minimal_symbol *msym;
@@ -352,7 +353,7 @@ elf_symtab_read (struct objfile *objfile, int type,
            }
          filesym = sym;
          filesymname = bcache (filesym->name, strlen (filesym->name) + 1,
-                               objfile->filename_cache);
+                               objfile->per_bfd->filename_cache);
        }
       else if (sym->flags & BSF_SECTION_SYM)
        continue;
@@ -367,7 +368,7 @@ elf_symtab_read (struct objfile *objfile, int type,
          symaddr = sym->value + sym->section->vma;
          /* Relocate all non-absolute and non-TLS symbols by the
             section offset.  */
-         if (sym->section != &bfd_abs_section
+         if (sym->section != bfd_abs_section_ptr
              && !(sym->section->flags & SEC_THREAD_LOCAL))
            {
              symaddr += offset;
@@ -375,7 +376,7 @@ elf_symtab_read (struct objfile *objfile, int type,
          /* For non-absolute symbols, use the type of the section
             they are relative to, to intuit text/data.  Bfd provides
             no way of figuring this out for absolute symbols.  */
-         if (sym->section == &bfd_abs_section)
+         if (sym->section == bfd_abs_section_ptr)
            {
              /* This is a hack to get the minimal symbol type
                 right for Irix 5, which has absolute addresses
@@ -517,7 +518,7 @@ elf_symtab_read (struct objfile *objfile, int type,
                      symaddr = sym->value + sym->section->vma;
                      /* Relocate non-absolute symbols by the
                         section offset.  */
-                     if (sym->section != &bfd_abs_section)
+                     if (sym->section != bfd_abs_section_ptr)
                        symaddr += offset;
                      sectinfo->sections[special_local_sect] = symaddr;
                      /* The special local symbols don't go in the
@@ -569,7 +570,7 @@ elf_symtab_read (struct objfile *objfile, int type,
                elf_sym = (elf_symbol_type *) sym->udata.p;
 
              if (elf_sym)
-               MSYMBOL_SIZE(msym) = elf_sym->internal_elf_sym.st_size;
+               SET_MSYMBOL_SIZE (msym, elf_sym->internal_elf_sym.st_size);
 
              msym->filename = filesymname;
              gdbarch_elf_make_msymbol_special (gdbarch, sym, msym);
@@ -593,7 +594,8 @@ elf_symtab_read (struct objfile *objfile, int type,
                                                  sym->section, objfile);
                  if (mtramp)
                    {
-                     MSYMBOL_SIZE (mtramp) = MSYMBOL_SIZE (msym);
+                     SET_MSYMBOL_SIZE (mtramp, MSYMBOL_SIZE (msym));
+                     mtramp->created_by_gdb = 1;
                      mtramp->filename = filesymname;
                      gdbarch_elf_make_msymbol_special (gdbarch, sym, mtramp);
                    }
@@ -616,7 +618,6 @@ elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
   bfd *obfd = objfile->obfd;
   const struct elf_backend_data *bed = get_elf_backend_data (obfd);
   asection *plt, *relplt, *got_plt;
-  unsigned u;
   int plt_elf_idx;
   bfd_size_type reloc_count, reloc;
   char *string_buffer = NULL;
@@ -655,7 +656,7 @@ elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
   reloc_count = relplt->size / elf_section_data (relplt)->this_hdr.sh_entsize;
   for (reloc = 0; reloc < reloc_count; reloc++)
     {
-      const char *name, *name_got_plt;
+      const char *name;
       struct minimal_symbol *msym;
       CORE_ADDR address;
       const size_t got_suffix_len = strlen (SYMBOL_GOT_PLT_SUFFIX);
@@ -688,7 +689,7 @@ elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
                                     1, address, mst_slot_got_plt, got_plt,
                                    objfile);
       if (msym)
-       MSYMBOL_SIZE (msym) = ptr_size;
+       SET_MSYMBOL_SIZE (msym, ptr_size);
     }
 
   do_cleanups (back_to);
@@ -1020,6 +1021,7 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
   struct type *func_func_type = builtin_type (gdbarch)->builtin_func_func;
   struct type *value_type = TYPE_TARGET_TYPE (func_func_type);
   struct regcache *regcache = get_thread_regcache (inferior_ptid);
+  struct value *func_func;
   struct value *value;
   CORE_ADDR resolved_address, resolved_pc;
   struct symtab_and_line sal;
@@ -1027,14 +1029,6 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
 
   gdb_assert (b->type == bp_gnu_ifunc_resolver_return);
 
-  value = allocate_value (value_type);
-  gdbarch_return_value (gdbarch, func_func_type, value_type, regcache,
-                       value_contents_raw (value), NULL);
-  resolved_address = value_as_address (value);
-  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
-                                                   resolved_address,
-                                                   &current_target);
-
   while (b->related_breakpoint != b)
     {
       struct breakpoint *b_next = b->related_breakpoint;
@@ -1055,6 +1049,18 @@ elf_gnu_ifunc_resolver_return_stop (struct breakpoint *b)
       b = b_next;
     }
   gdb_assert (b->type == bp_gnu_ifunc_resolver);
+  gdb_assert (b->loc->next == NULL);
+
+  func_func = allocate_value (func_func_type);
+  set_value_address (func_func, b->loc->related_address);
+
+  value = allocate_value (value_type);
+  gdbarch_return_value (gdbarch, func_func, value_type, regcache,
+                       value_contents_raw (value), NULL);
+  resolved_address = value_as_address (value);
+  resolved_pc = gdbarch_convert_from_func_ptr_addr (gdbarch,
+                                                   resolved_address,
+                                                   &current_target);
 
   gdb_assert (current_program_space == b->pspace || b->pspace == NULL);
   elf_gnu_ifunc_record_cache (b->addr_string, resolved_pc);
@@ -1103,7 +1109,7 @@ build_id_verify (const char *filename, struct build_id *check)
   int retval = 0;
 
   /* We expect to be silent on the non-existing files.  */
-  abfd = bfd_open_maybe_remote (filename);
+  abfd = gdb_bfd_open_maybe_remote (filename);
   if (abfd == NULL)
     return 0;
 
@@ -1118,7 +1124,7 @@ build_id_verify (const char *filename, struct build_id *check)
   else
     retval = 1;
 
-  gdb_bfd_close_or_warn (abfd);
+  gdb_bfd_unref (abfd);
 
   xfree (found);
 
@@ -1246,6 +1252,13 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
   asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
   asymbol *synthsyms;
 
+  if (symtab_create_debug)
+    {
+      fprintf_unfiltered (gdb_stdlog,
+                         "Reading minimal symbols of objfile %s ...\n",
+                         objfile->name);
+    }
+
   init_minimal_symbol_collection ();
   back_to = make_cleanup_discard_minimal_symbols ();
 
@@ -1432,12 +1445,17 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
 
       if (debugfile)
        {
+         struct cleanup *cleanup = make_cleanup (xfree, debugfile);
          bfd *abfd = symfile_bfd_open (debugfile);
 
+         make_cleanup_bfd_unref (abfd);
          symbol_file_add_separate (abfd, symfile_flags, objfile);
-         xfree (debugfile);
+         do_cleanups (cleanup);
        }
     }
+
+  if (symtab_create_debug)
+    fprintf_unfiltered (gdb_stdlog, "Done reading minimal symbols.\n");
 }
 
 /* Callback to lazily read psymtabs.  */
@@ -1620,33 +1638,29 @@ elf_get_probes (struct objfile *objfile)
    symfile.h.  */
 
 static unsigned
-elf_get_probe_argument_count (struct objfile *objfile,
-                             struct probe *probe)
+elf_get_probe_argument_count (struct probe *probe)
 {
-  return probe->pops->get_probe_argument_count (probe, objfile);
+  return probe->pops->get_probe_argument_count (probe);
 }
 
 /* Implementation of `sym_evaluate_probe_argument', as documented in
    symfile.h.  */
 
 static struct value *
-elf_evaluate_probe_argument (struct objfile *objfile,
-                            struct probe *probe,
-                            unsigned n)
+elf_evaluate_probe_argument (struct probe *probe, unsigned n)
 {
-  return probe->pops->evaluate_probe_argument (probe, objfile, n);
+  return probe->pops->evaluate_probe_argument (probe, n);
 }
 
 /* Implementation of `sym_compile_to_ax', as documented in symfile.h.  */
 
 static void
-elf_compile_to_ax (struct objfile *objfile,
-                  struct probe *probe,
+elf_compile_to_ax (struct probe *probe,
                   struct agent_expr *expr,
                   struct axs_value *value,
                   unsigned n)
 {
-  probe->pops->compile_to_ax (probe, objfile, expr, value, n);
+  probe->pops->compile_to_ax (probe, expr, value, n);
 }
 
 /* Implementation of `sym_relocate_probe', as documented in symfile.h.  */