* hppa.c: Get rid of DEFUN, use more conventional prolog stuff.
[deliverable/binutils-gdb.git] / bfd / elf.c
index c41ba0a5194a7bf71aebb97769245a1f465b2497..d6b28d34d872c77c79bb80cc2cb71e51f68bdf98 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -1,9 +1,9 @@
 /* ELF executable support for BFD.
-   Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1991, 1992 Free Software Foundation, Inc.
 
    Written by Fred Fish @ Cygnus Support, from information published
    in "UNIX System V Release 4, Programmers Guide: ANSI C and
-   Programming Support Tools". Sufficient support for gdb.
+   Programming Support Tools".  Sufficient support for gdb.
 
    Rewritten by Mark Eichin @ Cygnus Support, from information
    published in "System V Application Binary Interface", chapters 4
@@ -90,6 +90,26 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #define bfd_prpsinfo(abfd, descdata, descsz, filepos)  /* Define away */
 #endif
 
+/* Forward declarations of static functions */
+
+static char *
+elf_read PARAMS ((bfd *, long, int));
+
+static struct sec *
+section_from_elf_index PARAMS ((bfd *, int));
+
+static int
+elf_section_from_bfd_section PARAMS ((bfd *, struct sec *));
+
+static boolean
+elf_slurp_symbol_table PARAMS ((bfd *, asymbol **));
+
+static void
+elf_info_to_howto PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
+
+static char *
+elf_get_str_section PARAMS ((bfd *, unsigned int));
+     
 /* Forward data declarations */
 
 extern bfd_target elf_little_vec, elf_big_vec;
@@ -320,29 +340,49 @@ DEFUN(elf_swap_reloca_out,(abfd, src, dst),
   bfd_h_put_32 (abfd, src->r_addend, dst->r_addend);
 }
 
-static char *EXFUN(elf_read, (bfd *, long, int));
-static struct sec * EXFUN(section_from_elf_index, (bfd *, int));
-static int EXFUN(elf_section_from_bfd_section, (bfd *, struct sec *));
-static boolean EXFUN(elf_slurp_symbol_table, (bfd *, Elf_Internal_Shdr*));
-static void EXFUN(elf_info_to_howto, (bfd *, arelent *, Elf_Internal_Rela *));
-static char *EXFUN(elf_get_str_section, (bfd *, unsigned int));
-     
-/* Helper functions for GDB to locate the string tables.  */
+/* 
+INTERNAL_FUNCTION
+       bfd_elf_find_section
+
+SYNOPSIS
+       Elf_Internal_Shdr *bfd_elf_find_section (bfd *abfd, char *name);
+
+DESCRIPTION
+       Helper functions for GDB to locate the string tables.
+       Since BFD hides string tables from callers, GDB needs to use an
+       internal hook to find them.  Sun's .stabstr, in particular,
+       isn't even pointed to by the .stab section, so ordinary
+       mechanisms wouldn't work to find it, even if we had some.
+*/
 
 Elf_Internal_Shdr *
