include/elf/ChangeLog
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
index d4d543bd17facd45bdf71b46034b6af1f568972d..8db111504da4a1b92fe25bff8dc08f1646f927e6 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.
@@ -31,7 +31,13 @@ static reloc_howto_type * cris_reloc_type_lookup
   PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
 
 static void cris_info_to_howto_rela
-  PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
+  PARAMS ((bfd *, arelent *, Elf_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 *,
@@ -46,7 +52,7 @@ static boolean cris_elf_gc_sweep_hook
           const Elf_Internal_Rela *));
 
 static asection * cris_elf_gc_mark_hook
-  PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
           struct elf_link_hash_entry *, Elf_Internal_Sym *));
 
 static boolean cris_elf_object_p PARAMS ((bfd *));
@@ -84,7 +90,7 @@ 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 *));
 
@@ -174,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 */
@@ -189,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 */
@@ -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 >= 0;)
+  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];
 
@@ -453,7 +458,7 @@ static void
 cris_info_to_howto_rela (abfd, cache_ptr, dst)
      bfd * abfd ATTRIBUTE_UNUSED;
      arelent * cache_ptr;
-     Elf32_Internal_Rela * dst;
+     Elf_Internal_Rela * dst;
 {
   unsigned int r_type;
 
@@ -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 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.  */
 
@@ -476,7 +547,7 @@ cris_info_to_howto_rela (abfd, cache_ptr, dst)
 static const bfd_byte elf_cris_plt0_entry[PLT_ENTRY_SIZE] =
 {
   0xfc, 0xe1,
-  0x7e, 0x7e,  /* push mof. */
+  0x7e, 0x7e,  /* push mof.  */
   0x7f, 0x0d,   /*  (dip [pc+]) */
   0, 0, 0, 0,  /*  Replaced with address of .got + 4.  */
   0x30, 0x7a,  /* move [...],mof */
@@ -639,14 +710,14 @@ elf_cris_link_hash_table_create (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, amt));
+  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;
     }
 
@@ -728,17 +799,15 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
   Elf_Internal_Rela *           rel;
   Elf_Internal_Rela *           relend;
 
+  if (info->relocateable)
+    return true;
+
   dynobj = elf_hash_table (info)->dynobj;
   local_got_offsets = elf_local_got_offsets (input_bfd);
   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
   relend     = relocs + input_section->reloc_count;
 
-  /* It seems this can happen with erroneous or unsupported input (mixing
-     a.out and elf in an archive, for example.)  */
-  if (sym_hashes == NULL)
-    return false;
-
   sgot = NULL;
   splt = NULL;
   sreloc = NULL;
@@ -767,29 +836,8 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          || r_type == R_CRIS_GNU_VTENTRY)
        continue;
 
-      r_symndx = ELF32_R_SYM (rel->r_info);
-
-      if (info->relocateable)
-       {
-         /* This is a relocateable link.  We don't have to change
-             anything, unless the reloc is against a section symbol,
-             in which case we have to adjust according to where the
-             section symbol winds up in the output section.  */
-         if (r_symndx < symtab_hdr->sh_info)
-           {
-             sym = local_syms + r_symndx;
-
-             if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
-               {
-                 sec = local_sections [r_symndx];
-                 rel->r_addend += sec->output_offset + sym->st_value;
-               }
-           }
-
-         continue;
-       }
-
       /* This is a final link.  */
+      r_symndx = ELF32_R_SYM (rel->r_info);
       howto  = cris_elf_howto_table + r_type;
       h      = NULL;
       sym    = NULL;
@@ -799,9 +847,7 @@ 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);
 
          symname = (bfd_elf_string_from_elf_section
                     (input_bfd, symtab_hdr->sh_link, sym->st_name));
