public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-remove-obj_section: use a synthetic BFD section index when needed
@ 2013-01-08 21:57 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2013-01-08 21:57 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-remove-obj_section has been updated
       via  e418f5299e89e5f11909a87134d2509150e1f20d (commit)
       via  d6fa6818afb56750169fa78663baa9a2867d74bc (commit)
      from  6e53645cf8a5770ef3f83408bc97bfb50e52550f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit e418f5299e89e5f11909a87134d2509150e1f20d
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Jan 8 14:23:27 2013 -0700

    use a synthetic BFD section index when needed
    
    BFD may report a symbol belonging to one of the special "std"
    sections, like bfd_com_section_ptr.  These sections have section index
    0 and are not associated with a particular BFD.
    
    This patch introduces a new synthetic section index managed by gdb,
    then updates various users to use it instead.

commit d6fa6818afb56750169fa78663baa9a2867d74bc
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Jan 8 13:44:36 2013 -0700

    fix section computation when reading SOM
    
    fix section computation when reading SOM
    this required exposing an existing function from BFD

-----------------------------------------------------------------------

Summary of changes:
 bfd/som.c          |    4 +-
 bfd/som.h          |    3 +-
 gdb/coffread.c     |    4 +-
 gdb/elfread.c      |   12 +++++++---
 gdb/gdb_bfd.c      |   32 ++++++++++++++++++++++++++++++-
 gdb/gdb_bfd.h      |   16 ++++++++++++++-
 gdb/machoread.c    |   10 +++++---
 gdb/objfiles.c     |   53 ++++++++++++++++++++++++++++++++++++---------------
 gdb/objfiles.h     |    5 ++-
 gdb/solib-dsbt.c   |    4 +-
 gdb/solib-frv.c    |    4 +-
 gdb/solib-target.c |    5 ++-
 gdb/somread.c      |   34 +++++++++++++++++++++++++++++++-
 gdb/symfile.c      |   11 +++++----
 gdb/symtab.c       |    4 +-
 gdb/xcoffread.c    |    4 +-
 16 files changed, 155 insertions(+), 50 deletions(-)

First 500 lines of diff:
diff --git a/bfd/som.c b/bfd/som.c
index f0ef8dc..338250e 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -1,7 +1,7 @@
 /* bfd back-end for HP PA-RISC SOM objects.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
-   2012  Free Software Foundation, Inc.
+   2012, 2013  Free Software Foundation, Inc.
 
    Contributed by the Center for Software Science at the
    University of Utah.
@@ -4573,7 +4573,7 @@ som_get_symtab_upper_bound (bfd *abfd)
 
 /* Convert from a SOM subspace index to a BFD section.  */
 
