* elf.c (_bfd_elf_rela_local_sym): Accept asection **, and return
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
index e50d05cca755bc7227ac869e2467ce1b352ebffc..e145b26b43f47b297afcbb22d070aec75aa5e32a 100644 (file)
@@ -1,24 +1,24 @@
 /* CRIS-specific support for 32-bit ELF.
-   Copyright 2000, 2001 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002, 2003 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.
 
-This file is part of BFD, the Binary File Descriptor library.
+   This file is part of BFD, the Binary File Descriptor library.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -31,9 +31,15 @@ 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_relocate_section
+static bfd_boolean cris_elf_grok_prstatus
+  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
+
+static bfd_boolean cris_elf_grok_psinfo
+  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
+
+static bfd_boolean cris_elf_relocate_section
   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
 
@@ -41,52 +47,52 @@ static bfd_reloc_status_type cris_final_link_relocate
   PARAMS ((reloc_howto_type *, bfd *, asection *, bfd_byte *,
           Elf_Internal_Rela *, bfd_vma));
 
-static boolean cris_elf_gc_sweep_hook
+static bfd_boolean cris_elf_gc_sweep_hook
   PARAMS ((bfd *, struct bfd_link_info *, asection *,
           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 *));
+static bfd_boolean cris_elf_object_p PARAMS ((bfd *));
 
-static void cris_elf_final_write_processing PARAMS ((bfd *, boolean));
+static void cris_elf_final_write_processing PARAMS ((bfd *, bfd_boolean));
 
-static boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
+static bfd_boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
 
-static boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
+static bfd_boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
 
 struct elf_cris_link_hash_entry;
-static boolean elf_cris_discard_excess_dso_dynamics
+static bfd_boolean elf_cris_discard_excess_dso_dynamics
   PARAMS ((struct elf_cris_link_hash_entry *, PTR));
-static boolean elf_cris_discard_excess_program_dynamics
+static bfd_boolean elf_cris_discard_excess_program_dynamics
   PARAMS ((struct elf_cris_link_hash_entry *, PTR));
-static boolean elf_cris_adjust_gotplt_to_got
+static bfd_boolean elf_cris_adjust_gotplt_to_got
   PARAMS ((struct elf_cris_link_hash_entry *, PTR));
-static boolean elf_cris_try_fold_plt_to_got
+static bfd_boolean elf_cris_try_fold_plt_to_got
   PARAMS ((struct elf_cris_link_hash_entry *, PTR));
 static struct bfd_hash_entry *elf_cris_link_hash_newfunc
   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
 static struct bfd_link_hash_table *elf_cris_link_hash_table_create
   PARAMS ((bfd *));
-static boolean elf_cris_adjust_dynamic_symbol
+static bfd_boolean elf_cris_adjust_dynamic_symbol
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
-static boolean cris_elf_check_relocs
+static bfd_boolean cris_elf_check_relocs
   PARAMS ((bfd *, struct bfd_link_info *, asection *,
           const Elf_Internal_Rela *));
 
-static boolean elf_cris_size_dynamic_sections
+static bfd_boolean elf_cris_size_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
-static boolean elf_cris_finish_dynamic_symbol
+static bfd_boolean elf_cris_finish_dynamic_symbol
   PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
           Elf_Internal_Sym *));
-static boolean elf_cris_finish_dynamic_sections
+static bfd_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 *, bfd_boolean));
 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 [] =
 {
@@ -95,135 +101,135 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_NONE",         /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0,                     /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* An 8 bit absolute relocation.  */
   HOWTO (R_CRIS_8,             /* type */
         0,                     /* rightshift */
         0,                     /* size (0 = byte, 1 = short, 2 = long) */
         8,                     /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_8",            /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0x0000,                /* src_mask */
         0x00ff,                /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* A 16 bit absolute relocation.  */
   HOWTO (R_CRIS_16,            /* type */
         0,                     /* rightshift */
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_16",           /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0x00000000,            /* src_mask */
         0x0000ffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* A 32 bit absolute relocation.  */
   HOWTO (R_CRIS_32,            /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_32",           /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0x00000000,            /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* An 8 bit PC-relative relocation.  */
   HOWTO (R_CRIS_8_PCREL,       /* type */
         0,                     /* rightshift */
         0,                     /* size (0 = byte, 1 = short, 2 = long) */
         8,                     /* bitsize */
-        true,                  /* pc_relative */
+        TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_8_PCREL",      /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0x0000,                /* src_mask */
         0x00ff,                /* dst_mask */
-        true),                 /* pcrel_offset */
+        TRUE),                 /* pcrel_offset */
 
   /* A 16 bit PC-relative relocation.  */
   HOWTO (R_CRIS_16_PCREL,      /* type */
         0,                     /* rightshift */
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
-        true,                  /* pc_relative */
+        TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
-        "R_CRIS_16",           /* name */
-        false,                 /* partial_inplace */
+        "R_CRIS_16_PCREL",     /* name */
+        FALSE,                 /* partial_inplace */
         0x00000000,            /* src_mask */
         0x0000ffff,            /* dst_mask */
-        true),                 /* pcrel_offset */
+        TRUE),                 /* pcrel_offset */
 
   /* A 32 bit PC-relative relocation.  */
   HOWTO (R_CRIS_32_PCREL,      /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        true,                  /* pc_relative */
+        TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
-        "R_CRIS_32",           /* name */
-        false,                 /* partial_inplace */
+        "R_CRIS_32_PCREL",     /* name */
+        FALSE,                 /* partial_inplace */
         0x00000000,            /* src_mask */
         0xffffffff,            /* dst_mask */
-        true),                 /* pcrel_offset */
+        TRUE),                 /* pcrel_offset */
 
   /* GNU extension to record C++ vtable hierarchy.  */
   HOWTO (R_CRIS_GNU_VTINHERIT, /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         0,                     /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
         NULL,                  /* special_function */
         "R_CRIS_GNU_VTINHERIT", /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0,                     /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* GNU extension to record C++ vtable member usage.  */
   HOWTO (R_CRIS_GNU_VTENTRY,   /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         0,                     /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_dont, /* complain_on_overflow */
         _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
         "R_CRIS_GNU_VTENTRY",   /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0,                     /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* This is used only by the dynamic linker.  The symbol should exist
      both in the object being run and in some shared library.  The
@@ -234,45 +240,45 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_COPY",         /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0,                     /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* Like R_CRIS_32, but used when setting global offset table entries.  */
   HOWTO (R_CRIS_GLOB_DAT,      /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_GLOB_DAT",     /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* Marks a procedure linkage table entry for a symbol.  */
   HOWTO (R_CRIS_JUMP_SLOT,     /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_JUMP_SLOT",    /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0,                     /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* Used only by the dynamic linker.  When the object is run, this
      longword is set to the load address of the object, plus the
@@ -281,44 +287,44 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_RELATIVE",     /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* Like R_CRIS_32, but referring to the GOT table entry for the symbol.  */
   HOWTO (R_CRIS_16_GOT,                /* type */
         0,                     /* rightshift */
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_16_GOT",       /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   HOWTO (R_CRIS_32_GOT,                /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_32_GOT",       /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* Like R_CRIS_32_GOT, but referring to (and requesting a) PLT part of
      the GOT table for the symbol.  */
@@ -326,29 +332,29 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
         16,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_16_GOTPLT",    /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   HOWTO (R_CRIS_32_GOTPLT,     /* type */
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_32_GOTPLT",    /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* A 32-bit offset from GOT to (local const) symbol: no GOT entry should
      be necessary.  */
@@ -356,15 +362,15 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_32_GOTREL",    /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* A 32-bit offset from GOT to entry for this symbol in PLT and request
      to create PLT entry for symbol.  */
@@ -372,15 +378,15 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        false,                 /* pc_relative */
+        FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_32_PLT_GOTREL", /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        false),                /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
   /* A 32-bit offset from PC (location after the relocation) + addend to
      entry for this symbol in PLT and request to create PLT entry for
@@ -389,15 +395,15 @@ static reloc_howto_type cris_elf_howto_table [] =
         0,                     /* rightshift */
         2,                     /* size (0 = byte, 1 = short, 2 = long) */
         32,                    /* bitsize */
-        true,                  /* pc_relative */
+        TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
         bfd_elf_generic_reloc, /* special_function */
         "R_CRIS_32_PLT_PCREL", /* name */
-        false,                 /* partial_inplace */
+        FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
         0xffffffff,            /* dst_mask */
-        true)                  /* pcrel_offset */
+        TRUE)                  /* pcrel_offset */
 };
 \f
 /* Map BFD reloc types to CRIS ELF reloc types.  */
@@ -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];
 
@@ -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 bfd_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 bfd_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 */
@@ -588,7 +659,7 @@ struct elf_cris_link_hash_table
 #define elf_cris_link_hash_traverse(table, func, info)                 \
   (elf_link_hash_traverse                                              \
    (&(table)->root,                                                    \
-    (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
+    (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
     (info)))
 
 /* Get the CRIS ELF linker hash table from a link_info structure.  */
@@ -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;
     }
 
@@ -706,27 +777,30 @@ cris_final_link_relocate (howto, input_bfd, input_section, contents, rel,
 /* Relocate an CRIS ELF section.  See elf32-fr30.c, from where this was
    copied, for further comments.  */
 
-static boolean
+static bfd_boolean
 cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                           contents, relocs, local_syms, local_sections)
-     bfd *                   output_bfd ATTRIBUTE_UNUSED;
-     struct bfd_link_info *  info;
-     bfd *                   input_bfd;
-     asection *              input_section;
-     bfd_byte *              contents;
-     Elf_Internal_Rela *     relocs;
-     Elf_Internal_Sym *      local_syms;
-     asection **             local_sections;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
+     struct bfd_link_info *info;
+     bfd *input_bfd;
+     asection *input_section;
+     bfd_byte *contents;
+     Elf_Internal_Rela *relocs;
+     Elf_Internal_Sym *local_syms;
+     asection **local_sections;
 {
   bfd *dynobj;
-  Elf_Internal_Shdr *           symtab_hdr;
-  struct elf_link_hash_entry ** sym_hashes;
+  Elf_Internal_Shdr *symtab_hdr;
+  struct elf_link_hash_entry **sym_hashes;
   bfd_vma *local_got_offsets;
   asection *sgot;
   asection *splt;
   asection *sreloc;
-  Elf_Internal_Rela *           rel;
-  Elf_Internal_Rela *           relend;
+  Elf_Internal_Rela *rel;
+  Elf_Internal_Rela *relend;
+
+  if (info->relocatable)
+    return TRUE;
 
   dynobj = elf_hash_table (info)->dynobj;
   local_got_offsets = elf_local_got_offsets (input_bfd);
@@ -734,11 +808,6 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
   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;
@@ -751,15 +820,15 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
   for (rel = relocs; rel < relend; rel ++)
     {
-      reloc_howto_type *           howto;
-      unsigned long                r_symndx;
-      Elf_Internal_Sym *           sym;
-      asection *                   sec;
-      struct elf_link_hash_entry * h;
-      bfd_vma                      relocation;
-      bfd_reloc_status_type        r;
-      const char *                 symname = NULL;
-      int                          r_type;
+      reloc_howto_type *howto;
+      unsigned long r_symndx;
+      Elf_Internal_Sym *sym;
+      asection *sec;
+      struct elf_link_hash_entry *h;
+      bfd_vma relocation;
+      bfd_reloc_status_type r;
+      const char *symname = NULL;
+      int r_type;
 
       r_type = ELF32_R_TYPE (rel->r_info);
 
@@ -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,19 +856,12 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        }
       else
        {
-         h = sym_hashes [r_symndx - symtab_hdr->sh_info];
-
-         while (h->root.type == bfd_link_hash_indirect
-                || h->root.type == bfd_link_hash_warning)
-           h = (struct elf_link_hash_entry *) h->root.u.i.link;
+         bfd_boolean warned;
+         bfd_boolean unresolved_reloc;
 
-         symname = h->root.root.string;
-
-         if (h->root.type == bfd_link_hash_defined
-             || h->root.type == bfd_link_hash_defweak)
-           {
-             sec = h->root.u.def.section;
+         RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx, symtab_hdr, relocation, sec, unresolved_reloc, info, warned);
 
+         if (unresolved_reloc
              /* Perhaps we should detect the cases that
                 sec->output_section is expected to be NULL like i386 and
                 m68k, but apparently (and according to elfxx-ia64.c) all
@@ -837,72 +876,54 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                 is *not* dynamically linked against.  Thus this will
                 automatically remind us so we can see if there are other
                 valid cases we need to revisit.  */
-             if ((sec->output_section == NULL
-                  && (sec->owner->flags & DYNAMIC) != 0)
-
-                 /* Here follow the cases where the relocation value must
-                    be zero (or when further handling is simplified when
-                    zero).  I can't claim to understand the various
-                    conditions and they weren't described in the files
-                    where I copied them from (elf32-m68k.c and
-                    elf32-i386.c), but let's mention examples of where
-                    they happen.  FIXME: Perhaps define and use a
-                    dynamic_symbol_p function like ia64.
-
-                    - When creating a shared library, we can have an
-                    ordinary relocation for a symbol defined in a shared
-                    library (perhaps the one we create).  We then make
-                    the relocation value zero, as the value seen now will
-                    be added into the relocation addend in this shared
-                    library, but must be handled only at dynamic-link
-                    time.  FIXME: Not sure this example covers the
-                    h->elf_link_hash_flags test, though it's there in
-                    other targets.  */
-                 || (info->shared
-                     && ((! info->symbolic && h->dynindx != -1)
-                         || (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0)
-                     && (input_section->flags & SEC_ALLOC) != 0
-                     && (r_type == R_CRIS_8
-                         || r_type == R_CRIS_16
-                         || r_type == R_CRIS_32
-                         || r_type == R_CRIS_8_PCREL
-                         || r_type == R_CRIS_16_PCREL
-                         || r_type == R_CRIS_32_PCREL)))
+             && (sec->owner->flags & DYNAMIC) != 0)
+           relocation = 0;
+
+         else if (h->root.type == bfd_link_hash_defined
+                  || h->root.type == bfd_link_hash_defweak)
+           {
+             /* Here follow the cases where the relocation value must
+                be zero (or when further handling is simplified when
+                zero).  I can't claim to understand the various
+                conditions and they weren't described in the files
+                where I copied them from (elf32-m68k.c and
+                elf32-i386.c), but let's mention examples of where
+                they happen.  FIXME: Perhaps define and use a
+                dynamic_symbol_p function like ia64.
+
+                - When creating a shared library, we can have an
+                ordinary relocation for a symbol defined in a shared
+                library (perhaps the one we create).  We then make
+                the relocation value zero, as the value seen now will
+                be added into the relocation addend in this shared
+                library, but must be handled only at dynamic-link
+                time.  FIXME: Not sure this example covers the
+                h->elf_link_hash_flags test, though it's there in
+                other targets.  */
+             if (info->shared
+                 && ((! info->symbolic && h->dynindx != -1)
+                     || (h->elf_link_hash_flags
+                         & ELF_LINK_HASH_DEF_REGULAR) == 0)
+                 && (input_section->flags & SEC_ALLOC) != 0
+                 && (r_type == R_CRIS_8
+                     || r_type == R_CRIS_16
+                     || r_type == R_CRIS_32
+                     || r_type == R_CRIS_8_PCREL
+                     || r_type == R_CRIS_16_PCREL
+                     || r_type == R_CRIS_32_PCREL))
                relocation = 0;
-             else if (sec->output_section != NULL)
-               relocation = (h->root.u.def.value
-                             + sec->output_section->vma
-                             + sec->output_offset);
-             else
+             else if (unresolved_reloc)
                {
-                 (*_bfd_error_handler)
+                 _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;
+                 return FALSE;
                }
            }
-         else if (h->root.type == bfd_link_hash_undefweak)
-           relocation = 0;
-         else if (info->shared
-                  && (!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, symname, input_bfd,
-                    input_section, rel->r_offset,
-                    (!info->shared || info->no_undefined
-                     || ELF_ST_VISIBILITY (h->other)))))
-               return false;
-             relocation = 0;
-           }
        }
 
       switch (r_type)
@@ -950,7 +971,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                 do; this is probably an internal error.  But it is true
                 that we didn't like that particular input.  */
              bfd_set_error (bfd_error_bad_value);
-             return false;
+             return FALSE;
            }
          /* Fall through.  */
 
@@ -971,35 +992,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 +1049,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;
@@ -1074,14 +1094,21 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                     bfd_get_section_name (input_bfd, input_section));
 
                bfd_set_error (bfd_error_bad_value);
