Fix -Werror -Wuninitialized warnings.
[deliverable/binutils-gdb.git] / gdb / elfread.c
index e76d5cda7fffdb4f7746402efb3b28a573a2de13..71e383dc187cb8c95c82ea8303987af7bbbcad45 100644 (file)
@@ -1,5 +1,7 @@
 /* Read ELF (Executable and Linking Format) object files for GDB.
-   Copyright 1991, 92, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
+   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
+   2001
+   Free Software Foundation, Inc.
    Written by Fred Fish at Cygnus Support.
 
    This file is part of GDB.
@@ -33,7 +35,7 @@
 #include "complaints.h"
 #include "demangle.h"
 
-extern void _initialize_elfread PARAMS ((void));
+extern void _initialize_elfread (void);
 
 /* The struct elfinfo is available only during ELF symbol table and
    psymtab reading.  It is destroyed at the completion of psymtab-reading.
@@ -64,32 +66,29 @@ struct complaint stab_info_mismatch_complaint =
 struct complaint stab_info_questionable_complaint =
 {"elf/stab section information questionable for %s", 0, 0};
 
-static void
-elf_symfile_init PARAMS ((struct objfile *));
+static void elf_symfile_init (struct objfile *);
 
-static void
-elf_new_init PARAMS ((struct objfile *));
+static void elf_new_init (struct objfile *);
 
-static void
-elf_symfile_read PARAMS ((struct objfile *, int));
+static void elf_symfile_read (struct objfile *, int);
 
-static void
-elf_symfile_finish PARAMS ((struct objfile *));
+static void elf_symfile_finish (struct objfile *);
 
-static void
-elf_symtab_read PARAMS ((struct objfile *, int));
+static void elf_symtab_read (struct objfile *, int);
 
-static void
-free_elfinfo PARAMS ((void *));
+static void free_elfinfo (void *);
 
-static struct minimal_symbol *
-  record_minimal_symbol_and_info PARAMS ((char *, CORE_ADDR,
-                                         enum minimal_symbol_type, char *,
-                                         asection * bfd_section,
-                                         struct objfile *));
+static struct minimal_symbol *record_minimal_symbol_and_info (char *,
+                                                             CORE_ADDR,
+                                                             enum
+                                                             minimal_symbol_type,
+                                                             char *,
+                                                             asection *
+                                                             bfd_section,
+                                                             struct objfile
+                                                             *);
 
-static void
-elf_locate_sections PARAMS ((bfd *, asection *, void *));
+static void elf_locate_sections (bfd *, asection *, void *);
 
 /* We are called once per section from elf_symfile_read.  We
    need to examine each section we are passed, check to see
@@ -111,10 +110,7 @@ elf_locate_sections PARAMS ((bfd *, asection *, void *));
    -kingdon).  */
 
 static void
