2002-04-23 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
index a679c4fd465f70b6680303062f01dbf460bbe153..ab72483304b34bba2ff124a5a9b5cbe675cd89fa 100644 (file)
@@ -1,5 +1,5 @@
 /* CRIS-specific support for 32-bit ELF.
-   Copyright 2000, 2001 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed by Axis Communications AB.
    Written by Hans-Peter Nilsson, based on elf32-fr30.c
    PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
@@ -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 **));
@@ -72,6 +78,10 @@ static struct bfd_link_hash_table *elf_cris_link_hash_table_create
   PARAMS ((bfd *));
 static boolean elf_cris_adjust_dynamic_symbol
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+static boolean cris_elf_check_relocs
+  PARAMS ((bfd *, struct bfd_link_info *, asection *,
+          const Elf_Internal_Rela *));
+
 static boolean elf_cris_size_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static boolean elf_cris_finish_dynamic_symbol
@@ -80,7 +90,9 @@ static boolean elf_cris_finish_dynamic_symbol
 static boolean elf_cris_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static void elf_cris_hide_symbol
-  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
+static enum elf_reloc_type_class elf_cris_reloc_type_class
+  PARAMS ((const Elf_Internal_Rela *));
 
 static reloc_howto_type cris_elf_howto_table [] =
 {
@@ -168,7 +180,7 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
-        "R_CRIS_16",           /* name */
+        "R_CRIS_16_PCREL",     /* name */
         false,                 /* partial_inplace */
         0x00000000,            /* src_mask */
         0x0000ffff,            /* dst_mask */
@@ -183,7 +195,7 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
-        "R_CRIS_32",           /* name */
+        "R_CRIS_32_PCREL",     /* name */
         false,                 /* partial_inplace */
         0x00000000,            /* src_mask */
         0xffffffff,            /* dst_mask */
@@ -433,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];
 
@@ -456,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 214:                /* 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 = 140;
+
+       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.  */
 
@@ -631,16 +708,16 @@ elf_cris_link_hash_table_create (abfd)
      bfd *abfd;
 {
   struct elf_cris_link_hash_table *ret;
+  bfd_size_type amt = sizeof (struct elf_cris_link_hash_table);
 
-  ret = ((struct elf_cris_link_hash_table *)
-        bfd_alloc (abfd, sizeof (struct elf_cris_link_hash_table)));
+  ret = ((struct elf_cris_link_hash_table *) bfd_malloc (amt));
   if (ret == (struct elf_cris_link_hash_table *) NULL)
     return NULL;
 
   if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
                                       elf_cris_link_hash_newfunc))
     {
-      bfd_release (abfd, ret);
+      free (ret);
       return NULL;
     }
 
@@ -752,7 +829,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
       struct elf_link_hash_entry * h;
       bfd_vma                      relocation;
       bfd_reloc_status_type        r;
-      const char *                 name = NULL;
+      const char *                 symname = NULL;
       int                          r_type;
 
       r_type = ELF32_R_TYPE (rel->r_info);
@@ -793,13 +870,12 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections [r_symndx];
-         relocation = (sec->output_section->vma
-                       + sec->output_offset
-                       + sym->st_value);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
 
-         name = bfd_elf_string_from_elf_section
-           (input_bfd, symtab_hdr->sh_link, sym->st_name);
-         name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
+         symname = (bfd_elf_string_from_elf_section
+                    (input_bfd, symtab_hdr->sh_link, sym->st_name));
+         if (symname == NULL)
+           symname = bfd_section_name (input_bfd, sec);
        }
       else
        {
@@ -809,7 +885,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                 || h->root.type == bfd_link_hash_warning)
            h = (struct elf_link_hash_entry *) h->root.u.i.link;
 
-         name = h->root.root.string;
+         symname = h->root.root.string;
 
          if (h->root.type == bfd_link_hash_defined
              || h->root.type == bfd_link_hash_defweak)
