* coffread.c (cs_to_section): Use gdb_bfd_section_index.
authorTom Tromey <tromey@redhat.com>
Mon, 8 Apr 2013 20:04:42 +0000 (20:04 +0000)
committerTom Tromey <tromey@redhat.com>
Mon, 8 Apr 2013 20:04:42 +0000 (20:04 +0000)
* elfread.c (record_minimal_symbol, elf_symtab_read): Use
gdb_bfd_section_index.
* gdb_bfd.c (gdb_bfd_section_index, gdb_bfd_count_sections):
New functions.
* gdb_bfd.h (gdb_bfd_section_index, gdb_bfd_count_sections):
Declare.
* machoread.c (macho_symtab_add_minsym, macho_symfile_offsets):
Update.
* objfiles.c (add_to_objfile_sections_full): New function.
(add_to_objfile_sections): Use it.
(build_section_table): Rewrite.
(objfile_relocate1): Use gdb_bfd_section_index.  Update.
* objfiles.h (obj_section_offset): Use gdb_bfd_section_index.
(struct objfile) <sections>: Update comment.
(ALL_OBJFILE_OSECTIONS): Skip sections where the_bfd_section
is NULL.
(ALL_OBJSECTIONS): Use it.
* solib-dsbt.c (dsbt_relocate_main_executable): Update.
* solib-frv.c (frv_relocate_main_executable): Update.
* solib-target.c (solib_target_relocate_section_addresses):
Use gdb_bfd_section_index.
* symfile.c (build_section_addr_info_from_section_table):
Use gdb_bfd_section_index.
(build_section_addr_info_from_bfd, place_section): Likewise.
* symtab.c (fixup_section): Update.
* xcoffread.c (find_targ_sec): Use gdb_bfd_section_index.

14 files changed:
gdb/ChangeLog
gdb/coffread.c
gdb/elfread.c
gdb/gdb_bfd.c
gdb/gdb_bfd.h
gdb/machoread.c
gdb/objfiles.c
gdb/objfiles.h
gdb/solib-dsbt.c
gdb/solib-frv.c
gdb/solib-target.c
gdb/symfile.c
gdb/symtab.c
gdb/xcoffread.c

index 793aa91e779027fefdd4bc43e39e69bca36118a7..bfb7c6b0471bade85ce54233831b4cca66284ec0 100644 (file)
@@ -1,3 +1,33 @@
+2013-04-08  Tom Tromey  <tromey@redhat.com>
+
+       * coffread.c (cs_to_section): Use gdb_bfd_section_index.
+       * elfread.c (record_minimal_symbol, elf_symtab_read): Use
+       gdb_bfd_section_index.
+       * gdb_bfd.c (gdb_bfd_section_index, gdb_bfd_count_sections):
+       New functions.
+       * gdb_bfd.h (gdb_bfd_section_index, gdb_bfd_count_sections):
+       Declare.
+       * machoread.c (macho_symtab_add_minsym, macho_symfile_offsets):
+       Update.
+       * objfiles.c (add_to_objfile_sections_full): New function.
+       (add_to_objfile_sections): Use it.
+       (build_section_table): Rewrite.
+       (objfile_relocate1): Use gdb_bfd_section_index.  Update.
+       * objfiles.h (obj_section_offset): Use gdb_bfd_section_index.
+       (struct objfile) <sections>: Update comment.
+       (ALL_OBJFILE_OSECTIONS): Skip sections where the_bfd_section
+       is NULL.
+       (ALL_OBJSECTIONS): Use it.
+       * solib-dsbt.c (dsbt_relocate_main_executable): Update.
+       * solib-frv.c (frv_relocate_main_executable): Update.
+       * solib-target.c (solib_target_relocate_section_addresses):
+       Use gdb_bfd_section_index.
+       * symfile.c (build_section_addr_info_from_section_table):
+       Use gdb_bfd_section_index.
+       (build_section_addr_info_from_bfd, place_section): Likewise.
+       * symtab.c (fixup_section): Update.
+       * xcoffread.c (find_targ_sec): Use gdb_bfd_section_index.
+
 2013-04-08  Tom Tromey  <tromey@redhat.com>
 
        * minsyms.h (struct bound_minimal_symbol): New.