-               return false;
+               return FALSE;
              }
          }
          break;
 
        case R_CRIS_32_GOTREL:
-         /* This relocation must only be performed against local symbols.  */
-         if (h != NULL)
+         /* This relocation must only be performed against local symbols.
+            It's also ok when we link a program and the symbol is either
+            defined in an ordinary (non-DSO) object or is undefined weak.  */
+         if (h != NULL
+             && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+             && !(!info->shared
+                  && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
+                      || ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
+                          && h->root.type == bfd_link_hash_undefweak))))
            {
              (*_bfd_error_handler)
                (_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
@@ -1090,7 +1117,21 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                 symname,
                 bfd_get_section_name (input_bfd, input_section));
              bfd_set_error (bfd_error_bad_value);
-             return false;
+             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
@@ -1107,7 +1148,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 +1173,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 +1195,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 +1203,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,7 +1213,8 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
            {
              Elf_Internal_Rela outrel;
-             boolean skip, relocate;
+             bfd_byte *loc;
+             bfd_boolean skip, relocate;
 
              /* When generating a shared object, these relocations
                 are copied into the output file to be resolved at run
@@ -1186,7 +1229,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                           elf_elfheader (input_bfd)->e_shstrndx,
                           elf_section_data (input_section)->rel_hdr.sh_name));
                  if (name == NULL)
-                   return false;
+                   return FALSE;
 
                  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
                              && strcmp (bfd_get_section_name (input_bfd,
@@ -1207,36 +1250,25 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                         name);
 
                      bfd_set_error (bfd_error_bad_value);
-                     return false;
+                     return FALSE;
                    }
                }
 
-             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;
-               }
+             skip = FALSE;
+             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 +1277,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;
                }
@@ -1253,7 +1284,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                {
                  if (r_type == R_CRIS_32)
                    {
-                     relocate = true;
+                     relocate = TRUE;
                      outrel.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
                      outrel.r_addend = relocation + rel->r_addend;
                    }
@@ -1261,21 +1292,12 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                    {
                      long indx;
 
-                     if (h == NULL)
-                       sec = local_sections[r_symndx];
-                     else
-                       {
-                         BFD_ASSERT (h->root.type == bfd_link_hash_defined
-                                     || (h->root.type
-                                         == bfd_link_hash_defweak));
-                         sec = h->root.u.def.section;
-                       }
-                     if (sec != NULL && bfd_is_abs_section (sec))
+                     if (bfd_is_abs_section (sec))
                        indx = 0;
                      else if (sec == NULL || sec->owner == NULL)
                        {
                          bfd_set_error (bfd_error_bad_value);
-                         return false;
+                         return FALSE;
                        }
                      else
                        {
@@ -1286,17 +1308,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
@@ -1326,7 +1345,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            case bfd_reloc_undefined:
              r = info->callbacks->undefined_symbol
                (info, symname, input_bfd, input_section, rel->r_offset,
-                true);
+                TRUE);
              break;
 
            case bfd_reloc_outofrange:
@@ -1351,17 +1370,17 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              (info, msg, symname, input_bfd, input_section, rel->r_offset);
 
          if (! r)
-           return false;
+           return FALSE;
        }
     }
 
-  return true;
+  return TRUE;
 }
 \f
 /* Finish up dynamic symbol handling.  We set the contents of various
    dynamic sections here.  */
 
-static boolean
+static bfd_boolean
 elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
      bfd *output_bfd;
      struct bfd_link_info *info;
@@ -1384,7 +1403,8 @@ 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;
-      boolean has_gotplt = gotplt_offset != 0;
+      bfd_byte *loc;
+      bfd_boolean has_gotplt = gotplt_offset != 0;
 
       /* Get the index in the procedure linkage table which
         corresponds to this symbol.  This is the index of this symbol
@@ -1464,9 +1484,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 +1509,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 +1554,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 +1580,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.  */
@@ -1567,12 +1589,12 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
       || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
     sym->st_shndx = SHN_ABS;
 
-  return true;
+  return TRUE;
 }
 \f
 /* Finish up the dynamic sections.  */
 
-static boolean
+static bfd_boolean
 elf_cris_finish_dynamic_sections (output_bfd, info)
      bfd *output_bfd;
      struct bfd_link_info *info;
@@ -1692,19 +1714,19 @@ elf_cris_finish_dynamic_sections (output_bfd, info)
 
   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
 
-  return true;
+  return TRUE;
 }
 \f
 /* Return the section that should be marked against GC for a given
    relocation.  */
 
 static asection *