@@ -869,21 +945,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,
-                      name,
-                      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,
-                      name,
-                      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;
                }
@@ -891,14 +958,14 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
          else if (info->shared
-                  && !info->symbolic
+                  && (!info->symbolic || info->allow_shlib_undefined)
                   && !info->no_undefined
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
          else
            {
              if (!(info->callbacks->undefined_symbol
-                   (info, name, input_bfd,
+                   (info, symname, input_bfd,
                     input_section, rel->r_offset,
                     (!info->shared || info->no_undefined
                      || ELF_ST_VISIBILITY (h->other)))))
@@ -943,9 +1010,9 @@ 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,
-                name[0] != '\0' ? name : _("[whose name is lost]"),
+                symname[0] != '\0' ? symname : _("[whose name is lost]"),
                 bfd_get_section_name (input_bfd, input_section));
 
              /* FIXME: Perhaps blaming input is not the right thing to
@@ -1062,17 +1129,17 @@ 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,
-                    name[0] != '\0' ? name : _("[whose name is lost]"),
+                    symname[0] != '\0' ? symname : _("[whose name is lost]"),
                     bfd_get_section_name (input_bfd, input_section));
 
                bfd_set_error (bfd_error_bad_value);
@@ -1087,9 +1154,23 @@ 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));
+             bfd_set_error (bfd_error_bad_value);
+             return false;
+           }
+
+         /* This can happen if we get a link error with the input ELF
+            variant mismatching the output variant.  Emit an error so
+            it's noticed if it happens elsewhere.  */
+         if (sgot == NULL)
+           {
+             (*_bfd_error_handler)
+               (_("%s: relocation %s in section %s with no GOT created"),
+                bfd_archive_filename (input_bfd),
                 cris_elf_howto_table[r_type].name,
-                name,
                 bfd_get_section_name (input_bfd, input_section));
              bfd_set_error (bfd_error_bad_value);
              return false;
@@ -1164,6 +1245,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_CRIS_16:
        case R_CRIS_32:
          if (info->shared
+             && r_symndx != 0
              && (input_section->flags & SEC_ALLOC) != 0
              && ((r_type != R_CRIS_8_PCREL
                   && r_type != R_CRIS_16_PCREL
@@ -1205,7 +1287,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);
@@ -1214,31 +1296,20 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                }
 
              skip = false;
-
-             if (elf_section_data (input_section)->stab_info == NULL)
-               outrel.r_offset = rel->r_offset;
-             else
-               {
-                 bfd_vma off;
-
-                 off = (_bfd_stab_section_offset
-                        (output_bfd, &elf_hash_table (info)->stab_info,
-                         input_section,
-                         &elf_section_data (input_section)->stab_info,
-                         rel->r_offset));
-                 if (off == (bfd_vma) -1)
-                   skip = true;
-                 outrel.r_offset = off;
-               }
-
+             relocate = false;
+
+             outrel.r_offset =
+               _bfd_elf_section_offset (output_bfd, info, input_section,
+                                        rel->r_offset);
+             if (outrel.r_offset == (bfd_vma) -1)
+               skip = true;
+             else if (outrel.r_offset == (bfd_vma) -2)
+               skip = true, relocate = true;
              outrel.r_offset += (input_section->output_section->vma
                                  + input_section->output_offset);
 
              if (skip)
-               {
-                 memset (&outrel, 0, sizeof outrel);
-                 relocate = false;
-               }
+               memset (&outrel, 0, sizeof outrel);
              /* h->dynindx may be -1 if the symbol was marked to
                 become local.  */
              else if (h != NULL
@@ -1247,7 +1318,6 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                               & ELF_LINK_HASH_DEF_REGULAR) == 0))
                {
                  BFD_ASSERT (h->dynindx != -1);
-                 relocate = false;
                  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
                  outrel.r_addend = relocation + rel->r_addend;
                }
@@ -1288,7 +1358,6 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                          BFD_ASSERT (indx > 0);
                        }
 
-                     relocate = false;
                      outrel.r_info = ELF32_R_INFO (indx, r_type);
                      outrel.r_addend = relocation + rel->r_addend;
                    }
