Detect the absence of a symbol hash table.
[deliverable/binutils-gdb.git] / gdb / somread.c
index 35def2254abbf707e931670350ee267e978b469f..ed0fe976997ba187bddd7b980c4b36b7e46348ba 100644 (file)
@@ -1,5 +1,5 @@
 /* Read HP PA/Risc object files for GDB.
-   Copyright 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1991, 1992, 1996 Free Software Foundation, Inc.
    Written by Fred Fish at Cygnus Support.
 
 This file is part of GDB.
@@ -16,12 +16,10 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "bfd.h"
-#include "som.h"
-#include "libhppa.h"
 #include <syms.h>
 #include "symtab.h"
 #include "symfile.h"
@@ -30,9 +28,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "stabsread.h"
 #include "gdb-stabs.h"
 #include "complaints.h"
-#include <string.h>
+#include "gdb_string.h"
 #include "demangle.h"
-#include <sys/file.h>
+#include "som.h"
+#include "libhppa.h"
 
 /* Various things we might complain about... */
 
@@ -55,21 +54,16 @@ som_symtab_read PARAMS ((bfd *, struct objfile *,
 static struct section_offsets *
 som_symfile_offsets PARAMS ((struct objfile *, CORE_ADDR));
 
-static void
-record_minimal_symbol PARAMS ((char *, CORE_ADDR,
-                              enum minimal_symbol_type,
-                              struct objfile *));
+/* FIXME: These should really be in a common header somewhere */
 
-static void
-record_minimal_symbol (name, address, ms_type, objfile)
-     char *name;
-     CORE_ADDR address;
-     enum minimal_symbol_type ms_type;
-     struct objfile *objfile;
-{
-  name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
-  prim_record_minimal_symbol (name, address, ms_type, objfile);
-}
+extern void
+hpread_build_psymtabs PARAMS ((struct objfile *, struct section_offsets *, int));
+
+extern void
+hpread_symfile_finish PARAMS ((struct objfile *));
+
+extern void
+hpread_symfile_init PARAMS ((struct objfile *));
 
 /*
 
@@ -103,22 +97,22 @@ som_symtab_read (abfd, objfile, section_offsets)
   struct symbol_dictionary_record *buf, *bufp, *endbufp;
   char *symname;
   CONST int symsize = sizeof (struct symbol_dictionary_record);
-  CORE_ADDR text_offset;
+  CORE_ADDR text_offset, data_offset;
 
 
-  /* FIXME.  Data stuff needs dynamic relocation too!  */
   text_offset = ANOFFSET (section_offsets, 0);
+  data_offset = ANOFFSET (section_offsets, 1);
 
   number_of_symbols = bfd_get_symcount (abfd);
 
   buf = alloca (symsize * number_of_symbols);
-  bfd_seek (abfd, obj_som_sym_filepos (abfd), L_SET);
+  bfd_seek (abfd, obj_som_sym_filepos (abfd), SEEK_SET);
   val = bfd_read (buf, symsize * number_of_symbols, 1, abfd);
   if (val != symsize * number_of_symbols)
     error ("Couldn't read symbol dictionary!");
 
   stringtab = alloca (obj_som_stringtab_size (abfd));
-  bfd_seek (abfd, obj_som_str_filepos (abfd), L_SET);
+  bfd_seek (abfd, obj_som_str_filepos (abfd), SEEK_SET);
   val = bfd_read (stringtab, obj_som_stringtab_size (abfd), 1, abfd);
   if (val != obj_som_stringtab_size (abfd))
     error ("Can't read in HP string table.");
@@ -190,6 +184,7 @@ som_symtab_read (abfd, objfile, section_offsets)
 
            case ST_DATA:
              symname = bufp->name.n_strx + stringtab;
+             bufp->symbol_value += data_offset;
              ms_type = mst_data;
              break;
            default:
@@ -226,9 +221,15 @@ som_symtab_read (abfd, objfile, section_offsets)
                 the nasty habit of placing section symbols from the literal
                 subspaces in the middle of the program's text.  Filter
                 those out as best we can.  Check for first and last character
-                being '$'.  */
+                being '$'. 
+
+                And finally, the newer HP compilers emit crud like $PIC_foo$N
+                in some circumstance (PIC code I guess).  It's also claimed
+                that they emit D$ symbols too.  What stupidity.  */
              if ((symname[0] == 'L' && symname[1] == '$')
-                 || (symname[0] == '$' && symname[strlen(symname) - 1] == '$'))
+                 || (symname[0] == '$' && symname[strlen(symname) - 1] == '$')
+                 || (symname[0] == 'D' && symname[1] == '$')
+                 || (strncmp (symname, "$PIC", 4) == 0))
                continue;
              break;
 
@@ -270,6 +271,7 @@ som_symtab_read (abfd, objfile, section_offsets)
 
            case ST_DATA:
              symname = bufp->name.n_strx + stringtab;
+             bufp->symbol_value += data_offset;
              ms_type = mst_file_data;
              goto check_strange_names;
 
@@ -278,6 +280,27 @@ som_symtab_read (abfd, objfile, section_offsets)
            }
          break;
 