-DEFUN(bfd_elf_find_section, (abfd, name),      /* .stabstr offset */
+DEFUN(bfd_elf_find_section, (abfd, name),
       bfd              *abfd AND
       char             *name)
 {
-  Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
-  char *shstrtab = elf_get_str_section (abfd, elf_elfheader (abfd)->e_shstrndx);
-  unsigned int max = elf_elfheader (abfd)->e_shnum;
+  Elf_Internal_Shdr *i_shdrp;
+  Elf_Internal_Shdr *gotit = NULL;
+  char *shstrtab;
+  unsigned int max;
   unsigned int i;
 
-  for (i = 1; i < max; i++)
-    if (!strcmp (&shstrtab[i_shdrp[i].sh_name], name))
-      return &i_shdrp[i];
-  return 0;
+  i_shdrp = elf_elfsections (abfd);
+  if (i_shdrp != NULL)
+    {
+      shstrtab = elf_get_str_section (abfd, elf_elfheader (abfd)->e_shstrndx);
+      if (shstrtab != NULL)
+       {
+         max = elf_elfheader (abfd)->e_shnum;
+         for (i = 1; i < max; i++)
+           {
+             if (!strcmp (&shstrtab[i_shdrp[i].sh_name], name))
+               {
+                 gotit = &i_shdrp[i];
+               }
+           }
+       }
+    }
+  return (gotit);
 }
 
 /* End of GDB support.  */
@@ -352,20 +392,25 @@ DEFUN(elf_get_str_section, (abfd, shindex),
       bfd              *abfd AND
       unsigned int     shindex)
 {
-  Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
-  unsigned int shstrtabsize = i_shdrp[shindex].sh_size;
-  unsigned int offset = i_shdrp[shindex].sh_offset;
-  char *shstrtab = i_shdrp[shindex].rawdata;
-
-  if (shstrtab)
-    return shstrtab;
+  Elf_Internal_Shdr *i_shdrp;
+  char *shstrtab = NULL;
+  unsigned int offset;
+  unsigned int shstrtabsize;
 
-  if ((shstrtab = elf_read (abfd, offset, shstrtabsize)) == NULL)
+  i_shdrp = elf_elfsections (abfd);
+  if (i_shdrp != NULL)
     {
-      return (NULL);
+      shstrtab = i_shdrp[shindex].rawdata;
+      if (shstrtab == NULL)
+       {
+         /* No cached one, attempt to read, and cache what we read. */
+         offset = i_shdrp[shindex].sh_offset;
+         shstrtabsize = i_shdrp[shindex].sh_size;
+         shstrtab = elf_read (abfd, offset, shstrtabsize);
+         i_shdrp[shindex].rawdata = (void*) shstrtab;
+       }
     }
-  i_shdrp[shindex].rawdata = (void*)shstrtab;
-  return shstrtab;
+  return (shstrtab);
 }
 
 static char *
@@ -406,9 +451,11 @@ DEFUN(bfd_section_from_shdr, (abfd, shindex),
     elf_string_from_elf_strtab (abfd, hdr->sh_name) : "unnamed";
 
   switch(hdr->sh_type) {
+
   case SHT_NULL:
     /* inactive section. Throw it away. */
     return true;
+
   case SHT_PROGBITS:
   case SHT_NOBITS:
     /* Bits that get saved. This one is real. */
@@ -439,28 +486,16 @@ DEFUN(bfd_section_from_shdr, (abfd, shindex),
       }
     return true;
     break;
-  case SHT_SYMTAB:
-    /* we may be getting called by reference. Bring'em in... */
-    if (! hdr->rawdata) {
-      /* fetch our corresponding string table. */
-      bfd_section_from_shdr (abfd, hdr->sh_link);
-
-      /* start turning our elf symbols into bfd symbols. */
-      BFD_ASSERT (hdr->sh_entsize == sizeof (Elf_External_Sym));
-      elf_slurp_symbol_table (abfd, hdr);
-      abfd->flags |= HAS_SYMS;
-      
-    }
+
+  case SHT_SYMTAB:                     /* A symbol table */
+    BFD_ASSERT (hdr->sh_entsize == sizeof (Elf_External_Sym));
+    elf_onesymtab (abfd) = shindex;
+    abfd->flags |= HAS_SYMS;
     return true;
-  case SHT_STRTAB:
-    /* we may be getting called by reference. Bring'em in... */
-    if (! hdr->rawdata)
-      {
-       /* we don't need to do anything, just make the data available. */
-       if (elf_get_str_section (abfd, shindex) == NULL)
-         return false;
-      }
+
+  case SHT_STRTAB:                     /* A string table */
     return true;
+
   case SHT_REL:
   case SHT_RELA:
     /* *these* do a lot of work -- but build no sections! */
@@ -473,12 +508,13 @@ DEFUN(bfd_section_from_shdr, (abfd, shindex),
        
     {
       asection         *target_sect;
-      unsigned int     idx;
       
       bfd_section_from_shdr (abfd, hdr->sh_link); /* symbol table */
       bfd_section_from_shdr (abfd, hdr->sh_info); /* target */
       target_sect = section_from_elf_index (abfd, hdr->sh_info);
-      
+      if (target_sect == NULL)
+         return false;
+
 #if 0
       /* FIXME:  We are only prepared to read one symbol table, so
         do NOT read the dynamic symbol table since it is only a
@@ -491,14 +527,10 @@ DEFUN(bfd_section_from_shdr, (abfd, shindex),
       target_sect->flags |= SEC_RELOC;
       target_sect->relocation = 0;
       target_sect->rel_filepos = hdr->sh_offset;
-#if 0
-      fprintf(stderr, "ELF>> section %s reading %d relocs\n",
-             target_sect->name, target_sect->reloc_count);
-#endif
       return true;
-
     }
     break;
+
   case SHT_HASH:
   case SHT_DYNAMIC:
   case SHT_DYNSYM:             /* could treat this like symtab... */
@@ -507,12 +539,14 @@ DEFUN(bfd_section_from_shdr, (abfd, shindex),
     abort ();
 #endif
     break;
+
   case SHT_NOTE:
 #if 0
     fprintf(stderr, "Note Sections not yet supported.\n");
     abort ();
 #endif
     break;
+
   case SHT_SHLIB:
 #if 0
     fprintf(stderr, "SHLIB Sections not supported (and non conforming.)\n");
@@ -526,7 +560,7 @@ DEFUN(bfd_section_from_shdr, (abfd, shindex),
   return (true);
 }
 
-      
+
 
 
 struct strtab {
@@ -694,7 +728,7 @@ DEFUN(bfd_section_from_phdr, (abfd, hdr, index),
           (hdr -> p_memsz > hdr -> p_filesz));
   sprintf (namebuf, split ? "segment%da" : "segment%d", index);
   name = bfd_alloc (abfd, strlen (namebuf) + 1);
-  (void) strcpy (name, namebuf);
+  strcpy (name, namebuf);
   newsect = bfd_make_section (abfd, name);
   newsect -> vma = hdr -> p_vaddr;
   newsect -> _raw_size = hdr -> p_filesz;
@@ -720,7 +754,7 @@ DEFUN(bfd_section_from_phdr, (abfd, hdr, index),
     {
       sprintf (namebuf, "segment%db", index);
       name = bfd_alloc (abfd, strlen (namebuf) + 1);
-      (void) strcpy (name, namebuf);
+      strcpy (name, namebuf);
       newsect = bfd_make_section (abfd, name);
       newsect -> vma = hdr -> p_vaddr + hdr -> p_filesz;
       newsect -> _raw_size = hdr -> p_memsz - hdr -> p_filesz;
@@ -778,7 +812,7 @@ DEFUN(bfd_prpsinfo,(abfd, descdata, descsz, filepos),
     {
       if ((core_prpsinfo (abfd) = bfd_alloc (abfd, descsz)) != NULL)
        {
-         bcopy (descdata, core_prpsinfo (abfd), descsz);
+         memcpy (core_prpsinfo (abfd), descdata, descsz);
        }
     }
 }
@@ -944,7 +978,7 @@ DEFUN(elf_corefile_note, (abfd, hdr),
 
   if (hdr -> p_filesz > 0
       && (buf = (char *) bfd_xmalloc (hdr -> p_filesz)) != NULL
-      && bfd_seek (abfd, hdr -> p_offset, SEEK_SET) != -1L
+      && bfd_seek (abfd, hdr -> p_offset, SEEK_SET) != -1
       && bfd_read ((PTR) buf, hdr -> p_filesz, 1, abfd) == hdr -> p_filesz)
     {
       x_note_p = (Elf_External_Note *) buf;
@@ -1044,7 +1078,6 @@ DEFUN (elf_object_p, (abfd), bfd *abfd)
   Elf_Internal_Shdr *i_shdrp;  /* Section header table, internal form */
   int shindex;
   char *shstrtab;              /* Internal copy of section header stringtab */
-  Elf_Off offset;              /* Temp place to stash file offsets */
   
   /* Read in the ELF header in external format.  */
 
@@ -1446,8 +1479,6 @@ DEFUN (elf_make_sections, (abfd, asect, obj),
          rela_hdr->sh_entsize = sizeof (Elf_External_Rela);
          /* orelocation has the data, reloc_count has the count... */
          rela_hdr->sh_size = rela_hdr->sh_entsize * asect->reloc_count;
-         fprintf(stderr,"ELF>> sending out %d relocs to %s\n",
-                 asect->reloc_count, asect->name);
          outbound_relocs = (Elf_External_Rela *)
            bfd_alloc(abfd, asect->reloc_count * sizeof(Elf_External_Rela));
          for (idx = 0; idx < asect->reloc_count; idx++)
@@ -1724,7 +1755,6 @@ DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
     symtab_hdr->sh_link = symstrtab_section;
     symstrtab_hdr->sh_type = SHT_STRTAB;
 
-    fprintf(stderr,"ELF>> sending out %d syms\n",symcount);
     outbound_syms = (Elf_External_Sym*)
       bfd_alloc(abfd, (1+symcount) * sizeof(Elf_External_Sym));
     /* now generate the data (for "contents") */
@@ -1740,6 +1770,10 @@ DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
          sym.st_info = ELF_ST_INFO(STB_LOCAL, STT_OBJECT);
        else if (syms[idx]->flags & BSF_GLOBAL)
          sym.st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
+       else if (syms[idx]->flags & BSF_SECTION_SYM)
+         sym.st_info = ELF_ST_INFO(STB_LOCAL, STT_SECTION);
+       else if (syms[idx]->flags & BSF_FILE)
+         sym.st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE);
 
        sym.st_other = 0;
        if (syms[idx]->section) 
@@ -1784,7 +1818,7 @@ DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
 
   /* swap the header before spitting it out... */
   elf_swap_ehdr_out (abfd, i_ehdrp, &x_ehdr);
-  bfd_seek (abfd, 0L, SEEK_SET);
+  bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
   bfd_write ((PTR) &x_ehdr, sizeof(x_ehdr), 1, abfd);
 
   outbase += i_ehdrp->e_shentsize * i_ehdrp->e_shnum;
@@ -1805,7 +1839,6 @@ DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
       return (false);
     }
 
-  fprintf(stderr, "ELF>> total sections: %d\n", i_ehdrp->e_shnum);
   for (count = 0; count < i_ehdrp->e_shnum; count ++)
     {
       elf_swap_shdr_out (abfd, i_shdrp+count, x_shdrp+count);
@@ -1819,15 +1852,13 @@ DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
     {
       if(i_shdrp[count].contents)
        {
-         fprintf(stderr, "found some userdata: count %d, pos 0x%x\n",
-                 count, i_shdrp[count].sh_offset);
          bfd_seek (abfd, i_shdrp[count].sh_offset, SEEK_SET);
          bfd_write (i_shdrp[count].contents, i_shdrp[count].sh_size, 1, abfd);
        }
     }
   
   /* sample use of bfd:
-   * bfd_seek (abfd, 0L, false);
+   * bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
    * bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd);
    * if (bfd_seek(abfd, scn_base, SEEK_SET) != 0)
    * return false;
@@ -1865,7 +1896,7 @@ DEFUN (section_from_elf_index, (abfd, index),
       return (struct sec *)hdr->rawdata;
       break;
     default:
-      return 0;
+      return (struct sec *)&bfd_abs_section;
     }
 }
 
@@ -1901,19 +1932,18 @@ DEFUN (elf_section_from_bfd_section, (abfd, asect),
 }
 
 static boolean
-DEFUN (elf_slurp_symbol_table, (abfd, hdr),
+DEFUN (elf_slurp_symbol_table, (abfd, symptrs),
        bfd             *abfd AND
-       Elf_Internal_Shdr *hdr)
+       asymbol         **symptrs)      /* Buffer for generated bfd symbols */
 {
+  Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
+  Elf_Internal_Shdr *hdr = i_shdrp + elf_onesymtab (abfd);
   int symcount;                /* Number of external ELF symbols */
-  char *strtab;                /* Buffer for raw ELF string table section */
+  int i;
   asymbol *sym;                /* Pointer to current bfd symbol */
   asymbol *symbase;    /* Buffer for generated bfd symbols */
-  asymbol **vec;       /* Pointer to current bfd symbol pointer */
   Elf_Internal_Sym i_sym;
-  Elf_External_Sym x_sym;
   Elf_External_Sym *x_symp;
-  unsigned int *table_ptr;     /* bfd symbol translation table */
 
   /* this is only valid because there is only one symtab... */
   /* FIXME:  This is incorrect, there may also be a dynamic symbol
@@ -1932,10 +1962,9 @@ DEFUN (elf_slurp_symbol_table, (abfd, hdr),
 
      Note that we allocate the initial bfd canonical symbol buffer
      based on a one-to-one mapping of the ELF symbols to canonical
-     symbols.  However, it is likely that not all the ELF symbols will
-     be used, so there will be some space leftover at the end.  Once
-     we know how many symbols we actual generate, we realloc the buffer
-     to the correct size and then build the pointer vector. */
+     symbols.  We actually use all the ELF symbols, so there will be no
+     space left over at the end.  When we have all the symbols, we
+     build the caller's pointer vector. */
 
   if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
     {
@@ -1944,111 +1973,96 @@ DEFUN (elf_slurp_symbol_table, (abfd, hdr),
     }
 
   symcount = hdr->sh_size / sizeof (Elf_External_Sym);
-  sym = symbase = (asymbol *) bfd_zalloc (abfd, symcount * sizeof (asymbol));
-  x_symp = (Elf_External_Sym *)
-    bfd_zalloc (abfd, symcount * sizeof (Elf_External_Sym));
+  symbase = (asymbol *) bfd_zalloc (abfd, symcount * sizeof (asymbol));
+  sym = symbase;
+
+  /* Temporarily allocate room for the raw ELF symbols.  */
+  x_symp = (Elf_External_Sym *) malloc (symcount * sizeof (Elf_External_Sym));
 
   if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd) 
       != symcount * sizeof (Elf_External_Sym))
     {
+      free ((PTR)x_symp);
       bfd_error = system_call_error;
       return (false);
     }
-  while (symcount-- > 0)
+  /* Skip first symbol, which is a null dummy.  */
+  for (i = 1; i < symcount; i++)
     {
-      elf_swap_symbol_in (abfd, x_symp + symcount, &i_sym);
+      elf_swap_symbol_in (abfd, x_symp + i, &i_sym);
+      sym -> the_bfd = abfd;
       if (i_sym.st_name > 0)
-       {
-         sym -> the_bfd = abfd;
-         sym -> name = elf_string_from_elf_section(abfd, hdr->sh_link,
-                                                   i_sym.st_name);
-         sym -> value = i_sym.st_value;
+       sym -> name = elf_string_from_elf_section(abfd, hdr->sh_link,
+                                               i_sym.st_name);
+      else
+       sym -> name = "unnamed"; /* perhaps should include the number? */
+      sym -> value = i_sym.st_value;
 /* FIXME -- this is almost certainly bogus.  It's from Pace Willisson's
-   hasty Solaris support, to pass the sizes of object files or functions
-   down into GDB via the back door, to circumvent some other kludge in
-   how Sun hacked stabs.  */
-         sym -> udata = (PTR)i_sym.st_size;
+hasty Solaris support, to pass the sizes of object files or functions
+down into GDB via the back door, to circumvent some other kludge in
+how Sun hacked stabs.   -- gnu@cygnus.com  */
+      sym -> udata = (PTR)i_sym.st_size;
 /* FIXME -- end of bogosity.  */
-         if (i_sym.st_shndx > 0 && i_sym.st_shndx < SHN_LORESERV)
-           {
-             sym -> section = section_from_elf_index (abfd, i_sym.st_shndx);
-           }
-         else if (i_sym.st_shndx == SHN_ABS)
-           {
-             sym -> section = &bfd_abs_section;
-           }
-         else if (i_sym.st_shndx == SHN_COMMON)
-           {
-             sym -> section = &bfd_com_section;
-           }
-         else if (i_sym.st_shndx == SHN_UNDEF)
-           {
-             sym -> section = &bfd_und_section;
-           }
-         
-         switch (ELF_ST_BIND (i_sym.st_info))
-           {
-             case STB_LOCAL:
-               sym -> flags |= BSF_LOCAL;
-               break;
-             case STB_GLOBAL:
-               sym -> flags |= (BSF_GLOBAL | BSF_EXPORT);
-               break;
-             case STB_WEAK:
-               sym -> flags |= BSF_WEAK;
-               break;
-           }
-         sym++;
+      if (i_sym.st_shndx > 0 && i_sym.st_shndx < SHN_LORESERV)
+       {
+         sym -> section = section_from_elf_index (abfd, i_sym.st_shndx);
        }
-      else 
+      else if (i_sym.st_shndx == SHN_ABS)
        {
-         /* let's try *not* punting unnamed symbols... */
-         sym -> the_bfd = abfd;
-         sym -> name = "unnamed"; /* perhaps should include the number? */
-         sym -> value = i_sym.st_value;
-         if (i_sym.st_shndx > 0 && i_sym.st_shndx < SHN_LORESERV)
-           {
-             sym -> section = section_from_elf_index (abfd, i_sym.st_shndx);
-           }
-         else if (i_sym.st_shndx == SHN_ABS)
-           {
-             sym -> section = &bfd_abs_section;
-           }
-         else if (i_sym.st_shndx == SHN_COMMON)
-           {
-             sym -> section = &bfd_com_section;
-           }
-         else if (i_sym.st_shndx == SHN_UNDEF)
-           {
-             sym -> section = &bfd_und_section;
-           }
-         
-         switch (ELF_ST_BIND (i_sym.st_info))
-           {
-             case STB_LOCAL:
-               sym -> flags |= BSF_LOCAL;
-               break;
-             case STB_GLOBAL:
-               sym -> flags |= (BSF_GLOBAL | BSF_EXPORT);
-               break;
-             case STB_WEAK:
-               sym -> flags |= BSF_WEAK;
-               break;
-           }
-         sym++;
+         sym -> section = &bfd_abs_section;
+       }
+      else if (i_sym.st_shndx == SHN_COMMON)
+       {
+         sym -> section = &bfd_com_section;
+       }
+      else if (i_sym.st_shndx == SHN_UNDEF)
+       {
+         sym -> section = &bfd_und_section;
+       }
+      else
+       sym -> section = &bfd_abs_section;
+      
+      switch (ELF_ST_BIND (i_sym.st_info))
+       {
+         case STB_LOCAL:
+           sym -> flags |= BSF_LOCAL;
+           break;
+         case STB_GLOBAL:
+           sym -> flags |= (BSF_GLOBAL | BSF_EXPORT);
+           break;
+         case STB_WEAK:
+           sym -> flags |= BSF_WEAK;
+           break;
+       }
 
+      switch (ELF_ST_TYPE (i_sym.st_info))
+       {
+         case STT_SECTION:
+           sym->flags |= BSF_SECTION_SYM | BSF_DEBUGGING;
+           break;
+         case STT_FILE:
+           sym->flags |= BSF_FILE | BSF_DEBUGGING;
+           break;
        }
+      sym++;
     }
 
-  bfd_get_symcount(abfd) = symcount = sym - symbase;
-  sym = symbase = (asymbol *)
-    bfd_realloc (abfd, symbase, symcount * sizeof (asymbol));
-  bfd_get_outsymbols(abfd) = vec = (asymbol **)
-    bfd_alloc (abfd, symcount * sizeof (asymbol *));
+  /* We rely on the zalloc to clear out the final symbol entry.  */
+
+  /* We're now done with the raw symbols.  */
+  free ((PTR)x_symp);
 
-  while (symcount-- > 0)
+  bfd_get_symcount(abfd) = symcount = sym - symbase;
+  
+  /* Fill in the user's symbol pointer vector if needed.  */
+  if (symptrs)
     {
-      *vec++ = sym++;
+      sym = symbase;
+      while (symcount-- > 0)
+       {
+         *symptrs++ = sym++;
+       }
+      *symptrs = 0;                    /* Final null pointer */
     }
 
   return (true);
@@ -2057,16 +2071,23 @@ DEFUN (elf_slurp_symbol_table, (abfd, hdr),
 /* Return the number of bytes required to hold the symtab vector.
 
    Note that we base it on the count plus 1, since we will null terminate
-   the vector allocated based on this size. */
+   the vector allocated based on this size.  However, the ELF symbol table
+   always has a dummy entry as symbol #0, so it ends up even.  */
 
 static unsigned int
 DEFUN (elf_get_symtab_upper_bound, (abfd), bfd *abfd)
 {
+  unsigned int symcount;
   unsigned int symtab_size = 0;
+  Elf_Internal_Shdr *i_shdrp;
+  Elf_Internal_Shdr *hdr;
 
-  /* if (elf_slurp_symbol_table (abfd, FIXME...)) */
+  i_shdrp = elf_elfsections (abfd);
+  if (i_shdrp != NULL)
     {
-      symtab_size = (bfd_get_symcount (abfd) + 1) * (sizeof (asymbol));
+      hdr = i_shdrp + elf_onesymtab (abfd);
+      symcount = hdr->sh_size / sizeof (Elf_External_Sym);
+      symtab_size = (symcount - 1 + 1) * (sizeof (asymbol));
     }
   return (symtab_size);
 }
@@ -2189,14 +2210,10 @@ DEFUN(elf_slurp_reloca_table,(abfd, asect, symbols),
     return true;
   if (asect->flags & SEC_CONSTRUCTOR)
     return true;
-  /* if (!elf_slurp_symbol_table(abfd))
-    return false; -- should be done by now */
 
   bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
   native_relocs = (Elf_External_Rela *)
     bfd_alloc(abfd, asect->reloc_count * sizeof(Elf_External_Rela));
-  fprintf(stderr, "ELF>> really reading %d relocs for section %s\n",
-         asect->reloc_count, asect->name);
   bfd_read ((PTR) native_relocs,
            sizeof(Elf_External_Rela), asect->reloc_count, abfd);
   
@@ -2223,7 +2240,6 @@ DEFUN(elf_slurp_reloca_table,(abfd, asect, symbols),
       RELOC_PROCESSING(cache_ptr, &dst, symbols, abfd, asect);
 #else
       Elf_Internal_Rela dst;
-      asymbol        *ptr;
       Elf_External_Rela  *src;
 
       cache_ptr = reloc_cache + idx;
@@ -2244,7 +2260,6 @@ DEFUN(elf_slurp_reloca_table,(abfd, asect, symbols),
       /* ELF_R_SYM(dst.r_info) is the symbol table offset... */
       cache_ptr->sym_ptr_ptr = symbols + ELF_R_SYM(dst.r_info);
       cache_ptr->addend = dst.r_addend;
-      /* ptr = *(cache_ptr->sym_ptr_ptr); */
 
       /* Fill in the cache_ptr->howto field from dst.r_type */
       elf_info_to_howto(abfd, cache_ptr, &dst);
@@ -2286,22 +2301,11 @@ DEFUN (elf_get_symtab, (abfd, alocation),
        bfd            *abfd AND
        asymbol       **alocation)
 {
-  unsigned int symcount;
-  asymbol **vec;
 
-/*  if (!elf_slurp_symbol_table (abfd))
+  if (!elf_slurp_symbol_table (abfd, alocation))
     return (0);
-  else */
-    {
-      symcount = bfd_get_symcount (abfd);
-      vec = bfd_get_outsymbols (abfd);
-      while (symcount-- > 0)
-       {
-         *alocation++ = *vec++;
-       }
-      *alocation++ = NULL;
-      return (bfd_get_symcount (abfd));
-    }
+  else
+    return (bfd_get_symcount (abfd));
 }
 
 static asymbol *
@@ -2344,12 +2348,11 @@ DEFUN (elf_print_symbol,(ignore_abfd, filep, symbol, how),
     case bfd_print_symbol_nm:
     case bfd_print_symbol_all:
       {
-       char *section_name;
+       CONST char *section_name;
        section_name = symbol->section? symbol->section->name : "(*none*)";
        bfd_print_symbol_vandf((PTR) file, symbol);
-       fprintf(file, " %-5s %s %s %s",
+       fprintf(file, " %s\t%s",
                section_name,
-               " ", " ",
                symbol->name);
       }
       break;
@@ -2468,14 +2471,12 @@ DEFUN(elf_set_section_contents, (abfd, section, location, offset, count),
    one for little-endian machines.   */
 
 /* Archives are generic or unimplemented.  */
-#define elf_slurp_armap                        bfd_false
+#define elf_slurp_armap                        bfd_slurp_coff_armap
 #define elf_slurp_extended_name_table  _bfd_slurp_extended_name_table
 #define elf_truncate_arname            bfd_dont_truncate_arname
 #define elf_openr_next_archived_file   bfd_generic_openr_next_archived_file
 #define elf_generic_stat_arch_elt      bfd_generic_stat_arch_elt
-#define        elf_write_armap                 (PROTO (boolean, (*),           \
-     (bfd *arch, unsigned int elength, struct orl *map, unsigned int orl_count,        \
-      int stridx))) bfd_false
+#define        elf_write_armap                 coff_write_armap
 
 /* Ordinary section reading and writing */
 #define elf_new_section_hook           _bfd_dummy_new_section_hook
@@ -2511,6 +2512,10 @@ bfd_target elf_big_vec =
   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
    SEC_CODE | SEC_DATA), 
 
+   /* leading_symbol_char: is the first char of a user symbol
+      predictable, and if so what is it */
+   0,
+
   /* ar_pad_char: pad character for filenames within an archive header
      FIXME:  this really has nothing to do with ELF, this is a characteristic
      of the archiver and/or os and should be independently tunable */
@@ -2553,12 +2558,20 @@ bfd_target elf_big_vec =
     bfd_false
   },
 
-  /* Initialize a jump table with the standard macro.  All names start
-     with "elf" */
+  /* Initialize a jump table with the standard macro.  All names start with
+     "elf" */
   JUMP_TABLE(elf),
 
-  /* SWAP_TABLE */
-  NULL, NULL, NULL
+  /* reloc_type_lookup: How applications can find out about amiga relocation
+     types (see documentation on reloc types).  */
+  NULL,
+
+  /* _bfd_make_debug_symbol:  Back-door to allow format aware applications to
+     create debug symbols while using BFD for everything else. */
+  NULL,
+
+  /* backend_data: */
+  NULL
 };
 
 bfd_target elf_little_vec =
@@ -2583,6 +2596,10 @@ bfd_target elf_little_vec =
   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
    SEC_DATA), 
 
+   /* leading_symbol_char: is the first char of a user symbol
+      predictable, and if so what is it */
+   0,
+
   /* ar_pad_char: pad character for filenames within an archive header
      FIXME:  this really has nothing to do with ELF, this is a characteristic
      of the archiver and/or os and should be independently tunable */
@@ -2625,10 +2642,18 @@ bfd_target elf_little_vec =
     bfd_false
   },
 
-  /* Initialize a jump table with the standard macro.  All names start
-     with "elf" */
+  /* Initialize a jump table with the standard macro.  All names start with
+     "elf" */
   JUMP_TABLE(elf),
 
-  /* SWAP_TABLE */
-  NULL, NULL, NULL
+  /* reloc_type_lookup: How applications can find out about amiga relocation
+     types (see documentation on reloc types).  */
+  NULL,
+
+  /* _bfd_make_debug_symbol:  Back-door to allow format aware applications to
+     create debug symbols while using BFD for everything else. */
+  NULL,
+
+  /* backend_data: */
+  NULL
 };
This page took 0.032662 seconds and 4 git commands to generate.