+/* Read and return the section contents at DATA converted to a host
+ integer (bfd_vma). The number of bytes read is given by the HOWTO. */
+
+static bfd_vma
+read_reloc (bfd *abfd, bfd_byte *data, reloc_howto_type *howto)
+{
+ switch (howto->size)
+ {
+ case 0:
+ return bfd_get_8 (abfd, data);
+
+ case 1:
+ return bfd_get_16 (abfd, data);
+
+ case 2:
+ return bfd_get_32 (abfd, data);
+
+ case 3:
+ break;
+
+#ifdef BFD64
+ case 4:
+ return bfd_get_64 (abfd, data);
+#endif
+
+ case 5:
+ return bfd_get_24 (abfd, data);
+
+ default:
+ abort ();
+ }
+ return 0;
+}
+
+/* Convert VAL to target format and write to DATA. The number of
+ bytes written is given by the HOWTO. */
+
+static void
+write_reloc (bfd *abfd, bfd_vma val, bfd_byte *data, reloc_howto_type *howto)
+{
+ switch (howto->size)
+ {
+ case 0:
+ bfd_put_8 (abfd, val, data);
+ break;
+
+ case 1:
+ bfd_put_16 (abfd, val, data);
+ break;
+
+ case 2:
+ bfd_put_32 (abfd, val, data);
+ break;
+
+ case 3:
+ break;
+
+#ifdef BFD64
+ case 4:
+ bfd_put_64 (abfd, val, data);
+ break;
+#endif
+
+ case 5:
+ bfd_put_24 (abfd, val, data);
+ break;
+
+ default:
+ abort ();
+ }
+}
+
+/* Apply RELOCATION value to target bytes at DATA, according to
+ HOWTO. */
+
+static void
+apply_reloc (bfd *abfd, bfd_byte *data, reloc_howto_type *howto,
+ bfd_vma relocation)
+{
+ bfd_vma val = read_reloc (abfd, data, howto);
+
+ if (howto->negate)
+ relocation = -relocation;
+
+ val = ((val & ~howto->dst_mask)
+ | (((val & howto->src_mask) + relocation) & howto->dst_mask));
+
+ write_reloc (abfd, val, data, howto);
+}
+