index f4f2afd05f45a60cc8f7b47f9201dbca5b11c957..9076262566bd28eceaa4555c923c8bf9200f6dcd 100644 (file)
@@ -297,7 +297,7 @@ cs_to_section (struct coff_symbol *cs, struct objfile *objfile)
 
   if (sect == NULL)
     return SECT_OFF_TEXT (objfile);
-  return sect->index;
+  return gdb_bfd_section_index (objfile->obfd, sect);
 }
 
 /* Return the address of the section of a COFF symbol.  */
index 866e496da542e1316b9bb137e3e344b361f7b851..668b9745dcd7d0bd7ffd0a5a4cada6a92325447b 100644 (file)
@@ -208,7 +208,9 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
     address = gdbarch_addr_bits_remove (gdbarch, address);
 
   return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
-                                         ms_type, bfd_section->index,
+                                         ms_type,
+                                         gdb_bfd_section_index (objfile->obfd,
+                                                                bfd_section),
                                          bfd_section, objfile);
 }
 
@@ -271,7 +273,8 @@ elf_symtab_read (struct objfile *objfile, int type,
          continue;
        }
 
-      offset = ANOFFSET (objfile->section_offsets, sym->section->index);
+      offset = ANOFFSET (objfile->section_offsets,
+                        gdb_bfd_section_index (objfile->obfd, sym->section));
       if (type == ST_DYNAMIC
          && sym->section == bfd_und_section_ptr
          && (sym->flags & BSF_FUNCTION))
@@ -326,7 +329,8 @@ elf_symtab_read (struct objfile *objfile, int type,
              && bfd_get_section_by_name (abfd, ".plt") != NULL)
            continue;
 
-         symaddr += ANOFFSET (objfile->section_offsets, sect->index);
+         symaddr += ANOFFSET (objfile->section_offsets,
+                              gdb_bfd_section_index (objfile->obfd, sect));
 
          msym = record_minimal_symbol
            (sym->name, strlen (sym->name), copy_names,
index 53c3a1244e075e117e6fa1d696fbd4d73a44062b..e7cd5237943c6899e299f7030394bc197de92631 100644 (file)
@@ -605,6 +605,36 @@ gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
 
 \f
 
+gdb_static_assert (ARRAY_SIZE (_bfd_std_section) == 4);
+
+/* See gdb_bfd.h.  */
+
+int
+gdb_bfd_section_index (bfd *abfd, asection *section)
+{
+  if (section == NULL)
+    return -1;
+  else if (section == bfd_com_section_ptr)
+    return bfd_count_sections (abfd) + 1;
+  else if (section == bfd_und_section_ptr)
+    return bfd_count_sections (abfd) + 2;
+  else if (section == bfd_abs_section_ptr)
+    return bfd_count_sections (abfd) + 3;
+  else if (section == bfd_ind_section_ptr)
+    return bfd_count_sections (abfd) + 4;
+  return section->index;
+}
+
+/* See gdb_bfd.h.  */
+
+int
+gdb_bfd_count_sections (bfd *abfd)
+{
+  return bfd_count_sections (abfd) + 4;
+}
+
+\f
+
 /* A callback for htab_traverse that prints a single BFD.  */
 
 static int
index 1e74bfe608d3b4f7e9f1cba2132aa3cd2c1bc4ab..ca2eddc142096f82efc735a172a406b5ce4bddfe 100644 (file)
@@ -121,4 +121,18 @@ bfd *gdb_bfd_openr_next_archived_file (bfd *archive, bfd *previous);
 
 bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
 
+\f
+
+/* Return the index of the BFD section SECTION.  Ordinarily this is
+   just the section's index, but for some special sections, like
+   bfd_com_section_ptr, it will be a synthesized value.  */
+
+int gdb_bfd_section_index (bfd *abfd, asection *section);
+
+
+/* Like bfd_count_sections, but include any possible global sections,
+   like bfd_com_section_ptr.  */
+
+int gdb_bfd_count_sections (bfd *abfd);
+
 #endif /* GDB_BFD_H */
index eff8bdf054ec76721818e46fbeb202dee19b50b7..54d8e31df25ad264a8ac163fecfe840d97efdcf6 100644 (file)
@@ -116,7 +116,8 @@ macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
       CORE_ADDR offset;
       enum minimal_symbol_type ms_type;
 
-      offset = ANOFFSET (objfile->section_offsets, sym->section->index);
+      offset = ANOFFSET (objfile->section_offsets,
+                        gdb_bfd_section_index (objfile->obfd, sym->section));
 
       /* Bfd symbols are section relative.  */
       symaddr = sym->value + sym->section->vma;
@@ -164,8 +165,9 @@ macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
         return;        /* Skip this symbol.  */
 
       prim_record_minimal_symbol_and_info
-        (sym->name, symaddr, ms_type, sym->section->index,
-         sym->section, objfile);
+        (sym->name, symaddr, ms_type,
+        gdb_bfd_section_index (objfile->obfd, sym->section),
+        sym->section, objfile);
     }
 }
 