@@ -1321,13 +1390,13 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
            case bfd_reloc_overflow:
              r = info->callbacks->reloc_overflow
-               (info, name, howto->name, (bfd_vma) 0,
+               (info, symname, howto->name, (bfd_vma) 0,
                 input_bfd, input_section, rel->r_offset);
              break;
 
            case bfd_reloc_undefined:
              r = info->callbacks->undefined_symbol
-               (info, name, input_bfd, input_section, rel->r_offset,
+               (info, symname, input_bfd, input_section, rel->r_offset,
                 true);
              break;
 
@@ -1350,7 +1419,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
          if (msg)
            r = info->callbacks->warning
-             (info, msg, name, input_bfd, input_section, rel->r_offset);
+             (info, msg, symname, input_bfd, input_section, rel->r_offset);
 
          if (! r)
            return false;
@@ -1499,6 +1568,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
       asection *sgot;
       asection *srela;
       Elf_Internal_Rela rela;
+      bfd_byte *where;
 
       /* This symbol has an entry in the global offset table.  Set it up.  */
 
@@ -1508,27 +1578,25 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
 
       rela.r_offset = (sgot->output_section->vma
                       + sgot->output_offset
-                      + (h->got.offset &~ 1));
+                      + (h->got.offset &~ (bfd_vma) 1));
 
       /* If this is a static link, or it is a -Bsymbolic link and the
         symbol is defined locally or was forced to be local because
         of a version file, we just want to emit a RELATIVE reloc.
         The entry in the global offset table will already have been
         initialized in the relocate_section function.  */
+      where = sgot->contents + (h->got.offset &~ (bfd_vma) 1);
       if (! elf_hash_table (info)->dynamic_sections_created
          || (info->shared
              && (info->symbolic || h->dynindx == -1)
              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
        {
          rela.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
-         rela.r_addend = bfd_get_signed_32 (output_bfd,
-                                            (sgot->contents
-                                             + (h->got.offset & ~1)));
+         rela.r_addend = bfd_get_signed_32 (output_bfd, where);
        }
       else
        {
-         bfd_put_32 (output_bfd, (bfd_vma) 0,
-                     sgot->contents + (h->got.offset & ~1));
+         bfd_put_32 (output_bfd, (bfd_vma) 0, where);
          rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_GLOB_DAT);
          rela.r_addend = 0;
        }
@@ -1734,13 +1802,7 @@ cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
     }
   else
     {
-      if (!(elf_bad_symtab (abfd)
-           && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
-         && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
-               && sym->st_shndx != SHN_COMMON))
-       {
-         return bfd_section_from_elf_index (abfd, sym->st_shndx);
-       }
+      return bfd_section_from_elf_index (abfd, sym->st_shndx);
     }
 
   return NULL;
@@ -1868,6 +1930,9 @@ elf_cris_adjust_gotplt_to_got (h, p)
 
   BFD_ASSERT (dynobj != NULL);
 
+  if (h->root.root.type == bfd_link_hash_warning)
+    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+
   /* If nobody wanted a GOTPLT with this symbol, we're done.  */
   if (h->gotplt_refcount <= 0)
     return true;
@@ -1892,28 +1957,9 @@ elf_cris_adjust_gotplt_to_got (h, p)
 
       h->gotplt_refcount = -1;
 
-      /* We always have a .got section when there are dynamic
-        relocs.  */
-      BFD_ASSERT (sgot != NULL /* Surely have .got section.  */);
-
-      /* We might have had a PLT but with no GOT entry and
-        further no GOT reloc section at all needed before.
-        Add it.  */
-      if (srelgot == NULL)
-       {
-         srelgot = bfd_make_section (dynobj, ".rela.got");
-
-         if (srelgot == NULL
-             || !bfd_set_section_flags (dynobj, srelgot,
-                                        (SEC_ALLOC
-                                         | SEC_LOAD
-                                         | SEC_HAS_CONTENTS
-                                         | SEC_IN_MEMORY
-                                         | SEC_LINKER_CREATED
-                                         | SEC_READONLY))
-             || !bfd_set_section_alignment (dynobj, srelgot, 2))
-           return false;
-       }
+      /* We always have a .got and a .rela.got section if there were
+        GOTPLT relocs in input.  */
+      BFD_ASSERT (sgot != NULL && srelgot != NULL);
 
       /* Allocate space in the .got section.  */
       sgot->_raw_size += 4;
@@ -1978,13 +2024,14 @@ elf_cris_try_fold_plt_to_got (h, p)
    entry.  */
 
 static void
-elf_cris_hide_symbol (info, h)
+elf_cris_hide_symbol (info, h, force_local)
      struct bfd_link_info *info;
      struct elf_link_hash_entry *h;
+     boolean force_local;
 {
   elf_cris_adjust_gotplt_to_got ((struct elf_cris_link_hash_entry *) h, info);
 
-  _bfd_elf_link_hash_hide_symbol (info, h);
+  _bfd_elf_link_hash_hide_symbol (info, h, force_local);
 }
 
 /* Adjust a symbol defined by a dynamic object and referenced by a
@@ -2302,8 +2349,38 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
         specific GOT entry).  */
       switch (r_type)
        {
+         /* For R_CRIS_16_GOTPLT and R_CRIS_32_GOTPLT, we need a GOT
+            entry only for local symbols.  Unfortunately, we don't know
+            until later on if there's a version script that forces the
+            symbol local.  We must have the .rela.got section in place
+            before we know if the symbol looks global now, so we need
+            to treat the reloc just like for R_CRIS_16_GOT and
+            R_CRIS_32_GOT.  */
+       case R_CRIS_16_GOTPLT:
+       case R_CRIS_32_GOTPLT:
        case R_CRIS_16_GOT:
        case R_CRIS_32_GOT:
+         if (srelgot == NULL
+             && (h != NULL || info->shared))
+           {
+             srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
+             if (srelgot == NULL)
+               {
+                 srelgot = bfd_make_section (dynobj, ".rela.got");
+                 if (srelgot == NULL
+                     || !bfd_set_section_flags (dynobj, srelgot,
+                                                (SEC_ALLOC
+                                                 | SEC_LOAD
+                                                 | SEC_HAS_CONTENTS
+                                                 | SEC_IN_MEMORY
+                                                 | SEC_LINKER_CREATED
+                                                 | SEC_READONLY))
+                     || !bfd_set_section_alignment (dynobj, srelgot, 2))
+                   return false;
+               }
+           }
+         /* Fall through.  */
+
        case R_CRIS_32_GOTREL:
        case R_CRIS_32_PLT_GOTREL:
          if (sgot == NULL)
@@ -2311,17 +2388,16 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
 
          if (local_got_refcounts == NULL)
            {
-             size_t size;
+             bfd_size_type amt;
 
              /* We use index local_got_refcounts[-1] to count all
                 GOT-relative relocations that do not have explicit
                 GOT entries.  */
-             size = (symtab_hdr->sh_info + 1) * sizeof (bfd_signed_vma);
-             local_got_refcounts = ((bfd_signed_vma *)
-                                    bfd_alloc (abfd, size));
+             amt = symtab_hdr->sh_info + 1;
+             amt *= sizeof (bfd_signed_vma);
+             local_got_refcounts = ((bfd_signed_vma *) bfd_zalloc (abfd, amt));
              if (local_got_refcounts == NULL)
                return false;
-             memset (local_got_refcounts, -1, size);
 
              local_got_refcounts++;
              elf_local_got_refcounts (abfd) = local_got_refcounts;
@@ -2351,33 +2427,10 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
        case R_CRIS_16_GOT:
        case R_CRIS_32_GOT:
          /* This symbol requires a global offset table entry.  */
-
-         if (srelgot == NULL
-             && (h != NULL || info->shared))
-           {
-             srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
-             if (srelgot == NULL)
-               {
-                 srelgot = bfd_make_section (dynobj, ".rela.got");
-                 if (srelgot == NULL
-                     || !bfd_set_section_flags (dynobj, srelgot,
-                                                (SEC_ALLOC
-                                                 | SEC_LOAD
-                                                 | SEC_HAS_CONTENTS
-                                                 | SEC_IN_MEMORY
-                                                 | SEC_LINKER_CREATED
-                                                 | SEC_READONLY))
-                     || !bfd_set_section_alignment (dynobj, srelgot, 2))
-                   return false;
-               }
-           }
-
          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)
                    {
@@ -2390,16 +2443,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)
                    {
@@ -2409,8 +2459,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;
 
@@ -2443,10 +2492,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:
@@ -2464,19 +2510,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.  */
 
@@ -2489,10 +2527,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
@@ -2571,6 +2606,8 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                      || !bfd_set_section_alignment (dynobj, sreloc, 2))
                    return false;
                }
+             if (sec->flags & SEC_READONLY)
+               info->flags |= DF_TEXTREL;
            }
 
          sreloc->_raw_size += sizeof (Elf32_External_Rela);