-cris_elf_gc_mark_hook (abfd, info, rel, h, sym)
-     bfd *                        abfd;
-     struct bfd_link_info *       info ATTRIBUTE_UNUSED;
-     Elf_Internal_Rela *          rel;
-     struct elf_link_hash_entry * h;
-     Elf_Internal_Sym *           sym;
+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;
+     Elf_Internal_Sym *sym;
 {
   if (h != NULL)
     {
@@ -1730,27 +1752,19 @@ 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;
 }
 
 /* Update the got entry reference counts for the section being removed.  */
 
-static boolean
+static bfd_boolean
 cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
-     bfd *                     abfd ATTRIBUTE_UNUSED;
-     struct bfd_link_info *    info ATTRIBUTE_UNUSED;
-     asection *                sec ATTRIBUTE_UNUSED;
-     const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED;
+     bfd *abfd ATTRIBUTE_UNUSED;
+     struct bfd_link_info *info ATTRIBUTE_UNUSED;
+     asection *sec ATTRIBUTE_UNUSED;
+     const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;
 {
   Elf_Internal_Shdr *symtab_hdr;
   struct elf_link_hash_entry **sym_hashes;
@@ -1768,7 +1782,7 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
 
   dynobj = elf_hash_table (info)->dynobj;
   if (dynobj == NULL)
-    return true;
+    return TRUE;
 
   sgot = bfd_get_section_by_name (dynobj, ".got");
   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
@@ -1835,7 +1849,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;
@@ -1845,7 +1860,7 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
        }
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
@@ -1855,7 +1870,7 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
    or elf_cris_size_dynamic_sections if no dynamic sections will be
    created (we're only linking static objects).  */
 
-static boolean
+static bfd_boolean
 elf_cris_adjust_gotplt_to_got (h, p)
      struct elf_cris_link_hash_entry *h;
      PTR p;
@@ -1865,9 +1880,12 @@ 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;
+    return TRUE;
 
   if (h->root.got.refcount > 0)
     {
@@ -1889,28 +1907,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;
@@ -1919,7 +1918,7 @@ elf_cris_adjust_gotplt_to_got (h, p)
       srelgot->_raw_size += sizeof (Elf32_External_Rela);
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Try to fold PLT entries with GOT entries.  There are two cases when we
@@ -1940,7 +1939,7 @@ elf_cris_adjust_gotplt_to_got (h, p)
    version scripts.  The differing cases are handled by
    elf_cris_hide_symbol.  */
 
-static boolean
+static bfd_boolean
 elf_cris_try_fold_plt_to_got (h, p)
      struct elf_cris_link_hash_entry *h;
      PTR p;
@@ -1951,7 +1950,7 @@ elf_cris_try_fold_plt_to_got (h, p)
      other reference so there's nothing to do.  Likewise if there are no
      PLT references; GOTPLT references included.  */
   if (h->root.got.refcount <= 0 || h->root.plt.refcount <= 0)
-    return true;
+    return TRUE;
 
   /* GOTPLT relocs are supposed to be included into the PLT refcount.  */
   BFD_ASSERT (h->gotplt_refcount <= h->root.plt.refcount);
@@ -1961,13 +1960,13 @@ elf_cris_try_fold_plt_to_got (h, p)
       /* The only PLT references are GOTPLT references, and there are GOT
         references.  Convert PLT to GOT references.  */
       if (! elf_cris_adjust_gotplt_to_got (h, info))
-       return false;
+       return FALSE;
 
       /* Clear the PLT references, so no PLT will be created.  */
       h->root.plt.offset = (bfd_vma) -1;
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Our own version of hide_symbol, so that we can adjust a GOTPLT reloc
@@ -1975,13 +1974,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;
+     bfd_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
@@ -1990,7 +1990,7 @@ elf_cris_hide_symbol (info, h)
    change the definition to something the rest of the link can
    understand.  */
 
-static boolean
+static bfd_boolean
 elf_cris_adjust_dynamic_symbol (info, h)
      struct bfd_link_info *info;
      struct elf_link_hash_entry *h;
@@ -2018,23 +2018,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,
@@ -2045,21 +2045,21 @@ elf_cris_adjust_dynamic_symbol (info, h)
         PLT entry, get rid of the PLT.  */
       if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
                                          h, info))
-       return false;
+       return FALSE;
 
       /* GC or folding may have rendered this entry unused.  */
       if (h->plt.refcount <= 0)
        {
          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
          h->plt.offset = (bfd_vma) -1;
-         return true;
+         return TRUE;
        }
 
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1)
        {
          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
-           return false;
+           return FALSE;
        }
 
       s = bfd_get_section_by_name (dynobj, ".plt");