@@ -1008,7 +1010,7 @@ macho_symfile_offsets (struct objfile *objfile,
   ALL_OBJFILE_OSECTIONS (objfile, osect)
     {
       const char *bfd_sect_name = osect->the_bfd_section->name;
-      int sect_index = osect->the_bfd_section->index;
+      int sect_index = osect - objfile->sections;;
 
       if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
        bfd_sect_name += 11;
index 3017fdfc7a85e8e18d4a9d8cb7dd69d6d078422c..93b7ba7b2ca529eef2ab0963de262fd6cf4855a5 100644 (file)
@@ -181,51 +181,56 @@ set_objfile_per_bfd (struct objfile *objfile)
    of the table (objfile->sections) and to the first location after
    the end of the table (objfile->sections_end).  */
 
+static void
+add_to_objfile_sections_full (struct bfd *abfd, struct bfd_section *asect,
+                             struct objfile *objfile, int force)
+{
+  struct obj_section *section;
+
+  if (!force)
+    {
+      flagword aflag;
+
+      aflag = bfd_get_section_flags (abfd, asect);
+      if (!(aflag & SEC_ALLOC))
+       return;
+    }
+
+  section = &objfile->sections[gdb_bfd_section_index (abfd, asect)];
+  section->objfile = objfile;
+  section->the_bfd_section = asect;
+  section->ovly_mapped = 0;
+}
+
 static void
 add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
                         void *objfilep)
 {
-  struct objfile *objfile = (struct objfile *) objfilep;
-  struct obj_section section;
-  flagword aflag;
-
-  aflag = bfd_get_section_flags (abfd, asect);
-  if (!(aflag & SEC_ALLOC))
-    return;
-  if (bfd_section_size (abfd, asect) == 0)
-    return;
-
-  section.objfile = objfile;
-  section.the_bfd_section = asect;
-  section.ovly_mapped = 0;
-  obstack_grow (&objfile->objfile_obstack,
-               (char *) &section, sizeof (section));
-  objfile->sections_end
-    = (struct obj_section *) (((size_t) objfile->sections_end) + 1);
+  add_to_objfile_sections_full (abfd, asect, objfilep, 0);
 }
 
 /* Builds a section table for OBJFILE.
 
-   Note that while we are building the table, which goes into the
-   objfile obstack, we hijack the sections_end pointer to instead hold
-   a count of the number of sections.  When bfd_map_over_sections
-   returns, this count is used to compute the pointer to the end of
-   the sections table, which then overwrites the count.
-
-   Also note that the OFFSET and OVLY_MAPPED in each table entry
-   are initialized to zero.
-
-   Also note that if anything else writes to the objfile obstack while
-   we are building the table, we're pretty much hosed.  */
+   Note that the OFFSET and OVLY_MAPPED in each table entry are
+   initialized to zero.  */
 
 void
 build_objfile_section_table (struct objfile *objfile)
 {
-  objfile->sections_end = 0;
+  int count = gdb_bfd_count_sections (objfile->obfd);
+
+  objfile->sections = OBSTACK_CALLOC (&objfile->objfile_obstack,
+                                     count,
+                                     struct obj_section);
+  objfile->sections_end = (objfile->sections + count);
   bfd_map_over_sections (objfile->obfd,
                         add_to_objfile_sections, (void *) objfile);
-  objfile->sections = obstack_finish (&objfile->objfile_obstack);
-  objfile->sections_end = objfile->sections + (size_t) objfile->sections_end;
+
+  /* See gdb_bfd_section_index.  */
+  add_to_objfile_sections_full (objfile->obfd, bfd_com_section_ptr, objfile, 1);
+  add_to_objfile_sections_full (objfile->obfd, bfd_und_section_ptr, objfile, 1);
+  add_to_objfile_sections_full (objfile->obfd, bfd_abs_section_ptr, objfile, 1);
+  add_to_objfile_sections_full (objfile->obfd, bfd_ind_section_ptr, objfile, 1);
 }
 
 /* Given a pointer to an initialized bfd (ABFD) and some flag bits
@@ -804,7 +809,11 @@ objfile_relocate1 (struct objfile *objfile,
       struct obj_section *s;
       s = find_pc_section (objfile->ei.entry_point);
       if (s)
-        objfile->ei.entry_point += ANOFFSET (delta, s->the_bfd_section->index);
+       {
+         int idx = gdb_bfd_section_index (objfile->obfd, s->the_bfd_section);
+
+         objfile->ei.entry_point += ANOFFSET (delta, idx);
+       }
       else
         objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
     }
@@ -822,7 +831,7 @@ objfile_relocate1 (struct objfile *objfile,
   /* Update the table in exec_ops, used to read memory.  */
   ALL_OBJFILE_OSECTIONS (objfile, s)
     {
-      int idx = s->the_bfd_section->index;
+      int idx = s - objfile->sections;
 
       exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
                                obj_section_addr (s));
index 9646bbd3604f10eb168c18c28fb74737dfc94626..1fbb2558a233f7731af181f7a439c72cab1f4556 100644 (file)
@@ -24,6 +24,7 @@
 #include "symfile.h"           /* For struct psymbol_allocation_list.  */
 #include "progspace.h"
 #include "registry.h"
+#include "gdb_bfd.h"
 
 struct bcache;
 struct htab;
@@ -123,7 +124,7 @@ struct obj_section
 
 /* Relocation offset applied to S.  */
 #define obj_section_offset(s)                                          \
-  (((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index])
+  (((s)->objfile->section_offsets)->offsets[gdb_bfd_section_index ((s)->objfile->obfd, (s)->the_bfd_section)])
 
 /* The memory address of section S (vma + offset).  */
 #define obj_section_addr(s)                                            \
@@ -349,9 +350,10 @@ struct objfile
        among other things, is used to map pc addresses into sections.
        SECTIONS points to the first entry in the table, and
        SECTIONS_END points to the first location past the last entry
-       in the table.  The table is stored on the objfile_obstack.
-       There is no particular order to the sections in this table, and it
-       only contains sections we care about (e.g. non-empty, SEC_ALLOC).  */
+       in the table.  The table is stored on the objfile_obstack.  The
+       sections are indexed by the BFD section index; but the
+       structure data is only valid for certain sections
+       (e.g. non-empty, SEC_ALLOC).  */
 
     struct obj_section *sections, *sections_end;
 
@@ -576,7 +578,12 @@ extern void default_iterate_over_objfiles_in_search_order
     ALL_OBJFILE_MSYMBOLS (objfile, m)
 
 #define ALL_OBJFILE_OSECTIONS(objfile, osect)  \
-  for (osect = objfile->sections; osect < objfile->sections_end; osect++)
+  for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
+    if (osect->the_bfd_section == NULL)                                        \
+      {                                                                        \
+       /* Nothing.  */                                                 \
+      }                                                                        \
+    else
 
 /* Traverse all obj_sections in all objfiles in the current program
    space.
@@ -612,9 +619,7 @@ extern void default_iterate_over_objfiles_in_search_order
        ? ((objfile) = (objfile)->next,                                 \
           (objfile) != NULL ? (osect) = (objfile)->sections_end : 0)   \
        : 0))                                                           \
-    for ((osect) = (objfile)->sections;                                        \
-        (osect) < (objfile)->sections_end;                             \
-        (osect)++)
+    ALL_OBJFILE_OSECTIONS (objfile, osect)
 
 #define SECT_OFF_DATA(objfile) \
      ((objfile->sect_index_data == -1) \
index ea2acd1d27773d4fed41fbc3eaf13e36b138ec53..e2822c1b0c6887a5bc581b325723cae38daa438b 100644 (file)
@@ -1054,7 +1054,7 @@ dsbt_relocate_main_executable (void)
       int osect_idx;
       int seg;
 
-      osect_idx = osect->the_bfd_section->index;
+      osect_idx = osect - symfile_objfile->sections;
 
       /* Current address of section.  */
       addr = obj_section_addr (osect);
index 57e418f0cbca522a125d6b221c3de04de0012d6f..52588bc880dfe07fb030be0aee986dc506e2348e 100644 (file)
@@ -812,7 +812,7 @@ frv_relocate_main_executable (void)
       int osect_idx;
       int seg;
       
-      osect_idx = osect->the_bfd_section->index;
+      osect_idx = osect - symfile_objfile->sections;
 
       /* Current address of section.  */
       addr = obj_section_addr (osect);
index d897bc0f278a1f5547f19320c8c9388e4d5c230a..0ad29ba32355647bdda8abe0c25fa7e5a0a86735 100644 (file)
@@ -456,7 +456,8 @@ Could not relocate shared library \"%s\": bad offsets"), so->so_name);
        }
     }
 
