include/
[deliverable/binutils-gdb.git] / bfd / elf32-cris.c
index 40327b650e4149ceb5d54c1fbc25f483e3aa0a85..c80146b1b77c800f599940e296e9b3b2f53c06c8 100644 (file)
@@ -1,5 +1,6 @@
 /* CRIS-specific support for 32-bit ELF.
-   Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+   Copyright 2000, 2001, 2002, 2003, 2004, 2005
+   Free Software Foundation, Inc.
    Contributed by Axis Communications AB.
    Written by Hans-Peter Nilsson, based on elf32-fr30.c
    PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
@@ -33,6 +34,9 @@ static reloc_howto_type * cris_reloc_type_lookup
 static void cris_info_to_howto_rela
   PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
 
+static bfd_reloc_status_type cris_elf_pcrel_reloc
+  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+
 static bfd_boolean cris_elf_grok_prstatus
   PARAMS ((bfd *abfd, Elf_Internal_Note *note));
 
@@ -59,9 +63,13 @@ static bfd_boolean cris_elf_object_p PARAMS ((bfd *));
 
 static void cris_elf_final_write_processing PARAMS ((bfd *, bfd_boolean));
 
+static bfd_boolean cris_elf_set_mach_from_flags
+  PARAMS ((bfd *, unsigned long int));
+
 static bfd_boolean cris_elf_print_private_bfd_data PARAMS ((bfd *, PTR));
 
 static bfd_boolean cris_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
+static bfd_boolean cris_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
 
 struct elf_cris_link_hash_entry;
 static bfd_boolean elf_cris_discard_excess_dso_dynamics
@@ -164,7 +172,7 @@ static reloc_howto_type cris_elf_howto_table [] =
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        cris_elf_pcrel_reloc,  /* special_function */
         "R_CRIS_8_PCREL",      /* name */
         FALSE,                 /* partial_inplace */
         0x0000,                /* src_mask */
@@ -179,7 +187,7 @@ static reloc_howto_type cris_elf_howto_table [] =
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        cris_elf_pcrel_reloc,  /* special_function */
         "R_CRIS_16_PCREL",     /* name */
         FALSE,                 /* partial_inplace */
         0x00000000,            /* src_mask */
@@ -194,7 +202,7 @@ static reloc_howto_type cris_elf_howto_table [] =
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        cris_elf_pcrel_reloc,  /* special_function */
         "R_CRIS_32_PCREL",     /* name */
         FALSE,                 /* partial_inplace */
         0x00000000,            /* src_mask */
@@ -398,7 +406,7 @@ static reloc_howto_type cris_elf_howto_table [] =
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_bitfield, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
+        cris_elf_pcrel_reloc,  /* special_function */
         "R_CRIS_32_PLT_PCREL", /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
@@ -466,8 +474,39 @@ cris_info_to_howto_rela (abfd, cache_ptr, dst)
   BFD_ASSERT (r_type < (unsigned int) R_CRIS_max);
   cache_ptr->howto = & cris_elf_howto_table [r_type];
 }
+
+bfd_reloc_status_type
+cris_elf_pcrel_reloc (abfd, reloc_entry, symbol, data, input_section,
+                     output_bfd, error_message)
+     bfd *abfd ATTRIBUTE_UNUSED;
+     arelent *reloc_entry;
+     asymbol *symbol;
+     PTR data ATTRIBUTE_UNUSED;
+     asection *input_section;
+     bfd *output_bfd;
+     char **error_message ATTRIBUTE_UNUSED;
+{
+  /* By default (using only bfd_elf_generic_reloc when linking to
+     non-ELF formats) PC-relative relocs are relative to the beginning
+     of the reloc.  CRIS PC-relative relocs are relative to the position
+     *after* the reloc because that's what pre-CRISv32 PC points to
+     after reading an insn field with that reloc.  (For CRISv32, PC is
+     actually relative to the start of the insn, but we keep the old
+     definition.)  Still, we use as much generic machinery as we can.
+
+     Only adjust when doing a final link.  */
+  if (output_bfd == (bfd *) NULL)
+    reloc_entry->addend -= 1 << reloc_entry->howto->size;
+
+  return
+    bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
+                          input_section, output_bfd, error_message);
+}
 \f
-/* Support for core dump NOTE sections.  */
+/* Support for core dump NOTE sections.
+   The slightly unintuitive code layout is an attempt to keep at least
+   some similarities with other ports, hoping to simplify general
+   changes, while still keeping Linux/CRIS and Linux/CRISv32 code apart.  */
 
 static bfd_boolean
 cris_elf_grok_prstatus (abfd, note)
@@ -475,10 +514,30 @@ cris_elf_grok_prstatus (abfd, note)
      Elf_Internal_Note *note;
 {
   int offset;
-  size_t raw_size;
+  size_t size;
 
-  switch (note->descsz)
-    {
+  if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
+    switch (note->descsz)
+      {
+      default:
+       return FALSE;
+
+      case 202:                /* Linux/CRISv32 */
+       /* 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;
+       size = 128;
+
+       break;
+      }
+  else
+    switch (note->descsz)
+      {
       default:
        return FALSE;
 
@@ -491,14 +550,14 @@ cris_elf_grok_prstatus (abfd, note)
 
        /* pr_reg */
        offset = 70;
-       raw_size = 140;
+       size = 140;
 
        break;
-    }
+      }
 
   /* Make a ".reg/999" section.  */
   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
-                                         raw_size, note->descpos + offset);
+                                         size, note->descpos + offset);
 }
 
 static bfd_boolean
@@ -506,17 +565,30 @@ cris_elf_grok_psinfo (abfd, note)
      bfd *abfd;
      Elf_Internal_Note *note;
 {
-  switch (note->descsz)
-    {
+  if (bfd_get_mach (abfd) == bfd_mach_cris_v32)
+    switch (note->descsz)
+      {
+      default:
+       return FALSE;
+
+      case 124:                /* Linux/CRISv32 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);
+      }
+  else
+    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);
+         = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
        elf_tdata (abfd)->core_command
-        = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
-    }
+         = _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)
@@ -541,6 +613,7 @@ cris_elf_grok_psinfo (abfd, note)
 /* The size in bytes of an entry in the procedure linkage table.  */
 
 #define PLT_ENTRY_SIZE 20
+#define PLT_ENTRY_SIZE_V32 26
 
 /* The first entry in an absolute procedure linkage table looks like this.  */
 
@@ -553,7 +626,21 @@ static const bfd_byte elf_cris_plt0_entry[PLT_ENTRY_SIZE] =
   0x30, 0x7a,  /* move [...],mof */
   0x7f, 0x0d,   /*  (dip [pc+]) */
   0, 0, 0, 0,  /*  Replaced with address of .got + 8.  */
-  0x30, 0x09,  /* jump [...] */
+  0x30, 0x09   /* jump [...] */
+};
+
+static const bfd_byte elf_cris_plt0_entry_v32[PLT_ENTRY_SIZE_V32] =
+{
+  0x84, 0xe2,  /* subq 4,$sp */
+  0x6f, 0xfe,  /* move.d 0,$acr */
+  0, 0, 0, 0,  /*  Replaced by address of .got + 4.  */
+  0x7e, 0x7a,  /* move $mof,[$sp] */
+  0x3f, 0x7a,  /* move [$acr],$mof */
+  0x04, 0xf2,  /* addq 4,acr */
+  0x6f, 0xfa,  /* move.d [$acr],$acr */
+  0xbf, 0x09,  /* jump $acr */
+  0xb0, 0x05,  /* nop */
+  0, 0         /*  Pad out to 26 bytes.  */
 };
 
 /* Subsequent entries in an absolute procedure linkage table look like
@@ -571,6 +658,20 @@ static const bfd_byte elf_cris_plt_entry[PLT_ENTRY_SIZE] =
   0xff, 0xff   /*  Replaced with offset to start of .plt.  */
 };
 
+static const bfd_byte elf_cris_plt_entry_v32[PLT_ENTRY_SIZE_V32] =
+{
+  0x6f, 0xfe,  /* move.d 0,$acr */
+  0, 0, 0, 0,  /*  Replaced with address of this symbol in .got.  */
+  0x6f, 0xfa,   /* move.d [$acr],$acr */
+  0xbf, 0x09,   /* jump $acr */
+  0xb0, 0x05,  /* nop */
+  0x3f, 0x7e,  /* move 0,mof */
+  0, 0, 0, 0,  /*  Replaced with offset into relocation table. */
+  0xbf, 0x0e,  /* ba start_of_plt0_entry */
+  0, 0, 0, 0,  /*  Replaced with offset to plt0 entry.  */
+  0xb0, 0x05   /* nop */
+};
+
 /* The first entry in a PIC procedure linkage table looks like this.  */
 
 static const bfd_byte elf_cris_pic_plt0_entry[PLT_ENTRY_SIZE] =
@@ -581,6 +682,21 @@ static const bfd_byte elf_cris_pic_plt0_entry[PLT_ENTRY_SIZE] =
   0, 0, 0, 0, 0, 0, 0, 0,      /*  Pad out to 20 bytes.  */
 };
 