@@ -2072,9 +2072,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)
        {
@@ -2105,7 +2103,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
          /* Make room for this entry.  */
          s->_raw_size += PLT_ENTRY_SIZE;
 
-         return true;
+         return TRUE;
        }
 
       /* No GOT reference for this symbol; prepare for an ordinary PLT.  */
@@ -2130,7 +2128,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
       BFD_ASSERT (s != NULL);
       s->_raw_size += sizeof (Elf32_External_Rela);
 
-      return true;
+      return TRUE;
     }
 
   /* Reinitialize the plt offset now that it is not used as a reference
@@ -2146,7 +2144,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
                  || h->weakdef->root.type == bfd_link_hash_defweak);
       h->root.u.def.section = h->weakdef->root.u.def.section;
       h->root.u.def.value = h->weakdef->root.u.def.value;
-      return true;
+      return TRUE;
     }
 
   /* This is a reference to a symbol defined by a dynamic object which
@@ -2157,12 +2155,12 @@ elf_cris_adjust_dynamic_symbol (info, h)
      For such cases we need not do anything here; the relocations will
      be handled correctly by relocate_section.  */
   if (info->shared)
-    return true;
+    return TRUE;
 
   /* If there are no references to this symbol that do not use the
      GOT, we don't need to generate a copy reloc.  */
   if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
