* gdb.texinfo (Command Files): Mention -x, use @enumerate for
[deliverable/binutils-gdb.git] / gdb / elfread.c
index f0ad2bed8b2e92e9f5375336563bfa13f36b4ebe..d63d16a30fabea9f6a1d7bc0c68064348731fc0a 100644 (file)
@@ -36,7 +36,7 @@
 extern void _initialize_elfread PARAMS ((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
@@ -71,13 +71,13 @@ static void
 elf_new_init PARAMS ((struct objfile *));
 
 static void
-elf_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
+elf_symfile_read PARAMS ((struct objfile *, int));
 
 static void
 elf_symfile_finish PARAMS ((struct objfile *));
 
 static void
-elf_symtab_read PARAMS ((bfd *, CORE_ADDR, struct objfile *, int));
+elf_symtab_read PARAMS ((struct objfile *, int));
 
 static void
 free_elfinfo PARAMS ((void *));
@@ -221,15 +221,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 +238,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 +250,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 +264,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 +276,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 +286,15 @@ 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 ()));
+      /* FIXME: Should use section specific offset, not SECT_OFF_TEXT. */
+      offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
       for (i = 0; i < number_of_symbols; i++)
        {
          sym = symbol_table[i];
@@ -316,14 +315,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 +364,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 +375,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 +396,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)
@@ -498,10 +497,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 +583,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;
@@ -609,13 +607,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 +648,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 +661,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 +670,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 +812,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 +832,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.027644 seconds and 4 git commands to generate.