+static const bfd_byte elf_cris_pic_plt0_entry_v32[PLT_ENTRY_SIZE_V32] =
+{
+  0x84, 0xe2,  /* subq 4,$sp */
+  0x04, 0x01,  /* addoq 4,$r0,$acr */
+  0x7e, 0x7a,  /* move $mof,[$sp] */
+  0x3f, 0x7a,  /* move [$acr],$mof */
+  0x04, 0xf2,  /* addq 4,$acr */
+  0x6f, 0xfa,  /* move.d [$acr],$acr */
+  0xbf, 0x09,  /* jump $acr */
+  0xb0, 0x05,  /* nop */
+  0, 0,                /*  Pad out to 26 bytes.  */
+  0, 0, 0, 0,
+  0, 0, 0, 0
+};
+
 /* Subsequent entries in a PIC procedure linkage table look like this.  */
 
 static const bfd_byte elf_cris_pic_plt_entry[PLT_ENTRY_SIZE] =
@@ -594,6 +710,20 @@ static const bfd_byte elf_cris_pic_plt_entry[PLT_ENTRY_SIZE] =
   0xec, 0xff,  /*  Replaced with offset to start of .plt.  */
   0xff, 0xff
 };
+
+static const bfd_byte elf_cris_pic_plt_entry_v32[PLT_ENTRY_SIZE_V32] =
+{
+  0x6f, 0x0d,  /* addo.d 0,$r0,$acr */
+  0, 0, 0, 0,  /*  Replaced with offset of this symbol in .got.  */
+  0x6f, 0xfa,  /* move.d [$acr],$acr */
+  0xbf, 0x09,  /* jump $acr */
+  0xb0, 0x05,  /* nop */
+  0x3f, 0x7e,  /* move relocoffs,$mof */
+  0, 0, 0, 0,  /*  Replaced with offset into relocation table.  */
+  0xbf, 0x0e,  /* ba start_of_plt */
+  0, 0, 0, 0,  /*  Replaced with offset to start of .plt.  */
+  0xb0, 0x05   /* nop */
+};
 \f
 /* We copy elf32-m68k.c and elf32-i386.c for the basic linker hash bits
    (and most other PIC/shlib stuff).  Check that we don't drift away
@@ -799,7 +929,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
-  if (info->relocateable)
+  if (info->relocatable)
     return TRUE;
 
   dynobj = elf_hash_table (info)->dynobj;
@@ -847,7 +977,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections [r_symndx];
-         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+         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));
@@ -856,24 +986,15 @@ 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];
+         bfd_boolean warned;
+         bfd_boolean unresolved_reloc;
 
-         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;
-
-         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 (info, input_bfd, input_section, rel,
+                                  r_symndx, symtab_hdr, sym_hashes,
+                                  h, sec, relocation,
+                                  unresolved_reloc, 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
@@ -888,71 +1009,53 @@ 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->def_regular)
+                 && (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)
-                   (_("%s: unresolvable relocation %s against symbol `%s' from %s section"),
-                    bfd_archive_filename (input_bfd),
+                 _bfd_error_handler
+                   (_("%B, section %A: unresolvable relocation %s against symbol `%s'"),
+                    input_bfd,
+                    input_section,
                     cris_elf_howto_table[r_type].name,
-                    symname,
-                    bfd_get_section_name (input_bfd, input_section));
+                    symname);
                  bfd_set_error (bfd_error_bad_value);
                  return FALSE;
                }
            }
-         else if (h->root.type == bfd_link_hash_undefweak)
-           relocation = 0;
-         else if (info->shared
-                  && !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)
@@ -986,15 +1089,28 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
             statically linking PIC code, or when using -Bsymbolic.  Check
             that we instead have a GOT entry as done for us by
             elf_cris_adjust_dynamic_symbol, and drop through into the
-            ordinary GOT cases.  */
-         if (h != NULL && h->got.offset == (bfd_vma) -1)
+            ordinary GOT cases.  This must not happen for the
+            executable, because any reference it does to a function
+            that is satisfied by a DSO must generate a PLT.  We assume
+            these call-specific relocs don't address non-functions.  */
+         if (h != NULL
+             && (h->got.offset == (bfd_vma) -1
+                 || (!info->shared
+                     && !(h->def_regular
+                          || (!h->def_dynamic
+                              && h->root.type == bfd_link_hash_undefweak)))))
            {
              (*_bfd_error_handler)
-               (_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
-                bfd_archive_filename (input_bfd),
+               ((h->got.offset == (bfd_vma) -1)
+                ? _("%B, section %A: No PLT nor GOT for relocation %s"
+                    " against symbol `%s'")
+                : _("%B, section %A: No PLT for relocation %s"
+                    " against symbol `%s'"),
+                input_bfd,
+                input_section,
                 cris_elf_howto_table[r_type].name,
-                symname[0] != '\0' ? symname : _("[whose name is lost]"),
-                bfd_get_section_name (input_bfd, input_section));
+                (symname != NULL && symname[0] != '\0'
+                 ? symname : _("[whose name is lost]")));
 
              /* FIXME: Perhaps blaming input is not the right thing to
                 do; this is probably an internal error.  But it is true
@@ -1022,18 +1138,22 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
                if (!elf_hash_table (info)->dynamic_sections_created
                    || (! info->shared
-                       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+                       && (h->def_regular
+                           || h->type == STT_FUNC
+                           || h->needs_plt))
                    || (info->shared
                        && (info->symbolic || h->dynindx == -1)
-                       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+                       && h->def_regular))
                  {
                    /* This wasn't checked above for ! info->shared, but
-                      must hold there if we get here; the symbol must be
-                      defined in the regular program, or be undefweak.  */
+                      must hold there if we get here; the symbol must
+                      be defined in the regular program or be undefweak
+                      or be a function or otherwise need a PLT.  */
                    BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
                                || info->shared
-                               || (h->elf_link_hash_flags
-                                   & ELF_LINK_HASH_DEF_REGULAR) != 0
+                               || h->def_regular
+                               || h->type == STT_FUNC
+                               || h->needs_plt
                                || h->root.type == bfd_link_hash_undefweak);
 
                    /* This is actually a static link, or it is a
@@ -1108,19 +1228,21 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                   allowed to pass us these kinds of things.  */
                if (h == NULL)
                  (*_bfd_error_handler)