-    return true;
+    return TRUE;
 
   /* We must allocate the symbol in our .dynbss section, which will
      become part of the .bss section of the executable.  There will be
@@ -2206,7 +2204,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
   if (power_of_two > bfd_get_section_alignment (dynobj, s))
     {
       if (!bfd_set_section_alignment (dynobj, s, power_of_two))
-       return false;
+       return FALSE;
     }
 
   /* Define the symbol as being at this point in the section.  */
@@ -2216,12 +2214,12 @@ elf_cris_adjust_dynamic_symbol (info, h)
   /* Increment the section size to make room for the symbol.  */
   s->_raw_size += h->size;
 
-  return true;
+  return TRUE;
 }
 
 /* Look through the relocs for a section during the first phase.  */
 
-static boolean
+static bfd_boolean
 cris_elf_check_relocs (abfd, info, sec, relocs)
      bfd *abfd;
      struct bfd_link_info *info;
@@ -2238,8 +2236,8 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
   asection *srelgot;
   asection *sreloc;
 
-  if (info->relocateable)
-    return true;
+  if (info->relocatable)
+    return TRUE;
 
   dynobj = elf_hash_table (info)->dynobj;
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
@@ -2287,7 +2285,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
              /* Create the .got section, so we can assume it's always
                 present whenever there's a dynobj.  */
              if (!_bfd_elf_create_got_section (dynobj, info))
