* elfread.c (elf_symtab_read): Handle error return from
[deliverable/binutils-gdb.git] / gdb / elfread.c
index 48a8182ee2b2c31cb695cd68fc68610f54b5512e..67ce6086dac7bab19ae37371194a7c8ad0ddb3ce 100644 (file)
@@ -20,9 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include "defs.h"
 #include "bfd.h"
-#include <time.h> /* For time_t in libbfd.h.  */
-#include <sys/types.h> /* For time_t, if not in time.h.  */
-#include "libbfd.h"            /* For bfd_elf_find_section */
+#include <string.h>
 #include "libelf.h"
 #include "elf/mips.h"
 #include "symtab.h"
@@ -32,7 +30,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "stabsread.h"
 #include "gdb-stabs.h"
 #include "complaints.h"
-#include <string.h>
 #include "demangle.h"
 
 /* The struct elfinfo is available only during ELF symbol table and
@@ -267,12 +264,20 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
   int stripped = (bfd_get_symcount (abfd) == 0);
  
   if (dynamic)
-    storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
+    {
+      storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
+
+      /* Nothing to be done if there is no dynamic symtab.  */
+      if (storage_needed < 0)
+       return;
+    }
   else
-    storage_needed = bfd_get_symtab_upper_bound (abfd);
-  if (storage_needed < 0)
-    error ("Can't read symbols from %s: %s", bfd_get_filename (abfd),
-          bfd_errmsg (bfd_get_error ()));
+    {
+      storage_needed = bfd_get_symtab_upper_bound (abfd);
+      if (storage_needed < 0)
+       error ("Can't read symbols from %s: %s", bfd_get_filename (abfd),
+              bfd_errmsg (bfd_get_error ()));
+    }
   if (storage_needed > 0)
     {
       symbol_table = (asymbol **) xmalloc (storage_needed);
@@ -350,6 +355,7 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
                  symaddr = sym -> value;
                  if (symaddr == 0)
                    continue;
+                 symaddr += addr;
                }
              else if (sym -> section == &bfd_abs_section)
                {
@@ -560,10 +566,9 @@ elf_symfile_read (objfile, section_offsets, mainline)
   offset = ANOFFSET (section_offsets, 0);
   elf_symtab_read (abfd, offset, objfile, 0);
 
-  /* Add the dynamic symbols if we are reading the main symbol table.  */
+  /* Add the dynamic symbols.  */
 
-  if (mainline)
-    elf_symtab_read (abfd, offset, objfile, 1);
+  elf_symtab_read (abfd, offset, objfile, 1);
 
   /* Now process debugging information, which is contained in
      special ELF sections.  We first have to find them... */
@@ -579,25 +584,21 @@ elf_symfile_read (objfile, section_offsets, mainline)
     }
   if (ei.stabsect)
     {
-      /* STABS sections */
-
-      /* FIXME:  Sun didn't really know how to implement this well.
-        They made .stab sections that don't point to the .stabstr
-        section with the sh_link field.  BFD doesn't make string table
-        sections visible to the caller.  So we have to search the
-        ELF section table, not the BFD section table, for the string
-        table.  */
-      struct elf32_internal_shdr *elf_sect;
-
-      elf_sect = bfd_elf_find_section (abfd, ".stabstr");
-      if (elf_sect)
+      asection *str_sect;
+
+      /* Stab sections have an associated string table that looks like
+        a separate section.  */
+      str_sect = bfd_get_section_by_name (abfd, ".stabstr");
+
+      /* FIXME should probably warn about a stab section without a stabstr.  */
+      if (str_sect)
        elfstab_build_psymtabs (objfile,
-         section_offsets,
-         mainline,
-         ei.stabsect->filepos,                         /* .stab offset */
-         bfd_get_section_size_before_reloc (ei.stabsect),/* .stab size */
-         (file_ptr) elf_sect->sh_offset,               /* .stabstr offset */
-         elf_sect->sh_size);                           /* .stabstr size */
+                               section_offsets,
+                               mainline,
+                               ei.stabsect->filepos,
+                               bfd_section_size (abfd, ei.stabsect),
+                               str_sect->filepos,
+                               bfd_section_size (abfd, str_sect));
     }
   if (ei.mdebugsect)
     {
@@ -611,13 +612,6 @@ elf_symfile_read (objfile, section_offsets, mainline)
                                  section_offsets);
     }
 
-  if (!have_partial_symbols ())
-    {
-      wrap_here ("");
-      printf_filtered ("(no debugging symbols found)...");
-      wrap_here ("");
-    }
-
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile. */
 
This page took 0.024752 seconds and 4 git commands to generate.