MIPS/LD: Continue processing with refused relocations in PIC code
[binutils-gdb.git] / gdb / psymtab.c
index f144fa339655dab764754ec3acf86d3dab366bc4..6d76e8d4898a00e3d607f194c11e24932cc6ebe7 100644 (file)
@@ -62,9 +62,6 @@ static struct partial_symbol *find_pc_sect_psymbol (struct objfile *,
                                                    CORE_ADDR,
                                                    struct obj_section *);
 
-static void fixup_psymbol_section (struct partial_symbol *psym,
-                                  struct objfile *objfile);
-
 static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile,
                                                  struct partial_symtab *pst);
 
@@ -81,11 +78,8 @@ require_partial_symbols (struct objfile *objfile, int verbose)
       if (objfile->sf->sym_read_psymbols)
        {
          if (verbose)
-           {
-             printf_unfiltered (_("Reading symbols from %s..."),
-                                objfile_name (objfile));
-             gdb_flush (gdb_stdout);
-           }
+           printf_filtered (_("Reading symbols from %s...\n"),
+                            objfile_name (objfile));
          (*objfile->sf->sym_read_psymbols) (objfile);
 
          /* Partial symbols list are not expected to changed after this
@@ -93,17 +87,9 @@ require_partial_symbols (struct objfile *objfile, int verbose)
          objfile->global_psymbols.shrink_to_fit ();
          objfile->static_psymbols.shrink_to_fit ();
 
-         if (verbose)
-           {
-             if (!objfile_has_symbols (objfile))
-               {
-                 wrap_here ("");
-                 printf_unfiltered (_("(no debugging symbols found)..."));
-                 wrap_here ("");
-               }
-
-             printf_unfiltered (_("done.\n"));
-           }
+         if (verbose && !objfile_has_symbols (objfile))
+           printf_filtered (_("(No debugging symbols found in %s)\n"),
+                            objfile_name (objfile));
        }
     }
 
@@ -232,7 +218,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 {
   struct partial_symtab *tpst;
   struct partial_symtab *best_pst = pst;
-  CORE_ADDR best_addr = pst->textlow;
+  CORE_ADDR best_addr = pst->text_low (objfile);
 
   gdb_assert (!pst->psymtabs_addrmap_supported);
 
@@ -256,7 +242,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
      that is closest and still less than the given PC.  */
   for (tpst = pst; tpst != NULL; tpst = tpst->next)
     {
-      if (pc >= tpst->textlow && pc < tpst->texthigh)
+      if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile))
        {
          struct partial_symbol *p;
          CORE_ADDR this_addr;
@@ -277,7 +263,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
          if (p != NULL)
            this_addr = p->address (objfile);
          else
-           this_addr = tpst->textlow;
+           this_addr = tpst->text_low (objfile);
 
          /* Check whether it is closer than our current
             BEST_ADDR.  Since this symbol address is
@@ -310,6 +296,8 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
                      struct bound_minimal_symbol msymbol)
 {
   struct partial_symtab *pst;
+  CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
+                                SECT_OFF_TEXT (objfile));
 
   /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
      than the later used TEXTLOW/TEXTHIGH one.  */
@@ -317,7 +305,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
   if (objfile->psymtabs_addrmap != NULL)
     {
       pst = ((struct partial_symtab *)
-            addrmap_find (objfile->psymtabs_addrmap, pc));
+            addrmap_find (objfile->psymtabs_addrmap, pc - baseaddr));
       if (pst != NULL)
        {
          /* FIXME: addrmaps currently do not handle overlayed sections,
@@ -361,7 +349,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     if (!pst->psymtabs_addrmap_supported
-       && pc >= pst->textlow && pc < pst->texthigh)
+       && pc >= pst->text_low (objfile) && pc < pst->text_high (objfile))
       {
        struct partial_symtab *best_pst;
 
@@ -411,11 +399,12 @@ find_pc_sect_psymbol (struct objfile *objfile,
 {
   struct partial_symbol *best = NULL;
   CORE_ADDR best_pc;
+  const CORE_ADDR textlow = psymtab->text_low (objfile);
 
   gdb_assert (psymtab != NULL);
 
   /* Cope with programs that start at address 0.  */
-  best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
+  best_pc = (textlow != 0) ? textlow - 1 : 0;
 
   /* Search the global symbols as well as the static symbols, so that
      find_pc_partial_function doesn't use a minimal symbol and thus
@@ -428,12 +417,11 @@ find_pc_sect_psymbol (struct objfile *objfile,
          && p->aclass == LOC_BLOCK
          && pc >= p->address (objfile)
          && (p->address (objfile) > best_pc
-             || (psymtab->textlow == 0
+             || (psymtab->text_low (objfile) == 0
                  && best_pc == 0 && p->address (objfile) == 0)))
        {
          if (section != NULL)  /* Match on a specific section.  */
            {
-             fixup_psymbol_section (p, objfile);
              if (!matching_obj_sections (p->obj_section (objfile),
                                          section))
                continue;
@@ -451,12 +439,11 @@ find_pc_sect_psymbol (struct objfile *objfile,
          && p->aclass == LOC_BLOCK
          && pc >= p->address (objfile)
          && (p->address (objfile) > best_pc
-             || (psymtab->textlow == 0
+             || (psymtab->text_low (objfile) == 0
                  && best_pc == 0 && p->address (objfile) == 0)))
        {
          if (section != NULL)  /* Match on a specific section.  */
            {
-             fixup_psymbol_section (p, objfile);
              if (!matching_obj_sections (p->obj_section (objfile),
                                          section))
                continue;
@@ -469,35 +456,6 @@ find_pc_sect_psymbol (struct objfile *objfile,
   return best;
 }
 
-static void
-fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
-{
-  CORE_ADDR addr;
-
-  if (psym == NULL)
-    return;
-
-  if (psym->section >= 0)
-    return;
-
-  gdb_assert (objfile);
-
-  switch (psym->aclass)
-    {
-    case LOC_STATIC:
-    case LOC_LABEL:
-    case LOC_BLOCK:
-      addr = psym->address (objfile);
-      break;
-    default:
-      /* Nothing else will be listed in the minsyms -- no use looking
-        it up.  */
-      return;
-    }
-
-  fixup_section (psym, addr, objfile);
-}
-
 /* Psymtab version of lookup_symbol.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
@@ -794,40 +752,6 @@ psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
   return pst->compunit_symtab;
 }
 
-/* Psymtab version of relocate.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-static void
-psym_relocate (struct objfile *objfile,
-              const struct section_offsets *new_offsets,
-              const struct section_offsets *delta)
-{
-  struct partial_symtab *p;
-
-  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
-    {
-      p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-      p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-    }
-
-  for (partial_symbol *psym : objfile->global_psymbols)
-    {
-      fixup_psymbol_section (psym, objfile);
-      if (psym->section >= 0)
-       psym->set_address (psym->unrelocated_address ()
-                          + ANOFFSET (delta, psym->section));
-    }
-  for (partial_symbol *psym : objfile->static_psymbols)
-    {
-      fixup_psymbol_section (psym, objfile);
-      if (psym->section >= 0)
-       psym->set_address (psym->unrelocated_address ()
-                          + ANOFFSET (delta, psym->section));
-    }
-
-  objfile->psymbol_map.clear ();
-}
-
 /* Psymtab version of find_last_source_symtab.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
@@ -996,10 +920,10 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
   fprintf_filtered (outfile, "(object ");
   gdb_print_host_address (psymtab, outfile);
   fprintf_filtered (outfile, ")\n\n");
-  fprintf_unfiltered (outfile, "  Read from object file %s (",
-                     objfile_name (objfile));
+  fprintf_filtered (outfile, "  Read from object file %s (",
+                   objfile_name (objfile));
   gdb_print_host_address (objfile, outfile);
-  fprintf_unfiltered (outfile, ")\n");
+  fprintf_filtered (outfile, ")\n");
 
   if (psymtab->readin)
     {
@@ -1012,9 +936,9 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
     }
 
   fprintf_filtered (outfile, "  Symbols cover text addresses ");
-  fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
+  fputs_filtered (paddress (gdbarch, psymtab->text_low (objfile)), outfile);
   fprintf_filtered (outfile, "-");
-  fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
+  fputs_filtered (paddress (gdbarch, psymtab->text_high (objfile)), outfile);
   fprintf_filtered (outfile, "\n");
   fprintf_filtered (outfile, "  Address map supported - %s.\n",
                    psymtab->psymtabs_addrmap_supported ? "yes" : "no");
@@ -1205,12 +1129,11 @@ psymtab_to_fullname (struct partial_symtab *ps)
   if (ps->fullname == NULL)
     {
       gdb::unique_xmalloc_ptr<char> fullname;
-      int fd = find_and_open_source (ps->filename, ps->dirname, &fullname);
+      scoped_fd fd = find_and_open_source (ps->filename, ps->dirname,
+                                          &fullname);
       ps->fullname = fullname.release ();
 
-      if (fd >= 0)
-       close (fd);
-      else
+      if (fd.get () < 0)
        {
          /* rewrite_source_path would be applied by find_and_open_source, we
             should report the pathname where GDB tried to find the file.  */
@@ -1306,7 +1229,9 @@ psym_map_matching_symbols (struct objfile *objfile,
 
 static bool
 recursively_search_psymtabs
-  (struct partial_symtab *ps, struct objfile *objfile, enum search_domain domain,
+  (struct partial_symtab *ps,
+   struct objfile *objfile,
+   enum search_domain domain,
    const lookup_name_info &lookup_name,
    gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher)
 {
@@ -1548,7 +1473,6 @@ const struct quick_symbol_functions psym_functions =
   psym_lookup_symbol,
   psym_print_stats,
   psym_dump,
-  psym_relocate,
   psym_expand_symtabs_for_function,
   psym_expand_all_symtabs,
   psym_expand_symtabs_with_fullname,
@@ -1594,8 +1518,8 @@ start_psymtab_common (struct objfile *objfile,
   struct partial_symtab *psymtab;
 
   psymtab = allocate_psymtab (filename, objfile);
-  psymtab->textlow = textlow;
-  psymtab->texthigh = psymtab->textlow;                /* default */
+  psymtab->set_text_low (textlow);
+  psymtab->set_text_high (psymtab->raw_text_low ()); /* default */
   psymtab->globals_offset = global_psymbols.size ();
   psymtab->statics_offset = static_psymbols.size ();
   return psymtab;
@@ -1715,14 +1639,15 @@ static struct partial_symbol *
 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
                       domain_enum domain,
                       enum address_class theclass,
+                      short section,
                       CORE_ADDR coreaddr,
                       enum language language, struct objfile *objfile,
                       int *added)
 {
   struct partial_symbol psymbol;
 
-  psymbol.set_address (coreaddr);
-  psymbol.section = -1;
+  psymbol.set_unrelocated_address (coreaddr);
+  psymbol.section = section;
   psymbol.domain = domain;
   psymbol.aclass = theclass;
 
@@ -1756,6 +1681,7 @@ void
 add_psymbol_to_list (const char *name, int namelength, int copy_name,
                     domain_enum domain,
                     enum address_class theclass,
+                    short section,
                     std::vector<partial_symbol *> *list,
                     CORE_ADDR coreaddr,
                     enum language language, struct objfile *objfile)
@@ -1766,7 +1692,7 @@ add_psymbol_to_list (const char *name, int namelength, int copy_name,
 
   /* Stash the partial symbol away in the cache.  */
   psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, theclass,
-                               coreaddr, language, objfile, &added);
+                               section, coreaddr, language, objfile, &added);
 
   /* Do not duplicate global partial symbols.  */
   if (list == &objfile->global_psymbols
@@ -1830,13 +1756,13 @@ allocate_psymtab (const char *filename, struct objfile *objfile)
        {
          xfree (last_objfile_name);
          last_objfile_name = xstrdup (objfile_name (objfile));
-         fprintf_unfiltered (gdb_stdlog,
-                             "Creating one or more psymtabs for objfile %s ...\n",
-                             last_objfile_name);
+         fprintf_filtered (gdb_stdlog,
+                           "Creating one or more psymtabs for objfile %s ...\n",
+                           last_objfile_name);
        }
-      fprintf_unfiltered (gdb_stdlog,
-                         "Created psymtab %s for module %s.\n",
-                         host_address_to_string (psymtab), filename);
+      fprintf_filtered (gdb_stdlog,
+                       "Created psymtab %s for module %s.\n",
+                       host_address_to_string (psymtab), filename);
     }
 
   return psymtab;
@@ -2147,10 +2073,10 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
                               psymtab->fullname
                               ? psymtab->fullname : "(null)");
              printf_filtered ("    text addresses ");
-             fputs_filtered (paddress (gdbarch, psymtab->textlow),
+             fputs_filtered (paddress (gdbarch, psymtab->text_low (objfile)),
                              gdb_stdout);
              printf_filtered (" -- ");
-             fputs_filtered (paddress (gdbarch, psymtab->texthigh),
+             fputs_filtered (paddress (gdbarch, psymtab->text_high (objfile)),
                              gdb_stdout);
              printf_filtered ("\n");
              printf_filtered ("    psymtabs_addrmap_supported %s\n",
@@ -2230,14 +2156,16 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     cust = ps->compunit_symtab;
 
     /* First do some checks that don't require the associated symtab.  */
-    if (ps->texthigh < ps->textlow)
+    if (ps->text_high (objfile) < ps->text_low (objfile))
       {
        printf_filtered ("Psymtab ");
        puts_filtered (ps->filename);
        printf_filtered (" covers bad range ");
-       fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
+       fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+                       gdb_stdout);
        printf_filtered (" - ");
-       fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
+       fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+                       gdb_stdout);
        printf_filtered ("\n");
        continue;
       }
@@ -2282,15 +2210,18 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
          }
        psym++;
       }
-    if (ps->texthigh != 0
-       && (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b)))
+    if (ps->raw_text_high () != 0
+       && (ps->text_low (objfile) < BLOCK_START (b)
+           || ps->text_high (objfile) > BLOCK_END (b)))
       {
        printf_filtered ("Psymtab ");
        puts_filtered (ps->filename);
        printf_filtered (" covers ");
-       fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
+       fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+                       gdb_stdout);
        printf_filtered (" - ");
-       fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
+       fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+                       gdb_stdout);
        printf_filtered (" but symtab covers only ");
        fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
        printf_filtered (" - ");