]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/elf32-sh.c
* elf.c (_bfd_elf_rela_local_sym): Accept asection **, and return
[thirdparty/binutils-gdb.git] / bfd / elf32-sh.c
index ca17d09016c25a53cdbfeedd2bf65aa4a3d94b7e..9ffd05ba50680e9d96c930a6171bddfe412dd949 100644 (file)
@@ -1,4 +1,4 @@
-/* Hitachi SH specific support for 32-bit ELF
+/* Renesas / SuperH SH specific support for 32-bit ELF
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Contributed by Ian Lance Taylor, Cygnus Support.
 #include "elf/sh.h"
 
 static bfd_reloc_status_type sh_elf_reloc
-  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 static bfd_reloc_status_type sh_elf_ignore_reloc
-  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
+  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 static reloc_howto_type *sh_elf_reloc_type_lookup
-  PARAMS ((bfd *, bfd_reloc_code_real_type));
+  (bfd *, bfd_reloc_code_real_type);
 static void sh_elf_info_to_howto
-  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
+  (bfd *, arelent *, Elf_Internal_Rela *);
 static bfd_boolean sh_elf_set_private_flags
-  PARAMS ((bfd *, flagword));
+  (bfd *, flagword);
 static bfd_boolean sh_elf_copy_private_data
-  PARAMS ((bfd *, bfd *));
+  (bfd *, bfd *);
 static bfd_boolean sh_elf_merge_private_data
-  PARAMS ((bfd *, bfd *));
+  (bfd *, bfd *);
 static bfd_boolean sh_elf_set_mach_from_flags
-  PARAMS ((bfd *));
+  (bfd *);
 static bfd_boolean sh_elf_relax_section
-  PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
+  (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
 static bfd_boolean sh_elf_relax_delete_bytes
-  PARAMS ((bfd *, asection *, bfd_vma, int));
+  (bfd *, asection *, bfd_vma, int);
 static bfd_boolean sh_elf_align_loads
-  PARAMS ((bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *));
+  (bfd *, asection *, Elf_Internal_Rela *, bfd_byte *, bfd_boolean *);
 static bfd_boolean sh_elf_swap_insns
-  PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));
+  (bfd *, asection *, void *, bfd_byte *, bfd_vma);
 static bfd_boolean sh_elf_relocate_section
-  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
-          Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
+  (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
+   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
 static bfd_byte *sh_elf_get_relocated_section_contents
-  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,
-          bfd_byte *, bfd_boolean, asymbol **));
+  (bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
+   bfd_boolean, asymbol **);
 static void sh_elf_copy_indirect_symbol
-  PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
-          struct elf_link_hash_entry *));
+  (const struct elf_backend_data *, struct elf_link_hash_entry *,
+   struct elf_link_hash_entry *);
 static int sh_elf_optimized_tls_reloc
-  PARAMS ((struct bfd_link_info *, int, int));
+  (struct bfd_link_info *, int, int);
 static bfd_boolean sh_elf_mkobject
-  PARAMS ((bfd *));
+  (bfd *);
 static bfd_boolean sh_elf_object_p
-  PARAMS ((bfd *));
+  (bfd *);
 static bfd_boolean sh_elf_check_relocs
-  PARAMS ((bfd *, struct bfd_link_info *, asection *,
-          const Elf_Internal_Rela *));
+  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
 static struct bfd_hash_entry *sh_elf_link_hash_newfunc
-  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
+  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
 static struct bfd_link_hash_table *sh_elf_link_hash_table_create
-  PARAMS ((bfd *));
+  (bfd *);
 static bfd_boolean sh_elf_adjust_dynamic_symbol
-  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+  (struct bfd_link_info *, struct elf_link_hash_entry *);
 static bfd_boolean sh_elf_size_dynamic_sections
-  PARAMS ((bfd *, struct bfd_link_info *));
+  (bfd *, struct bfd_link_info *);
 static bfd_boolean sh_elf_finish_dynamic_symbol
-  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
-          Elf_Internal_Sym *));
+  (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
+   Elf_Internal_Sym *);
 static bfd_boolean sh_elf_finish_dynamic_sections
-  PARAMS ((bfd *, struct bfd_link_info *));
+  (bfd *, struct bfd_link_info *);
 static bfd_reloc_status_type sh_elf_reloc_loop
-  PARAMS ((int, bfd *, asection *, bfd_byte *, bfd_vma, asection *,
-          bfd_vma, bfd_vma));
+  (int, bfd *, asection *, bfd_byte *, bfd_vma, asection *, bfd_vma,
+   bfd_vma);
 static bfd_boolean create_got_section
-  PARAMS ((bfd *, struct bfd_link_info *));
+  (bfd *, struct bfd_link_info *);
 static bfd_boolean sh_elf_create_dynamic_sections
-  PARAMS ((bfd *, struct bfd_link_info *));
+  (bfd *, struct bfd_link_info *);
 static bfd_vma dtpoff_base
-  PARAMS ((struct bfd_link_info *));
+  (struct bfd_link_info *);
+static bfd_vma tpoff
+  (struct bfd_link_info *, bfd_vma);
 static asection * sh_elf_gc_mark_hook
-  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
-          struct elf_link_hash_entry *, Elf_Internal_Sym *));
+  (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
+   struct elf_link_hash_entry *, Elf_Internal_Sym *);
 static bfd_boolean sh_elf_gc_sweep_hook
-  PARAMS ((bfd *, struct bfd_link_info *, asection *,
-          const Elf_Internal_Rela *));
+  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
 static bfd_boolean allocate_dynrelocs
-  PARAMS ((struct elf_link_hash_entry *, PTR));
+  (struct elf_link_hash_entry *, void *);
 static bfd_boolean readonly_dynrelocs
-  PARAMS ((struct elf_link_hash_entry *, PTR));
+  (struct elf_link_hash_entry *, void *);
 static enum elf_reloc_type_class sh_elf_reloc_type_class
-  PARAMS ((const Elf_Internal_Rela *));
+  (const Elf_Internal_Rela *);
 #ifdef INCLUDE_SHMEDIA
-inline static void movi_shori_putval PARAMS ((bfd *, unsigned long, char *));
+inline static void movi_shori_putval (bfd *, unsigned long, char *);
 #endif
 static bfd_boolean elf32_shlin_grok_prstatus
-  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
+  (bfd *abfd, Elf_Internal_Note *note);
 static bfd_boolean elf32_shlin_grok_psinfo
-  PARAMS ((bfd *abfd, Elf_Internal_Note *note));
+  (bfd *abfd, Elf_Internal_Note *note);
 
 /* The name of the dynamic interpreter.  This is put in the .interp
    section.  */
@@ -179,6 +179,8 @@ static reloc_howto_type sh_elf_howto_table[] =
         TRUE),                 /* pcrel_offset */
 
   /* 12 bit PC relative branch divided by 2.  */