-  offset = so->lm_info->offsets->offsets[sec->the_bfd_section->index];
+  offset = so->lm_info->offsets->offsets[gdb_bfd_section_index (sec->bfd,
+                                                               sec->the_bfd_section)];
   sec->addr += offset;
   sec->endaddr += offset;
 }
index edb05e4e6ddaedd7077c053c011432a710f8dbaa..3e66bd101c9cbcca2d3ab182a4e828d450b09f4e 100644 (file)
@@ -237,7 +237,8 @@ build_section_addr_info_from_section_table (const struct target_section *start,
          sap->other[oidx].addr = stp->addr;
          sap->other[oidx].name
            = xstrdup (bfd_section_name (stp->bfd, stp->the_bfd_section));
-         sap->other[oidx].sectindex = stp->the_bfd_section->index;
+         sap->other[oidx].sectindex
+           = gdb_bfd_section_index (stp->bfd, stp->the_bfd_section);
          oidx++;
        }
     }
@@ -262,7 +263,7 @@ build_section_addr_info_from_bfd (bfd *abfd)
       {
        sap->other[i].addr = bfd_get_section_vma (abfd, sec);
        sap->other[i].name = xstrdup (bfd_get_section_name (abfd, sec));
-       sap->other[i].sectindex = sec->index;
+       sap->other[i].sectindex = gdb_bfd_section_index (abfd, sec);
        i++;
       }
 
