[RFC,1/3] gdb: remove symfile_find_segment_sections and part of init_objfile_sect_indices

Message ID 20200519161431.1577904-2-simon.marchi@efficios.com
State New
Headers show
Series
  • What to do with objfiles with no .text section?
Related show

Commit Message

Simon Marchi via Gdb-patches May 19, 2020, 4:14 p.m.
See explanation in the cover letter.
---
 gdb/symfile.c | 84 +--------------------------------------------------
 1 file changed, 1 insertion(+), 83 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 946443f07a89..62ad704f27d3 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -106,8 +106,6 @@  static int simple_read_overlay_table (void);
 
 static int simple_overlay_update_1 (struct obj_section *);
 
-static void symfile_find_segment_sections (struct objfile *objfile);
-
 /* List of all available sym_fns.  On gdb startup, each object file reader
    calls add_symtab_fns() to register information on each format it is
    prepared to read.  */
@@ -280,7 +278,6 @@  static void
 init_objfile_sect_indices (struct objfile *objfile)
 {
   asection *sect;
-  int i;
 
   sect = bfd_get_section_by_name (objfile->obfd, ".text");
   if (sect)
@@ -297,42 +294,6 @@  init_objfile_sect_indices (struct objfile *objfile)
   sect = bfd_get_section_by_name (objfile->obfd, ".rodata");
   if (sect)
     objfile->sect_index_rodata = sect->index;
-
-  /* This is where things get really weird...  We MUST have valid
-     indices for the various sect_index_* members or gdb will abort.
-     So if for example, there is no ".text" section, we have to
-     accomodate that.  First, check for a file with the standard
-     one or two segments.  */
-
-  symfile_find_segment_sections (objfile);
-
-  /* Except when explicitly adding symbol files at some address,
-     section_offsets contains nothing but zeros, so it doesn't matter
-     which slot in section_offsets the individual sect_index_* members
-     index into.  So if they are all zero, it is safe to just point
-     all the currently uninitialized indices to the first slot.  But
-     beware: if this is the main executable, it may be relocated
-     later, e.g. by the remote qOffsets packet, and then this will
-     be wrong!  That's why we try segments first.  */
-
-  for (i = 0; i < objfile->section_offsets.size (); i++)
-    {
-      if (objfile->section_offsets[i] != 0)
-	{
-	  break;
-	}
-    }
-  if (i == objfile->section_offsets.size ())
-    {
-      if (objfile->sect_index_text == -1)
-	objfile->sect_index_text = 0;
-      if (objfile->sect_index_data == -1)
-	objfile->sect_index_data = 0;
-      if (objfile->sect_index_bss == -1)
-	objfile->sect_index_bss = 0;
-      if (objfile->sect_index_rodata == -1)
-	objfile->sect_index_rodata = 0;
-    }
 }
 
 /* The arguments to place_section.  */
@@ -629,7 +590,7 @@  addr_info_make_relative (section_addr_info *addrs, bfd *abfd)
    of how to represent it for fast symbol reading.  This is the default
    version of the sym_fns.sym_offsets function for symbol readers that
    don't need to do anything special.  It allocates a section_offsets table
-   for the objectfile OBJFILE and stuffs ADDR into all of the offsets.  */
+   for the object file OBJFILE and stuffs ADDR into all of the offsets.  */
 
 void
 default_symfile_offsets (struct objfile *objfile,
@@ -3697,49 +3658,6 @@  symfile_map_offsets_to_segments (bfd *abfd,
   return 1;
 }
 
-static void
-symfile_find_segment_sections (struct objfile *objfile)
-{
-  bfd *abfd = objfile->obfd;
-  int i;
-  asection *sect;
-  struct symfile_segment_data *data;
-
-  data = get_symfile_segment_data (objfile->obfd);
-  if (data == NULL)
-    return;
-
-  if (data->num_segments != 1 && data->num_segments != 2)
-    {
-      free_symfile_segment_data (data);
-      return;
-    }
-
-  for (i = 0, sect = abfd->sections; sect != NULL; i++, sect = sect->next)
-    {
-      int which = data->segment_info[i];
-
-      if (which == 1)
-	{
-	  if (objfile->sect_index_text == -1)
-	    objfile->sect_index_text = sect->index;
-
-	  if (objfile->sect_index_rodata == -1)
-	    objfile->sect_index_rodata = sect->index;
-	}
-      else if (which == 2)
-	{
-	  if (objfile->sect_index_data == -1)
-	    objfile->sect_index_data = sect->index;
-
-	  if (objfile->sect_index_bss == -1)
-	    objfile->sect_index_bss = sect->index;
-	}
-    }
-
-  free_symfile_segment_data (data);
-}
-
 /* Listen for free_objfile events.  */
 
 static void