Revert previous ser-unix change. Locks up serial device.
[deliverable/binutils-gdb.git] / gdb / elfread.c
index f0ad2bed8b2e92e9f5375336563bfa13f36b4ebe..edd4786d3ee3ce9b83e610b0a14bf8dbae509b3f 100644 (file)
 #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 complation of psymtab-reading.
+   psymtab reading.  It is destroyed at the completion of psymtab-reading.
    It's local to elf_symfile_read.  */
 
 struct elfinfo
@@ -64,32 +64,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 *, struct section_offsets *, 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 ((bfd *, CORE_ADDR, 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
@@ -191,18 +188,16 @@ record_minimal_symbol_and_info (name, address, ms_type, info, bfd_section,
     {
     case mst_text:
     case mst_file_text:
-      section = SECT_OFF_TEXT;
+      section = bfd_section->index;
 #ifdef SMASH_TEXT_ADDRESS
       SMASH_TEXT_ADDRESS (address);
 #endif
       break;
     case mst_data:
     case mst_file_data:
-      section = SECT_OFF_DATA;
-      break;
     case mst_bss:
     case mst_file_bss:
-      section = SECT_OFF_BSS;
+      section = bfd_section->index;
       break;
     default:
       section = -1;
@@ -221,15 +216,13 @@ record_minimal_symbol_and_info (name, address, ms_type, info, bfd_section,
 
    SYNOPSIS
 
-   void elf_symtab_read (bfd *abfd, CORE_ADDR addr,
-   struct objfile *objfile, int dynamic)
+   void elf_symtab_read (struct objfile *objfile, int dynamic)
 
    DESCRIPTION
 
-   Given an open bfd, a base address to relocate symbols to, and a
-   flag that specifies whether or not this bfd is for an executable
-   or not (may be shared library for example), add all the global
-   function and data symbols to the minimal symbol table.
+   Given an objfile and a flag that specifies whether or not the objfile
+   is for an executable or not (may be shared library for example), add
+   all the global function and data symbols to the minimal symbol table.
 
    In stabs-in-ELF, as implemented by Sun, there are some local symbols
    defined in the ELF symbol table, which can be used to locate
@@ -240,9 +233,7 @@ record_minimal_symbol_and_info (name, address, ms_type, info, bfd_section,
  */
 
 static void
-elf_symtab_read (abfd, addr, objfile, dynamic)
-     bfd *abfd;
-     CORE_ADDR addr;
+elf_symtab_read (objfile, dynamic)
      struct objfile *objfile;
      int dynamic;
 {
@@ -254,6 +245,7 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
   int index;
   struct cleanup *back_to;
   CORE_ADDR symaddr;
+  CORE_ADDR offset;
   enum minimal_symbol_type ms_type;
   /* If sectinfo is nonNULL, it contains section info that should end up
      filed in the objfile.  */
@@ -267,11 +259,11 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
 #endif
   struct dbx_symfile_info *dbx = objfile->sym_stab_info;
   unsigned long size;
-  int stripped = (bfd_get_symcount (abfd) == 0);
+  int stripped = (bfd_get_symcount (objfile->obfd) == 0);
 
   if (dynamic)
     {
-      storage_needed = bfd_get_dynamic_symtab_upper_bound (abfd);
+      storage_needed = bfd_get_dynamic_symtab_upper_bound (objfile->obfd);
 
       /* Nothing to be done if there is no dynamic symtab.  */
       if (storage_needed < 0)
@@ -279,9 +271,9 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
     }
   else
     {
-      storage_needed = bfd_get_symtab_upper_bound (abfd);
+      storage_needed = bfd_get_symtab_upper_bound (objfile->obfd);
       if (storage_needed < 0)
-       error ("Can't read symbols from %s: %s", bfd_get_filename (abfd),
+       error ("Can't read symbols from %s: %s", bfd_get_filename (objfile->obfd),
               bfd_errmsg (bfd_get_error ()));
     }
   if (storage_needed > 0)
@@ -289,13 +281,14 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
       symbol_table = (asymbol **) xmalloc (storage_needed);
       back_to = make_cleanup (free, symbol_table);
       if (dynamic)
-       number_of_symbols = bfd_canonicalize_dynamic_symtab (abfd,
+       number_of_symbols = bfd_canonicalize_dynamic_symtab (objfile->obfd,
                                                             symbol_table);
       else
-       number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+       number_of_symbols = bfd_canonicalize_symtab (objfile->obfd, symbol_table);
       if (number_of_symbols < 0)
-       error ("Can't read symbols from %s: %s", bfd_get_filename (abfd),
+       error ("Can't read symbols from %s: %s", bfd_get_filename (objfile->obfd),
               bfd_errmsg (bfd_get_error ()));
+
       for (i = 0; i < number_of_symbols; i++)
        {
          sym = symbol_table[i];
@@ -306,6 +299,7 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
              continue;
            }
 
+          offset = ANOFFSET (objfile->section_offsets, sym->section->index);
          if (dynamic
              && sym->section == &bfd_und_section
              && (sym->flags & BSF_FUNCTION))
@@ -316,14 +310,14 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
                 a shared library.
                 If its value is non zero then it is usually the address
                 of the corresponding entry in the procedure linkage table,
-                relative to the base address.
+                plus the desired section offset.
                 If its value is zero then the dynamic linker has to resolve
                 the symbol. We are unable to find any meaningful address
                 for this symbol in the executable file, so we skip it.  */
              symaddr = sym->value;
              if (symaddr == 0)
                continue;
-             symaddr += addr;
+             symaddr += offset;
              msym = record_minimal_symbol_and_info
                ((char *) sym->name, symaddr,
                 mst_solib_trampoline, NULL, sym->section, objfile);
@@ -365,10 +359,10 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
                 interested in will have a section. */
              /* Bfd symbols are section relative. */
              symaddr = sym->value + sym->section->vma;
-             /* Relocate all non-absolute symbols by base address.  */
+             /* Relocate all non-absolute symbols by the section offset.  */
              if (sym->section != &bfd_abs_section)
                {
-                 symaddr += addr;
+                 symaddr += offset;
                }
              /* For non-absolute symbols, use the type of the section
                 they are relative to, to intuit text/data.  Bfd provides
@@ -376,7 +370,7 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
              if (sym->section == &bfd_abs_section)
                {
                  /* This is a hack to get the minimal symbol type
-                    right for Irix 5, which has absolute adresses
+                    right for Irix 5, which has absolute addresses
                     with special section indices for dynamic symbols. */
                  unsigned short shndx =
                  ((elf_symbol_type *) sym)->internal_elf_sym.st_shndx;
@@ -397,12 +391,12 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
                    }
 
                  /* If it is an Irix dynamic symbol, skip section name
-                    symbols, relocate all others. */
+                    symbols, relocate all others by section offset. */
                  if (ms_type != mst_abs)
                    {
                      if (sym->name[0] == '.')
                        continue;
-                     symaddr += addr;
+                     symaddr += offset;
                    }
                }
              else if (sym->section->flags & SEC_CODE)
@@ -461,15 +455,15 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
                      index = SECT_OFF_MAX;
                      if (STREQ ("Bbss.bss", sym->name))
                        {
-                         index = SECT_OFF_BSS;
+                         index = SECT_OFF_BSS (objfile);
                        }
                      else if (STREQ ("Ddata.data", sym->name))
                        {
-                         index = SECT_OFF_DATA;
+                         index = SECT_OFF_DATA (objfile);
                        }
                      else if (STREQ ("Drodata.rodata", sym->name))
                        {
-                         index = SECT_OFF_RODATA;
+                         index = SECT_OFF_RODATA (objfile);
                        }
                      if (index != SECT_OFF_MAX)
                        {
@@ -498,10 +492,10 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
                            }
                          /* Bfd symbols are section relative. */
                          symaddr = sym->value + sym->section->vma;
-                         /* Relocate non-absolute symbols by base address.  */
+                         /* Relocate non-absolute symbols by the section offset. */
                          if (sym->section != &bfd_abs_section)
                            {
-                             symaddr += addr;
+                             symaddr += offset;
                            }
                          sectinfo->sections[index] = symaddr;
                          /* The special local symbols don't go in the
@@ -584,9 +578,8 @@ elf_symtab_read (abfd, addr, objfile, dynamic)
    capability even for files compiled without -g.  */
 
 static void
-elf_symfile_read (objfile, section_offsets, mainline)
+elf_symfile_read (objfile, mainline)
      struct objfile *objfile;
-     struct section_offsets *section_offsets;
      int mainline;
 {
   bfd *abfd = objfile->obfd;
@@ -595,7 +588,7 @@ elf_symfile_read (objfile, section_offsets, 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));
 
@@ -609,13 +602,11 @@ elf_symfile_read (objfile, section_offsets, mainline)
      chain of info into the dbx_symfile_info in objfile->sym_stab_info,
      which can later be used by elfstab_offset_sections.  */
 
-  /* FIXME, should take a section_offsets param, not just an offset.  */
-  offset = ANOFFSET (section_offsets, 0);
-  elf_symtab_read (abfd, offset, objfile, 0);
+  elf_symtab_read (objfile, 0);
 
   /* Add the dynamic symbols.  */
 
-  elf_symtab_read (abfd, offset, objfile, 1);
+  elf_symtab_read (objfile, 1);
 
   /* Now process debugging information, which is contained in
      special ELF sections. */
@@ -652,8 +643,7 @@ elf_symfile_read (objfile, section_offsets, mainline)
          information.  */
       swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap;
       if (swap)
-       elfmdebug_build_psymtabs (objfile, swap, ei.mdebugsect,
-                                 section_offsets);
+       elfmdebug_build_psymtabs (objfile, swap, ei.mdebugsect);
     }
   if (ei.stabsect)
     {
@@ -666,7 +656,6 @@ elf_symfile_read (objfile, section_offsets, mainline)
       /* FIXME should probably warn about a stab section without a stabstr.  */
       if (str_sect)
        elfstab_build_psymtabs (objfile,
-                               section_offsets,
                                mainline,
                                ei.stabsect->filepos,
                                bfd_section_size (abfd, ei.stabsect),
@@ -676,13 +665,13 @@ elf_symfile_read (objfile, section_offsets, mainline)
   if (dwarf2_has_info (abfd))
     {
       /* DWARF 2 sections */
-      dwarf2_build_psymtabs (objfile, section_offsets, mainline);
+      dwarf2_build_psymtabs (objfile, mainline);
     }
   else if (ei.dboffset && ei.lnoffset)
     {
       /* DWARF sections */
       dwarf_build_psymtabs (objfile,
-                           section_offsets, mainline,
+                           mainline,
                            ei.dboffset, ei.dbsize,
                            ei.lnoffset, ei.lnsize);
     }
@@ -818,10 +807,7 @@ elfstab_offset_sections (objfile, pst)
       /* Found it!  Allocate a new psymtab struct, and fill it in.  */
       maybe->found++;
       pst->section_offsets = (struct section_offsets *)
-       obstack_alloc (&objfile->psymbol_obstack,
-                      sizeof (struct section_offsets) +
-              sizeof (pst->section_offsets->offsets) * (SECT_OFF_MAX - 1));
-
+       obstack_alloc (&objfile->psymbol_obstack, SIZEOF_SECTION_OFFSETS);
       for (i = 0; i < SECT_OFF_MAX; i++)
        ANOFFSET (pst->section_offsets, i) = maybe->sections[i];
       return;
@@ -841,8 +827,7 @@ static struct sym_fns elf_sym_fns =
   elf_symfile_init,            /* sym_init: read initial info, setup for sym_read() */
   elf_symfile_read,            /* sym_read: read a symbol file into symtab */
   elf_symfile_finish,          /* sym_finish: finished with file, cleanup */
-  default_symfile_offsets,
-                       /* sym_offsets:  Translate ext. to int. relocation */
+  default_symfile_offsets,     /* sym_offsets:  Translate ext. to int. relocation */
   NULL                         /* next: pointer to next struct sym_fns */
 };
 
This page took 0.027979 seconds and 4 git commands to generate.