-                   (_("%s: relocation %s with non-zero addend %d against local symbol from %s section"),
-                    bfd_archive_filename (input_bfd),
+                   (_("%B, section %A: relocation %s with non-zero addend %d"
+                      " against local symbol"),
+                    input_bfd,
+                    input_section,
                     cris_elf_howto_table[r_type].name,
-                    rel->r_addend,
-                    bfd_get_section_name (input_bfd, input_section));
+                    rel->r_addend);
                else
                  (*_bfd_error_handler)
-                   (_("%s: relocation %s with non-zero addend %d against symbol `%s' from %s section"),
-                    bfd_archive_filename (input_bfd),
+                   (_("%B, section %A: relocation %s with non-zero addend %d"
+                      " against symbol `%s'"),
+                    input_bfd,
+                    input_section,
                     cris_elf_howto_table[r_type].name,
                     rel->r_addend,
-                    symname[0] != '\0' ? symname : _("[whose name is lost]"),
-                    bfd_get_section_name (input_bfd, input_section));
+                    symname[0] != '\0' ? symname : _("[whose name is lost]"));
 
                bfd_set_error (bfd_error_bad_value);
                return FALSE;
@@ -1129,15 +1251,23 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          break;
 
        case R_CRIS_32_GOTREL:
-         /* This relocation must only be performed against local symbols.  */
-         if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+         /* 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->def_regular
+                      || (!h->def_dynamic
+                          && h->root.type == bfd_link_hash_undefweak))))
            {
              (*_bfd_error_handler)
-               (_("%s: relocation %s is not allowed for global symbol: `%s' from %s section"),
-                bfd_archive_filename (input_bfd),
+               (_("%B, section %A: relocation %s is"
+                  " not allowed for global symbol: `%s'"),
+                input_bfd,
+                input_section,
                 cris_elf_howto_table[r_type].name,
-                symname,
-                bfd_get_section_name (input_bfd, input_section));
+                symname);
              bfd_set_error (bfd_error_bad_value);
              return FALSE;
            }
@@ -1148,10 +1278,10 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          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));
+               (_("%B, section %A: relocation %s with no GOT created"),
+                input_bfd,
+                input_section,
+                cris_elf_howto_table[r_type].name);
              bfd_set_error (bfd_error_bad_value);
              return FALSE;
            }
@@ -1231,8 +1361,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                   && r_type != R_CRIS_16_PCREL
                   && r_type != R_CRIS_32_PCREL)
                  || (!info->symbolic
-                     || (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)))
+                     || !h->def_regular)))
            {
              Elf_Internal_Rela outrel;
              bfd_byte *loc;
@@ -1267,8 +1396,8 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  if (sreloc == NULL)
                    {
                      (*_bfd_error_handler)
-                       (_("%s: Internal inconsistency; no relocation section %s"),
-                        bfd_archive_filename (input_bfd),
+                       (_("%B: Internal inconsistency; no relocation section %s"),
+                        input_bfd,
                         name);
 
                      bfd_set_error (bfd_error_bad_value);
@@ -1295,8 +1424,7 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                 become local.  */
              else if (h != NULL
                       && ((! info->symbolic && h->dynindx != -1)
-                          || (h->elf_link_hash_flags
-                              & ELF_LINK_HASH_DEF_REGULAR) == 0))
+                          || !h->def_regular))
                {
                  BFD_ASSERT (h->dynindx != -1);
                  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
@@ -1314,16 +1442,7 @@ 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)
                        {
@@ -1369,8 +1488,8 @@ cris_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
            case bfd_reloc_overflow:
              r = info->callbacks->reloc_overflow
-               (info, symname, howto->name, (bfd_vma) 0,
-                input_bfd, input_section, rel->r_offset);
+               (info, (h ? &h->root : NULL), symname, howto->name,
+                (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
              break;
 
            case bfd_reloc_undefined:
@@ -1419,8 +1538,33 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
      Elf_Internal_Sym *sym;
 {
   bfd *dynobj;
+
+  /* Where in the plt entry to put values.  */
   int plt_off1 = 2, plt_off2 = 10, plt_off3 = 16;
 
+  /* What offset to add to the distance to the first PLT entry for the
+     value at plt_off3.   */
+  int plt_off3_value_bias = 4;
+
+  /* Where in the PLT entry the call-dynlink-stub is (happens to be same
+     for PIC and non-PIC for v32 and pre-v32).  */
+  int plt_stub_offset = 8;
+  int plt_entry_size = PLT_ENTRY_SIZE;
+  const bfd_byte *plt_entry = elf_cris_plt_entry;
+  const bfd_byte *plt_pic_entry = elf_cris_pic_plt_entry;
+
+  /* Adjust the various PLT entry offsets.  */
+  if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32)
+    {
+      plt_off2 = 14;
+      plt_off3 = 20;
+      plt_off3_value_bias = -2;
+      plt_stub_offset = 12;
+      plt_entry_size = PLT_ENTRY_SIZE_V32;
+      plt_entry = elf_cris_plt_entry_v32;
+      plt_pic_entry = elf_cris_pic_plt_entry_v32;
+    }
+
   dynobj = elf_hash_table (info)->dynobj;
 
   if (h->plt.offset != (bfd_vma) -1)
@@ -1449,7 +1593,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
         to this function.  Note that we embed knowledge that "incoming"
         .got goes after .got.plt in the output without padding (pointer
         aligned).  However, that knowledge is present in several other
-        places too, here and in elflink.h at least.  */
+        places too.  */
       bfd_vma got_offset
        = (has_gotplt
           ? gotplt_offset
@@ -1472,8 +1616,8 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
       /* Fill in the entry in the procedure linkage table.  */
       if (! info->shared)
        {
-         memcpy (splt->contents + h->plt.offset, elf_cris_plt_entry,
-                 PLT_ENTRY_SIZE);
+         memcpy (splt->contents + h->plt.offset, plt_entry,
+                 plt_entry_size);
 
          /* We need to enter the absolute address of the GOT entry here.  */
          bfd_put_32 (output_bfd, got_base + got_offset,
@@ -1481,8 +1625,8 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
        }
       else
        {
-         memcpy (splt->contents + h->plt.offset, elf_cris_pic_plt_entry,
-                 PLT_ENTRY_SIZE);
+         memcpy (splt->contents + h->plt.offset, plt_pic_entry,
+                 plt_entry_size);
          bfd_put_32 (output_bfd, got_offset,
                      splt->contents + h->plt.offset + plt_off1);
        }
@@ -1491,13 +1635,14 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
         PLT entry.  */
       if (has_gotplt)
        {
-         /* Fill in the offset into the reloc table.  */
+         /* Fill in the offset to the reloc table.  */
          bfd_put_32 (output_bfd,
                      gotplt_index * sizeof (Elf32_External_Rela),
                      splt->contents + h->plt.offset + plt_off2);
 
          /* Fill in the offset to the first PLT entry, where to "jump".  */
-         bfd_put_32 (output_bfd, - (h->plt.offset + plt_off3 + 4),
+         bfd_put_32 (output_bfd,
+                     - (h->plt.offset + plt_off3 + plt_off3_value_bias),
                      splt->contents + h->plt.offset + plt_off3);
 
          /* Fill in the entry in the global offset table with the address of
@@ -1506,7 +1651,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
                      (splt->output_section->vma
                       + splt->output_offset
                       + h->plt.offset
-                      + 8),
+                      + plt_stub_offset),
                      sgotplt->contents + got_offset);
 
          /* Fill in the entry in the .rela.plt section.  */
@@ -1519,7 +1664,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
        }
 
-      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+      if (!h->def_regular)
        {
          /* Mark the symbol as undefined, rather than as defined in
             the .plt section.  Leave the value alone.  */
@@ -1533,19 +1678,21 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
             Otherwise, the PLT entry would provide a definition for
             the symbol even if the symbol wasn't defined anywhere,
             and so the symbol would never be NULL.  */
-         if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
-             == 0)
+         if (!h->ref_regular_nonweak)
            sym->st_value = 0;
        }
     }
 
-  /* We don't emit .got relocs for symbols that aren't in the
-     dynamic-symbols table for an ordinary program and are either defined
-     by the program or are undefined weak symbols.  */
+  /* For an ordinary program, we emit .got relocs only for symbols that
+     are in the dynamic-symbols table and are either defined by the
+     program or are undefined weak symbols, or are function symbols
+     where we do not output a PLT: the PLT reloc was output above and all
+     references to the function symbol are redirected to the PLT.  */
   if (h->got.offset != (bfd_vma) -1
       && (info->shared
          || (h->dynindx != -1
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
+             && h->plt.offset == (bfd_vma) -1
+             && !h->def_regular
              && h->root.type != bfd_link_hash_undefweak)))
     {
       asection *sgot;
@@ -1573,7 +1720,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
       if (! elf_hash_table (info)->dynamic_sections_created
          || (info->shared
              && (info->symbolic || h->dynindx == -1)
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+             && h->def_regular))
        {
          rela.r_info = ELF32_R_INFO (0, R_CRIS_RELATIVE);
          rela.r_addend = bfd_get_signed_32 (output_bfd, where);
@@ -1590,7 +1737,7 @@ elf_cris_finish_dynamic_symbol (output_bfd, info, h, sym)
       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     }
 
-  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
+  if (h->needs_copy)
     {
       asection *s;
       Elf_Internal_Rela rela;
@@ -1649,7 +1796,7 @@ elf_cris_finish_dynamic_sections (output_bfd, info)
       BFD_ASSERT (splt != NULL && sdyn != NULL);
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
-      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
@@ -1681,10 +1828,8 @@ elf_cris_finish_dynamic_sections (output_bfd, info)
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
              if (s == NULL)
                dyn.d_un.d_val = 0;
-             else if (s->_cooked_size != 0)
-               dyn.d_un.d_val = s->_cooked_size;
              else
-               dyn.d_un.d_val = s->_raw_size;
+               dyn.d_un.d_val = s->size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
 
@@ -1698,40 +1843,60 @@ elf_cris_finish_dynamic_sections (output_bfd, info)
                 about changing the DT_RELA entry.  */
              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
              if (s != NULL)
-               {
-                 if (s->_cooked_size != 0)
-                   dyn.d_un.d_val -= s->_cooked_size;
-                 else
-                   dyn.d_un.d_val -= s->_raw_size;
-               }
+               dyn.d_un.d_val -= s->size;
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
              break;
            }
        }
 
       /* Fill in the first entry in the procedure linkage table.  */
-      if (splt->_raw_size > 0)
+      if (splt->size > 0)
        {
-         if (info->shared)
-           memcpy (splt->contents, elf_cris_pic_plt0_entry, PLT_ENTRY_SIZE);
+         if (bfd_get_mach (output_bfd) == bfd_mach_cris_v32)
+           {
+             if (info->shared)
+               memcpy (splt->contents, elf_cris_pic_plt0_entry_v32,
+                       PLT_ENTRY_SIZE_V32);
+             else
+               {
+                 memcpy (splt->contents, elf_cris_plt0_entry_v32,
+                         PLT_ENTRY_SIZE_V32);
+                 bfd_put_32 (output_bfd,
+                             sgot->output_section->vma
+                             + sgot->output_offset + 4,
+                             splt->contents + 4);
+
+                 elf_section_data (splt->output_section)->this_hdr.sh_entsize
+                   = PLT_ENTRY_SIZE_V32;
+               }
+           }
          else
-            {
-             memcpy (splt->contents, elf_cris_plt0_entry, PLT_ENTRY_SIZE);
-             bfd_put_32 (output_bfd,
-                         sgot->output_section->vma + sgot->output_offset + 4,
-                         splt->contents + 6);
-             bfd_put_32 (output_bfd,
-                         sgot->output_section->vma + sgot->output_offset + 8,
-                         splt->contents + 14);
-
-              elf_section_data (splt->output_section)->this_hdr.sh_entsize
-               = PLT_ENTRY_SIZE;
+           {
+             if (info->shared)
+               memcpy (splt->contents, elf_cris_pic_plt0_entry,
+                       PLT_ENTRY_SIZE);
+             else
+               {
+                 memcpy (splt->contents, elf_cris_plt0_entry,
+                         PLT_ENTRY_SIZE);
+                 bfd_put_32 (output_bfd,
+                             sgot->output_section->vma
+                             + sgot->output_offset + 4,
+                             splt->contents + 6);
+                 bfd_put_32 (output_bfd,
+                             sgot->output_section->vma
+                             + sgot->output_offset + 8,
+                             splt->contents + 14);
+
+                 elf_section_data (splt->output_section)->this_hdr.sh_entsize
+                   = PLT_ENTRY_SIZE;
+               }
             }
        }
     }
 
   /* Fill in the first three entries in the global offset table.  */
-  if (sgot->_raw_size > 0)
+  if (sgot->size > 0)
     {
       if (sdyn == NULL)
        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
@@ -1801,42 +1966,50 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
   struct elf_link_hash_entry **sym_hashes;
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
-  unsigned long r_symndx;
-  struct elf_link_hash_entry *h;
   bfd *dynobj;
   asection *sgot;
   asection *srelgot;
 
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
-  sym_hashes = elf_sym_hashes (abfd);
-  local_got_refcounts = elf_local_got_refcounts (abfd);
-
   dynobj = elf_hash_table (info)->dynobj;
   if (dynobj == NULL)
     return TRUE;
 
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  sym_hashes = elf_sym_hashes (abfd);
+  local_got_refcounts = elf_local_got_refcounts (abfd);
+
   sgot = bfd_get_section_by_name (dynobj, ".got");
   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
 
   relend = relocs + sec->reloc_count;
   for (rel = relocs; rel < relend; rel++)
     {
+      unsigned long r_symndx;
+      struct elf_link_hash_entry *h = NULL;
+
+      r_symndx = ELF32_R_SYM (rel->r_info);
+      if (r_symndx >= symtab_hdr->sh_info)
+       {
+         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;
+       }
+
       switch (ELF32_R_TYPE (rel->r_info))
        {
        case R_CRIS_16_GOT:
        case R_CRIS_32_GOT:
-         r_symndx = ELF32_R_SYM (rel->r_info);
-         if (r_symndx >= symtab_hdr->sh_info)
+         if (h != NULL)
            {
-             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
              if (h->got.refcount > 0)
                {
                  --h->got.refcount;
                  if (h->got.refcount == 0)
                    {
                      /* We don't need the .got entry any more.  */
-                     sgot->_raw_size -= 4;
-                     srelgot->_raw_size -= sizeof (Elf32_External_Rela);
+                     sgot->size -= 4;
+                     srelgot->size -= sizeof (Elf32_External_Rela);
                    }
                }
              break;
@@ -1851,9 +2024,9 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
                  if (local_got_refcounts[r_symndx] == 0)
                    {
                      /* We don't need the .got entry any more.  */
-                     sgot->_raw_size -= 4;
+                     sgot->size -= 4;
                      if (info->shared)
-                       srelgot->_raw_size -= sizeof (Elf32_External_Rela);
+                       srelgot->size -= sizeof (Elf32_External_Rela);
                    }
                }
            }
@@ -1862,9 +2035,9 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
        case R_CRIS_16_GOTPLT:
        case R_CRIS_32_GOTPLT:
          /* For local symbols, treat these like GOT relocs.  */
-         r_symndx = ELF32_R_SYM (rel->r_info);
-         if (r_symndx < symtab_hdr->sh_info)
+         if (h == NULL)
            goto local_got_reloc;
+         /* Fall through.  */
 
        case R_CRIS_32_PLT_GOTREL:
          /* FIXME: We don't garbage-collect away the .got section.  */
@@ -1876,10 +2049,8 @@ cris_elf_gc_sweep_hook (abfd, info, sec, relocs)
        case R_CRIS_16_PCREL:
        case R_CRIS_32_PCREL:
        case R_CRIS_32_PLT_PCREL:
-         r_symndx = ELF32_R_SYM (rel->r_info);
-         if (r_symndx >= symtab_hdr->sh_info)
+         if (h != NULL)
            {
-             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
              if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
                  && h->plt.refcount > 0)
                --h->plt.refcount;
@@ -1924,7 +2095,7 @@ elf_cris_adjust_gotplt_to_got (h, p)
         Probably not necessary at this stage, but keeping it accurate
         helps avoiding surprises later.  */
       h->root.got.refcount += h->gotplt_refcount;
-      h->gotplt_refcount = -1;
+      h->gotplt_refcount = 0;
     }
   else
     {
@@ -1936,17 +2107,17 @@ elf_cris_adjust_gotplt_to_got (h, p)
       /* Put an accurate refcount there.  */
       h->root.got.refcount = h->gotplt_refcount;
 
-      h->gotplt_refcount = -1;
+      h->gotplt_refcount = 0;
 
       /* 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;
+      sgot->size += 4;
 
       /* Allocate relocation space.  */
-      srelgot->_raw_size += sizeof (Elf32_External_Rela);
+      srelgot->size += sizeof (Elf32_External_Rela);
     }
 
   return TRUE;
@@ -1956,16 +2127,22 @@ elf_cris_adjust_gotplt_to_got (h, p)
    want to do this:
 
    - When all PLT references are GOTPLT references, and there are GOT
-     references.  We don't have to generate a PLT at all.
+     references, and this is not the executable.  We don't have to
+     generate a PLT at all.
 
-   - When there are both (ordinary) PLT references and GOT references.
+   - When there are both (ordinary) PLT references and GOT references,
+     and this isn't the executable.
      We want to make the PLT reference use the ordinary GOT entry rather
-     than a run-time dynamically resolved GOTPLT entry (since the GOT
-     entry will have to be resolved at startup anyway).
+     than R_CRIS_JUMP_SLOT, a run-time dynamically resolved GOTPLT entry,
+     since the GOT entry will have to be resolved at startup anyway.
 
    Though the latter case is handled when room for the PLT is allocated,
    not here.
 
+   By folding into the GOT, we may need a round-trip to a PLT in the
+   executable for calls, a loss in performance.  Still, losing a
+   reloc is a win in size and at least in start-up time.
+
    Note that this function is called before symbols are forced local by
    version scripts.  The differing cases are handled by
    elf_cris_hide_symbol.  */
@@ -2029,25 +2206,27 @@ elf_cris_adjust_dynamic_symbol (info, h)
   bfd *dynobj;
   asection *s;
   unsigned int power_of_two;
+  bfd_size_type plt_entry_size;
 
   dynobj = elf_hash_table (info)->dynobj;
 
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (dynobj != NULL
-             && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
-                 || h->weakdef != NULL
-                 || ((h->elf_link_hash_flags
-                      & ELF_LINK_HASH_DEF_DYNAMIC) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_REF_REGULAR) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)));
+             && (h->needs_plt
+                 || h->u.weakdef != NULL
+                 || (h->def_dynamic
+                     && h->ref_regular
+                     && !h->def_regular)));
+
+  plt_entry_size
+    = (bfd_get_mach (dynobj) == bfd_mach_cris_v32
+       ? PLT_ENTRY_SIZE_V32 : PLT_ENTRY_SIZE);
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later,
      when we know the address of the .got section.  */
   if (h->type == STT_FUNC
-      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
+      || h->needs_plt)
     {
       /* 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
@@ -2056,15 +2235,15 @@ elf_cris_adjust_dynamic_symbol (info, h)
         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->def_dynamic)
        {
          /* This case can occur if we saw a PLT reloc in an input file,
             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;
+         BFD_ASSERT (h->needs_plt);
+         h->needs_plt = 0;
          h->plt.offset = (bfd_vma) -1;
          return
            elf_cris_adjust_gotplt_to_got ((struct
@@ -2072,16 +2251,20 @@ elf_cris_adjust_dynamic_symbol (info, h)
                                           info);
        }
 
-      /* If there are only GOT references and GOTPLT references to this
-        PLT entry, get rid of the PLT.  */
-      if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
-                                         h, info))
+      /* If we had a R_CRIS_GLOB_DAT that didn't have to point to a PLT;
+        where a pointer-equivalent symbol was unimportant (i.e. more
+        like R_CRIS_JUMP_SLOT after symbol evaluation) we could get rid
+        of the PLT.  We can't for the executable, because the GOT
+        entries will point to the PLT there (and be constant).  */
+      if (info->shared
+         && !elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry*)
+                                           h, info))
        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->needs_plt = 0;
          h->plt.offset = (bfd_vma) -1;
          return TRUE;
        }