+  /* This cannot be partial_inplace because relaxation can't know the
+     eventual value of a symbol.  */
   HOWTO (R_SH_IND12W,          /* type */
         1,                     /* rightshift */
         1,                     /* size (0 = byte, 1 = short, 2 = long) */
@@ -186,10 +188,10 @@ static reloc_howto_type sh_elf_howto_table[] =
         TRUE,                  /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        sh_elf_reloc,          /* special_function */
+        NULL,                  /* special_function */
         "R_SH_IND12W",         /* name */
-        TRUE,                  /* partial_inplace */
-        0xfff,                 /* src_mask */
+        FALSE,                 /* partial_inplace */
+        0x0,                   /* src_mask */
         0xfff,                 /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
@@ -274,8 +276,36 @@ static reloc_howto_type sh_elf_howto_table[] =
         0xff,                  /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
-  EMPTY_HOWTO (10),
-  EMPTY_HOWTO (11),
+  /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
+  HOWTO (R_SH_LOOP_START,      /* type */
+        1,                     /* rightshift */
+        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        8,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        sh_elf_ignore_reloc,   /* special_function */
+        "R_SH_LOOP_START",     /* name */
+        TRUE,                  /* partial_inplace */
+        0xff,                  /* src_mask */
+        0xff,                  /* dst_mask */
+        TRUE),                 /* pcrel_offset */
+
+  /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
+  HOWTO (R_SH_LOOP_END,                /* type */
+        1,                     /* rightshift */
+        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        8,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        sh_elf_ignore_reloc,   /* special_function */
+        "R_SH_LOOP_END",       /* name */
+        TRUE,                  /* partial_inplace */
+        0xff,                  /* src_mask */
+        0xff,                  /* dst_mask */
+        TRUE),                 /* pcrel_offset */
+
   EMPTY_HOWTO (12),
   EMPTY_HOWTO (13),
   EMPTY_HOWTO (14),
@@ -286,15 +316,59 @@ static reloc_howto_type sh_elf_howto_table[] =
   EMPTY_HOWTO (19),
   EMPTY_HOWTO (20),
   EMPTY_HOWTO (21),
-  EMPTY_HOWTO (22),
-  EMPTY_HOWTO (23),
-  EMPTY_HOWTO (24),
 
   /* The remaining relocs are a GNU extension used for relaxing.  The
      final pass of the linker never needs to do anything with any of
      these relocs.  Any required operations are handled by the
      relaxation code.  */
 
+  /* GNU extension to record C++ vtable hierarchy */
+  HOWTO (R_SH_GNU_VTINHERIT, /* type */
+        0,                     /* rightshift */
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
+        0,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_dont, /* complain_on_overflow */
+        NULL,                  /* special_function */
+        "R_SH_GNU_VTINHERIT", /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0,                     /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  /* GNU extension to record C++ vtable member usage */
+  HOWTO (R_SH_GNU_VTENTRY,     /* type */
+        0,                     /* rightshift */
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
+        0,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_dont, /* complain_on_overflow */
+        _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
+        "R_SH_GNU_VTENTRY",   /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0,                     /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  /* An 8 bit switch table entry.  This is generated for an expression
+     such as ``.word L1 - L2''.  The offset holds the difference
+     between the reloc address and L2.  */
+  HOWTO (R_SH_SWITCH8,         /* type */
+        0,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        8,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_unsigned, /* complain_on_overflow */
+        sh_elf_ignore_reloc,   /* special_function */
+        "R_SH_SWITCH8",        /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0,                     /* dst_mask */
+        TRUE),                 /* pcrel_offset */
+
   /* A 16 bit switch table entry.  This is generated for an expression
      such as ``.word L1 - L2''.  The offset holds the difference
      between the reloc address and L2.  */
@@ -432,90 +506,174 @@ static reloc_howto_type sh_elf_howto_table[] =
         0,                     /* dst_mask */
         TRUE),                 /* pcrel_offset */
 
-  /* An 8 bit switch table entry.  This is generated for an expression
-     such as ``.word L1 - L2''.  The offset holds the difference
-     between the reloc address and L2.  */
-  HOWTO (R_SH_SWITCH8,         /* type */
+  /* The next 12 are only supported via linking in SHC-generated objects.  */
+  HOWTO (R_SH_DIR16,           /* type */
+        0,                     /* rightshift */
+        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        16,                    /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_dont, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR16",          /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0xffff,                /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  HOWTO (R_SH_DIR8,            /* type */
         0,                     /* rightshift */
         0,                     /* size (0 = byte, 1 = short, 2 = long) */
         8,                     /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
+        complain_overflow_dont, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR8",           /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0xff,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  HOWTO (R_SH_DIR8UL,          /* type */
+        2,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        8,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
         complain_overflow_unsigned, /* complain_on_overflow */
-        sh_elf_ignore_reloc,   /* special_function */
-        "R_SH_SWITCH8",        /* name */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR8UL",         /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0,                     /* dst_mask */
-        TRUE),                 /* pcrel_offset */
+        0xff,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
 
-  /* GNU extension to record C++ vtable hierarchy */
-  HOWTO (R_SH_GNU_VTINHERIT, /* type */
-        0,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        0,                     /* bitsize */
+  HOWTO (R_SH_DIR8UW,          /* type */
+        1,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        8,                     /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont, /* complain_on_overflow */
-        NULL,                  /* special_function */
-        "R_SH_GNU_VTINHERIT", /* name */
+        complain_overflow_unsigned, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR8UW",         /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0,                     /* dst_mask */
+        0xff,                  /* dst_mask */
         FALSE),                /* pcrel_offset */
 
-  /* GNU extension to record C++ vtable member usage */
-  HOWTO (R_SH_GNU_VTENTRY,     /* type */
+  HOWTO (R_SH_DIR8U,           /* type */
         0,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        0,                     /* bitsize */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        8,                     /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
-        complain_overflow_dont, /* complain_on_overflow */
-        _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
-        "R_SH_GNU_VTENTRY",   /* name */
+        complain_overflow_unsigned, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR8U",          /* name */
         FALSE,                 /* partial_inplace */
         0,                     /* src_mask */
-        0,                     /* dst_mask */
+        0xff,                  /* dst_mask */
         FALSE),                /* pcrel_offset */
 
-  /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
-  HOWTO (R_SH_LOOP_START,      /* type */
+  HOWTO (R_SH_DIR8SW,          /* type */
         1,                     /* rightshift */
-        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
         8,                     /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        sh_elf_ignore_reloc,   /* special_function */
-        "R_SH_LOOP_START",     /* name */
-        TRUE,                  /* partial_inplace */
-        0xff,                  /* src_mask */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR8SW",         /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
         0xff,                  /* dst_mask */
-        TRUE),                 /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
 
-  /* 8 bit PC relative divided by 2 - but specified in a very odd way.  */
-  HOWTO (R_SH_LOOP_END,                /* type */
-        1,                     /* rightshift */
-        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+  HOWTO (R_SH_DIR8S,           /* type */
+        0,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
         8,                     /* bitsize */
         FALSE,                 /* pc_relative */
         0,                     /* bitpos */
         complain_overflow_signed, /* complain_on_overflow */
-        sh_elf_ignore_reloc,   /* special_function */
-        "R_SH_LOOP_END",       /* name */
-        TRUE,                  /* partial_inplace */
-        0xff,                  /* src_mask */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR8S",          /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
         0xff,                  /* dst_mask */
-        TRUE),                 /* pcrel_offset */
+        FALSE),                /* pcrel_offset */
+
+  HOWTO (R_SH_DIR4UL,          /* type */
+        2,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        4,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_unsigned, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR4UL",         /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x0f,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  HOWTO (R_SH_DIR4UW,          /* type */
+        1,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        4,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_unsigned, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR4UW",         /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x0f,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  HOWTO (R_SH_DIR4U,           /* type */
+        0,                     /* rightshift */
+        0,                     /* size (0 = byte, 1 = short, 2 = long) */
+        4,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_unsigned, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR4U",          /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x0f,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
 
-  EMPTY_HOWTO (38),
-  EMPTY_HOWTO (39),
-  EMPTY_HOWTO (40),
-  EMPTY_HOWTO (41),
-  EMPTY_HOWTO (42),
-  EMPTY_HOWTO (43),
-  EMPTY_HOWTO (44),
+  HOWTO (R_SH_PSHA,            /* type */
+        0,                     /* rightshift */
+        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        7,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        4,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_PSHA",           /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x0f,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
+  HOWTO (R_SH_PSHL,            /* type */
+        0,                     /* rightshift */
+        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        7,                     /* bitsize */
+        FALSE,                 /* pc_relative */
+        4,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_PSHL",           /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0x0f,                  /* dst_mask */
+        FALSE),                /* pcrel_offset */
 
 #ifdef INCLUDE_SHMEDIA
   /* Used in SHLLI.L and SHLRI.L.  */
@@ -634,7 +792,21 @@ static reloc_howto_type sh_elf_howto_table[] =
 #endif
 
   EMPTY_HOWTO (52),
-  EMPTY_HOWTO (53),
+
+  HOWTO (R_SH_DIR16S,          /* type */
+        0,                     /* rightshift */
+        1,                     /* size (0 = byte, 1 = short, 2 = long) */
+        16,                    /* bitsize */
+        FALSE,                 /* pc_relative */
+        0,                     /* bitpos */
+        complain_overflow_signed, /* complain_on_overflow */
+        bfd_elf_generic_reloc, /* special_function */
+        "R_SH_DIR16S",         /* name */
+        FALSE,                 /* partial_inplace */
+        0,                     /* src_mask */
+        0xffff,                /* dst_mask */
+        FALSE),                /* pcrel_offset */
+
   EMPTY_HOWTO (54),
   EMPTY_HOWTO (55),
   EMPTY_HOWTO (56),
@@ -1660,15 +1832,10 @@ static reloc_howto_type sh_elf_howto_table[] =
 };
 
 static bfd_reloc_status_type
-sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr,
-                  symbol_section, start, end)
-     int r_type ATTRIBUTE_UNUSED;
-     bfd *input_bfd;
-     asection *input_section;
-     bfd_byte *contents;
-     bfd_vma addr;
-     asection *symbol_section;
-     bfd_vma start, end;
+sh_elf_reloc_loop (int r_type ATTRIBUTE_UNUSED, bfd *input_bfd,
+                  asection *input_section, bfd_byte *contents,
+                  bfd_vma addr, asection *symbol_section,
+                  bfd_vma start, bfd_vma end)
 {
   static bfd_vma last_addr;
   static asection *last_symbol_section;
@@ -1770,15 +1937,9 @@ sh_elf_reloc_loop (r_type, input_bfd, input_section, contents, addr,
    function, and is almost certainly incorrect for other ELF targets.  */
 
 static bfd_reloc_status_type
-sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
-             error_message)
-     bfd *abfd;
-     arelent *reloc_entry;
-     asymbol *symbol_in;
-     PTR data;
-     asection *input_section;
-     bfd *output_bfd;
-     char **error_message ATTRIBUTE_UNUSED;
+sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
+             void *data, asection *input_section, bfd *output_bfd,
+             char **error_message ATTRIBUTE_UNUSED)
 {
   unsigned long insn;
   bfd_vma sym_value;
@@ -1845,15 +2006,11 @@ sh_elf_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd,
    which the linker should otherwise ignore.  */
 
 static bfd_reloc_status_type
-sh_elf_ignore_reloc (abfd, reloc_entry, symbol, data, input_section,
-                    output_bfd, error_message)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     arelent *reloc_entry;
-     asymbol *symbol ATTRIBUTE_UNUSED;
-     PTR data ATTRIBUTE_UNUSED;
-     asection *input_section;
-     bfd *output_bfd;
-     char **error_message ATTRIBUTE_UNUSED;
+sh_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
+                    asymbol *symbol ATTRIBUTE_UNUSED,
+                    void *data ATTRIBUTE_UNUSED, asection *input_section,
+                    bfd *output_bfd,
+                    char **error_message ATTRIBUTE_UNUSED)
 {
   if (output_bfd != NULL)
     reloc_entry->address += input_section->output_offset;
@@ -1874,6 +2031,8 @@ static const struct elf_reloc_map sh_reloc_map[] =
 {
   { BFD_RELOC_NONE, R_SH_NONE },
   { BFD_RELOC_32, R_SH_DIR32 },
+  { BFD_RELOC_16, R_SH_DIR16 },
+  { BFD_RELOC_8, R_SH_DIR8 },
   { BFD_RELOC_CTOR, R_SH_DIR32 },
   { BFD_RELOC_32_PCREL, R_SH_REL32 },
   { BFD_RELOC_SH_PCDISP8BY2, R_SH_DIR8WPN },
@@ -1967,9 +2126,8 @@ static const struct elf_reloc_map sh_reloc_map[] =
    corresponding SH ELf reloc.  */
 
 static reloc_howto_type *
-sh_elf_reloc_type_lookup (abfd, code)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     bfd_reloc_code_real_type code;
+sh_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                         bfd_reloc_code_real_type code)
 {
   unsigned int i;
 
@@ -1985,10 +2143,8 @@ sh_elf_reloc_type_lookup (abfd, code)
 /* Given an ELF reloc, fill in the howto field of a relent.  */
 
 static void
-sh_elf_info_to_howto (abfd, cache_ptr, dst)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     arelent *cache_ptr;
-     Elf_Internal_Rela *dst;
+sh_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
+                     Elf_Internal_Rela *dst)
 {
   unsigned int r;
 
@@ -2015,11 +2171,8 @@ sh_elf_info_to_howto (abfd, cache_ptr, dst)
    they come from enum elf_sh_reloc_type in include/elf/sh.h.  */
 
 static bfd_boolean
-sh_elf_relax_section (abfd, sec, link_info, again)
-     bfd *abfd;
-     asection *sec;
-     struct bfd_link_info *link_info;
-     bfd_boolean *again;
+sh_elf_relax_section (bfd *abfd, asection *sec,
+                     struct bfd_link_info *link_info, bfd_boolean *again)
 {
   Elf_Internal_Shdr *symtab_hdr;
   Elf_Internal_Rela *internal_relocs;
@@ -2030,7 +2183,7 @@ sh_elf_relax_section (abfd, sec, link_info, again)
 
   *again = FALSE;
 
-  if (link_info->relocateable
+  if (link_info->relocatable
       || (sec->flags & SEC_RELOC) == 0
       || sec->reloc_count == 0)
     return TRUE;
@@ -2050,8 +2203,8 @@ sh_elf_relax_section (abfd, sec, link_info, again)
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
 
-  internal_relocs = (_bfd_elf32_link_read_relocs
-                    (abfd, sec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
+  internal_relocs = (_bfd_elf_link_read_relocs
+                    (abfd, sec, NULL, (Elf_Internal_Rela *) NULL,
                      link_info->keep_memory));
   if (internal_relocs == NULL)
     goto error_return;
@@ -2232,6 +2385,12 @@ sh_elf_relax_section (abfd, sec, link_info, again)
       /* Change the R_SH_USES reloc into an R_SH_IND12W reloc, and
         replace the jsr with a bsr.  */
       irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irelfn->r_info), R_SH_IND12W);
+      /* We used to test (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
+        here, but that only checks if the symbol is an external symbol,
+        not if the symbol is in a different section.  Besides, we need
+        a consistent meaning for the relocation, so we just assume here that
+        the value of the symbol is not available.  */
+#if 0
       if (ELF32_R_SYM (irelfn->r_info) < symtab_hdr->sh_info)
        {
          /* If this needs to be changed because of future relaxing,
@@ -2242,12 +2401,14 @@ sh_elf_relax_section (abfd, sec, link_info, again)
                      contents + irel->r_offset);
        }
       else
+#endif
        {
          /* We can't fully resolve this yet, because the external
             symbol value may be changed by future relaxing.  We let
             the final link phase handle it.  */
          bfd_put_16 (abfd, (bfd_vma) 0xb000, contents + irel->r_offset);
        }
+      irel->r_addend = -4;
 
       /* See if there is another R_SH_USES reloc referring to the same
         register load.  */
@@ -2316,7 +2477,8 @@ sh_elf_relax_section (abfd, sec, link_info, again)
 
   /* Look for load and store instructions that we can align on four
      byte boundaries.  */
-  if (have_code)
+  if ((elf_elfheader (abfd)->e_flags & EF_SH_MACH_MASK) != EF_SH4
+      && have_code)
     {
       bfd_boolean swapped;
 
@@ -2398,11 +2560,8 @@ sh_elf_relax_section (abfd, sec, link_info, again)
    in coff-sh.c.  */
 
 static bfd_boolean
-sh_elf_relax_delete_bytes (abfd, sec, addr, count)
-     bfd *abfd;
-     asection *sec;
-     bfd_vma addr;
-     int count;
+sh_elf_relax_delete_bytes (bfd *abfd, asection *sec, bfd_vma addr,
+                          int count)
 {
   Elf_Internal_Shdr *symtab_hdr;
   unsigned int sec_shndx;
@@ -2542,14 +2701,28 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
          break;
 
        case R_SH_IND12W:
-         if (ELF32_R_SYM (irel->r_info) >= symtab_hdr->sh_info)
-           start = stop = addr;
+         off = insn & 0xfff;
+         if (! off)
+           {
+             /* This has been made by previous relaxation.  Since the
+                relocation will be against an external symbol, the
+                final relocation will just do the right thing.  */
+             start = stop = addr;
+           }
          else
            {
-             off = insn & 0xfff;
              if (off & 0x800)
                off -= 0x1000;
              stop = (bfd_vma) ((bfd_signed_vma) start + 4 + off * 2);
+
+             /* The addend will be against the section symbol, thus
+                for adjusting the addend, the relevant start is the
+                start of the section.
+                N.B. If we want to abandom in-place changes here and
+                test directly using symbol + addend, we have to take into
+                account that the addend has already been adjusted by -4.  */
+             if (stop > addr && stop < toaddr)
+               irel->r_addend -= count;
            }
          break;
 
@@ -2709,9 +2882,8 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
       /* We always cache the relocs.  Perhaps, if info->keep_memory is
         FALSE, we should free them, if we are permitted to, when we
         leave sh_coff_relax_section.  */
-      internal_relocs = (_bfd_elf32_link_read_relocs
-                        (abfd, o, (PTR) NULL, (Elf_Internal_Rela *) NULL,
-                         TRUE));
+      internal_relocs = (_bfd_elf_link_read_relocs
+                        (abfd, o, NULL, (Elf_Internal_Rela *) NULL, TRUE));
       if (internal_relocs == NULL)
        return FALSE;
 
@@ -2865,12 +3037,10 @@ sh_elf_relax_delete_bytes (abfd, sec, addr, count)
    boundaries.  This is like sh_align_loads in coff-sh.c.  */
 
 static bfd_boolean
-sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     asection *sec;
-     Elf_Internal_Rela *internal_relocs;
-     bfd_byte *contents ATTRIBUTE_UNUSED;
-     bfd_boolean *pswapped;
+sh_elf_align_loads (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
+                   Elf_Internal_Rela *internal_relocs,
+                   bfd_byte *contents ATTRIBUTE_UNUSED,
+                   bfd_boolean *pswapped)
 {
   Elf_Internal_Rela *irel, *irelend;
   bfd_vma *labels = NULL;
@@ -2921,7 +3091,7 @@ sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
        stop = sec->_cooked_size;
 
       if (! _bfd_sh_align_load_span (abfd, sec, contents, sh_elf_swap_insns,
-                                    (PTR) internal_relocs, &label,
+                                    internal_relocs, &label,
                                     label_end, start, stop, pswapped))
        goto error_return;
     }
@@ -2939,12 +3109,8 @@ sh_elf_align_loads (abfd, sec, internal_relocs, contents, pswapped)
 /* Swap two SH instructions.  This is like sh_swap_insns in coff-sh.c.  */
 
 static bfd_boolean
-sh_elf_swap_insns (abfd, sec, relocs, contents, addr)
-     bfd *abfd;
-     asection *sec;
-     PTR relocs;
-     bfd_byte *contents;
-     bfd_vma addr;
+sh_elf_swap_insns (bfd *abfd, asection *sec, void *relocs,
+                  bfd_byte *contents, bfd_vma addr)
 {
   Elf_Internal_Rela *internal_relocs = (Elf_Internal_Rela *) relocs;
   unsigned short i1, i2;
@@ -3225,10 +3391,7 @@ static const bfd_byte *elf_sh_pic_plt_entry;
 #define elf_sh_plt_reloc_offset(info) (info->shared ? 52 : 44)
 
 inline static void
-movi_shori_putval (output_bfd, value, addr)
-     bfd *output_bfd;
-     unsigned long value;
-     char *addr;
+movi_shori_putval (bfd *output_bfd, unsigned long value, char *addr)
 {
   bfd_put_32 (output_bfd,
              bfd_get_32 (output_bfd, addr)
@@ -3500,9 +3663,6 @@ struct elf_sh_dyn_relocs
 
   /* Number of pc-relative relocs copied for the input section.  */
   bfd_size_type pc_count;
-
-  /* If TRUE, R_SH_TLS_TPOFF32 relocation is generated.  */
-  bfd_boolean tls_tpoff32;
 };
 
 /* sh ELF linker hash entry.  */
@@ -3549,8 +3709,7 @@ struct sh_elf_obj_tdata
    as the specific tdata.  */
 
 static bfd_boolean
-sh_elf_mkobject (abfd)
-     bfd *abfd;
+sh_elf_mkobject (bfd *abfd)
 {
   bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
   abfd->tdata.any = bfd_zalloc (abfd, amt);
@@ -3590,7 +3749,7 @@ struct elf_sh_link_hash_table
 #define sh_elf_link_hash_traverse(table, func, info)                   \
   (elf_link_hash_traverse                                              \
    (&(table)->root,                                                    \
-    (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
+    (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
     (info)))
 
 /* Get the sh ELF linker hash table from a link_info structure.  */
@@ -3601,10 +3760,9 @@ struct elf_sh_link_hash_table
 /* Create an entry in an sh ELF linker hash table.  */
 
 static struct bfd_hash_entry *
-sh_elf_link_hash_newfunc (entry, table, string)
-     struct bfd_hash_entry *entry;
-     struct bfd_hash_table *table;
-     const char *string;
+sh_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
+                         struct bfd_hash_table *table,
+                         const char *string)
 {
   struct elf_sh_link_hash_entry *ret =
     (struct elf_sh_link_hash_entry *) entry;
@@ -3638,8 +3796,7 @@ sh_elf_link_hash_newfunc (entry, table, string)
 /* Create an sh ELF linker hash table.  */
 
 static struct bfd_link_hash_table *
-sh_elf_link_hash_table_create (abfd)
-     bfd *abfd;
+sh_elf_link_hash_table_create (bfd *abfd)
 {
   struct elf_sh_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct elf_sh_link_hash_table);
@@ -3672,9 +3829,7 @@ sh_elf_link_hash_table_create (abfd)
    shortcuts to them in our hash table.  */
 
 static bfd_boolean
-create_got_section (dynobj, info)
-     bfd *dynobj;
-     struct bfd_link_info *info;
+create_got_section (bfd *dynobj, struct bfd_link_info *info)
 {
   struct elf_sh_link_hash_table *htab;
 
@@ -3704,14 +3859,12 @@ create_got_section (dynobj, info)
 /* Create dynamic sections when linking against a dynamic object.  */
 
 static bfd_boolean
-sh_elf_create_dynamic_sections (abfd, info)
-     bfd *abfd;
-     struct bfd_link_info *info;
+sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
 {
   struct elf_sh_link_hash_table *htab;
   flagword flags, pltflags;
   register asection *s;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   int ptralign = 0;
 
   switch (bed->s->arch_size)
@@ -3730,6 +3883,8 @@ sh_elf_create_dynamic_sections (abfd, info)
     }
 
   htab = sh_elf_hash_table (info);
+  if (htab->root.dynamic_sections_created)
+    return TRUE;
 
   /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
      .rel[a].bss sections.  */
@@ -3781,7 +3936,8 @@ sh_elf_create_dynamic_sections (abfd, info)
       || ! bfd_set_section_alignment (abfd, s, ptralign))
     return FALSE;
 
-  if (! create_got_section (abfd, info))
+  if (htab->sgot == NULL
+      && !create_got_section (abfd, info))
     return FALSE;
 
   {
@@ -3800,6 +3956,8 @@ sh_elf_create_dynamic_sections (abfd, info)
        relname = (char *) bfd_malloc ((bfd_size_type) strlen (secname) + 6);
        strcpy (relname, ".rela");
        strcat (relname, secname);
+       if (bfd_get_section_by_name (abfd, secname))
+         continue;
        s = bfd_make_section (abfd, relname);
        if (s == NULL
            || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
@@ -3856,21 +4014,19 @@ sh_elf_create_dynamic_sections (abfd, info)
    understand.  */
 
 static bfd_boolean
-sh_elf_adjust_dynamic_symbol (info, h)
-     struct bfd_link_info *info;
-     struct elf_link_hash_entry *h;
+sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
+                             struct elf_link_hash_entry *h)
 {
   struct elf_sh_link_hash_table *htab;
   struct elf_sh_link_hash_entry *eh;
   struct elf_sh_dyn_relocs *p;
-  bfd *dynobj;
   asection *s;
   unsigned int power_of_two;
 
-  dynobj = elf_hash_table (info)->dynobj;
+  htab = sh_elf_hash_table (info);
 
   /* Make sure we know what is going on here.  */
-  BFD_ASSERT (dynobj != NULL
+  BFD_ASSERT (htab->root.dynobj != NULL
              && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
                  || h->weakdef != NULL
                  || ((h->elf_link_hash_flags
@@ -3887,11 +4043,9 @@ sh_elf_adjust_dynamic_symbol (info, h)
       || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
     {
       if (h->plt.refcount <= 0
-         || (! info->shared
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
-             && h->root.type != bfd_link_hash_undefweak
-             && h->root.type != bfd_link_hash_undefined))
+         || SYMBOL_CALLS_LOCAL (info, h)
+         || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             && h->root.type == bfd_link_hash_undefweak))
        {
          /* This case can occur if we saw a PLT reloc in an input
             file, but the symbol was never referred to by a dynamic
@@ -3916,6 +4070,10 @@ sh_elf_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;
+      if (info->nocopyreloc)
+       h->elf_link_hash_flags
+         = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
+            | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
       return TRUE;
     }
 
@@ -3968,7 +4126,6 @@ sh_elf_adjust_dynamic_symbol (info, h)
      both the dynamic object and the regular object will refer to the
      same memory location for the variable.  */
 
-  htab = sh_elf_hash_table (info);
   s = htab->sdynbss;
   BFD_ASSERT (s != NULL);
 
@@ -3994,9 +4151,9 @@ sh_elf_adjust_dynamic_symbol (info, h)
 
   /* Apply the required alignment.  */
   s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
+  if (power_of_two > bfd_get_section_alignment (htab->root.dynobj, s))
     {
-      if (! bfd_set_section_alignment (dynobj, s, power_of_two))
+      if (! bfd_set_section_alignment (htab->root.dynobj, s, power_of_two))
        return FALSE;
     }
 
@@ -4014,9 +4171,9 @@ sh_elf_adjust_dynamic_symbol (info, h)
    will be called from elflink.h.  If elflink.h doesn't call our
    finish_dynamic_symbol routine, we'll need to do something about
    initializing any .plt and .got entries in sh_elf_relocate_section.  */
-#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
+#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
   ((DYN)                                                               \
-   && ((INFO)->shared                                                  \
+   && ((SHARED)                                                                \
        || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)     \
    && ((H)->dynindx != -1                                              \
        || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
@@ -4025,9 +4182,7 @@ sh_elf_adjust_dynamic_symbol (info, h)
    dynamic relocs.  */
 
 static bfd_boolean
-allocate_dynrelocs (h, inf)
-     struct elf_link_hash_entry *h;
-     PTR inf;
+allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 {
   struct bfd_link_info *info;
   struct elf_sh_link_hash_table *htab;
@@ -4052,14 +4207,16 @@ allocate_dynrelocs (h, inf)
       && eh->gotplt_refcount > 0)
     {
       /* The symbol has been forced local, or we have some direct got refs,
-         so treat all the gotplt refs as got refs. */
+        so treat all the gotplt refs as got refs. */
       h->got.refcount += eh->gotplt_refcount;
       if (h->plt.refcount >= eh->gotplt_refcount)
        h->plt.refcount -= eh->gotplt_refcount;
     }
 
   if (htab->root.dynamic_sections_created
-      && h->plt.refcount > 0)
+      && h->plt.refcount > 0
+      && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+         || h->root.type != bfd_link_hash_undefweak))
     {
       /* Make sure this symbol is output as a dynamic symbol.
         Undefined weak syms won't yet be marked as dynamic.  */
@@ -4070,7 +4227,8 @@ allocate_dynrelocs (h, inf)
            return FALSE;
        }
 
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
+      if (info->shared
+         || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
        {
          asection *s = htab->splt;
 
@@ -4137,14 +4295,17 @@ allocate_dynrelocs (h, inf)
       if (tls_type == GOT_TLS_GD)
        s->_raw_size += 4;
       dyn = htab->root.dynamic_sections_created;
-      /* R_SH_TLS_IE_32 needs one dynamic relocation,
+      /* R_SH_TLS_IE_32 needs one dynamic relocation if dynamic,
         R_SH_TLS_GD needs one if local symbol and two if global.  */
       if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
-         || tls_type == GOT_TLS_IE)
+         || (tls_type == GOT_TLS_IE && dyn))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
       else if (tls_type == GOT_TLS_GD)
        htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
-      else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+      else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+               || h->root.type != bfd_link_hash_undefweak)
+              && (info->shared
+                  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     }
   else
@@ -4169,7 +4330,7 @@ allocate_dynrelocs (h, inf)
       eh->datalabel_got.offset = s->_raw_size;
       s->_raw_size += 4;
       dyn = htab->root.dynamic_sections_created;
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
+      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     }
   else
@@ -4187,9 +4348,7 @@ allocate_dynrelocs (h, inf)
 
   if (info->shared)
     {
-      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-         && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
-             || info->symbolic))
+      if (SYMBOL_CALLS_LOCAL (info, h))
        {
          struct elf_sh_dyn_relocs **pp;
 
@@ -4203,13 +4362,15 @@ allocate_dynrelocs (h, inf)
                pp = &p->next;
            }
        }
+
+      /* Also discard relocs on undefined weak syms with non-default
+        visibility.  */
+      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+         && h->root.type == bfd_link_hash_undefweak)
+       eh->dyn_relocs = NULL;
     }
   else
     {
-      for (p = eh->dyn_relocs; p; p = p->next)
-       if (p->tls_tpoff32)
-         goto keep;
-
       /* For the non-shared case, discard space for relocs against
         symbols which turn out to need copy relocs or are not
         dynamic.  */
@@ -4254,9 +4415,7 @@ allocate_dynrelocs (h, inf)
 /* Find any dynamic relocs that apply to read-only sections.  */
 
 static bfd_boolean
-readonly_dynrelocs (h, inf)
-     struct elf_link_hash_entry *h;
-     PTR inf;
+readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 {
   struct elf_sh_link_hash_entry *eh;
   struct elf_sh_dyn_relocs *p;
@@ -4285,9 +4444,8 @@ readonly_dynrelocs (h, inf)
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
-sh_elf_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd ATTRIBUTE_UNUSED;
-     struct bfd_link_info *info;
+sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
+                             struct bfd_link_info *info)
 {
   struct elf_sh_link_hash_table *htab;
   bfd *dynobj;
@@ -4302,7 +4460,7 @@ sh_elf_size_dynamic_sections (output_bfd, info)
   if (htab->root.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);
@@ -4396,7 +4554,7 @@ sh_elf_size_dynamic_sections (output_bfd, info)
 
   /* Allocate global sym .plt and .got entries, and space for global
      sym dynamic relocs.  */
-  elf_link_hash_traverse (&htab->root, allocate_dynrelocs, (PTR) info);
+  elf_link_hash_traverse (&htab->root, allocate_dynrelocs, info);
 
   /* We now have determined the sizes of the various dynamic sections.
      Allocate memory for them.  */
@@ -4464,7 +4622,7 @@ sh_elf_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (! info->shared)
+      if (info->executable)
        {
          if (! add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
@@ -4490,8 +4648,7 @@ sh_elf_size_dynamic_sections (output_bfd, info)
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
          if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->root, readonly_dynrelocs,
-                                   (PTR) info);
+           elf_link_hash_traverse (&htab->root, readonly_dynrelocs, info);
 
          if ((info->flags & DF_TEXTREL) != 0)
            {
@@ -4508,16 +4665,11 @@ sh_elf_size_dynamic_sections (output_bfd, info)
 /* Relocate an SH ELF section.  */
 
 static bfd_boolean
-sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
-                        contents, relocs, local_syms, local_sections)
-     bfd *output_bfd;
-     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;
+sh_elf_relocate_section (bfd *output_bfd, 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)
 {
   struct elf_sh_link_hash_table *htab;
   Elf_Internal_Shdr *symtab_hdr;
@@ -4566,8 +4718,8 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
       /* Many of the relocs are only used for relaxing, and are
         handled entirely by the relaxation code.  */
-      if (r_type > (int) R_SH_LAST_INVALID_RELOC
-         && r_type < (int) R_SH_LOOP_START)
+      if (r_type >= (int) R_SH_GNU_VTINHERIT
+         && r_type <= (int) R_SH_LABEL)
        continue;
       if (r_type == (int) R_SH_NONE)
        continue;
@@ -4614,9 +4766,9 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
             (info,
              _("Unexpected STO_SH5_ISA32 on local symbol is not handled"),
              input_bfd, input_section, rel->r_offset));
-         if (info->relocateable)
+         if (info->relocatable)
            {
-             /* This is a relocateable link.  We don't have to change
+             /* This is a relocatable 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.  */
@@ -4653,7 +4805,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            }
          else if (! howto->partial_inplace)
            {
-             relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+             relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
              addend = rel->r_addend;
            }
          else if ((sec->flags & SEC_MERGE)
@@ -4683,10 +4835,12 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        }
       else
        {
+         /* FIXME: Ought to make use of the RELOC_FOR_GLOBAL_SYMBOL macro.  */
+
          /* Section symbol are never (?) placed in the hash table, so
             we can just ignore hash relocations when creating a
-            relocateable object file.  */
-         if (info->relocateable)
+            relocatable object file.  */
+         if (info->relocatable)
            continue;
 
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
@@ -4727,7 +4881,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                       || r_type == R_SH_GOT_MEDLOW16
                       || r_type == R_SH_GOT_MEDHI16
                       || r_type == R_SH_GOT_HI16)
-                     && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+                     && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
                      && (! info->shared
                          || (! info->symbolic && h->dynindx != -1)
                          || (h->elf_link_hash_flags
@@ -4784,17 +4938,18 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            }
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
-         else if (info->shared
-                  && ! info->no_undefined
+         else if (! info->executable
+                  && info->unresolved_syms_in_objects == RM_IGNORE
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
          else
            {
-             if (! ((*info->callbacks->undefined_symbol)
-                    (info, h->root.root.string, input_bfd,
-                     input_section, rel->r_offset,
-                     (!info->shared || info->no_undefined
-                      || ELF_ST_VISIBILITY (h->other)))))
+             if (! info->callbacks->undefined_symbol
+                 (info, h->root.root.string, input_bfd,
+                  input_section, rel->r_offset,
+                  ((info->shared && info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
+                   || (!info->shared && info->unresolved_syms_in_objects == RM_GENERATE_ERROR)
+                   || ELF_ST_VISIBILITY (h->other))))
                return FALSE;
              relocation = 0;
            }
@@ -4811,7 +4966,6 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          break;
 
        case R_SH_IND12W:
-         relocation -= 4;
          goto final_link_relocate;
 
        case R_SH_DIR8WPN:
@@ -4861,17 +5015,86 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
 
+       case R_SH_DIR16:
+       case R_SH_DIR8:
+       case R_SH_DIR8U:
+       case R_SH_DIR8S:
+       case R_SH_DIR4U:
+         goto final_link_relocate;
+
+       case R_SH_DIR8UL:
+       case R_SH_DIR4UL:
+         if (relocation & 3)
+           {
+             ((*_bfd_error_handler)
+              (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
+               bfd_archive_filename (input_section->owner),
+               (unsigned long) rel->r_offset, howto->name, 
+               (unsigned long)relocation));
+             bfd_set_error (bfd_error_bad_value);
+             return FALSE;
+           }
+         goto final_link_relocate;
+
+       case R_SH_DIR8UW:
+       case R_SH_DIR8SW:
+       case R_SH_DIR4UW:
+         if (relocation & 1)
+           {
+             ((*_bfd_error_handler)
+              (_("%s: 0x%lx: fatal: unaligned %s relocation 0x%lx"),
+               bfd_archive_filename (input_section->owner),
+               (unsigned long) rel->r_offset, howto->name, 
+               (unsigned long)relocation));
+             bfd_set_error (bfd_error_bad_value);
+             return FALSE;
+           }
+         goto final_link_relocate;
+
+       case R_SH_PSHA:
+         if ((signed int)relocation < -32
+             || (signed int)relocation > 32)
+           {
+             ((*_bfd_error_handler)
+              (_("%s: 0x%lx: fatal: R_SH_PSHA relocation %d not in range -32..32"),
+               bfd_archive_filename (input_section->owner),
+               (unsigned long) rel->r_offset,
+               (unsigned long)relocation));
+             bfd_set_error (bfd_error_bad_value);
+             return FALSE;
+           }
+         goto final_link_relocate;
+
+       case R_SH_PSHL:
+         if ((signed int)relocation < -16
+             || (signed int)relocation > 16)
+           {
+             ((*_bfd_error_handler)
+              (_("%s: 0x%lx: fatal: R_SH_PSHL relocation %d not in range -32..32"),
+               bfd_archive_filename (input_section->owner),
+               (unsigned long) rel->r_offset,
+               (unsigned long)relocation));
+             bfd_set_error (bfd_error_bad_value);
+             return FALSE;
+           }
+         goto final_link_relocate;
+
        case R_SH_DIR32:
        case R_SH_REL32:
+#ifdef INCLUDE_SHMEDIA
+       case R_SH_IMM_LOW16_PCREL:
+       case R_SH_IMM_MEDLOW16_PCREL:
+       case R_SH_IMM_MEDHI16_PCREL:
+       case R_SH_IMM_HI16_PCREL:
+#endif
          if (info->shared
+             && (h == NULL
+                 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                 || h->root.type != bfd_link_hash_undefweak)
              && r_symndx != 0
              && (input_section->flags & SEC_ALLOC) != 0
-             && (r_type != R_SH_REL32
-                 || (h != NULL
-                     && h->dynindx != -1
-                     && (! info->symbolic
-                         || (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+             && (r_type == R_SH_DIR32
+                 || !SYMBOL_CALLS_LOCAL (info, h)))
            {
              Elf_Internal_Rela outrel;
              bfd_byte *loc;
@@ -4923,6 +5146,17 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  outrel.r_addend
                    = bfd_get_32 (input_bfd, contents + rel->r_offset);
                }
+#ifdef INCLUDE_SHMEDIA
+             else if (r_type == R_SH_IMM_LOW16_PCREL
+                      || r_type == R_SH_IMM_MEDLOW16_PCREL
+                      || r_type == R_SH_IMM_MEDHI16_PCREL
+                      || r_type == R_SH_IMM_HI16_PCREL)
+               {
+                 BFD_ASSERT (h != NULL && h->dynindx != -1);
+                 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
+                 outrel.r_addend = addend;
+               }
+#endif
              else
                {
                  /* h->dynindx may be -1 if this symbol was marked to
@@ -5028,11 +5262,11 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              BFD_ASSERT (off != (bfd_vma) -1);
 
              dyn = htab->root.dynamic_sections_created;
-             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
                  || (info->shared
-                     && (info->symbolic || h->dynindx == -1
-                         || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+                     && SYMBOL_REFERENCES_LOCAL (info, h))
+                 || (ELF_ST_VISIBILITY (h->other)
+                     && h->root.type == bfd_link_hash_undefweak))
                {
                  /* This is actually a static link, or it is a
                     -Bsymbolic link and the symbol is defined
@@ -5256,17 +5490,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              if (! info->shared
                  && (h->dynindx == -1
                      || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
-               {
-                 struct elf_sh_dyn_relocs *p;
-
-                 /* If TPOFF32 relocation can be created, convert it.  */
-                 for (p = sh_elf_hash_entry (h)->dyn_relocs; p; p = p->next)
-                   if (p->sec == input_section && p->tls_tpoff32)
-                     {
-                       r_type = R_SH_TLS_LE_32;
-                       break;
-                     }
-               }
+               r_type = R_SH_TLS_LE_32;
            }
 
          if (r_type == R_SH_TLS_GD_32 && tls_type == GOT_TLS_IE)
@@ -5276,9 +5500,6 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            {
              bfd_vma offset;
              unsigned short insn;
-             int indx;
-             Elf_Internal_Rela outrel;
-             bfd_byte *loc;
 
              if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_GD_32)
                {
@@ -5355,45 +5576,8 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                  bfd_put_16 (output_bfd, 0x0009, contents + offset + 4);
                }
 
-             if (sreloc == NULL)
-               {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (input_bfd,
-                          elf_elfheader (input_bfd)->e_shstrndx,
-                          elf_section_data (input_section)->rel_hdr.sh_name));
-                 if (name == NULL)
-                   return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
-               }
-
-             if (h == NULL
-                 || h->dynindx == -1
-                 || (! info->shared
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
-               indx = 0;
-             else
-               indx = h->dynindx;
-             outrel.r_offset = (input_section->output_section->vma
-                                + input_section->output_offset
-                                + rel->r_offset);
-             outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
-             if (indx == 0)
-               outrel.r_addend = relocation - dtpoff_base (info);
-             else
-               outrel.r_addend = 0;
-
-             loc = sreloc->contents;
-             loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
-             bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
+             bfd_put_32 (output_bfd, tpoff (info, relocation),
+                         contents + rel->r_offset);
              continue;
            }
 
@@ -5411,9 +5595,21 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              off = local_got_offsets[r_symndx];
            }
 
+         /* Relocate R_SH_TLS_IE_32 directly when statically linking.  */
+         if (r_type == R_SH_TLS_IE_32
+             && ! htab->root.dynamic_sections_created)
+           {
+             off &= ~1;
+             bfd_put_32 (output_bfd, tpoff (info, relocation),
+                         sgot->contents + off);
+             bfd_put_32 (output_bfd, sgot->output_offset + off,
+                         contents + rel->r_offset);
+             continue;
+           }
+
          if ((off & 1) != 0)
            off &= ~1;
-          else
+         else
            {
              Elf_Internal_Rela outrel;
              bfd_byte *loc;
@@ -5428,13 +5624,11 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              outrel.r_offset = (sgot->output_section->vma
                                 + sgot->output_offset + off);
 
-             if (h == NULL
-                 || h->dynindx == -1
-                 || (! info->shared
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+             if (h == NULL || h->dynindx == -1)
                indx = 0;
              else
                indx = h->dynindx;
+
              dr_type = (r_type == R_SH_TLS_GD_32 ? R_SH_TLS_DTPMOD32 :
                         R_SH_TLS_TPOFF32);
              if (dr_type == R_SH_TLS_TPOFF32 && indx == 0)
@@ -5616,46 +5810,7 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
        case R_SH_TLS_LDO_32:
          if (! info->shared)
-           {
-             int indx;
-             Elf_Internal_Rela outrel;
-             bfd_byte *loc;
-
-             if (sreloc == NULL)
-               {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (input_bfd,
-                          elf_elfheader (input_bfd)->e_shstrndx,
-                          elf_section_data (input_section)->rel_hdr.sh_name));
-                 if (name == NULL)
-                   return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
-               }
-
-             indx = (h && h->dynindx != -1) ? h->dynindx : 0;
-             outrel.r_offset = (input_section->output_section->vma
-                                + input_section->output_offset
-                                + rel->r_offset);
-             outrel.r_info = ELF32_R_INFO (indx, R_SH_TLS_TPOFF32);
-             if (indx == 0)
-               outrel.r_addend = relocation - dtpoff_base (info);
-             else
-               outrel.r_addend = 0;
-
-             loc = sreloc->contents;
-             loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
-             bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
-             continue;
-           }
+           relocation = tpoff (info, relocation);
          else
            relocation -= dtpoff_base (info);
 
@@ -5668,6 +5823,13 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            Elf_Internal_Rela outrel;
            bfd_byte *loc;
 
+           if (! info->shared)
+             {
+               relocation = tpoff (info, relocation);
+               addend = rel->r_addend;
+               goto final_link_relocate;
+             }
+
            if (sreloc == NULL)
              {
                const char *name;
@@ -5688,7 +5850,11 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                BFD_ASSERT (sreloc != NULL);
              }
 
-           indx = (h && h->dynindx != -1) ? h->dynindx : 0;
+           if (h == NULL || h->dynindx == -1)
+             indx = 0;
+           else
+             indx = h->dynindx;
+
            outrel.r_offset = (input_section->output_section->vma
                               + input_section->output_offset
                               + rel->r_offset);
@@ -5745,14 +5911,12 @@ sh_elf_relocate_section (output_bfd, info, input_bfd, input_section,
    which uses sh_elf_relocate_section.  */
 
 static bfd_byte *
-sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
-                                      data, relocateable, symbols)
-     bfd *output_bfd;
-     struct bfd_link_info *link_info;
-     struct bfd_link_order *link_order;
-     bfd_byte *data;
-     bfd_boolean relocateable;
-     asymbol **symbols;
+sh_elf_get_relocated_section_contents (bfd *output_bfd,
+                                      struct bfd_link_info *link_info,
+                                      struct bfd_link_order *link_order,
+                                      bfd_byte *data,
+                                      bfd_boolean relocatable,
+                                      asymbol **symbols)
 {
   Elf_Internal_Shdr *symtab_hdr;
   asection *input_section = link_order->u.indirect.section;
@@ -5763,11 +5927,11 @@ sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
 
   /* We only need to handle the case of relaxing, or of having a
      particular set of section contents, specially.  */
-  if (relocateable
+  if (relocatable
       || elf_section_data (input_section)->this_hdr.contents == NULL)
     return bfd_generic_get_relocated_section_contents (output_bfd, link_info,
                                                       link_order, data,
-                                                      relocateable,
+                                                      relocatable,
                                                       symbols);
 
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -5782,8 +5946,8 @@ sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
       Elf_Internal_Sym *isym, *isymend;
       bfd_size_type amt;
 
-      internal_relocs = (_bfd_elf32_link_read_relocs
-                        (input_bfd, input_section, (PTR) NULL,
+      internal_relocs = (_bfd_elf_link_read_relocs
+                        (input_bfd, input_section, NULL,
                          (Elf_Internal_Rela *) NULL, FALSE));
       if (internal_relocs == NULL)
        goto error_return;
@@ -5855,22 +6019,32 @@ sh_elf_get_relocated_section_contents (output_bfd, link_info, link_order,
    This is PT_TLS segment p_vaddr.  */
 
 static bfd_vma
-dtpoff_base (info)
-     struct bfd_link_info *info;
+dtpoff_base (struct bfd_link_info *info)
 {
- /* If tls_segment is NULL, we should have signalled an error already.  */
- if (elf_hash_table (info)->tls_segment == NULL)
-   return 0;
-  return elf_hash_table (info)->tls_segment->start;
+  /* If tls_sec is NULL, we should have signalled an error already.  */
+  if (elf_hash_table (info)->tls_sec == NULL)
+    return 0;
+  return elf_hash_table (info)->tls_sec->vma;
+}
+
+/* Return the relocation value for R_SH_TLS_TPOFF32..  */
+
+static bfd_vma
+tpoff (struct bfd_link_info *info, bfd_vma address)
+{
+  /* If tls_sec is NULL, we should have signalled an error already.  */
+  if (elf_hash_table (info)->tls_sec == NULL)
+    return 0;
+  /* SH TLS ABI is variant I and static TLS block start just after tcbhead
+     structure which has 2 pointer fields.  */
+  return address - elf_hash_table (info)->tls_sec->vma + 8;
 }
 
 static asection *
-sh_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;
+sh_elf_gc_mark_hook (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)
     {
@@ -5909,19 +6083,13 @@ sh_elf_gc_mark_hook (sec, info, rel, h, sym)
 /* Update the got entry reference counts for the section being removed.  */
 
 static bfd_boolean
-sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
-     bfd *abfd;
-     struct bfd_link_info *info;
-     asection *sec;
-     const Elf_Internal_Rela *relocs;
+sh_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
+                     asection *sec, const Elf_Internal_Rela *relocs)
 {
   Elf_Internal_Shdr *symtab_hdr;
   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;
-  struct elf_sh_link_hash_entry *eh;
 
   elf_section_data (sec)->local_dynrel = NULL;
 
@@ -5932,15 +6100,20 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
   relend = relocs + sec->reloc_count;
   for (rel = relocs; rel < relend; rel++)
     {
+      unsigned long r_symndx;
+      unsigned int r_type;
+      struct elf_link_hash_entry *h = NULL;
 #ifdef INCLUDE_SHMEDIA
       int seen_stt_datalabel = 0;
 #endif
 
       r_symndx = ELF32_R_SYM (rel->r_info);
-      if (r_symndx < symtab_hdr->sh_info)
-       h = NULL;
-      else
+      if (r_symndx >= symtab_hdr->sh_info)
        {
+         struct elf_sh_link_hash_entry *eh;
+         struct elf_sh_dyn_relocs **pp;
+         struct elf_sh_dyn_relocs *p;
+
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 #ifdef INCLUDE_SHMEDIA
          while (h->root.type == bfd_link_hash_indirect
@@ -5950,12 +6123,18 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
              h = (struct elf_link_hash_entry *) h->root.u.i.link;
            }
 #endif
+         eh = (struct elf_sh_link_hash_entry *) h;
+         for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+           if (p->sec == sec)
+             {
+               /* Everything must go for SEC.  */
+               *pp = p->next;
+               break;
+             }
        }
-      eh = (struct elf_sh_link_hash_entry *) h;
 
-      switch (sh_elf_optimized_tls_reloc (info, ELF32_R_TYPE (rel->r_info),
-                                         ELF32_R_SYM (rel->r_info)
-                                         >= symtab_hdr->sh_info))
+      r_type = ELF32_R_TYPE (rel->r_info);
+      switch (sh_elf_optimized_tls_reloc (info, r_type, h != NULL))
        {
        case R_SH_TLS_LD_32:
          if (sh_elf_hash_table (info)->tls_ldm_got.refcount > 0)
@@ -5988,6 +6167,8 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 #ifdef INCLUDE_SHMEDIA
              if (seen_stt_datalabel)
                {
+                 struct elf_sh_link_hash_entry *eh;
+                 eh = (struct elf_sh_link_hash_entry *) h;
                  if (eh->datalabel_got.refcount > 0)
                    eh->datalabel_got.refcount -= 1;
                }
@@ -6013,27 +6194,9 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 
        case R_SH_DIR32:
        case R_SH_REL32:
-         if (h != NULL)
-           {
-             struct elf_sh_dyn_relocs **pp;
-             struct elf_sh_dyn_relocs *p;
-
-
-             if (!info->shared && h->plt.refcount > 0)
-               h->plt.refcount -= 1;
-
-             for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-               if (p->sec == sec)
-                 {
-                   if (ELF32_R_TYPE (rel->r_info) == R_SH_REL32)
-                     p->pc_count -= 1;
-                   p->count -= 1;
-                   if (p->count == 0)
-                     *pp = p->next;
-                   break;
-                 }
-           }
-         break;
+         if (info->shared)
+           break;
+         /* Fall thru */
 
        case R_SH_PLT32:
 #ifdef INCLUDE_SHMEDIA
@@ -6060,6 +6223,8 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 #endif
          if (h != NULL)
            {
+             struct elf_sh_link_hash_entry *eh;
+             eh = (struct elf_sh_link_hash_entry *) h;
              if (eh->gotplt_refcount > 0)
                {
                  eh->gotplt_refcount -= 1;
@@ -6102,9 +6267,9 @@ sh_elf_gc_sweep_hook (abfd, info, sec, relocs)
 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
 
 static void
-sh_elf_copy_indirect_symbol (bed, dir, ind)
-     struct elf_backend_data *bed;
-     struct elf_link_hash_entry *dir, *ind;
+sh_elf_copy_indirect_symbol (const struct elf_backend_data *bed,
+                            struct elf_link_hash_entry *dir,
+                            struct elf_link_hash_entry *ind)
 {
   struct elf_sh_link_hash_entry *edir, *eind;
 #ifdef INCLUDE_SHMEDIA
@@ -6166,14 +6331,22 @@ sh_elf_copy_indirect_symbol (bed, dir, ind)
       eind->tls_type = GOT_UNKNOWN;
     }
 
-  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
+  if (ind->root.type != bfd_link_hash_indirect
+      && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
+    /* If called to transfer flags for a weakdef during processing
+       of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
+       We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
+    dir->elf_link_hash_flags |=
+      (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
+                                  | ELF_LINK_HASH_REF_REGULAR
+                                  | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
+  else
+    _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
 }
 
 static int
-sh_elf_optimized_tls_reloc (info, r_type, is_local)
-     struct bfd_link_info *info;
-     int r_type;
-     int is_local;
+sh_elf_optimized_tls_reloc (struct bfd_link_info *info, int r_type,
+                           int is_local)
 {
   if (info->shared)
     return r_type;
@@ -6197,18 +6370,14 @@ sh_elf_optimized_tls_reloc (info, r_type, is_local)
    virtual table relocs for gc.  */
 
 static bfd_boolean
-sh_elf_check_relocs (abfd, info, sec, relocs)
-     bfd *abfd;
-     struct bfd_link_info *info;
-     asection *sec;
-     const Elf_Internal_Rela *relocs;
+sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
+                    const Elf_Internal_Rela *relocs)
 {
   Elf_Internal_Shdr *symtab_hdr;
   struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
   struct elf_sh_link_hash_table *htab;
   const Elf_Internal_Rela *rel;
   const Elf_Internal_Rela *rel_end;
-  bfd *dynobj;
   bfd_vma *local_got_offsets;
   asection *sgot;
   asection *srelgot;
@@ -6220,7 +6389,7 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
   srelgot = NULL;
   sreloc = NULL;
 
-  if (info->relocateable)
+  if (info->relocatable)
     return TRUE;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
@@ -6230,7 +6399,6 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
     sym_hashes_end -= symtab_hdr->sh_info;
 
   htab = sh_elf_hash_table (info);
-  dynobj = htab->root.dynobj;
   local_got_offsets = elf_local_got_offsets (abfd);
 
   rel_end = relocs + sec->reloc_count;
@@ -6304,10 +6472,13 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
            case R_SH_TLS_GD_32:
            case R_SH_TLS_LD_32:
            case R_SH_TLS_IE_32:
-             if (dynobj == NULL)
-               htab->root.dynobj = dynobj = abfd;
-             if (! create_got_section (dynobj, info))
-               return FALSE;
+             if (htab->sgot == NULL)
+               {
+                 if (htab->root.dynobj == NULL)
+                   htab->root.dynobj = abfd;
+                 if (!create_got_section (htab->root.dynobj, info))
+                   return FALSE;
+               }
              break;
 
            default:
@@ -6331,12 +6502,12 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
            return FALSE;
          break;
 
-       force_got:
        case R_SH_TLS_IE_32:
          if (info->shared)
            info->flags |= DF_STATIC_TLS;
 
          /* FALLTHROUGH */
+       force_got:
        case R_SH_TLS_GD_32:
        case R_SH_GOT32:
 #ifdef INCLUDE_SHMEDIA
@@ -6501,6 +6672,12 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
 
        case R_SH_DIR32:
        case R_SH_REL32:
+#ifdef INCLUDE_SHMEDIA
+       case R_SH_IMM_LOW16_PCREL:
+       case R_SH_IMM_MEDLOW16_PCREL:
+       case R_SH_IMM_MEDHI16_PCREL:
+       case R_SH_IMM_HI16_PCREL:
+#endif
          if (h != NULL && ! info->shared)
            {
              h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
@@ -6544,8 +6721,8 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
              struct elf_sh_dyn_relocs *p;
              struct elf_sh_dyn_relocs **head;
 
-             if (dynobj == NULL)
-               htab->root.dynobj = dynobj = abfd;
+             if (htab->root.dynobj == NULL)
+               htab->root.dynobj = abfd;
 
              /* When creating a shared object, we must copy these
                 reloc types into the output file.  We create a reloc
@@ -6565,23 +6742,23 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
                              && strcmp (bfd_get_section_name (abfd, sec),
                                         name + 5) == 0);
 
-                 sreloc = bfd_get_section_by_name (dynobj, name);
+                 sreloc = bfd_get_section_by_name (htab->root.dynobj, name);
                  if (sreloc == NULL)
                    {
                      flagword flags;
 
-                     sreloc = bfd_make_section (dynobj, name);
+                     sreloc = bfd_make_section (htab->root.dynobj, name);
                      flags = (SEC_HAS_CONTENTS | SEC_READONLY
                               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
                      if ((sec->flags & SEC_ALLOC) != 0)
                        flags |= SEC_ALLOC | SEC_LOAD;
                      if (sreloc == NULL
-                         || ! bfd_set_section_flags (dynobj, sreloc, flags)
-                         || ! bfd_set_section_alignment (dynobj, sreloc, 2))
+                         || ! bfd_set_section_flags (htab->root.dynobj,
+                                                     sreloc, flags)
+                         || ! bfd_set_section_alignment (htab->root.dynobj,
+                                                         sreloc, 2))
                        return FALSE;
                    }
-                 if (sec->flags & SEC_READONLY)
-                   info->flags |= DF_TEXTREL;
                  elf_section_data (sec)->sreloc = sreloc;
                }
 
@@ -6607,7 +6784,7 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
              if (p == NULL || p->sec != sec)
                {
                  bfd_size_type amt = sizeof (*p);
-                 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
+                 p = bfd_alloc (htab->root.dynobj, amt);
                  if (p == NULL)
                    return FALSE;
                  p->next = *head;
@@ -6615,11 +6792,17 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
                  p->sec = sec;
                  p->count = 0;
                  p->pc_count = 0;
-                 p->tls_tpoff32 = FALSE;
                }
 
              p->count += 1;
-             if (r_type == R_SH_REL32)
+             if (r_type == R_SH_REL32
+#ifdef INCLUDE_SHMEDIA
+                 || r_type == R_SH_IMM_LOW16_PCREL
+                 || r_type == R_SH_IMM_MEDLOW16_PCREL
+                 || r_type == R_SH_IMM_MEDHI16_PCREL
+                 || r_type == R_SH_IMM_HI16_PCREL
+#endif
+                 )
                p->pc_count += 1;
            }
 
@@ -6633,92 +6816,10 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
              return FALSE;
            }
 
-         if (ELF32_R_TYPE (rel->r_info) == R_SH_TLS_LD_32)
-           break;
+         break;
 
-         /* FALLTHROUGH */
        case R_SH_TLS_LDO_32:
-         /* We make a R_SH_TLS_TPOFF32 relocation. Count it as a
-            copy relocation.  */
-         if (! info->shared)
-           {
-             struct elf_sh_dyn_relocs *p;
-             struct elf_sh_dyn_relocs **head;
-
-             if (dynobj == NULL)
-               htab->root.dynobj = dynobj = abfd;
-
-             if (sreloc == NULL)
-               {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (abfd,
-                          elf_elfheader (abfd)->e_shstrndx,
-                          elf_section_data (sec)->rel_hdr.sh_name));
-                 if (name == NULL)
-                   return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (abfd, sec),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 if (sreloc == NULL)
-                   {
-                     flagword flags;
-
-                     sreloc = bfd_make_section (dynobj, name);
-                     flags = (SEC_HAS_CONTENTS | SEC_READONLY
-                              | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-                     if ((sec->flags & SEC_ALLOC) != 0)
-                       flags |= SEC_ALLOC | SEC_LOAD;
-                     if (sreloc == NULL
-                         || ! bfd_set_section_flags (dynobj, sreloc, flags)
-                         || ! bfd_set_section_alignment (dynobj, sreloc, 2))
-                       return FALSE;
-                   }
-                 elf_section_data (sec)->sreloc = sreloc;
-                 if (sec->flags & SEC_READONLY)
-                   info->flags |= DF_TEXTREL;
-               }
-
-             /* If this is a global symbol, we count the number of
-                relocations we need for this symbol.  */
-             if (h != NULL)
-               head = &((struct elf_sh_link_hash_entry *) h)->dyn_relocs;
-             else
-               {
-                 asection *s;
-
-                 /* Track dynamic relocs needed for local syms too.  */
-                 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
-                                                sec, r_symndx);
-                 if (s == NULL)
-                   return FALSE;
-
-                 head = ((struct elf_sh_dyn_relocs **)
-                         &elf_section_data (s)->local_dynrel);
-               }
-
-             p = *head;
-             if (p == NULL || p->sec != sec)
-               {
-                 bfd_size_type amt = sizeof (*p);
-                 p = ((struct elf_sh_dyn_relocs *) bfd_alloc (dynobj, amt));
-                 if (p == NULL)
-                   return FALSE;
-                 p->next = *head;
-                 *head = p;
-                 p->sec = sec;
-                 p->count = 0;
-                 p->pc_count = 0;
-                 p->tls_tpoff32 = FALSE;
-               }
-
-             p->count += 1;
-             p->tls_tpoff32 = TRUE;
-           }
+         /* Nothing to do.  */
          break;
 
        default:
@@ -6731,8 +6832,7 @@ sh_elf_check_relocs (abfd, info, sec, relocs)
 
 #ifndef sh_elf_set_mach_from_flags
 static bfd_boolean
-sh_elf_set_mach_from_flags (abfd)
-     bfd *abfd;
+sh_elf_set_mach_from_flags (bfd *abfd)
 {
   flagword flags = elf_elfheader (abfd)->e_flags;
 
@@ -6763,6 +6863,18 @@ sh_elf_set_mach_from_flags (abfd)
     case EF_SH4:
       bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4);
       break;
+    case EF_SH4_NOFPU:
+      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4_nofpu);
+      break;
+    case EF_SH4A:
+      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4a);
+      break;
+    case EF_SH4A_NOFPU:
+      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4a_nofpu);
+      break;
+    case EF_SH4AL_DSP:
+      bfd_default_set_arch_mach (abfd, bfd_arch_sh, bfd_mach_sh4al_dsp);
+      break;
     default:
       return FALSE;
     }
@@ -6774,9 +6886,7 @@ sh_elf_set_mach_from_flags (abfd)
 /* Function to keep SH specific file flags.  */
 
 static bfd_boolean
-sh_elf_set_private_flags (abfd, flags)
-     bfd *abfd;
-     flagword flags;
+sh_elf_set_private_flags (bfd *abfd, flagword flags)
 {
   BFD_ASSERT (! elf_flags_init (abfd)
              || elf_elfheader (abfd)->e_flags == flags);
@@ -6791,9 +6901,7 @@ sh_elf_set_private_flags (abfd, flags)
 /* Copy backend specific data from one object module to another */
 
 static bfd_boolean
-sh_elf_copy_private_data (ibfd, obfd)
-     bfd * ibfd;
-     bfd * obfd;
+sh_elf_copy_private_data (bfd * ibfd, bfd * obfd)
 {
   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
@@ -6808,9 +6916,7 @@ sh_elf_copy_private_data (ibfd, obfd)
    together, and for linking sh-dsp with sh3e / sh4 objects.  */
 
 static bfd_boolean
-sh_elf_merge_private_data (ibfd, obfd)
-     bfd *ibfd;
-     bfd *obfd;
+sh_elf_merge_private_data (bfd *ibfd, bfd *obfd)
 {
   flagword old_flags, new_flags;
 
@@ -6851,8 +6957,7 @@ sh_elf_merge_private_data (ibfd, obfd)
    here.  */
 
 static bfd_boolean
-sh_elf_object_p (abfd)
-  bfd *abfd;
+sh_elf_object_p (bfd *abfd)
 {
   struct sh_elf_obj_tdata *new_tdata;
   bfd_size_type amt = sizeof (struct sh_elf_obj_tdata);
@@ -6873,17 +6978,13 @@ sh_elf_object_p (abfd)
    dynamic sections here.  */
 
 static bfd_boolean
-sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
-     bfd *output_bfd;
-     struct bfd_link_info *info;
-     struct elf_link_hash_entry *h;
-     Elf_Internal_Sym *sym;
+sh_elf_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
+                             struct elf_link_hash_entry *h,
+                             Elf_Internal_Sym *sym)
 {
   struct elf_sh_link_hash_table *htab;
-  bfd *dynobj;
 
   htab = sh_elf_hash_table (info);
-  dynobj = htab->root.dynobj;
 
   if (h->plt.offset != (bfd_vma) -1)
     {
@@ -7051,10 +7152,7 @@ sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
         The entry in the global offset table will already have been
         initialized in the relocate_section function.  */
       if (info->shared
-         && (info->symbolic
-             || h->dynindx == -1
-             || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+         && SYMBOL_REFERENCES_LOCAL (info, h))
        {
          rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
          rel.r_addend = (h->root.u.def.value
@@ -7102,10 +7200,7 @@ sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
           The entry in the global offset table will already have been
           initialized in the relocate_section function.  */
        if (info->shared
-           && (info->symbolic
-               || h->dynindx == -1
-               || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
-           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+           && SYMBOL_REFERENCES_LOCAL (info, h))
          {
            rel.r_info = ELF32_R_INFO (0, R_SH_RELATIVE);
            rel.r_addend = (h->root.u.def.value
@@ -7163,20 +7258,15 @@ sh_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
 /* Finish up the dynamic sections.  */
 
 static bfd_boolean
-sh_elf_finish_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
-     struct bfd_link_info *info;
+sh_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 {
   struct elf_sh_link_hash_table *htab;
-  bfd *dynobj;
   asection *sgot;
   asection *sdyn;
 
   htab = sh_elf_hash_table (info);
-  dynobj = htab->root.dynobj;
-
   sgot = htab->sgotplt;
-  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+  sdyn = bfd_get_section_by_name (htab->root.dynobj, ".dynamic");
 
   if (htab->root.dynamic_sections_created)
     {
@@ -7195,7 +7285,7 @@ sh_elf_finish_dynamic_sections (output_bfd, info)
          const char *name;
 #endif
 
-         bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
+         bfd_elf32_swap_dyn_in (htab->root.dynobj, dyncon, &dyn);
 
          switch (dyn.d_tag)
            {
@@ -7335,8 +7425,7 @@ sh_elf_finish_dynamic_sections (output_bfd, info)
 }
 
 static enum elf_reloc_type_class
-sh_elf_reloc_type_class (rela)
-     const Elf_Internal_Rela *rela;
+sh_elf_reloc_type_class (const Elf_Internal_Rela *rela)
 {
   switch ((int) ELF32_R_TYPE (rela->r_info))
     {
@@ -7353,9 +7442,7 @@ sh_elf_reloc_type_class (rela)
 
 /* Support for Linux core dump NOTE sections.  */
 static bfd_boolean
-elf32_shlin_grok_prstatus (abfd, note)
-     bfd *abfd;
-     Elf_Internal_Note *note;
+elf32_shlin_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
 {
   int offset;
   unsigned int raw_size;
@@ -7385,9 +7472,7 @@ elf32_shlin_grok_prstatus (abfd, note)
 }
 
 static bfd_boolean
-elf32_shlin_grok_psinfo (abfd, note)
-     bfd *abfd;
-     Elf_Internal_Note *note;
+elf32_shlin_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
 {
   switch (note->descsz)
     {
@@ -7422,7 +7507,11 @@ elf32_shlin_grok_psinfo (abfd, note)
 #define TARGET_LITTLE_NAME     "elf32-shl"
 #define ELF_ARCH               bfd_arch_sh
 #define ELF_MACHINE_CODE       EM_SH
-#define ELF_MAXPAGESIZE                128
+#ifdef __QNXTARGET__
+#define ELF_MAXPAGESIZE                0x1000
+#else
+#define ELF_MAXPAGESIZE                0x80
+#endif
 
 #define elf_symbol_leading_char '_'
 
@@ -7466,7 +7555,6 @@ elf32_shlin_grok_psinfo (abfd, note)
 #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
 
 #ifndef INCLUDE_SHMEDIA