dummy commit before egcs merge
[deliverable/binutils-gdb.git] / bfd / elfcode.h
index 87e02f2523604e61e8d3ed29f97f9a0451f4de7e..60ac0ea94604083d21ea8d8983d01f5f027c18c7 100644 (file)
@@ -1,5 +1,5 @@
 /* ELF executable support for BFD.
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
+   Copyright 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
 
    Written by Fred Fish @ Cygnus Support, from information published
    in "UNIX System V Release 4, Programmers Guide: ANSI C and
@@ -68,6 +68,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "fnmatch.h"
 
 /* Renaming structures, typedefs, macros and functions to be size-specific.  */
 #define Elf_External_Ehdr      NAME(Elf,External_Ehdr)
@@ -141,7 +142,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #define LOG_FILE_ALIGN 2
 #endif
 
-/* Forward declarations of static functions */
+/* Static functions */
 
 static void elf_swap_ehdr_in
   PARAMS ((bfd *, const Elf_External_Ehdr *, Elf_Internal_Ehdr *));
@@ -161,6 +162,8 @@ static boolean elf_slurp_reloc_table
 
 static void write_relocs PARAMS ((bfd *, asection *, PTR));
 
+static boolean elf_file_p PARAMS ((Elf_External_Ehdr *));
+
 #ifdef DEBUG
 static void elf_debug_section PARAMS ((int, Elf_Internal_Shdr *));
 static void elf_debug_file PARAMS ((Elf_Internal_Ehdr *));
@@ -173,11 +176,15 @@ static char *elf_symbol_flags PARAMS ((flagword));
    can be handled by explicitly specifying 32 bits or "the long type".  */
 #if ARCH_SIZE == 64
 #define put_word       bfd_h_put_64
+#define put_signed_word        bfd_h_put_signed_64
 #define get_word       bfd_h_get_64
+#define get_signed_word        bfd_h_get_signed_64
 #endif
 #if ARCH_SIZE == 32
 #define put_word       bfd_h_put_32
+#define put_signed_word        bfd_h_put_signed_32
 #define get_word       bfd_h_get_32
+#define get_signed_word        bfd_h_get_signed_32
 #endif
 
 /* Translate an ELF symbol in external format into an ELF symbol in internal
@@ -369,7 +376,7 @@ elf_swap_reloca_in (abfd, src, dst)
 {
   dst->r_offset = get_word (abfd, (bfd_byte *) src->r_offset);
   dst->r_info = get_word (abfd, (bfd_byte *) src->r_info);
-  dst->r_addend = get_word (abfd, (bfd_byte *) src->r_addend);
+  dst->r_addend = get_signed_word (abfd, (bfd_byte *) src->r_addend);
 }
 
 /* Translate an ELF reloc from internal format to external format. */
@@ -391,7 +398,7 @@ elf_swap_reloca_out (abfd, src, dst)
 {
   put_word (abfd, src->r_offset, dst->r_offset);
   put_word (abfd, src->r_info, dst->r_info);
-  put_word (abfd, src->r_addend, dst->r_addend);
+  put_signed_word (abfd, src->r_addend, dst->r_addend);
 }
 
 INLINE void
@@ -455,6 +462,7 @@ elf_object_p (abfd)
   struct elf_backend_data *ebd;
   struct elf_obj_tdata *preserved_tdata = elf_tdata (abfd);
   struct elf_obj_tdata *new_tdata = NULL;
+  asection *s;
 
   /* Read in the ELF header in external format.  */
 
@@ -658,6 +666,25 @@ elf_object_p (abfd)
        goto got_wrong_format_error;
     }
 
+  /* If we have created any reloc sections that are associated with
+     debugging sections, mark the reloc sections as debugging as well.  */
+  for (s = abfd->sections; s != NULL; s = s->next)
+    {
+      if ((elf_section_data (s)->this_hdr.sh_type == SHT_REL
+          || elf_section_data (s)->this_hdr.sh_type == SHT_RELA)
+         && elf_section_data (s)->this_hdr.sh_info > 0)
+       {
+         unsigned long targ_index;
+         asection *targ_sec;
+
+         targ_index = elf_section_data (s)->this_hdr.sh_info;
+         targ_sec = bfd_section_from_elf_index (abfd, targ_index);
+         if (targ_sec != NULL
+             && (targ_sec->flags & SEC_DEBUGGING) != 0)
+           s->flags |= SEC_DEBUGGING;
+       }
+    }
+
   return (abfd->xvec);
 
 got_wrong_format_error:
@@ -902,11 +929,13 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
      boolean dynamic;
 {
   Elf_Internal_Shdr *hdr;
-  long symcount;               /* Number of external ELF symbols */
+  Elf_Internal_Shdr *verhdr;
+  unsigned long symcount;      /* Number of external ELF symbols */
   elf_symbol_type *sym;                /* Pointer to current bfd symbol */
   elf_symbol_type *symbase;    /* Buffer for generated bfd symbols */
   Elf_Internal_Sym i_sym;
   Elf_External_Sym *x_symp = NULL;
+  Elf_External_Versym *x_versymp = NULL;
 
   /* Read each raw ELF symbol, converting from external ELF form to
      internal ELF form, and then using the information to create a
@@ -918,10 +947,28 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
      space left over at the end.  When we have all the symbols, we
      build the caller's pointer vector. */
 
-  if (dynamic)
-    hdr = &elf_tdata (abfd)->dynsymtab_hdr;
+  if (! dynamic)
+    {
+      hdr = &elf_tdata (abfd)->symtab_hdr;
+      verhdr = NULL;
+    }
   else
-    hdr = &elf_tdata (abfd)->symtab_hdr;
+    {
+      hdr = &elf_tdata (abfd)->dynsymtab_hdr;
+      if (elf_dynversym (abfd) == 0)
+       verhdr = NULL;
+      else
+       verhdr = &elf_tdata (abfd)->dynversym_hdr;
+      if ((elf_tdata (abfd)->dynverdef_section != 0
+          && elf_tdata (abfd)->verdef == NULL)
+         || (elf_tdata (abfd)->dynverref_section != 0
+             && elf_tdata (abfd)->verref == NULL))
+       {
+         if (! _bfd_elf_slurp_version_tables (abfd))
+           return -1;
+       }
+    }
+
   if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
     return -1;
 
@@ -931,7 +978,7 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
     sym = symbase = NULL;
   else
     {
-      long i;
+      unsigned long i;
 
       if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
        return -1;
@@ -951,6 +998,37 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
       if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd)
          != symcount * sizeof (Elf_External_Sym))
        goto error_return;
+
+      /* Read the raw ELF version symbol information.  */
+
+      if (verhdr != NULL
+         && verhdr->sh_size / sizeof (Elf_External_Versym) != symcount)
+       {
+         (*_bfd_error_handler)
+           (_("%s: version count (%ld) does not match symbol count (%ld)"),
+            abfd->filename,
+            (long) (verhdr->sh_size / sizeof (Elf_External_Versym)),
+            symcount);
+
+         /* Slurp in the symbols without the version information,
+             since that is more helpful than just quitting.  */
+         verhdr = NULL;
+       }
+
+      if (verhdr != NULL)
+       {
+         if (bfd_seek (abfd, verhdr->sh_offset, SEEK_SET) != 0)
+           goto error_return;
+
+         x_versymp = (Elf_External_Versym *) bfd_malloc (verhdr->sh_size);
+         if (x_versymp == NULL && verhdr->sh_size != 0)
+           goto error_return;
+
+         if (bfd_read ((PTR) x_versymp, 1, verhdr->sh_size, abfd)
+             != verhdr->sh_size)
+           goto error_return;
+       }
+
       /* Skip first symbol, which is a null dummy.  */
       for (i = 1; i < symcount; i++)
        {
@@ -999,7 +1077,10 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
          else
            sym->symbol.section = bfd_abs_section_ptr;
 
-         sym->symbol.value -= sym->symbol.section->vma;
+         /* If this is a relocateable file, then the symbol value is
+             already section relative.  */
+         if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
+           sym->symbol.value -= sym->symbol.section->vma;
 
          switch (ELF_ST_BIND (i_sym.st_info))
            {
@@ -1035,6 +1116,14 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
          if (dynamic)
            sym->symbol.flags |= BSF_DYNAMIC;
 
+         if (x_versymp != NULL)
+           {
+             Elf_Internal_Versym iversym;
+
+             _bfd_elf_swap_versym_in (abfd, x_versymp + i, &iversym);
+             sym->version = iversym.vs_vers;
+           }
+
          /* Do some backend-specific processing on this symbol.  */
          {
            struct elf_backend_data *ebd = get_elf_backend_data (abfd);
@@ -1071,10 +1160,14 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
       *symptrs = 0;            /* Final null pointer */
     }
 
+  if (x_versymp != NULL)
+    free (x_versymp);
   if (x_symp != NULL)
     free (x_symp);
   return symcount;
 error_return:
+  if (x_versymp != NULL)
+    free (x_versymp);
   if (x_symp != NULL)
     free (x_symp);
   return -1;
This page took 0.026638 seconds and 4 git commands to generate.