-static asection *
+asection *
 bfd_section_from_som_symbol
   (bfd *abfd, struct som_external_symbol_dictionary_record *symbol)
 {
diff --git a/bfd/som.h b/bfd/som.h
index cf8dcbf..7a54249 100644
--- a/bfd/som.h
+++ b/bfd/som.h
@@ -1,6 +1,6 @@
 /* HP PA-RISC SOM object file format:  definitions internal to BFD.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001,
-   2002, 2003, 2004, 2005, 2007, 2008, 2012 Free Software Foundation, Inc.
+   2002, 2003, 2004, 2005, 2007, 2008, 2012, 2013 Free Software Foundation, Inc.
 
    Contributed by the Center for Software Science at the
    University of Utah (pa-gdb-bugs@cs.utah.edu).
@@ -234,5 +234,6 @@ void         bfd_som_set_symbol_type           (asymbol *, unsigned int);
 bfd_boolean  bfd_som_attach_aux_hdr            (bfd *, int, char *);
 int **       hppa_som_gen_reloc_type           (bfd *, int, int, enum hppa_reloc_field_selector_type_alt, int, asymbol *);
 bfd_boolean  bfd_som_attach_compilation_unit   (bfd *, const char *, const char *, const char *, const char *);
+asection *   bfd_section_from_som_symbol       (bfd *abfd, struct som_external_symbol_dictionary_record *symbol);
 
 #endif /* _SOM_H */
diff --git a/gdb/coffread.c b/gdb/coffread.c
index f78b211..7b651fb 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -1,5 +1,5 @@
 /* Read coff symbol tables and convert to internal format, for GDB.
-   Copyright (C) 1987-2005, 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 1987-2005, 2007-2013 Free Software Foundation, Inc.
    Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
 
    This file is part of GDB.
@@ -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.  */
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 4669587..fc19931 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1,6 +1,6 @@
 /* Read ELF (Executable and Linking Format) object files for GDB.
 
-   Copyright (C) 1991-2012 Free Software Foundation, Inc.
+   Copyright (C) 1991-2013 Free Software Foundation, Inc.
 
    Written by Fred Fish at Cygnus Support.
 
@@ -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),
 					  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,
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index f0e349b..cd05e12 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -1,6 +1,6 @@
 /* Definitions for BFD wrappers used by GDB.
 
-   Copyright (C) 2011, 2012
+   Copyright (C) 2011, 2012, 2013
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -549,6 +549,36 @@ gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
 
 \f
 
+gdb_static_assert (ARRAY_SIZE (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
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index bb70b27..5537c60 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -1,6 +1,6 @@
 /* Definitions for BFD wrappers used by GDB.
 
-   Copyright (C) 2011, 2012
+   Copyright (C) 2011, 2012, 2013
    Free Software Foundation, Inc.
 
    This file is part of GDB.
@@ -116,4 +116,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 */
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 7ab8c68..defb881 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -1,5 +1,5 @@
 /* Darwin support for GDB, the GNU debugger.
-   Copyright (C) 2008-2012 Free Software Foundation, Inc.
+   Copyright (C) 2008-2013 Free Software Foundation, Inc.
 
    Contributed by AdaCore.
 
@@ -117,7 +117,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;
@@ -165,7 +166,8 @@ 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, objfile);
+        (sym->name, symaddr, ms_type,
+	 gdb_bfd_section_index (objfile->obfd, sym->section), objfile);
     }
 }
 
@@ -1011,7 +1013,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;
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 9662cfb..909a991 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1,6 +1,6 @@
 /* GDB routines for manipulating objfiles.
 
-   Copyright (C) 1992-2004, 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 1992-2004, 2007-2013 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
@@ -182,25 +182,35 @@ set_objfile_per_bfd (struct objfile *objfile)
    the end of the table (objfile->sections_end).  */
 
 static void
-add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
-			 void *objfilep)
+add_to_objfile_sections_full (struct bfd *abfd, struct bfd_section *asect,
+			      struct objfile *objfile, int force)
 {
-  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;
+  if (!force)
+    {
+      flagword aflag;
+
+      aflag = bfd_get_section_flags (abfd, asect);
+      if (!(aflag & SEC_ALLOC))
+	return;
+      if (bfd_section_size (abfd, asect) == 0)
+	return;
+    }
 
-  section = &objfile->sections[asect->index];
+  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)
+{
+  add_to_objfile_sections_full (abfd, asect, objfilep, 0);
+}
+
 /* Builds a section table for OBJFILE.
 
    Note that the OFFSET and OVLY_MAPPED in each table entry are
@@ -209,13 +219,20 @@ add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
 void
 build_objfile_section_table (struct objfile *objfile)
 {
+  int count = gdb_bfd_count_sections (objfile->obfd);
+
   objfile->sections = OBSTACK_CALLOC (&objfile->objfile_obstack,
-				      bfd_count_sections (objfile->obfd),
+				      count,
 				      struct obj_section);
-  objfile->sections_end = (objfile->sections
-			   + bfd_count_sections (objfile->obfd));
+  objfile->sections_end = (objfile->sections + count);
   bfd_map_over_sections (objfile->obfd,
 			 add_to_objfile_sections, (void *) objfile);
+
+  /* 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
@@ -836,7 +853,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));
     }
@@ -854,7 +875,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));
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 7aa5939..1b56ffa 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -1,6 +1,6 @@
 /* Definitions for symbol file management in GDB.
 
-   Copyright (C) 1992-2004, 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 1992-2004, 2007-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -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)				      		\
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 9024be2..586ab8e 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -1,5 +1,5 @@
 /* Handle TIC6X (DSBT) shared libraries for GDB, the GNU Debugger.
-   Copyright (C) 2010-2012 Free Software Foundation, Inc.
+   Copyright (C) 2010-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -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);
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index d259440..d47ee9e 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -1,5 +1,5 @@
 /* Handle FR-V (FDPIC) shared libraries for GDB, the GNU Debugger.
-   Copyright (C) 2004, 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2007-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -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);
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 0f3f850..b180920 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -1,6 +1,6 @@
 /* Definitions for targets which report shared library events.
 
-   Copyright (C) 2007-2012 Free Software Foundation, Inc.
+   Copyright (C) 2007-2013 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -449,7 +449,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;
 }
diff --git a/gdb/somread.c b/gdb/somread.c
index e9822fd..28fc02b 100644
--- a/gdb/somread.c
+++ b/gdb/somread.c
@@ -1,5 +1,5 @@
 /* Read HP PA/Risc object files for GDB.
-   Copyright (C) 1991-1992, 1994-1996, 1998-2002, 2004, 2007-2012 Free
+   Copyright (C) 1991-1992, 1994-1996, 1998-2002, 2004, 2007-2013 Free
    Software Foundation, Inc.
    Written by Fred Fish at Cygnus Support.
 
@@ -107,9 +107,36 @@ som_symtab_read (bfd *abfd, struct objfile *objfile,
       unsigned int symbol_scope =
         (flags >> SOM_SYMBOL_SCOPE_SH) & SOM_SYMBOL_SCOPE_MASK;
       CORE_ADDR symbol_value = bfd_getb32 (bufp->symbol_value);
+      asection *section = NULL;
 
       QUIT;
 
+      /* Compute the section.  */
+      switch (symbol_scope)
+	{
+	case SS_EXTERNAL:
+	  if (symbol_type != ST_STORAGE)
+	    section = bfd_und_section_ptr;
+	  else
+	    section = bfd_com_section_ptr;
+	  break;
+
+	case SS_UNSAT:
+	  if (symbol_type != ST_STORAGE)
+	    section = bfd_und_section_ptr;
+	  else
+	    section = bfd_com_section_ptr;
+	  break;
+
+	case SS_UNIVERSAL:
+	  section = bfd_section_from_som_symbol (abfd, bufp);
+	  break;
+
+	case SS_LOCAL:
+	  section = bfd_section_from_som_symbol (abfd, bufp);
+	  break;
+	}
+
       switch (symbol_scope)
 	{
 	case SS_UNIVERSAL:
@@ -268,7 +295,10 @@ som_symtab_read (bfd *abfd, struct objfile *objfile,
 	error (_("Invalid symbol data; bad HP string table offset: %s"),
 	       plongest (bfd_getb32 (bufp->name)));
 
-      prim_record_minimal_symbol (symname, symbol_value, ms_type, objfile);
+      prim_record_minimal_symbol_and_info (symname, symbol_value, ms_type,
+					   gdb_bfd_section_index (objfile->obfd,
+								  section),
+					   objfile);
     }
 }
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 6e09cbd..00e63ae 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1,6 +1,6 @@
 /* Generic symbol file reading for the GNU debugger, GDB.
 
-   Copyright (C) 1990-2012 Free Software Foundation, Inc.
+   Copyright (C) 1990-2013 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
@@ -291,7 +291,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++;
 	}


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-01-08 21:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-08 21:57 [SCM] archer-tromey-remove-obj_section: use a synthetic BFD section index when needed tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).