@@ -2597,7 +2634,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
              if (p == NULL)
                {
                  p = ((struct elf_cris_pcrel_relocs_copied *)
-                      bfd_alloc (dynobj, sizeof *p));
+                      bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
                  if (p == NULL)
                    return false;
                  p->next = eh->pcrel_relocs_copied;
@@ -2638,14 +2675,13 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
 
 static boolean
 elf_cris_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   bfd *dynobj;
   asection *s;
   boolean plt;
   boolean relocs;
-  boolean reltext;
 
   dynobj = elf_hash_table (info)->dynobj;
   BFD_ASSERT (dynobj != NULL);
@@ -2699,7 +2735,6 @@ elf_cris_size_dynamic_sections (output_bfd, info)
      memory for them.  */
   plt = false;
   relocs = false;
-  reltext = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
@@ -2745,41 +2780,11 @@ elf_cris_size_dynamic_sections (output_bfd, info)
            }
          else
            {
-             asection *target;
-
              /* Remember whether there are any reloc sections other
                  than .rela.plt.  */
              if (strcmp (name, ".rela.plt") != 0)
-               {
-                 const char *outname;
-
                  relocs = true;
 
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL entry.
-                    The entries in the .rela.plt section are actually
-                    associated with .got.plt, which we created ourselves
-                    and so know is not readonly.  */
-                 outname = bfd_get_section_name (output_bfd,
-                                                 s->output_section);
-                 target
-                   = bfd_get_section_by_name (output_bfd,
-                                              outname + strlen (".rela"));
-
-                 /* We have to test the .text section by name, becase for
-                    some reason it does not have SEC_READONLY set at this
-                    time.  That flag is actually set in ldmain.c:main
-                    specifically for ".text" at a time long after this
-                    function is called.  FIXME: This might be due to a
-                    general bug.  FIXME: Have testcase for this.  */
-                 if (target != NULL
-                     && (target->flags & SEC_ALLOC) != 0
-                     && ((target->flags & SEC_READONLY) != 0
-                         || strcmp (outname + strlen (".rela"),
-                                    ".text") == 0))
-                   reltext = true;
-               }
-
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
              s->reloc_count = 0;
@@ -2814,37 +2819,40 @@ elf_cris_size_dynamic_sections (output_bfd, info)
         must add the entries now so that we get the correct size for
         the .dynamic section.  The DT_DEBUG entry is filled in by the
         dynamic linker and used by the debugger.  */
+#define add_dynamic_entry(TAG, VAL) \
+  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+
       if (!info->shared)
        {
-         if (!bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
+         if (!add_dynamic_entry (DT_DEBUG, 0))
            return false;
        }
 
       if (plt)
        {
-         if (!bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
-             || !bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-             || !bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-             || !bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
+         if (!add_dynamic_entry (DT_PLTGOT, 0)
+             || !add_dynamic_entry (DT_PLTRELSZ, 0)
+             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
+             || !add_dynamic_entry (DT_JMPREL, 0))
            return false;
        }
 
       if (relocs)
        {
-         if (!bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
-             || !bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
-             || !bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
-                                              sizeof (Elf32_External_Rela)))
+         if (!add_dynamic_entry (DT_RELA, 0)
+             || !add_dynamic_entry (DT_RELASZ, 0)
+             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
            return false;
        }
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
        {
-         if (!bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
+         if (!add_dynamic_entry (DT_TEXTREL, 0))
            return false;
          info->flags |= DF_TEXTREL;
        }
     }
+#undef add_dynamic_entry
 
   return true;
 }
@@ -2866,6 +2874,9 @@ elf_cris_discard_excess_dso_dynamics (h, inf)
   struct elf_cris_pcrel_relocs_copied *s;
   struct bfd_link_info *info = (struct bfd_link_info *) inf;
 
+  if (h->root.root.type == bfd_link_hash_warning)
+    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+
   /* If a symbol has been forced local or we have found a regular
      definition for the symbolic link case, then we won't be needing
      any relocs.  */
@@ -2891,6 +2902,9 @@ elf_cris_discard_excess_program_dynamics (h, inf)
 {
   struct bfd_link_info *info = (struct bfd_link_info *) inf;
 
+  if (h->root.root.type == bfd_link_hash_warning)
+    h = (struct elf_cris_link_hash_entry *) h->root.root.u.i.link;
+
   /* If we're not creating a shared library and have a symbol which is
      referred to by .got references, but the symbol is defined locally,
      (or rather, not referred to by a DSO and not defined by a DSO) then
@@ -2908,7 +2922,7 @@ elf_cris_discard_excess_program_dynamics (h, inf)
          asection *srelgot;
 
          BFD_ASSERT (dynobj != NULL);
-         
+
          srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
 
          BFD_ASSERT (srelgot != NULL);
@@ -2919,8 +2933,14 @@ elf_cris_discard_excess_program_dynamics (h, inf)
       /* If the locally-defined symbol isn't used by a DSO, then we don't
         have to export it as a dynamic symbol.  This was already done for
         functions; doing this for all symbols would presumably not
-        introduce new problems.  */
-      h->root.dynindx = -1;
+        introduce new problems.  Of course we don't do this if we're
+        exporting all dynamic symbols.  */
+      if (! info->export_dynamic)
+       {
+         h->root.dynindx = -1;
+         _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+                                 h->root.dynstr_index);
+       }
     }
 
   return true;
@@ -3009,13 +3029,31 @@ 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;
     }
 
   return true;
 }
+
+
+static enum elf_reloc_type_class
+elf_cris_reloc_type_class (rela)
+     const Elf_Internal_Rela *rela;
+{
+  switch ((int) ELF32_R_TYPE (rela->r_info))
+    {
+    case R_CRIS_RELATIVE:
+      return reloc_class_relative;
+    case R_CRIS_JUMP_SLOT:
+      return reloc_class_plt;
+    case R_CRIS_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
 \f
 #define ELF_ARCH               bfd_arch_cris
 #define ELF_MACHINE_CODE       EM_CRIS
@@ -3031,8 +3069,11 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
 #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 \
@@ -3059,6 +3100,7 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
 #define bfd_elf32_bfd_final_link \
        _bfd_elf32_gc_common_final_link
 #define elf_backend_hide_symbol                        elf_cris_hide_symbol
+#define elf_backend_reloc_type_class           elf_cris_reloc_type_class
 
 #define elf_backend_want_got_plt       1
 #define elf_backend_plt_readonly       1
This page took 0.037057 seconds and 4 git commands to generate.