+       /* This can happen for common symbols when -E is passed to the
+          final link.  No idea _why_ that would make the linker force
+          common symbols to have an SS_UNSAT scope, but it does.
+
+          This also happens for weak symbols, but their type is
+          ST_DATA.  */
+       case SS_UNSAT:
+         switch (bufp->symbol_type)
+           {
+             case ST_STORAGE:
+             case ST_DATA:
+               symname = bufp->name.n_strx + stringtab;
+               bufp->symbol_value += data_offset;
+               ms_type = mst_data;
+               break;
+
+             default:
+               continue;
+           }
+         break;
+
        default:
          continue;
        }
@@ -286,9 +309,8 @@ som_symtab_read (abfd, objfile, section_offsets)
        error ("Invalid symbol data; bad HP string table offset: %d",
               bufp->name.n_strx);
 
-      record_minimal_symbol (symname,
-                            bufp->symbol_value, ms_type, 
-                            objfile);
+      prim_record_minimal_symbol (symname, bufp->symbol_value, ms_type, 
+                                 objfile);
     }
 }
 
@@ -341,17 +363,15 @@ som_symfile_read (objfile, section_offsets, mainline)
   stabsect_build_psymtabs (objfile, section_offsets, mainline,
                           "$GDB_SYMBOLS$", "$GDB_STRINGS$", "$TEXT$");
 
-/* start-sanitize-hpread */
   /* Now read the native debug information.  */
   hpread_build_psymtabs (objfile, section_offsets, mainline);
-/* end-sanitize-hpread */
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  */
   install_minimal_symbols (objfile);
 
   /* Force hppa-tdep.c to re-read the unwind descriptors.  */
-  OBJ_UNWIND_INFO (objfile) = NULL;
+  objfile->obj_private = NULL;
   do_cleanups (back_to);
 }
 
@@ -382,21 +402,20 @@ som_symfile_finish (objfile)
     {
       mfree (objfile -> md, objfile -> sym_stab_info);
     }
-/* start-sanitize-hpread */
   hpread_symfile_finish (objfile);
-/* end-sanitize-hpread */
 }
 
-/* SOM specific initialization routine for reading symbols.
+/* SOM specific initialization routine for reading symbols.  */
 
-   Nothing SOM specific left to do anymore.  */
 static void
 som_symfile_init (objfile)
      struct objfile *objfile;
 {
-/* start-sanitize-hpread */
+  /* SOM objects may be reordered, so set OBJF_REORDERED.  If we
+     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;
   hpread_symfile_init (objfile);
-/* end-sanitize-hpread */
 }
 
 /* SOM specific parsing routine for section offsets.
@@ -413,12 +432,15 @@ som_symfile_offsets (objfile, addr)
 
   objfile->num_sections = SECT_OFF_MAX;
   section_offsets = (struct section_offsets *)
-    obstack_alloc (&objfile -> psymbol_obstack,
-                  sizeof (struct section_offsets)
-                  + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
+    obstack_alloc (&objfile -> psymbol_obstack, SIZEOF_SECTION_OFFSETS);
 
-  for (i = 0; i < SECT_OFF_MAX; i++)
-    ANOFFSET (section_offsets, i) = addr;
+  /* First see if we're a shared library.  If so, get the section
+     offsets from the library, else get them from addr.  */
+  if (!som_solib_section_offsets (objfile, section_offsets))
+    {
+      for (i = 0; i < SECT_OFF_MAX; i++)
+       ANOFFSET (section_offsets, i) = addr;
+    }
 
   return section_offsets;
 }
This page took 0.025642 seconds and 4 git commands to generate.