-elf_locate_sections (ignore_abfd, sectp, eip)
-     bfd *ignore_abfd;
-     asection *sectp;
-     PTR eip;
+elf_locate_sections (bfd *ignore_abfd, asection *sectp, PTR eip)
 {
   register struct elfinfo *ei;
 
@@ -146,8 +142,7 @@ elf_locate_sections (ignore_abfd, sectp, eip)
 #if 0                          /* Currently unused */
 
 char *
-elf_interpreter (abfd)
-     bfd *abfd;
+elf_interpreter (bfd *abfd)
 {
   sec_ptr interp_sec;
   unsigned size;
@@ -174,43 +169,17 @@ elf_interpreter (abfd)
 #endif
 
 static struct minimal_symbol *
-record_minimal_symbol_and_info (name, address, ms_type, info, bfd_section,
-                               objfile)
-     char *name;
-     CORE_ADDR address;
-     enum minimal_symbol_type ms_type;
-     char *info;               /* FIXME, is this really char *? */
-     asection *bfd_section;
-     struct objfile *objfile;
+record_minimal_symbol_and_info (char *name, CORE_ADDR address,
+                               enum minimal_symbol_type ms_type, char *info,   /* FIXME, is this really char *? */
+                               asection *bfd_section, struct objfile *objfile)
 {
-  int section;
-
-  /* Guess the section from the type.  This is likely to be wrong in
-     some cases.  */
-  switch (ms_type)
-    {
-    case mst_text:
-    case mst_file_text:
-      section = SECT_OFF_TEXT (objfile);
 #ifdef SMASH_TEXT_ADDRESS
-      SMASH_TEXT_ADDRESS (address);
+  if (ms_type == mst_text || ms_type == mst_file_text)
+    SMASH_TEXT_ADDRESS (address);
 #endif
-      break;
-    case mst_data:
-    case mst_file_data:
-      section = SECT_OFF_DATA (objfile);
-      break;
-    case mst_bss:
-    case mst_file_bss:
-      section = SECT_OFF_BSS (objfile);
-      break;
-    default:
-      section = -1;
-      break;
-    }
 
   return prim_record_minimal_symbol_and_info
-    (name, address, ms_type, info, section, bfd_section, objfile);
+    (name, address, ms_type, info, bfd_section->index, bfd_section, objfile);
 }
 
 /*
@@ -238,9 +207,7 @@ record_minimal_symbol_and_info (name, address, ms_type, info, bfd_section,
  */
 
 static void
-elf_symtab_read (objfile, dynamic)
-     struct objfile *objfile;
-     int dynamic;
+elf_symtab_read (struct objfile *objfile, int dynamic)
 {
   long storage_needed;
   asymbol *sym;
@@ -284,7 +251,7 @@ elf_symtab_read (objfile, dynamic)
   if (storage_needed > 0)
     {
       symbol_table = (asymbol **) xmalloc (storage_needed);
-      back_to = make_cleanup (free, symbol_table);
+      back_to = make_cleanup (xfree, symbol_table);
       if (dynamic)
        number_of_symbols = bfd_canonicalize_dynamic_symtab (objfile->obfd,
                                                             symbol_table);
@@ -293,8 +260,7 @@ elf_symtab_read (objfile, dynamic)
       if (number_of_symbols < 0)
        error ("Can't read symbols from %s: %s", bfd_get_filename (objfile->obfd),
               bfd_errmsg (bfd_get_error ()));
-      /* FIXME: Should use section specific offset, not SECT_OFF_TEXT. */
-      offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+
       for (i = 0; i < number_of_symbols; i++)
        {
          sym = symbol_table[i];
@@ -305,6 +271,7 @@ elf_symtab_read (objfile, dynamic)
              continue;
            }
 
+          offset = ANOFFSET (objfile->section_offsets, sym->section->index);
          if (dynamic
              && sym->section == &bfd_und_section
              && (sym->flags & BSF_FUNCTION))
@@ -439,7 +406,7 @@ elf_symtab_read (objfile, dynamic)
                }
              else if (sym->section->flags & SEC_ALLOC)
                {
-                 if (sym->flags & BSF_GLOBAL)
+                 if (sym->flags & (BSF_GLOBAL | BSF_WEAK))
                    {
                      if (sym->section->flags & SEC_LOAD)
                        {
@@ -490,11 +457,17 @@ elf_symtab_read (objfile, dynamic)
                                    (char *) filesym->name;
                                }
                            }
-                         if (sectinfo->sections[index] != 0)
-                           {
-                             complain (&section_info_dup_complaint,
-                                       sectinfo->filename);
+                         if (index != -1)
+                           { 
+                             if (sectinfo->sections[index] != 0)
+                               {
+                                 complain (&section_info_dup_complaint,
+                                           sectinfo->filename);
+                               }
                            }
+                         else
+                           internal_error (__FILE__, __LINE__,
+                                           "Section index uninitialized.");
                          /* Bfd symbols are section relative. */
                          symaddr = sym->value + sym->section->vma;
                          /* Relocate non-absolute symbols by the section offset. */
@@ -502,7 +475,11 @@ elf_symtab_read (objfile, dynamic)
                            {
                              symaddr += offset;
                            }
-                         sectinfo->sections[index] = symaddr;
+                         if (index != -1)
+                           sectinfo->sections[index] = symaddr;
+                         else
+                           internal_error (__FILE__, __LINE__,
+                                           "Section index uninitialized.");
                          /* The special local symbols don't go in the
                             minimal symbol table, so ignore this one. */
                          continue;
@@ -583,9 +560,7 @@ elf_symtab_read (objfile, dynamic)
    capability even for files compiled without -g.  */
 
 static void
-elf_symfile_read (objfile, mainline)
-     struct objfile *objfile;
-     int mainline;
+elf_symfile_read (struct objfile *objfile, int mainline)
 {
   bfd *abfd = objfile->obfd;
   struct elfinfo ei;
@@ -593,7 +568,7 @@ elf_symfile_read (objfile, mainline)
   CORE_ADDR offset;
 
   init_minimal_symbol_collection ();
-  back_to = make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
+  back_to = make_cleanup_discard_minimal_symbols ();
 
   memset ((char *) &ei, 0, sizeof (ei));
 
@@ -693,8 +668,7 @@ elf_symfile_read (objfile, mainline)
    stab_section_info's, that might be dangling from it.  */
 
 static void
-free_elfinfo (objp)
-     PTR objp;
+free_elfinfo (PTR objp)
 {
   struct objfile *objfile = (struct objfile *) objp;
   struct dbx_symfile_info *dbxinfo = objfile->sym_stab_info;
@@ -719,8 +693,7 @@ free_elfinfo (objp)
    We reinitialize buildsym, since we may be reading stabs from an ELF file.  */
 
 static void
-elf_new_init (ignore)
-     struct objfile *ignore;
+elf_new_init (struct objfile *ignore)
 {
   stabsread_new_init ();
   buildsym_new_init ();
@@ -732,8 +705,7 @@ elf_new_init (ignore)
    objfile struct from the global list of known objfiles. */
 
 static void
-elf_symfile_finish (objfile)
-     struct objfile *objfile;
+elf_symfile_finish (struct objfile *objfile)
 {
   if (objfile->sym_stab_info != NULL)
     {
@@ -751,8 +723,7 @@ elf_symfile_finish (objfile)
    just a stub. */
 
 static void
-elf_symfile_init (objfile)
-     struct objfile *objfile;
+elf_symfile_init (struct objfile *objfile)
 {
   /* ELF objects may be reordered, so set OBJF_REORDERED.  If we
      find this causes a significant slowdown in gdb then we could
@@ -769,9 +740,7 @@ elf_symfile_init (objfile)
    with wierd names.  Go get 'em when needed.  */
 
 void
-elfstab_offset_sections (objfile, pst)
-     struct objfile *objfile;
-     struct partial_symtab *pst;
+elfstab_offset_sections (struct objfile *objfile, struct partial_symtab *pst)
 {
   char *filename = pst->filename;
   struct dbx_symfile_info *dbx = objfile->sym_stab_info;
@@ -814,7 +783,7 @@ elfstab_offset_sections (objfile, pst)
       pst->section_offsets = (struct section_offsets *)
        obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
       for (i = 0; i < SECT_OFF_MAX; i++)
-       ANOFFSET (pst->section_offsets, i) = maybe->sections[i];
+       (pst->section_offsets)->offsets[i] = maybe->sections[i];
       return;
     }
 
@@ -837,7 +806,7 @@ static struct sym_fns elf_sym_fns =
 };
 
 void
-_initialize_elfread ()
+_initialize_elfread (void)
 {
   add_symtab_fns (&elf_sym_fns);
 }
This page took 0.029012 seconds and 4 git commands to generate.