2001-11-06 Fred Fish <fnf@redhat.com>
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
index 0a94c12f91e132364d0b05b735ca3e79f0de9db8..c881ee4dc0a218827661298954340db6717e481a 100644 (file)
@@ -33,6 +33,12 @@ static reloc_howto_type * cris_reloc_type_lookup
 static void cris_info_to_howto_rela
   PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
 
+static boolean cris_elf_grok_prstatus
+  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
+
+static boolean cris_elf_grok_psinfo
+  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
+
 static boolean cris_elf_relocate_section
   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
@@ -86,7 +92,7 @@ static boolean elf_cris_finish_dynamic_sections
 static void elf_cris_hide_symbol
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
 static enum elf_reloc_type_class elf_cris_reloc_type_class
-  PARAMS ((int));
+  PARAMS ((const Elf_Internal_Rela *));
 
 static reloc_howto_type cris_elf_howto_table [] =
 {
@@ -439,8 +445,7 @@ cris_reloc_type_lookup (abfd, code)
 {
   unsigned int i;
 
-  for (i = sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]);
-       --i;)
+  for (i = 0; i < sizeof (cris_reloc_map) / sizeof (cris_reloc_map[0]); i++)
     if (cris_reloc_map [i].bfd_reloc_val == code)
       return & cris_elf_howto_table [cris_reloc_map[i].cris_reloc_val];
 
@@ -462,6 +467,72 @@ cris_info_to_howto_rela (abfd, cache_ptr, dst)
   cache_ptr->howto = & cris_elf_howto_table [r_type];
 }
 \f
+/* Support for core dump NOTE sections.  */
+
+static boolean
+cris_elf_grok_prstatus (abfd, note)
+     bfd *abfd;
+     Elf_Internal_Note *note;
+{
+  int offset;
+  size_t raw_size;
+
+  switch (note->descsz)
+    {
+      default:
+       return false;
+
+      case 166:                /* Linux/CRIS */
+       /* pr_cursig */
+       elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
+
+       /* pr_pid */
+       elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 22);
+
+       /* pr_reg */
+       offset = 70;
+       raw_size = 92;
+
+       break;
+    }
+
+  /* Make a ".reg/999" section.  */
+  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+                                         raw_size, note->descpos + offset);
+}
+
+static boolean
+cris_elf_grok_psinfo (abfd, note)
+     bfd *abfd;
+     Elf_Internal_Note *note;
+{
+  switch (note->descsz)
+    {
+      default:
+       return false;
+
+      case 124:                /* Linux/CRIS elf_prpsinfo */
+       elf_tdata (abfd)->core_program
+        = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
+       elf_tdata (abfd)->core_command
+        = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
+    }
+
+  /* Note that for some reason, a spurious space is tacked
+     onto the end of the args in some (at least one anyway)
+     implementations, so strip it off if it exists.  */
+
+  {
+    char *command = elf_tdata (abfd)->core_command;
+    int n = strlen (command);
+
+    if (0 < n && command[n - 1] == ' ')
+      command[n - 1] = '\0';
+  }
+
+  return true;
+}
+\f
 /* The name of the dynamic interpreter.  This is put in the .interp
    section.  */
 
@@ -876,21 +947,12 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                              + sec->output_offset);
              else
                {
-                 if (input_bfd->my_archive)
-                   (*_bfd_error_handler)
-                     (_("%s(%s): unresolvable relocation %s against symbol `%s' from %s section"),
-                      bfd_get_filename (bfd_my_archive (input_bfd)),
-                      bfd_get_filename (input_bfd),
-                      cris_elf_howto_table[r_type].name,
-                      symname,
-                      bfd_get_section_name (input_bfd, input_section));
-                 else
-                   (*_bfd_error_handler)
-                     (_("%s: unresolvable relocation %s against symbol `%s' from %s section"),
-                      bfd_get_filename (input_bfd),
-                      cris_elf_howto_table[r_type].name,
-                      symname,
-                      bfd_get_section_name (input_bfd, input_section));
+                 (*_bfd_error_handler)
+                   (_("%s: unresolvable relocation %s against symbol `%s' from %s section"),
+                    bfd_archive_filename (input_bfd),
+                    cris_elf_howto_table[r_type].name,
+                    symname,
+                    bfd_get_section_name (input_bfd, input_section));
                  bfd_set_error (bfd_error_bad_value);
                  return false;
                }
@@ -950,7 +1012,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              (*_bfd_error_handler)
                (_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
-                bfd_get_filename (input_bfd),
+                bfd_archive_filename (input_bfd),
                 cris_elf_howto_table[r_type].name,
                 symname[0] != '\0' ? symname : _("[whose name is lost]"),
                 bfd_get_section_name (input_bfd, input_section));
