+
+#if !defined ONLY_DECLARE_RELOCS && ! defined STATIC_RELOCS
+/* Given a .data section and a .emreloc in-memory section, store
+ relocation information into the .emreloc section which can be
+ used at runtime to relocate the section. This is called by the
+ linker when the --embedded-relocs switch is used. This is called
+ after the add_symbols entry point has been called for all the
+ objects, and before the final_link entry point is called. */
+
+bfd_boolean
+bfd_m68k_coff_create_embedded_relocs (abfd, info, datasec, relsec, errmsg)
+ bfd *abfd;
+ struct bfd_link_info *info;
+ asection *datasec;
+ asection *relsec;
+ char **errmsg;
+{
+ char *extsyms;
+ bfd_size_type symesz;
+ struct internal_reloc *irel, *irelend;
+ bfd_byte *p;
+ bfd_size_type amt;
+
+ BFD_ASSERT (! info->relocatable);
+
+ *errmsg = NULL;
+
+ if (datasec->reloc_count == 0)
+ return TRUE;
+
+ extsyms = obj_coff_external_syms (abfd);
+ symesz = bfd_coff_symesz (abfd);
+
+ irel = _bfd_coff_read_internal_relocs (abfd, datasec, TRUE, NULL, FALSE,
+ NULL);
+ irelend = irel + datasec->reloc_count;
+
+ amt = (bfd_size_type) datasec->reloc_count * 12;
+ relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
+ if (relsec->contents == NULL)
+ return FALSE;
+
+ p = relsec->contents;
+
+ for (; irel < irelend; irel++, p += 12)
+ {
+ asection *targetsec;
+
+ /* We are going to write a four byte longword into the runtime
+ reloc section. The longword will be the address in the data
+ section which must be relocated. It is followed by the name
+ of the target section NUL-padded or truncated to 8
+ characters. */
+
+ /* We can only relocate absolute longword relocs at run time. */
+ if (irel->r_type != R_RELLONG)
+ {
+ *errmsg = _("unsupported reloc type");
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ if (irel->r_symndx == -1)
+ targetsec = bfd_abs_section_ptr;
+ else
+ {
+ struct coff_link_hash_entry *h;
+
+ h = obj_coff_sym_hashes (abfd)[irel->r_symndx];
+ if (h == NULL)
+ {
+ struct internal_syment isym;
+
+ bfd_coff_swap_sym_in (abfd, extsyms + symesz * irel->r_symndx,
+ &isym);
+ targetsec = coff_section_from_bfd_index (abfd, isym.n_scnum);
+ }
+ else if (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)
+ targetsec = h->root.u.def.section;
+ else
+ targetsec = NULL;
+ }
+
+ bfd_put_32 (abfd,
+ (irel->r_vaddr - datasec->vma + datasec->output_offset), p);
+ memset (p + 4, 0, 8);
+ if (targetsec != NULL)
+ strncpy ((char *) p + 4, targetsec->output_section->name, 8);
+ }
+
+ return TRUE;
+}
+#endif /* neither ONLY_DECLARE_RELOCS not STATIC_RELOCS */