@@ -2089,7 +2272,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1)
        {
-         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+         if (! bfd_elf_link_record_dynamic_symbol (info, h))
            return FALSE;
        }
 
@@ -2098,33 +2281,36 @@ elf_cris_adjust_dynamic_symbol (info, h)
 
       /* If this is the first .plt entry, make room for the special
         first entry.  */
-      if (s->_raw_size == 0)
-       s->_raw_size += PLT_ENTRY_SIZE;
+      if (s->size == 0)
+       s->size += plt_entry_size;
 
       /* 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.  */
       if (!info->shared
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+         && !h->def_regular)
        {
          h->root.u.def.section = s;
-         h->root.u.def.value = s->_raw_size;
+         h->root.u.def.value = s->size;
        }
 
       /* If there's already a GOT entry, use that, not a .got.plt.  A
         GOT field still has a reference count when we get here; it's
-        not yet changed to an offset.  */
-      if (h->got.refcount > 0)
+        not yet changed to an offset.  We can't do this for an
+        executable, because then the reloc associated with the PLT
+        would get a non-PLT reloc pointing to the PLT.  FIXME: Move
+        this to elf_cris_try_fold_plt_to_got.  */
+      if (info->shared && h->got.refcount > 0)
        {
          h->got.refcount += h->plt.refcount;
 
          /* Mark the PLT offset to use the GOT entry by setting the low
             bit in the plt offset; it is always a multiple of
-            pointer-size.  */
-         BFD_ASSERT ((s->_raw_size & 3) == 0);
+            plt_entry_size (which is at least a multiple of 2).  */
+         BFD_ASSERT ((s->size % plt_entry_size) == 0);
 
          /* Change the PLT refcount to an offset.  */
-         h->plt.offset = s->_raw_size;
+         h->plt.offset = s->size;
 
          /* By not setting gotplt_offset (i.e. it remains at 0), we signal
             that the got entry should be used instead.  */
@@ -2132,16 +2318,16 @@ elf_cris_adjust_dynamic_symbol (info, h)
                       h)->gotplt_offset == 0);
 
          /* Make room for this entry.  */