-               return false;
+               return FALSE;
            }
          break;
 
@@ -2299,8 +2297,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)
@@ -2315,10 +2343,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);
+               return FALSE;
 
              local_got_refcounts++;
              elf_local_got_refcounts (abfd) = local_got_refcounts;
@@ -2348,38 +2375,15 @@ 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)
                    {
                      if (!bfd_elf32_link_record_dynamic_symbol (info, h))
-                       return false;
+                       return FALSE;
                    }
 
                  /* Allocate space in the .got section.  */
@@ -2387,16 +2391,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)
                    {
@@ -2406,8 +2407,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;
 
@@ -2436,14 +2436,11 @@ 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;
-         if (h->plt.refcount == -1)
-           h->plt.refcount = 1;
-         else
-           h->plt.refcount++;
+         h->plt.refcount++;
          break;
 
        case R_CRIS_8:
@@ -2478,9 +2475,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
+             if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
                h->plt.refcount++;
            }
 
@@ -2514,7 +2509,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
@@ -2539,7 +2534,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                       elf_elfheader (abfd)->e_shstrndx,
                       elf_section_data (sec)->rel_hdr.sh_name));
              if (name == NULL)
-               return false;
+               return FALSE;
 
              BFD_ASSERT (strncmp (name, ".rela", 5) == 0
                          && strcmp (bfd_get_section_name (abfd, sec),
@@ -2558,7 +2553,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                                                  | SEC_LINKER_CREATED
                                                  | SEC_READONLY))
                      || !bfd_set_section_alignment (dynobj, sreloc, 2))