@@ -810,6 +856,11 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        }
       else
        {
+         /* It seems this can happen with erroneous or unsupported input
+            (mixing a.out and elf in an archive, for example.)  */
+         if (sym_hashes == NULL)
+           return false;
+
          h = sym_hashes [r_symndx - symtab_hdr->sh_info];
 
          while (h->root.type == bfd_link_hash_indirect
@@ -971,35 +1022,35 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                BFD_ASSERT (off != (bfd_vma) -1);
 
                if (!elf_hash_table (info)->dynamic_sections_created
-                   || (! info->shared && h->dynindx == -1)
+                   || (! info->shared
+                       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
                    || (info->shared
                        && (info->symbolic || h->dynindx == -1)
                        && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
                  {
                    /* This wasn't checked above for ! info->shared, but
-                      must hold there if we get here; the symbol must not
-                      be used in, or defined by a DSO.  (Note that
-                      checking for ELF_LINK_HASH_DEF_REGULAR doesn't
-                      catch all cases.)  */
-                   BFD_ASSERT (info->shared
+                      must hold there if we get here; the symbol must be
+                      defined in the regular program, or be undefweak.  */
+                   BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
+                               || info->shared
                                || (h->elf_link_hash_flags
-                                   & (ELF_LINK_HASH_REF_DYNAMIC
-                                      | ELF_LINK_HASH_DEF_DYNAMIC)) == 0);
+                                   & ELF_LINK_HASH_DEF_REGULAR) != 0
+                               || h->root.type == bfd_link_hash_undefweak);
 
                    /* This is actually a static link, or it is a
-                      -Bsymbolic link and the symbol is defined
-                      locally, or the symbol was forced to be local
-                      because of a version file, or we're not creating a
-                      dynamic object and the symbol isn't referred to by
-                      a dynamic object.  We must initialize
-                      this entry in the global offset table.  Since
-                      the offset must always be a multiple of 4, we
-                      use the least significant bit to record whether
-                      we have initialized it already.
-
-                      When doing a dynamic link, we create a .rela.got
-                      relocation entry to initialize the value.  This
-                      is done in the finish_dynamic_symbol routine.  */
+                      -Bsymbolic link and the symbol is defined locally,
+                      or is undefweak, or the symbol was forced to be
+                      local because of a version file, or we're not
+                      creating a dynamic object.  We must initialize this
+                      entry in the global offset table.  Since the offset
+                      must always be a multiple of 4, we use the least
+                      significant bit to record whether we have
+                      initialized it already.
+
+                      If this GOT entry should be runtime-initialized, we
+                      will create a .rela.got relocation entry to
+                      initialize the value.  This is done in the
+                      finish_dynamic_symbol routine.  */
                    if ((off & 1) != 0)
                      off &= ~1;
                    else
@@ -1028,22 +1079,21 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
                    if (info->shared)
                      {
-                       asection *srelgot;
+                       asection *s;
                        Elf_Internal_Rela outrel;
+                       bfd_byte *loc;
 
-                       srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
-                       BFD_ASSERT (srelgot != NULL);
+                       s = bfd_get_section_by_name (dynobj, ".rela.got");
+                       BFD_ASSERT (s != NULL);
 
                        outrel.r_offset = (sgot->output_section->vma
                                           + sgot->output_offset
                                           + off);
                        outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
                        outrel.r_addend = relocation;
-                       bfd_elf32_swap_reloca_out (output_bfd, &outrel,
-                                                  (((Elf32_External_Rela *)
-                                                    srelgot->contents)
-                                                   + srelgot->reloc_count));
-                       ++srelgot->reloc_count;
+                       loc = s->contents;
+                       loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
+                       bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
                      }
 
                    local_got_offsets[r_symndx] |= 1;
@@ -1081,7 +1131,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
        case R_CRIS_32_GOTREL:
          /* This relocation must only be performed against local symbols.  */
-         if (h != NULL)
+         if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            {
              (*_bfd_error_handler)
                (_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
@@ -1093,6 +1143,20 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              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,
+                bfd_get_section_name (input_bfd, input_section));
+             bfd_set_error (bfd_error_bad_value);
+             return false;
+           }
+
          /* This relocation is like a PC-relative one, except the
             reference point is the location of GOT.  Note that
             sgot->output_offset is not involved in this calculation.  We
@@ -1107,7 +1171,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
          /* Resolve a PLT_PCREL reloc against a local symbol directly,
             without using the procedure linkage table.  */
-         if (h == NULL)
+         if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
            break;
 
          if (h->plt.offset == (bfd_vma) -1
@@ -1132,7 +1196,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
          /* Resolve a PLT_GOTREL reloc against a local symbol directly,
             without using the procedure linkage table.  */
-         if (h == NULL)
+         if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
            break;
 
          if (h->plt.offset == (bfd_vma) -1
@@ -1154,7 +1218,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_CRIS_16_PCREL:
        case R_CRIS_32_PCREL:
          /* If the symbol was local, we need no shlib-specific handling.  */
-         if (h == NULL)
+         if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
            break;
 
          /* Fall through.  */
@@ -1162,6 +1226,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
@@ -1171,6 +1236,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
            {
              Elf_Internal_Rela outrel;
+             bfd_byte *loc;
              boolean skip, relocate;
 
              /* When generating a shared object, these relocations
@@ -1212,31 +1278,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
@@ -1245,7 +1300,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;
                }
@@ -1286,17 +1340,14 @@ 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;
                    }
                }
 
-             bfd_elf32_swap_reloca_out (output_bfd, &outrel,
-                                        (((Elf32_External_Rela *)
-                                          sreloc->contents)
-                                         + sreloc->reloc_count));
-             ++sreloc->reloc_count;
+             loc = sreloc->contents;
+             loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
+             bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
 
              /* This reloc will be computed at runtime, so there's no
                  need to do anything now, except for R_CRIS_32 relocations
@@ -1384,6 +1435,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
       bfd_vma gotplt_offset
        = ((struct elf_cris_link_hash_entry *) h)->gotplt_offset;
       Elf_Internal_Rela rela;
+      bfd_byte *loc;
       boolean has_gotplt = gotplt_offset != 0;
 
       /* Get the index in the procedure linkage table which
@@ -1464,9 +1516,8 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
                           + got_offset);
          rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_JUMP_SLOT);
          rela.r_addend = 0;
-         bfd_elf32_swap_reloca_out (output_bfd, &rela,
-                                    ((Elf32_External_Rela *) srela->contents
-                                     + gotplt_index));
+         loc = srela->contents + gotplt_index * sizeof (Elf32_External_Rela);
+         bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
        }
 
       if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
@@ -1490,13 +1541,18 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
     }
 
   /* We don't emit .got relocs for symbols that aren't in the
-     dynamic-symbols table for an ordinary program.  */
+     dynamic-symbols table for an ordinary program and are either defined
+     by the program or are undefined weak symbols.  */
   if (h->got.offset != (bfd_vma) -1
-      && (info->shared || h->dynindx != -1))
+      && (info->shared
+         || (h->dynindx != -1
+             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
+             && h->root.type != bfd_link_hash_undefweak)))
     {
       asection *sgot;
       asection *srela;
       Elf_Internal_Rela rela;
+      bfd_byte *loc;
       bfd_byte *where;
 
       /* This symbol has an entry in the global offset table.  Set it up.  */
@@ -1530,16 +1586,16 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
          rela.r_addend = 0;
        }
 
-      bfd_elf32_swap_reloca_out (output_bfd, &rela,
-                                ((Elf32_External_Rela *) srela->contents
-                                 + srela->reloc_count));
-      ++srela->reloc_count;
+      loc = srela->contents;
+      loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
+      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     }
 
   if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
     {
       asection *s;
       Elf_Internal_Rela rela;
+      bfd_byte *loc;
 
       /* This symbol needs a copy reloc.  Set it up.  */
 
@@ -1556,10 +1612,8 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
                       + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_CRIS_COPY);
       rela.r_addend = 0;
-      bfd_elf32_swap_reloca_out (output_bfd, &rela,
-                                ((Elf32_External_Rela *) s->contents
-                                 + s->reloc_count));
-      ++s->reloc_count;
+      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
+      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     }
 
   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
@@ -1699,8 +1753,8 @@ elf_cris_finish_dynamic_sections (output_bfd, info)
    relocation.  */
 
 static asection *
-cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
-     bfd *                        abfd;
+cris_elf_gc_mark_hook (sec, info, rel, h, sym)
+     asection *                   sec;
      struct bfd_link_info *       info ATTRIBUTE_UNUSED;
      Elf_Internal_Rela *          rel;
      struct elf_link_hash_entry * h;
@@ -1730,15 +1784,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 (sec->owner, sym->st_shndx);
 
   return NULL;
 }
@@ -1835,7 +1881,8 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
          if (r_symndx >= symtab_hdr->sh_info)
            {
              h = sym_hashes[r_symndx - symtab_hdr->sh_info];
-             if (h->plt.refcount > 0)
+             if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                 && h->plt.refcount > 0)
                --h->plt.refcount;
            }
          break;
@@ -1865,6 +1912,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;
@@ -1889,28 +1939,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;
@@ -1975,13 +2006,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
@@ -2018,23 +2050,23 @@ elf_cris_adjust_dynamic_symbol (info, h)
   if (h->type == STT_FUNC
       || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
     {
+      /* If we link a program (not a DSO), we'll get rid of unnecessary
+        PLT entries; we point to the actual symbols -- even for pic
+        relocs, because a program built with -fpic should have the same
+        result as one built without -fpic, specifically considering weak
+        symbols.
+        FIXME: m68k and i386 differ here, for unclear reasons.  */
       if (! info->shared
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
-         /* We must always create the plt entry if it was referenced by a
-            PLT relocation.  In this case we already recorded it as a
-            dynamic symbol.  */
-         /* FIXME: m68k and i386 differ here, for unclear reasons.  */
-         && h->dynindx == -1)
+         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
        {
          /* This case can occur if we saw a PLT reloc in an input file,
-            but the symbol was never referred to by a dynamic object.  In
-            such a case, we don't actually need to build a procedure
-            linkage table, and we can just do a PC reloc instead, or
+            but the symbol was not defined by a dynamic object.  In such
+            a case, we don't actually need to build a procedure linkage
+            table, and we can just do an absolute or PC reloc instead, or
             change a .got.plt index to a .got index for GOTPLT relocs.  */
          BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
+         h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
          h->plt.offset = (bfd_vma) -1;
-
          return
            elf_cris_adjust_gotplt_to_got ((struct
                                            elf_cris_link_hash_entry *) h,
@@ -2072,9 +2104,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
 
       /* If this symbol is not defined in a regular file, and we are
         not generating a shared library, then set the symbol to this
-        location in the .plt.  This is required to make function
-        pointers compare as equal between the normal executable and
-        the shared library.  */
+        location in the .plt.  */
       if (!info->shared
          && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
        {
@@ -2299,8 +2329,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)
@@ -2347,27 +2407,6 @@ 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 == 0)
@@ -2429,7 +2468,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
 
          /* If this is a local symbol, we resolve it directly without
             creating a procedure linkage table entry.  */
-         if (h == NULL)
+         if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
            continue;
 
          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
@@ -2468,7 +2507,8 @@ 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.  */
-             h->plt.refcount++;
+             if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+               h->plt.refcount++;
            }
 
          /* If we are creating a shared library and this is not a local
@@ -2501,7 +2541,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
              || r_type == R_CRIS_32_PCREL)
            {
              /* If the symbol is local, then we can eliminate the reloc.  */
-             if (h == NULL)
+             if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
                break;
 
              /* If this is with -Bsymbolic and the symbol isn't weak, and
@@ -2815,6 +2855,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.  */
@@ -2840,12 +2883,14 @@ 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
-     lose the reloc for the .got (don't allocate room for it).  */
-  if ((h->root.elf_link_hash_flags
-       & (ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_HASH_DEF_DYNAMIC)) == 0)
+     (or rather, not not defined by a DSO) then lose the reloc for the
+     .got (don't allocate room for it).  */
+  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
     {
       if (h->root.got.refcount > 0
          /* The size of this section is only valid and in sync with the
@@ -2868,8 +2913,15 @@ 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.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
+       {
+         h->root.dynindx = -1;
+         _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+                                 h->root.dynstr_index);
+       }
     }
 
   return true;
@@ -2932,7 +2984,7 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
 {
   flagword old_flags, new_flags;
 
-  if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
+  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
     return false;
 
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
@@ -2998,6 +3050,8 @@ elf_cris_reloc_type_class (rela)
 #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
@@ -3040,6 +3094,7 @@ elf_cris_reloc_type_class (rela)
    take the easy route.  */
 #define elf_backend_may_use_rel_p 0
 #define elf_backend_may_use_rela_p 1
+#define elf_backend_rela_normal                1
 
 #include "elf32-target.h"
 
This page took 0.034339 seconds and 4 git commands to generate.