-         s->_raw_size += PLT_ENTRY_SIZE;
+         s->size += plt_entry_size;
 
          return TRUE;
        }
 
       /* No GOT reference for this symbol; prepare for an ordinary PLT.  */
-      h->plt.offset = s->_raw_size;
+      h->plt.offset = s->size;
 
       /* Make room for this entry.  */
-      s->_raw_size += PLT_ENTRY_SIZE;
+      s->size += plt_entry_size;
 
       /* We also need to make an entry in the .got.plt section, which
         will be placed in the .got section by the linker script.  */
@@ -2151,13 +2337,13 @@ elf_cris_adjust_dynamic_symbol (info, h)
 
       s = bfd_get_section_by_name (dynobj, ".got.plt");
       BFD_ASSERT (s != NULL);
-      s->_raw_size += 4;
+      s->size += 4;
 
       /* We also need to make an entry in the .rela.plt section.  */
 
       s = bfd_get_section_by_name (dynobj, ".rela.plt");
       BFD_ASSERT (s != NULL);
-      s->_raw_size += sizeof (Elf32_External_Rela);
+      s->size += sizeof (Elf32_External_Rela);
 
       return TRUE;
     }
@@ -2169,12 +2355,12 @@ elf_cris_adjust_dynamic_symbol (info, h)
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
      real definition first, and we can just use the same value.  */
