Put common variables into the appropriate section, based on relocation types
authorMichael Meissner <gnu@the-meissners.org>
Fri, 3 Jan 1997 16:55:34 +0000 (16:55 +0000)
committerMichael Meissner <gnu@the-meissners.org>
Fri, 3 Jan 1997 16:55:34 +0000 (16:55 +0000)
bfd/ChangeLog
bfd/elf32-v850.c

index b1d9e84bbbed0b3b91d78c2d4dd2bf39c35ee0c7..68527fb0e12d63ad209acf1fb5f3c0a3dd9292d7 100644 (file)
@@ -1,4 +1,15 @@
 start-sanitize-v850
+Fri Jan  3 11:42:53 1997  Michael Meissner  <meissner@tiktok.cygnus.com>
+
+       * elf32-v850.c (all functions and static variables): Go through
+       and regularize names to be of the form v850_elf_<xxx>.
+       (toplevel): Include <elf/v850.h>.
+       (enum reloc_type): Move to include/elf/v850.h.
+       (v850_elf_check_relocs): For common variables, if the variable is
+       referenced by a R_V850_{SDA,ZDA,TDA} relocation, put the variable
+       into the appropriate section.
+       (elf_backend_check_relocs): Define.
+
 Tue Dec 31 15:15:28 1996  Michael Meissner  <meissner@tiktok.cygnus.com>
 
        * elf32-v850.c (elf_v850_howto_table): Fix some spacing.
index 85335537205347d291e8f46a00cc8537941e843f..d9b126644bc61a13bba17442f54b539b4c12fd6d 100644 (file)
@@ -1,5 +1,5 @@
 /* V850-specific support for 32-bit ELF
-   Copyright (C) 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -28,267 +28,260 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "elf/v850.h"
 
-static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup
+static reloc_howto_type *v850_elf_reloc_type_lookup
   PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
-static void v850_info_to_howto_rel
+static void v850_elf_info_to_howto_rel
   PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
-static bfd_reloc_status_type bfd_elf32_v850_reloc
+static bfd_reloc_status_type v850_elf_reloc
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
-
-
+static boolean v850_elf_is_local_label PARAMS ((bfd *, asymbol *));
+static boolean v850_elf_relocate_section PARAMS((bfd *,
+                                                struct bfd_link_info *,
+                                                bfd *,
+                                                asection *,
+                                                bfd_byte *,
+                                                Elf_Internal_Rela *,
+                                                Elf_Internal_Sym *,
+                                                asection **));
 
 /* Try to minimize the amount of space occupied by relocation tables
    on the ROM (not that the ROM won't be swamped by other ELF overhead).  */
 #define USE_REL
 
