Fix NULL objfile's section_offsets dereference during symbol load.
authorJoel Brobecker <brobecker@gnat.com>
Sat, 15 Dec 2012 13:10:50 +0000 (13:10 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Sat, 15 Dec 2012 13:10:50 +0000 (13:10 +0000)
gdb/ChangeLog:

        * symfile.c (syms_from_objfile_1): Renames syms_from_objfile.
        Remove call to init_entry_point_info.  Add OBJFILE's
        section_offsets and num_sections initialization.  Add note
        about entry info in the function documentation.
        (syms_from_objfile): New function.
        * coffread.c (coff_symfile_init): Remove call to
        init_entry_point_info.
        * machoread.c (macho_symfile_init): Likewise.
        * xcoffread.c(xcoff_symfile_init): Likewise.

gdb/ChangeLog
gdb/coffread.c
gdb/machoread.c
gdb/symfile.c
gdb/xcoffread.c

index ea24d83996740665087f868115c732fdc061773e..aeb7b49334c8761e3fe1e8b94d400821e0f0f7a6 100644 (file)
@@ -1,3 +1,15 @@
+2012-12-15  Joel Brobecker  <brobecker@adacore.com>
+
+       * symfile.c (syms_from_objfile_1): Renames syms_from_objfile.
+       Remove call to init_entry_point_info.  Add OBJFILE's
+       section_offsets and num_sections initialization.  Add note
+       about entry info in the function documentation.
+       (syms_from_objfile): New function.
+       * coffread.c (coff_symfile_init): Remove call to
+       init_entry_point_info.
+       * machoread.c (macho_symfile_init): Likewise.
+       * xcoffread.c(xcoff_symfile_init): Likewise.
+
 2012-12-15  Yao Qi  <yao@codesourcery.com>
 
        * remote-notif.c (_initialize_notif): Add new commands
index 56ed5aea0d156b21fde994cab1e27a434a326e97..398e61c05b3a1803cad1d0d1eb49926fdcd22ca2 100644 (file)
@@ -469,8 +469,6 @@ coff_symfile_init (struct objfile *objfile)
      find this causes a significant slowdown in gdb then we could
      set it in the debug symbol readers only when necessary.  */
   objfile->flags |= OBJF_REORDERED;
-
-  init_entry_point_info (objfile);
 }
 
 /* This function is called for every section; it finds the outer
index 6a6eaa1fa9d7f46583f1aad9ebeec963e7ddf624..c0e6d9097267a0d9847d0f15e2f1f640dd305b0a 100644 (file)
@@ -79,7 +79,6 @@ static void
 macho_symfile_init (struct objfile *objfile)
 {
   objfile->flags |= OBJF_REORDERED;
-  init_entry_point_info (objfile);
 }
 
 /*  Add a new OSO to the vector of OSO to load.  */
index 6e09cbd1a8ed78e237d3b5ffa1e85cf8d7874095..2a152938980fcd1be3366dd54021139d4f20b57c 100644 (file)
@@ -896,6 +896,8 @@ read_symbols (struct objfile *objfile, int add_flags)
 /* Process a symbol file, as either the main file or as a dynamically
    loaded file.
 
+   This function does not set the OBJFILE's entry-point info.
+
    OBJFILE is where the symbols are to be read from.
 
    ADDRS is the list of section load addresses.  If the user has given
@@ -923,12 +925,12 @@ read_symbols (struct objfile *objfile, int add_flags)
    an extra symbol file such as dynamically loaded code, and wether
    breakpoint reset should be deferred.  */
 
-void
-syms_from_objfile (struct objfile *objfile,
-                   struct section_addr_info *addrs,
-                   struct section_offsets *offsets,
-                   int num_offsets,
-                  int add_flags)
+static void
+syms_from_objfile_1 (struct objfile *objfile,
+                    struct section_addr_info *addrs,
+                    struct section_offsets *offsets,
+                    int num_offsets,
+                    int add_flags)
 {
   struct section_addr_info *local_addr = NULL;
   struct cleanup *old_chain;
@@ -936,11 +938,21 @@ syms_from_objfile (struct objfile *objfile,
 
   gdb_assert (! (addrs && offsets));
 
-  init_entry_point_info (objfile);
   objfile->sf = find_sym_fns (objfile->obfd);
 
   if (objfile->sf == NULL)
-    return;    /* No symbols.  */
+    {
+      /* No symbols to load, but we still need to make sure
+        that the section_offsets table is allocated.  */
+      int num_sections = bfd_count_sections (objfile->obfd);
+      size_t size = SIZEOF_N_SECTION_OFFSETS (num_offsets);
+
+      objfile->num_sections = num_sections;
+      objfile->section_offsets
+        = obstack_alloc (&objfile->objfile_obstack, size);
+      memset (objfile->section_offsets, 0, size);
+      return;
+    }
 
   /* Make sure that partially constructed symbol tables will be cleaned up
      if an error occurs during symbol reading.  */
@@ -1021,6 +1033,20 @@ syms_from_objfile (struct objfile *objfile,
   xfree (local_addr);
 }
 
+/* Same as syms_from_objfile_1, but also initializes the objfile
+   entry-point info.  */
+
+void
+syms_from_objfile (struct objfile *objfile,
+                  struct section_addr_info *addrs,
+                  struct section_offsets *offsets,
+                  int num_offsets,
+                  int add_flags)
+{
+  syms_from_objfile_1 (objfile, addrs, offsets, num_offsets, add_flags);
+  init_entry_point_info (objfile);
+}
+
 /* Perform required actions after either reading in the initial
    symbols for a new objfile, or mapping in the symbols from a reusable
    objfile.  ADD_FLAGS is a bitmask of enum symfile_add_flags.  */
index ee47f6c6b93133125dc5bc5d270a8189cfb6fe7f..10c93cce109629a429c8994c6fc78295a30ba8b6 100644 (file)
@@ -1922,8 +1922,6 @@ xcoff_symfile_init (struct objfile *objfile)
      find this causes a significant slowdown in gdb then we could
      set it in the debug symbol readers only when necessary.  */
   objfile->flags |= OBJF_REORDERED;
-
-  init_entry_point_info (objfile);
 }
 
 /* Perform any local cleanups required when we are done with a particular
This page took 0.052613 seconds and 4 git commands to generate.