-  if (h->weakdef != NULL)
+  if (h->u.weakdef != NULL)
     {
-      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
-                 || 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;
+      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
+                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
+      h->root.u.def.section = h->u.weakdef->root.u.def.section;
+      h->root.u.def.value = h->u.weakdef->root.u.def.value;
       return TRUE;
     }
 
@@ -2190,7 +2376,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
 
   /* 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)
+  if (!h->non_got_ref)
     return TRUE;
 
   /* We must allocate the symbol in our .dynbss section, which will
@@ -2216,8 +2402,8 @@ elf_cris_adjust_dynamic_symbol (info, h)
 
       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
-      srel->_raw_size += sizeof (Elf32_External_Rela);
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
+      srel->size += sizeof (Elf32_External_Rela);
+      h->needs_copy = 1;
     }
 
   /* Historic precedent: m68k and i386 allow max 8-byte alignment for the
@@ -2230,8 +2416,7 @@ elf_cris_adjust_dynamic_symbol (info, h)
     power_of_two = 3;
 
   /* Apply the required alignment.  */
-  s->_raw_size = BFD_ALIGN (s->_raw_size,
-                           (bfd_size_type) (1 << power_of_two));
+  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
   if (power_of_two > bfd_get_section_alignment (dynobj, s))
     {
       if (!bfd_set_section_alignment (dynobj, s, power_of_two))
@@ -2240,10 +2425,10 @@ elf_cris_adjust_dynamic_symbol (info, h)
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
-  h->root.u.def.value = s->_raw_size;
+  h->root.u.def.value = s->size;
 
   /* Increment the section size to make room for the symbol.  */
-  s->_raw_size += h->size;
+  s->size += h->size;
 
   return TRUE;
 }
@@ -2267,7 +2452,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
   asection *srelgot;
   asection *sreloc;
 
-  if (info->relocateable)
+  if (info->relocatable)
     return TRUE;
 
   dynobj = elf_hash_table (info)->dynobj;
@@ -2313,6 +2498,18 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
            {
              elf_hash_table (info)->dynobj = dynobj = abfd;
 
+             /* We could handle this if we can get a handle on the
+                output bfd in elf_cris_adjust_dynamic_symbol.  Failing
+                that, we must insist on dynobj being a specific mach.  */
+             if (bfd_get_mach (dynobj) == bfd_mach_cris_v10_v32)
+               {
+                 (*_bfd_error_handler)
+                   (_("%B, section %A:\n  v10/v32 compatible object %s"
+                      " must not contain a PIC relocation"),
+                    abfd, sec);
+                 return FALSE;
+               }
+
              /* 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))
@@ -2413,14 +2610,14 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                  /* Make sure this symbol is output as a dynamic symbol.  */
                  if (h->dynindx == -1)
                    {
-                     if (!bfd_elf32_link_record_dynamic_symbol (info, h))
+                     if (!bfd_elf_link_record_dynamic_symbol (info, h))
                        return FALSE;
                    }
 
                  /* Allocate space in the .got section.  */
-                 sgot->_raw_size += 4;
+                 sgot->size += 4;
                  /* Allocate relocation space.  */
-                 srelgot->_raw_size += sizeof (Elf32_External_Rela);
+                 srelgot->size += sizeof (Elf32_External_Rela);
                }
              h->got.refcount++;
            }
@@ -2429,13 +2626,13 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
              /* This is a global offset table entry for a local symbol.  */
              if (local_got_refcounts[r_symndx] == 0)
                {
-                 sgot->_raw_size += 4;
+                 sgot->size += 4;
                  if (info->shared)
                    {
                      /* If we are generating a shared object, we need to
                         output a R_CRIS_RELATIVE reloc so that the dynamic
                         linker can adjust this GOT entry.  */
-                     srelgot->_raw_size += sizeof (Elf32_External_Rela);
+                     srelgot->size += sizeof (Elf32_External_Rela);
                    }
                }
              local_got_refcounts[r_symndx]++;
@@ -2465,12 +2662,16 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
              don't need to generate a procedure linkage table entry
              after all.  */
 
-         /* If this is a local symbol, we resolve it directly without
-            creating a procedure linkage table entry.  */
-         if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+         /* Beware: if we'd check for visibility of the symbol here
+            (and not marking the need for a PLT when non-visible), we'd
+            get into trouble with keeping handling consistent with
+            regards to relocs found before definition and GOTPLT
+            handling.  Eliminable PLT entries will be dealt with later
+            anyway.  */
+         if (h == NULL)
            continue;
 