-                   return false;
+                   return FALSE;
                }
              if (sec->flags & SEC_READONLY)
                info->flags |= DF_TEXTREL;
@@ -2590,7 +2585,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                  p = ((struct elf_cris_pcrel_relocs_copied *)
                       bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
                  if (p == NULL)
-                   return false;
+                   return FALSE;
                  p->next = eh->pcrel_relocs_copied;
                  eh->pcrel_relocs_copied = p;
                  p->section = sreloc;
@@ -2605,37 +2600,37 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
            Reconstruct it for later use during GC.  */
         case R_CRIS_GNU_VTINHERIT:
           if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
-            return false;
+            return FALSE;
           break;
 
         /* This relocation describes which C++ vtable entries are actually
            used.  Record for later use during GC.  */
         case R_CRIS_GNU_VTENTRY:
           if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
-            return false;
+            return FALSE;
           break;
 
        default:
          /* Other relocs do not appear here.  */
          bfd_set_error (bfd_error_bad_value);
-         return false;
+         return FALSE;
         }
     }
 
-  return true;
+  return TRUE;
 }
 
 /* Set the sizes of the dynamic sections.  */
 
-static boolean
+static bfd_boolean
 elf_cris_size_dynamic_sections (output_bfd, info)
      bfd *output_bfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   bfd *dynobj;
   asection *s;
-  boolean plt;
-  boolean relocs;
+  bfd_boolean plt;
+  bfd_boolean relocs;
 
   dynobj = elf_hash_table (info)->dynobj;
   BFD_ASSERT (dynobj != NULL);
@@ -2687,12 +2682,12 @@ elf_cris_size_dynamic_sections (output_bfd, info)
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = false;
-  relocs = false;
+  plt = FALSE;
+  relocs = FALSE;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
-      boolean strip;
+      bfd_boolean strip;
 
       if ((s->flags & SEC_LINKER_CREATED) == 0)
        continue;
@@ -2701,7 +2696,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
         of the dynobj section names depend upon the input files.  */
       name = bfd_get_section_name (dynobj, s);
 
-      strip = false;
+      strip = FALSE;
 
       if (strcmp (name, ".plt") == 0)
        {
@@ -2709,12 +2704,12 @@ elf_cris_size_dynamic_sections (output_bfd, info)
            {
              /* Strip this section if we don't need it; see the
                  comment below.  */
-             strip = true;
+             strip = TRUE;
            }
          else
            {
              /* Remember whether there is a PLT.  */
-             plt = true;
+             plt = TRUE;
            }
        }
       else if (strncmp (name, ".rela", 5) == 0)
@@ -2730,14 +2725,14 @@ elf_cris_size_dynamic_sections (output_bfd, info)
                 adjust_dynamic_symbol is called, and it is that
                 function which decides whether anything needs to go
                 into these sections.  */
-             strip = true;
+             strip = TRUE;
            }
          else
            {
              /* Remember whether there are any reloc sections other
                  than .rela.plt.  */
              if (strcmp (name, ".rela.plt") != 0)
-                 relocs = true;
+                 relocs = TRUE;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -2763,7 +2758,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
         this will make entries have the type R_CRIS_NONE.  */
       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
       if (s->contents == NULL && s->_raw_size != 0)
-       return false;
+       return FALSE;
     }
 
   if (elf_hash_table (info)->dynamic_sections_created)
@@ -2779,7 +2774,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
       if (!info->shared)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
-           return false;
+           return FALSE;
        }
 
       if (plt)