-enum reloc_type
-{
-  R_V850_NONE = 0,
-  R_V850_9_PCREL,
-  R_V850_22_PCREL,
-  R_V850_HI16_S,
-  R_V850_HI16,
-  R_V850_LO16,
-  R_V850_32,
-  R_V850_16,
-  R_V850_8,
-  R_V850_SDA_OFFSET,
-  R_V850_ZDA_OFFSET,
-  R_V850_TDA_OFFSET,
-  R_V850_max
-};
-
-static reloc_howto_type elf_v850_howto_table[] =
+static reloc_howto_type v850_elf_howto_table[] =
 {
   /* This reloc does nothing.  */
-  HOWTO (R_V850_NONE,          /* type */
-        0,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        32,                    /* bitsize */
-        false,                 /* pc_relative */
-        0,                     /* bitpos */
-        complain_overflow_bitfield, /* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
-        "R_V850_NONE",         /* name */
-        false,                 /* partial_inplace */
-        0,                     /* src_mask */
-        0,                     /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_NONE,                  /* type */
+        0,                             /* rightshift */
+        2,                             /* size (0 = byte, 1 = short, 2 = long) */
+        32,                            /* bitsize */
+        false,                         /* pc_relative */
+        0,                             /* bitpos */
+        complain_overflow_bitfield,    /* complain_on_overflow */
+        bfd_elf_generic_reloc,         /* special_function */
+        "R_V850_NONE",                 /* name */
+        false,                         /* partial_inplace */
+        0,                             /* src_mask */
+        0,                             /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* A PC relative 9 bit branch. */
-  HOWTO (R_V850_9_PCREL,       /* type */
-        2,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        26,                    /* bitsize */
-        true,                  /* pc_relative */
-        0,                     /* bitpos */
-        complain_overflow_bitfield, /* complain_on_overflow */
-        bfd_elf32_v850_reloc,  /* special_function */
-        "R_V850_9_PCREL",      /* name */
-        false,                 /* partial_inplace */
-        0x00ffffff,            /* src_mask */
-        0x00ffffff,            /* dst_mask */
-        true),                 /* pcrel_offset */
+  HOWTO (R_V850_9_PCREL,               /* type */
+        2,                             /* rightshift */
+        2,                             /* size (0 = byte, 1 = short, 2 = long) */
+        26,                            /* bitsize */
+        true,                          /* pc_relative */
+        0,                             /* bitpos */
+        complain_overflow_bitfield,    /* complain_on_overflow */
+        v850_elf_reloc,                /* special_function */
+        "R_V850_9_PCREL",              /* name */
+        false,                         /* partial_inplace */
+        0x00ffffff,                    /* src_mask */
+        0x00ffffff,                    /* dst_mask */
+        true),                         /* pcrel_offset */
 
   /* A PC relative 22 bit branch. */
-  HOWTO (R_V850_22_PCREL,      /* type */
-        2,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        22,                    /* bitsize */
-        true,                  /* pc_relative */
-        7,                     /* bitpos */
-        complain_overflow_signed, /* complain_on_overflow */
-        bfd_elf32_v850_reloc,  /* special_function */
-        "R_V850_22_PCREL",     /* name */
-        false,                 /* partial_inplace */
-        0x07ffff80,            /* src_mask */
-        0x07ffff80,            /* dst_mask */
-        true),                 /* pcrel_offset */
+  HOWTO (R_V850_22_PCREL,              /* type */
+        2,                             /* rightshift */
+        2,                             /* size (0 = byte, 1 = short, 2 = long) */
+        22,                            /* bitsize */
+        true,                          /* pc_relative */
+        7,                             /* bitpos */
+        complain_overflow_signed,      /* complain_on_overflow */
+        v850_elf_reloc,                /* special_function */
+        "R_V850_22_PCREL",             /* name */
+        false,                         /* partial_inplace */
+        0x07ffff80,                    /* src_mask */
+        0x07ffff80,                    /* dst_mask */
+        true),                         /* pcrel_offset */
 
   /* High 16 bits of symbol value.  */
-  HOWTO (R_V850_HI16_S,                /* 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_elf32_v850_reloc, /* special_function */
-        "R_V850_HI16_S",       /* name */
-        true,                  /* partial_inplace */
-        0xffff,                /* src_mask */
-        0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_HI16_S,                        /* type */
+        0,                             /* rightshift */
+        1,                             /* size (0 = byte, 1 = short, 2 = long) */
+        16,                            /* bitsize */
+        false,                         /* pc_relative */
+        0,                             /* bitpos */
+        complain_overflow_dont,        /* complain_on_overflow */
+        v850_elf_reloc,                /* special_function */
+        "R_V850_HI16_S",               /* name */
+        true,                          /* partial_inplace */
+        0xffff,                        /* src_mask */
+        0xffff,                        /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* High 16 bits of symbol value.  */
-  HOWTO (R_V850_HI16,          /* 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_elf32_v850_reloc, /* special_function */
-        "R_V850_HI16",         /* name */
-        true,                  /* partial_inplace */
-        0xffff,                /* src_mask */
-        0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_HI16,                  /* type */
+        0,                             /* rightshift */
+        1,                             /* size (0 = byte, 1 = short, 2 = long) */
+        16,                            /* bitsize */
+        false,                         /* pc_relative */
+        0,                             /* bitpos */
+        complain_overflow_dont,        /* complain_on_overflow */
+        v850_elf_reloc,                /* special_function */
+        "R_V850_HI16",                 /* name */
+        true,                          /* partial_inplace */
+        0xffff,                        /* src_mask */
+        0xffff,                        /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Low 16 bits of symbol value.  */
-  HOWTO (R_V850_LO16,          /* 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_V850_LO16",         /* name */
-        true,                  /* partial_inplace */
-        0xffff,                /* src_mask */
-        0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_LO16,                  /* 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_V850_LO16",                 /* name */
+        true,                          /* partial_inplace */
+        0xffff,                        /* src_mask */
+        0xffff,                        /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Simple 32bit reloc.  */
-  HOWTO (R_V850_32,          /* type */
-        0,                     /* rightshift */
-        2,                     /* size (0 = byte, 1 = short, 2 = long) */
-        32,                    /* bitsize */
-        false,                 /* pc_relative */
-        0,                     /* bitpos */
-        complain_overflow_dont,/* complain_on_overflow */
-        bfd_elf_generic_reloc, /* special_function */
-        "R_V850_32",         /* name */
-        true,                  /* partial_inplace */
-        0xffffffff,                /* src_mask */
-        0xffffffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_32,                    /* type */
+        0,                             /* rightshift */
+        2,                             /* size (0 = byte, 1 = short, 2 = long) */
+        32,                            /* bitsize */
+        false,                         /* pc_relative */
+        0,                             /* bitpos */
+        complain_overflow_dont,        /* complain_on_overflow */
+        bfd_elf_generic_reloc,         /* special_function */
+        "R_V850_32",                   /* name */
+        true,                          /* partial_inplace */
+        0xffffffff,                    /* src_mask */
+        0xffffffff,                    /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Simple 16bit reloc.  */
-  HOWTO (R_V850_16,          /* 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_V850_16",         /* name */
-        true,                  /* partial_inplace */
-        0xffff,                /* src_mask */
-        0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_16,                    /* 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_V850_16",                   /* name */
+        true,                          /* partial_inplace */
+        0xffff,                        /* src_mask */
+        0xffff,                        /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Simple 8bit reloc.         */
-  HOWTO (R_V850_8,          /* 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_V850_8",         /* name */
-        true,                  /* partial_inplace */
-        0xff,                /* src_mask */
-        0xff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_8,                     /* 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_V850_8",                    /* name */
+        true,                          /* partial_inplace */
+        0xff,                          /* src_mask */
+        0xff,                          /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Offset from the short data area pointer.  */
-  HOWTO (R_V850_SDA_OFFSET,    /* 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_V850_SDA_OFFSET",   /* name */
-        true,                  /* partial_inplace */
-        0xffff,                /* src_mask */
-        0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_SDA_OFFSET,            /* 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_V850_SDA_OFFSET",           /* name */
+        true,                          /* partial_inplace */
+        0xffff,                        /* src_mask */
+        0xffff,                        /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Offset from the zero data area pointer.  */
-  HOWTO (R_V850_ZDA_OFFSET,    /* 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_V850_ZDA_OFFSET",   /* name */
-        true,                  /* partial_inplace */
-        0xffff,                /* src_mask */
-        0xffff,                /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_ZDA_OFFSET,            /* 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_V850_ZDA_OFFSET",           /* name */
+        true,                          /* partial_inplace */
+        0xffff,                        /* src_mask */
+        0xffff,                        /* dst_mask */
+        false),                        /* pcrel_offset */
 
   /* Offset from the tiny data area pointer.  */
-  HOWTO (R_V850_TDA_OFFSET,    /* type */
-        0,                     /* rightshift */
-        2,                     /* 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_V850_TDA_OFFSET",   /* name */
-        true,                  /* partial_inplace */
-        0xff,                  /* src_mask */
-        0xff,                  /* dst_mask */
-        false),                /* pcrel_offset */
+  HOWTO (R_V850_TDA_OFFSET,            /* type */
+        0,                             /* rightshift */
+        2,                             /* 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_V850_TDA_OFFSET",           /* name */
+        true,                          /* partial_inplace */
+        0xff,                          /* src_mask */
+        0xff,                          /* dst_mask */
+        false),                        /* pcrel_offset */
 
 };
 
 /* Map BFD reloc types to V850 ELF reloc types.  */
 
-struct v850_reloc_map
+struct v850_elf_reloc_map
 {
   unsigned char bfd_reloc_val;
   unsigned char elf_reloc_val;
 };
 
-static const struct v850_reloc_map v850_reloc_map[] =
+static const struct v850_elf_reloc_map v850_elf_reloc_map[] =
 {
-  { BFD_RELOC_NONE, R_V850_NONE, },
-  { BFD_RELOC_V850_9_PCREL, R_V850_9_PCREL, },
-  { BFD_RELOC_V850_22_PCREL, R_V850_22_PCREL, },
-  { BFD_RELOC_HI16_S, R_V850_HI16_S, },
-  { BFD_RELOC_HI16, R_V850_HI16, },
-  { BFD_RELOC_LO16, R_V850_LO16, },
-  { BFD_RELOC_32, R_V850_32, },
-  { BFD_RELOC_16, R_V850_16, },
-  { BFD_RELOC_8, R_V850_8, },
-  { BFD_RELOC_V850_TDA_OFFSET, R_V850_TDA_OFFSET, },
-  { BFD_RELOC_V850_SDA_OFFSET, R_V850_SDA_OFFSET, },
-  { BFD_RELOC_V850_ZDA_OFFSET, R_V850_ZDA_OFFSET, },
+  { BFD_RELOC_NONE,            R_V850_NONE, },
+  { BFD_RELOC_V850_9_PCREL,    R_V850_9_PCREL, },
+  { BFD_RELOC_V850_22_PCREL,   R_V850_22_PCREL, },
+  { BFD_RELOC_HI16_S,          R_V850_HI16_S, },
+  { BFD_RELOC_HI16,            R_V850_HI16, },
+  { BFD_RELOC_LO16,            R_V850_LO16, },
+  { BFD_RELOC_32,              R_V850_32, },
+  { BFD_RELOC_16,              R_V850_16, },
+  { BFD_RELOC_8,               R_V850_8, },
+  { BFD_RELOC_V850_TDA_OFFSET, R_V850_TDA_OFFSET, },
+  { BFD_RELOC_V850_SDA_OFFSET, R_V850_SDA_OFFSET, },
+  { BFD_RELOC_V850_ZDA_OFFSET, R_V850_ZDA_OFFSET, },
 };
 
+\f
+/* Map a bfd relocation into the appropriate howto structure */
 static reloc_howto_type *
-bfd_elf32_bfd_reloc_type_lookup (abfd, code)
+v850_elf_reloc_type_lookup (abfd, code)
      bfd *abfd;
      bfd_reloc_code_real_type code;
 {
   unsigned int i;
 
   for (i = 0;
-       i < sizeof (v850_reloc_map) / sizeof (struct v850_reloc_map);
+       i < sizeof (v850_elf_reloc_map) / sizeof (struct v850_elf_reloc_map);
        i++)
     {
-      if (v850_reloc_map[i].bfd_reloc_val == code)
-       return &elf_v850_howto_table[v850_reloc_map[i].elf_reloc_val];
+      if (v850_elf_reloc_map[i].bfd_reloc_val == code)
+       return &v850_elf_howto_table[v850_elf_reloc_map[i].elf_reloc_val];
     }
 
   return NULL;
 }
 
+\f
 /* Set the howto pointer for an V850 ELF reloc.  */
-
 static void
-v850_info_to_howto_rel (abfd, cache_ptr, dst)
+v850_elf_info_to_howto_rel (abfd, cache_ptr, dst)
      bfd *abfd;
      arelent *cache_ptr;
      Elf32_Internal_Rel *dst;
@@ -297,11 +290,151 @@ v850_info_to_howto_rel (abfd, cache_ptr, dst)
 
   r_type = ELF32_R_TYPE (dst->r_info);
   BFD_ASSERT (r_type < (unsigned int) R_V850_max);
-  cache_ptr->howto = &elf_v850_howto_table[r_type];
+  cache_ptr->howto = &v850_elf_howto_table[r_type];
+}
+
+\f
+/* Look through the relocs for a section during the first phase, and
+   allocate space in the global offset table or procedure linkage
+   table.  */
+
+static boolean
+v850_elf_check_relocs (abfd, info, sec, relocs)
+     bfd *abfd;
+     struct bfd_link_info *info;
+     asection *sec;
+     const Elf_Internal_Rela *relocs;
+{
+  boolean ret = true;
+  bfd *dynobj;
+  Elf_Internal_Shdr *symtab_hdr;
+  struct elf_link_hash_entry **sym_hashes;
+  const Elf_Internal_Rela *rel;
+  const Elf_Internal_Rela *rel_end;
+  asection *sreloc;
+  enum reloc_type r_type;
+  int other = 0;
+  const char *common = (const char *)0;
+
+  if (info->relocateable)
+    return true;
+
+#ifdef DEBUG
+  fprintf (stderr, "v850_elf_check_relocs called for section %s in %s\n",
+          bfd_get_section_name (abfd, sec),
+          bfd_get_filename (abfd));
+#endif
+
+  dynobj = elf_hash_table (info)->dynobj;
+  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  sym_hashes = elf_sym_hashes (abfd);
+  sreloc = NULL;
+
+  rel_end = relocs + sec->reloc_count;
+  for (rel = relocs; rel < rel_end; rel++)
+    {
+      unsigned long r_symndx;
+      struct elf_link_hash_entry *h;
+
+      r_symndx = ELF32_R_SYM (rel->r_info);
+      if (r_symndx < symtab_hdr->sh_info)
+       h = NULL;
+      else
+       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+
+      r_type = (enum reloc_type) ELF32_R_TYPE (rel->r_info);
+      switch (r_type)
+       {
+       default:
+       case R_V850_NONE:
+       case R_V850_9_PCREL:
+       case R_V850_22_PCREL:
+       case R_V850_HI16_S:
+       case R_V850_HI16:
+       case R_V850_LO16:
+       case R_V850_32:
+       case R_V850_16:
+       case R_V850_8:
+         break;
+
+       case R_V850_SDA_OFFSET:
+         other = V850_OTHER_SDA;
+         common = ".scommon";
+         goto small_data_common;
+
+       case R_V850_ZDA_OFFSET:
+         other = V850_OTHER_ZDA;
+         common = ".zcommon";
+         goto small_data_common;
+
+       case R_V850_TDA_OFFSET:
+         other = V850_OTHER_TDA;
+         common = ".tcommon";
+         /* fall through */
+
+#define V850_OTHER_MASK (V850_OTHER_TDA | V850_OTHER_SDA | V850_OTHER_ZDA)
+
+       small_data_common:
+         if (h)
+           {
+             h->other |= other;        /* flag which type of relocation was used */
+             if ((h->other & V850_OTHER_MASK) != (other & V850_OTHER_MASK)
+                 && (h->other & V850_OTHER_ERROR) == 0)
+               {
+                 const char *msg;
+
+                 switch (h->other & V850_OTHER_MASK)
+                   {
+                   default:
+                     msg = "Variable cannot occupy in multiple small data regions";
+                     break;
+                   case V850_OTHER_SDA | V850_OTHER_ZDA | V850_OTHER_TDA:
+                     msg = "Variable can only be in one of the small, zero, and tiny data regions";
+                     break;
+                   case V850_OTHER_SDA | V850_OTHER_ZDA:
+                     msg = "Variable cannot be in both small and zero data regions simultaneously";
+                     break;
+                   case V850_OTHER_SDA | V850_OTHER_TDA:
+                     msg = "Variable cannot be in both small and tiny data regions simultaneously";
+                     break;
+                   case V850_OTHER_ZDA | V850_OTHER_TDA:
+                     msg = "Variable cannot be in both zero and tiny data regions simultaneously";
+                     break;
+                   }
+
+                 (*info->callbacks->warning) (info, msg, h->root.root.string,
+                                              abfd, h->root.u.def.section, 0);
+
+                 bfd_set_error (bfd_error_bad_value);
+                 h->other |= V850_OTHER_ERROR;
+                 ret = false;
+               }
+           }
+
+         if (h->root.type == bfd_link_hash_common
+             && h->root.u.c.p
+             && !strcmp (bfd_get_section_name (abfd, h->root.u.c.p->section), "COMMON"))
+           {
+             asection *section = h->root.u.c.p->section = bfd_make_section_old_way (abfd, common);
+             section->flags |= SEC_IS_COMMON;
+           }
+
+#ifdef DEBUG
+         fprintf (stderr, "v850_elf_check_relocs, found %s relocation for %s%s\n",
+                  v850_elf_howto_table[ (int)r_type ].name,
+                  (h && h->root.root.string) ? h->root.root.string : "<unknown>",
+                  (h->root.type == bfd_link_hash_common) ? ", symbol is common" : "");
+#endif
+         break;
+       }
+    }
+
+  return ret;
 }
 
+\f
 static bfd_reloc_status_type
-bfd_elf32_v850_reloc (abfd, reloc, symbol, data, isection, obfd, err)
+v850_elf_reloc (abfd, reloc, symbol, data, isection, obfd, err)
      bfd *abfd;
      arelent *reloc;
      asymbol *symbol;
@@ -414,11 +547,10 @@ bfd_elf32_v850_reloc (abfd, reloc, symbol, data, isection, obfd, err)
   return bfd_reloc_continue;
 }
 
-static boolean bfd_elf32_v850_is_local_label PARAMS ((bfd *, asymbol *));
-
+\f
 /*ARGSUSED*/
 static boolean
-bfd_elf32_v850_is_local_label (abfd, symbol)
+v850_elf_is_local_label (abfd, symbol)
      bfd *abfd;
      asymbol *symbol;
 {
@@ -427,9 +559,10 @@ bfd_elf32_v850_is_local_label (abfd, symbol)
              && symbol->name[3] == '_'));
 }
 
+\f
 /* Perform a relocation as part of a final link.  */
 static bfd_reloc_status_type
-elf32_v850_bfd_final_link_relocate (howto, input_bfd, output_bfd,
+v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
                                    input_section, contents, offset, value,
                                    addend, info, sym_sec, is_local)
      reloc_howto_type *howto;
@@ -650,11 +783,11 @@ elf32_v850_bfd_final_link_relocate (howto, input_bfd, output_bfd,
 
 }
 
+\f
 /* Relocate an V850 ELF section.  */
-
 static boolean
 v850_elf_relocate_section (output_bfd, info, input_bfd, input_section,
-                        contents, relocs, local_syms, local_sections)
+                          contents, relocs, local_syms, local_sections)
      bfd *output_bfd;
      struct bfd_link_info *info;
      bfd *input_bfd;
@@ -705,7 +838,7 @@ v850_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
       r_type = ELF32_R_TYPE (rel->r_info);
 
-      howto = elf_v850_howto_table + r_type;
+      howto = v850_elf_howto_table + r_type;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
@@ -749,11 +882,11 @@ v850_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
       /* FIXME: We should use the addend, but the COFF relocations
          don't.  */
-      r = elf32_v850_bfd_final_link_relocate (howto, input_bfd, output_bfd,
-                                             input_section,
-                                             contents, rel->r_offset,
-                                             relocation, rel->r_addend,
-                                             info, sec, h == NULL);
+      r = v850_elf_final_link_relocate (howto, input_bfd, output_bfd,
+                                       input_section,
+                                       contents, rel->r_offset,
+                                       relocation, rel->r_addend,
+                                       info, sec, h == NULL);
 
       if (r != bfd_reloc_ok)
        {
@@ -789,19 +922,21 @@ v850_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
   return true;
 }
-#define bfd_elf32_bfd_is_local_label   bfd_elf32_v850_is_local_label
-
-#define TARGET_LITTLE_SYM              bfd_elf32_v850_vec
-#define TARGET_LITTLE_NAME             "elf32-v850"
-#define ELF_ARCH               bfd_arch_v850
-#define ELF_MACHINE_CODE       EM_CYGNUS_V850
-#define ELF_MAXPAGESIZE                0x1000
-
-#define elf_info_to_howto      0
-#define elf_info_to_howto_rel  v850_info_to_howto_rel
-#define elf_backend_relocate_section    v850_elf_relocate_section
-
 
-#define elf_symbol_leading_char '_'
+\f
+#define TARGET_LITTLE_SYM                      bfd_elf32_v850_vec
+#define TARGET_LITTLE_NAME                     "elf32-v850"
+#define ELF_ARCH                               bfd_arch_v850
+#define ELF_MACHINE_CODE                       EM_CYGNUS_V850
+#define ELF_MAXPAGESIZE                                0x1000
+       
+#define elf_info_to_howto                      0
+#define elf_info_to_howto_rel                  v850_elf_info_to_howto_rel
+#define elf_backend_check_relocs               v850_elf_check_relocs
+#define elf_backend_relocate_section           v850_elf_relocate_section
+#define bfd_elf32_bfd_is_local_label           v850_elf_is_local_label
+#define bfd_elf32_bfd_reloc_type_lookup                v850_elf_reloc_type_lookup
+
+#define elf_symbol_leading_char                        '_'
 
 #include "elf32-target.h"