-         h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+         h->needs_plt = 1;
          h->plt.refcount++;
          break;
 
@@ -2490,9 +2691,10 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
            {
              /* FIXME: How do we make this optionally a warning only?  */
              (*_bfd_error_handler)
-               (_("%s, section %s:\n  relocation %s should not be used in a shared object; recompile with -fPIC"),
-                bfd_archive_filename (abfd),
-                sec->name,
+               (_("%B, section %A:\n  relocation %s should not"
+                  " be used in a shared object; recompile with -fPIC"),
+                abfd,
+                sec,
                 cris_elf_howto_table[r_type].name);
            }
          /* Fall through.  */
@@ -2502,7 +2704,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
        case R_CRIS_32_PCREL:
          if (h != NULL)
            {
-             h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
+             h->non_got_ref = 1;
 
              /* Make sure a plt entry is created for this symbol if it
                 turns out to be a function defined by a dynamic object.  */
@@ -2550,8 +2752,19 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                 we can't identify at this time.  */
              if (info->symbolic
                  && h->root.type != bfd_link_hash_defweak
-                 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
+                 && h->def_regular)
                break;
+
+             if ((sec->flags & SEC_READONLY) != 0)
+               {
+                 /* FIXME: How do we make this optionally a warning only?  */
+                 (*_bfd_error_handler)
+                   (_("%B, section %A:\n  relocation %s should not be used"
+                      " in a shared object; recompile with -fPIC"),
+                    abfd,
+                    sec,
+                    cris_elf_howto_table[r_type].name);
+               }
            }
 
          /* We create a reloc section in dynobj and make room for this
@@ -2590,7 +2803,7 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
                info->flags |= DF_TEXTREL;
            }
 
-         sreloc->_raw_size += sizeof (Elf32_External_Rela);
+         sreloc->size += sizeof (Elf32_External_Rela);
 
          /* If we are linking with -Bsymbolic, we count the number of PC
             relative relocations we have entered for this symbol, so that
@@ -2630,14 +2843,14 @@ cris_elf_check_relocs (abfd, info, sec, relocs)
         /* This relocation describes the C++ object vtable hierarchy.
            Reconstruct it for later use during GC.  */
         case R_CRIS_GNU_VTINHERIT:
-          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
+          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
             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))
+          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
             return FALSE;
           break;
 
@@ -2669,11 +2882,11 @@ elf_cris_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (!info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
-         s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
+         s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
        }
     }
@@ -2691,7 +2904,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
         below.  */
       s = bfd_get_section_by_name (dynobj, ".rela.got");
       if (s != NULL)
-       s->_raw_size = 0;
+       s->size = 0;
     }
 
   /* If this is a -Bsymbolic shared link, then we need to discard all PC
@@ -2731,7 +2944,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
 
       if (strcmp (name, ".plt") == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* Strip this section if we don't need it; see the
                  comment below.  */
@@ -2745,7 +2958,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
        }
       else if (strncmp (name, ".rela", 5) == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* If we don't need this section, strip it from the
                 output file.  This is mostly to handle .rela.bss and
@@ -2787,8 +3000,8 @@ elf_cris_size_dynamic_sections (output_bfd, info)
         contents are written out.  This should not happen, but this way
         if it does, we will not write out garbage.  For reloc sections,
         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)
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
+      if (s->contents == NULL && s->size != 0)
        return FALSE;
     }
 
@@ -2800,7 +3013,7 @@ elf_cris_size_dynamic_sections (output_bfd, info)
         the .dynamic section.  The DT_DEBUG entry is filled in by the
         dynamic linker and used by the debugger.  */
 #define add_dynamic_entry(TAG, VAL) \