@@ -389,7 +390,7 @@ place_section (bfd *abfd, asection *sect, void *obj)
     return;
 
   /* If the user specified an offset, honor it.  */
-  if (offsets[sect->index] != 0)
+  if (offsets[gdb_bfd_section_index (abfd, sect)] != 0)
     return;
 
   /* Otherwise, let's try to find a place for the section.  */
@@ -433,7 +434,7 @@ place_section (bfd *abfd, asection *sect, void *obj)
     }
   while (!done);
 
-  offsets[sect->index] = start_addr;
+  offsets[gdb_bfd_section_index (abfd, sect)] = start_addr;
   arg->lowest = start_addr + bfd_get_section_size (sect);
 }
 
index 1922d9bf539c9701fcaaf0e15b5624886eabcad6..252650355a2d4fa622ea4a05c33e551ded18ef6a 100644 (file)
@@ -1064,7 +1064,7 @@ fixup_section (struct general_symbol_info *ginfo,
 
       ALL_OBJFILE_OSECTIONS (objfile, s)
        {
-         int idx = s->the_bfd_section->index;
+         int idx = s - objfile->sections;
          CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx);
 
          if (obj_section_addr (s) - offset <= addr
index 45cb8f41be808b175250c917282bf4c5a18b2862..e6a562d13c90f5b235d62b52646c3f5d2fc96cd9 100644 (file)
@@ -278,7 +278,7 @@ find_targ_sec (bfd *abfd, asection *sect, void *obj)
       else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
        *args->resultp = SECT_OFF_DATA (objfile);
       else
-       *args->resultp = sect->index;
+       *args->resultp = gdb_bfd_section_index (abfd, sect);
       *args->bfd_sect = sect;
     }
 }
This page took 0.037665 seconds and 4 git commands to generate.