@@ -1069,14 +1131,14 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                if (h == NULL)
                  (*_bfd_error_handler)
                    (_("%s: relocation %s with non-zero addend %d against local symbol from %s section"),
-                    bfd_get_filename (input_bfd),
+                    bfd_archive_filename (input_bfd),
                     cris_elf_howto_table[r_type].name,
                     rel->r_addend,
                     bfd_get_section_name (input_bfd, input_section));
                else
                  (*_bfd_error_handler)
                    (_("%s: relocation %s with non-zero addend %d against symbol `%s' from %s section"),
-                    bfd_get_filename (input_bfd),
+                    bfd_archive_filename (input_bfd),
                     cris_elf_howto_table[r_type].name,
                     rel->r_addend,
                     symname[0] != '\0' ? symname : _("[whose name is lost]"),
@@ -1094,7 +1156,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              (*_bfd_error_handler)
                (_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
-                bfd_get_filename (input_bfd),
+                bfd_archive_filename (input_bfd),
                 cris_elf_howto_table[r_type].name,
                 symname,
                 bfd_get_section_name (input_bfd, input_section));
@@ -1212,7 +1274,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                    {
                      (*_bfd_error_handler)
                        (_("%s: Internal inconsistency; no relocation section %s"),
-                        bfd_get_filename (input_bfd),
+                        bfd_archive_filename (input_bfd),
                         name);
 
                      bfd_set_error (bfd_error_bad_value);
@@ -2324,10 +2386,9 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                 GOT entries.  */
              amt = symtab_hdr->sh_info + 1;
              amt *= sizeof (bfd_signed_vma);
-             local_got_refcounts = ((bfd_signed_vma *) bfd_alloc (abfd, amt));
+             local_got_refcounts = ((bfd_signed_vma *) bfd_zalloc (abfd, amt));
              if (local_got_refcounts == NULL)
                return false;
-             memset (local_got_refcounts, -1, (size_t) amt);
 
              local_got_refcounts++;
              elf_local_got_refcounts (abfd) = local_got_refcounts;
@@ -2380,10 +2441,8 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
 
          if (h != NULL)
            {
-             if (h->got.refcount == -1)
+             if (h->got.refcount == 0)
                {
-                 h->got.refcount = 1;
-
                  /* Make sure this symbol is output as a dynamic symbol.  */
                  if (h->dynindx == -1)
                    {
@@ -2396,16 +2455,13 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                  /* Allocate relocation space.  */
                  srelgot->_raw_size += sizeof (Elf32_External_Rela);
                }
-             else
-               h->got.refcount++;
+             h->got.refcount++;
            }
          else
            {
              /* This is a global offset table entry for a local symbol.  */
-             if (local_got_refcounts[r_symndx] == -1)
+             if (local_got_refcounts[r_symndx] == 0)
                {
-                 local_got_refcounts[r_symndx] = 1;
-
                  sgot->_raw_size += 4;
                  if (info->shared)
                    {
@@ -2415,8 +2471,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                      srelgot->_raw_size += sizeof (Elf32_External_Rela);
                    }
                }
-             else
-               local_got_refcounts[r_symndx]++;
+             local_got_refcounts[r_symndx]++;
            }
          break;
 
@@ -2449,10 +2504,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
            continue;
 
          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
-         if (h->plt.refcount == -1)
-           h->plt.refcount = 1;
-         else
-           h->plt.refcount++;
+         h->plt.refcount++;
          break;
 
        case R_CRIS_8:
@@ -2470,19 +2522,11 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
              && (sec->flags & SEC_READONLY) != 0)
            {
              /* FIXME: How do we make this optionally a warning only?  */
-             if (abfd->my_archive)
-               (*_bfd_error_handler)
-                 (_("%s(%s), section %s:\n  relocation %s should not be used in a shared object; recompile with -fPIC"),
-                  bfd_get_filename (bfd_my_archive (abfd)),
-                  bfd_get_filename (abfd),
-                  sec->name,
-                  cris_elf_howto_table[r_type].name);
-             else
-               (*_bfd_error_handler)
-                 (_("%s, section %s:\n  relocation %s should not be used in a shared object; recompile with -fPIC"),
-                  bfd_get_filename (abfd),
-                  sec->name,
-                  cris_elf_howto_table[r_type].name);
+             (*_bfd_error_handler)
+               (_("%s, section %s:\n  relocation %s should not be used in a shared object; recompile with -fPIC"),
+                bfd_archive_filename (abfd),
+                sec->name,
+                cris_elf_howto_table[r_type].name);
            }
          /* Fall through.  */
 
@@ -2495,10 +2539,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
 
              /* Make sure a plt entry is created for this symbol if it
                 turns out to be a function defined by a dynamic object.  */
-             if (h->plt.refcount == -1)
-               h->plt.refcount = 1;
-             else
-               h->plt.refcount++;
+             h->plt.refcount++;
            }
 
          /* If we are creating a shared library and this is not a local
@@ -2988,7 +3029,7 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
        ((new_flags & EF_CRIS_UNDERSCORE)
         ? _("%s: uses _-prefixed symbols, but writing file with non-prefixed symbols")
         : _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
-        bfd_get_filename (ibfd));
+        bfd_archive_filename (ibfd));
       bfd_set_error (bfd_error_bad_value);
       return false;
     }
@@ -2998,10 +3039,10 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
 
 
 static enum elf_reloc_type_class
-elf_cris_reloc_type_class (type)
-     int type;
+elf_cris_reloc_type_class (rela)
+     const Elf_Internal_Rela *rela;
 {
-  switch (type)
+  switch ((int) ELF32_R_TYPE (rela->r_info))
     {
     case R_CRIS_RELATIVE:
       return reloc_class_relative;
@@ -3028,8 +3069,11 @@ elf_cris_reloc_type_class (type)
 #define elf_backend_gc_mark_hook               cris_elf_gc_mark_hook
 #define elf_backend_gc_sweep_hook              cris_elf_gc_sweep_hook
 #define elf_backend_check_relocs                cris_elf_check_relocs
+#define elf_backend_grok_prstatus              cris_elf_grok_prstatus
+#define elf_backend_grok_psinfo                        cris_elf_grok_psinfo
 
 #define elf_backend_can_gc_sections            1
+#define elf_backend_can_refcount               1
 
 #define elf_backend_object_p                   cris_elf_object_p
 #define elf_backend_final_write_processing \
This page took 0.027542 seconds and 4 git commands to generate.