-  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
       if (!info->shared)
        {
@@ -2860,12 +3073,12 @@ elf_cris_discard_excess_dso_dynamics (h, inf)
   /* 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.  */
-  if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-      && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
+  if (h->root.def_regular
+      && (h->root.forced_local
          || info->symbolic))
     {
       for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
-       s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
+       s->section->size -= s->count * sizeof (Elf32_External_Rela);
     }
 
   return TRUE;
@@ -2887,9 +3100,11 @@ elf_cris_discard_excess_program_dynamics (h, inf)
 
   /* 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 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)
+     (or rather, not defined by a DSO) then lose the reloc for the .got
+     (don't allocate room for it).  Likewise for relocs for something
+     for which we create a PLT.  */
+  if (!h->root.def_dynamic
+      || h->root.plt.refcount > 0)
     {
       if (h->root.got.refcount > 0
          /* The size of this section is only valid and in sync with the
@@ -2906,7 +3121,7 @@ elf_cris_discard_excess_program_dynamics (h, inf)
 
          BFD_ASSERT (srelgot != NULL);
 
-         srelgot->_raw_size -= sizeof (Elf32_External_Rela);
+         srelgot->size -= sizeof (Elf32_External_Rela);
        }
 
       /* If the locally-defined symbol isn't used by a DSO, then we don't
@@ -2915,7 +3130,9 @@ elf_cris_discard_excess_program_dynamics (h, inf)
         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
+         && !h->root.def_dynamic
+         && !h->root.ref_dynamic)
        {
          h->root.dynindx = -1;
          _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
@@ -2933,23 +3150,81 @@ static bfd_boolean
 cris_elf_object_p (abfd)
      bfd *abfd;
 {
+  if (! cris_elf_set_mach_from_flags (abfd, elf_elfheader (abfd)->e_flags))
+    return FALSE;
+
   if ((elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE))
     return (bfd_get_symbol_leading_char (abfd) == '_');
   else
     return (bfd_get_symbol_leading_char (abfd) == 0);
 }
 
-/* Mark presence or absence of leading underscore.  */
+/* Mark presence or absence of leading underscore.  Set machine type
+   flags from mach type.  */
 
 static void
 cris_elf_final_write_processing (abfd, linker)
      bfd *abfd;
      bfd_boolean linker ATTRIBUTE_UNUSED;
 {
+  unsigned long e_flags = elf_elfheader (abfd)->e_flags;
+
+  e_flags &= ~EF_CRIS_UNDERSCORE;
   if (bfd_get_symbol_leading_char (abfd) == '_')
-    elf_elfheader (abfd)->e_flags |= EF_CRIS_UNDERSCORE;
-  else
-    elf_elfheader (abfd)->e_flags &= ~EF_CRIS_UNDERSCORE;
+    e_flags |= EF_CRIS_UNDERSCORE;
+
+  switch (bfd_get_mach (abfd))
+    {
+    case bfd_mach_cris_v0_v10:
+      e_flags |= EF_CRIS_VARIANT_ANY_V0_V10;
+      break;
+
+    case bfd_mach_cris_v10_v32:
+      e_flags |= EF_CRIS_VARIANT_COMMON_V10_V32;
+      break;
+
+    case bfd_mach_cris_v32:
+      e_flags |= EF_CRIS_VARIANT_V32;
+      break;
+
+    default:
+      _bfd_abort (__FILE__, __LINE__,
+                 _("Unexpected machine number"));
+    }
+
+  elf_elfheader (abfd)->e_flags = e_flags;
+}
+
+/* Set the mach type from e_flags value.  */
+
+static bfd_boolean
+cris_elf_set_mach_from_flags (abfd, flags)
+     bfd *abfd;
+     unsigned long flags;
+{
+  switch (flags & EF_CRIS_VARIANT_MASK)
+    {
+    case EF_CRIS_VARIANT_ANY_V0_V10:
+      bfd_default_set_arch_mach (abfd, bfd_arch_cris, bfd_mach_cris_v0_v10);
+      break;
+
+    case EF_CRIS_VARIANT_V32:
+      bfd_default_set_arch_mach (abfd, bfd_arch_cris, bfd_mach_cris_v32);
+      break;
+
+    case EF_CRIS_VARIANT_COMMON_V10_V32:
+      bfd_default_set_arch_mach (abfd, bfd_arch_cris, bfd_mach_cris_v10_v32);
+      break;
+
+    default:
+      /* Since we don't recognize them, we obviously can't support them
+        with this code; we'd have to require that all future handling
+        would be optional.  */
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
+
+  return TRUE;
 }
 
 /* Display the flags field.  */
@@ -2961,7 +3236,7 @@ cris_elf_print_private_bfd_data (abfd, ptr)
 {
   FILE *file = (FILE *) ptr;
 
-  BFD_ASSERT (abfd != NULL && ptr != NULL)
+  BFD_ASSERT (abfd != NULL && ptr != NULL);
 
   _bfd_elf_print_private_bfd_data (abfd, ptr);
 
@@ -2969,6 +3244,12 @@ cris_elf_print_private_bfd_data (abfd, ptr)
 
   if (elf_elfheader (abfd)->e_flags & EF_CRIS_UNDERSCORE)
     fprintf (file, _(" [symbols have a _ prefix]"));
+  if ((elf_elfheader (abfd)->e_flags & EF_CRIS_VARIANT_MASK)
+      == EF_CRIS_VARIANT_COMMON_V10_V32)
+    fprintf (file, _(" [v10 and v32]"));
+  if ((elf_elfheader (abfd)->e_flags & EF_CRIS_VARIANT_MASK)
+      == EF_CRIS_VARIANT_V32)
+    fprintf (file, _(" [v32]"));
 
   fputc ('\n', file);
   return TRUE;
@@ -2981,7 +3262,7 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
      bfd *ibfd;
      bfd *obfd;
 {
-  flagword old_flags, new_flags;
+  int imach, omach;
 
   if (! _bfd_generic_verify_endian_match (ibfd, obfd))
     return FALSE;
@@ -2990,33 +3271,91 @@ cris_elf_merge_private_bfd_data (ibfd, obfd)
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
     return TRUE;
 
+  imach = bfd_get_mach (ibfd);
+
   if (! elf_flags_init (obfd))
     {
       /* This happens when ld starts out with a 'blank' output file.  */
       elf_flags_init (obfd) = TRUE;
 
-      /* Set flags according to current bfd_target.  */
-      cris_elf_final_write_processing (obfd, FALSE);
+      /* We ignore the linker-set mach, and instead set it according to
+        the first input file.  This would also happen if we could
+        somehow filter out the OUTPUT_ARCH () setting from elf.sc.
+        This allows us to keep the same linker config across
+        cris(v0..v10) and crisv32.  The drawback is that we can't force
+        the output type, which might be a sane thing to do for a
+        v10+v32 compatibility object.  */
+      if (! bfd_set_arch_mach (obfd, bfd_arch_cris, imach))
+       return FALSE;
     }
 
-  old_flags = elf_elfheader (obfd)->e_flags;
-  new_flags = elf_elfheader (ibfd)->e_flags;
-
-  /* Is this good or bad?  We'll follow with other excluding flags.  */
-  if ((old_flags & EF_CRIS_UNDERSCORE) != (new_flags & EF_CRIS_UNDERSCORE))
+  if (bfd_get_symbol_leading_char (ibfd)
+      != bfd_get_symbol_leading_char (obfd))
     {
       (*_bfd_error_handler)
-       ((new_flags & EF_CRIS_UNDERSCORE)
-        ? _("%s: uses _-prefixed symbols, but writing file with non-prefixed symbols")
-        : _("%s: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
-        bfd_archive_filename (ibfd));
+       (bfd_get_symbol_leading_char (ibfd) == '_'
+        ? _("%B: uses _-prefixed symbols, but writing file with non-prefixed symbols")
+        : _("%B: uses non-prefixed symbols, but writing file with _-prefixed symbols"),
+        ibfd);
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
     }
 
+  omach = bfd_get_mach (obfd);
+
+  if (imach != omach)
+    {
+      /* We can get an incompatible combination only if either is
+        bfd_mach_cris_v32, and the other one isn't compatible.  */
+      if ((imach == bfd_mach_cris_v32
+          && omach != bfd_mach_cris_v10_v32)
+         || (omach == bfd_mach_cris_v32
+             && imach != bfd_mach_cris_v10_v32))
+       {
+         (*_bfd_error_handler)
+           ((imach == bfd_mach_cris_v32)
+            ? _("%B contains CRIS v32 code, incompatible"
+                " with previous objects")
+            : _("%B contains non-CRIS-v32 code, incompatible"
+                " with previous objects"),
+            ibfd);
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
+
+      /* We don't have to check the case where the input is compatible
+        with v10 and v32, because the output is already known to be set
+        to the other (compatible) mach.  */
+      if (omach == bfd_mach_cris_v10_v32
+         && ! bfd_set_arch_mach (obfd, bfd_arch_cris, imach))
+       return FALSE;
+    }
+
   return TRUE;
 }
 
+/* Do side-effects of e_flags copying to obfd.  */
+
+static bfd_boolean
+cris_elf_copy_private_bfd_data (ibfd, obfd)
+     bfd *ibfd;
+     bfd *obfd;
+{
+  /* Call the base function.  */
+  if (!_bfd_elf_copy_private_bfd_data (ibfd, obfd))
+    return FALSE;
+
+  /* If output is big-endian for some obscure reason, stop here.  */
+  if (_bfd_generic_verify_endian_match (ibfd, obfd) == FALSE)
+    return FALSE;
+
+  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
+      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
+    return TRUE;
+
+  /* Do what we really came here for.  */
+  return bfd_set_arch_mach (obfd, bfd_arch_cris, bfd_get_mach (ibfd));
+}
 
 static enum elf_reloc_type_class
 elf_cris_reloc_type_class (rela)
@@ -3062,6 +3401,8 @@ elf_cris_reloc_type_class (rela)
        cris_elf_print_private_bfd_data
 #define bfd_elf32_bfd_merge_private_bfd_data \
        cris_elf_merge_private_bfd_data
+#define bfd_elf32_bfd_copy_private_bfd_data \
+       cris_elf_copy_private_bfd_data
 
 #define bfd_elf32_bfd_reloc_type_lookup                cris_reloc_type_lookup
 
@@ -3078,7 +3419,7 @@ elf_cris_reloc_type_class (rela)
 #define elf_backend_create_dynamic_sections \
        _bfd_elf_create_dynamic_sections
 #define bfd_elf32_bfd_final_link \
-       _bfd_elf32_gc_common_final_link
+       bfd_elf_gc_common_final_link
 #define elf_backend_hide_symbol                        elf_cris_hide_symbol
 #define elf_backend_reloc_type_class           elf_cris_reloc_type_class
 
@@ -3086,7 +3427,6 @@ elf_cris_reloc_type_class (rela)
 #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,
This page took 0.047368 seconds and 4 git commands to generate.