@@ -2788,7 +2783,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
              || !add_dynamic_entry (DT_PLTRELSZ, 0)
              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
              || !add_dynamic_entry (DT_JMPREL, 0))
-           return false;
+           return FALSE;
        }
 
       if (relocs)
@@ -2796,19 +2791,19 @@ elf_cris_size_dynamic_sections (output_bfd, info)
          if (!add_dynamic_entry (DT_RELA, 0)
              || !add_dynamic_entry (DT_RELASZ, 0)
              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
-           return false;
+           return FALSE;
        }
 
       if ((info->flags & DF_TEXTREL) != 0)
        {
          if (!add_dynamic_entry (DT_TEXTREL, 0))
-           return false;
+           return FALSE;
          info->flags |= DF_TEXTREL;
        }
     }
 #undef add_dynamic_entry
 
-  return true;
+  return TRUE;
 }
 
 /* This function is called via elf_cris_link_hash_traverse if we are
@@ -2820,7 +2815,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
    check_relocs routine, but we won't fill them in in the
    relocate_section routine.  */
 
-static boolean
+static bfd_boolean
 elf_cris_discard_excess_dso_dynamics (h, inf)
      struct elf_cris_link_hash_entry *h;
      PTR inf;
@@ -2828,6 +2823,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.  */
@@ -2839,26 +2837,28 @@ elf_cris_discard_excess_dso_dynamics (h, inf)
        s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
     }
 
-  return true;
+  return TRUE;
 }
 
 /* This function is called via elf_cris_link_hash_traverse if we are *not*
    creating a shared object.  We discard space for relocs for symbols put
    in the .got, but which we found we do not have to resolve at run-time.  */
 
-static boolean
+static bfd_boolean
 elf_cris_discard_excess_program_dynamics (h, inf)
      struct elf_cris_link_hash_entry *h;
      PTR 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
@@ -2881,17 +2881,24 @@ 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;
+  return TRUE;
 }
 
 /* Reject a file depending on presence and expectation of prefixed
    underscores on symbols.  */
 
-static boolean
+static bfd_boolean
 cris_elf_object_p (abfd)
      bfd *abfd;
 {
@@ -2906,7 +2913,7 @@ cris_elf_object_p (abfd)
 static void
 cris_elf_final_write_processing (abfd, linker)
      bfd *abfd;
-     boolean linker ATTRIBUTE_UNUSED;
+     bfd_boolean linker ATTRIBUTE_UNUSED;
 {
   if (bfd_get_symbol_leading_char (abfd) == '_')
     elf_elfheader (abfd)->e_flags |= EF_CRIS_UNDERSCORE;
@@ -2916,7 +2923,7 @@ cris_elf_final_write_processing (abfd, linker)
 
 /* Display the flags field.  */
 
-static boolean
+static bfd_boolean
 cris_elf_print_private_bfd_data (abfd, ptr)
      bfd *abfd;
      PTR ptr;
@@ -2933,32 +2940,32 @@ cris_elf_print_private_bfd_data (abfd, ptr)
     fprintf (file, _(" [symbols have a _ prefix]"));
 
   fputc ('\n', file);
-  return true;
+  return TRUE;
 }
 
 /* Don't mix files with and without a leading underscore.  */
 
-static boolean
+static bfd_boolean
 cris_elf_merge_private_bfd_data (ibfd, obfd)
      bfd *ibfd;
      bfd *obfd;
 {
   flagword old_flags, new_flags;
 
-  if (_bfd_generic_verify_endian_match (ibfd, obfd) == false)
-    return false;
+  if (! _bfd_generic_verify_endian_match (ibfd, obfd))
+    return FALSE;
 
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
-    return true;
+    return TRUE;
 
   if (! elf_flags_init (obfd))
     {
       /* This happens when ld starts out with a 'blank' output file.  */
-      elf_flags_init (obfd) = true;
+      elf_flags_init (obfd) = TRUE;
 
       /* Set flags according to current bfd_target.  */
-      cris_elf_final_write_processing (obfd, false);
+      cris_elf_final_write_processing (obfd, FALSE);
     }
 
   old_flags = elf_elfheader (obfd)->e_flags;
@@ -2973,18 +2980,18 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
         : _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
         bfd_archive_filename (ibfd));
       bfd_set_error (bfd_error_bad_value);
-      return false;
+      return FALSE;
     }
 
-  return true;
+  return TRUE;
 }
 
 
 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;
@@ -3011,8 +3018,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 \
@@ -3045,13 +3055,13 @@ elf_cris_reloc_type_class (type)
 #define elf_backend_plt_readonly       1
 #define elf_backend_want_plt_sym       0
 #define elf_backend_got_header_size    12
-#define elf_backend_plt_header_size    PLT_ENTRY_SIZE
 
 /* Later, we my want to optimize RELA entries into REL entries for dynamic
    linking and libraries (if it's a win of any significance).  Until then,
    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.056867 seconds and 4 git commands to generate.