+ free_no_table:
+ (*info->callbacks->einfo)
+ (_("%P: error in %B(%A); no .eh_frame_hdr table will be created.\n"),
+ abfd, sec);
+ hdr_info->u.dwarf.table = FALSE;
+ if (sec_info)
+ free (sec_info);
+ success:
+ if (ehbuf)
+ free (ehbuf);
+ if (local_cies)
+ free (local_cies);
+#undef REQUIRE
+}
+
+/* Order eh_frame_hdr entries by the VMA of their text section. */
+
+static int
+cmp_eh_frame_hdr (const void *a, const void *b)
+{
+ bfd_vma text_a;
+ bfd_vma text_b;
+ asection *sec;
+
+ sec = *(asection *const *)a;
+ sec = (asection *) elf_section_data (sec)->sec_info;
+ text_a = sec->output_section->vma + sec->output_offset;
+ sec = *(asection *const *)b;
+ sec = (asection *) elf_section_data (sec)->sec_info;
+ text_b = sec->output_section->vma + sec->output_offset;
+
+ if (text_a < text_b)
+ return -1;
+ return text_a > text_b;
+
+}
+
+/* Add space for a CANTUNWIND terminator to SEC if the text sections
+ referenced by it and NEXT are not contiguous, or NEXT is NULL. */
+
+static void
+add_eh_frame_hdr_terminator (asection *sec,
+ asection *next)
+{
+ bfd_vma end;
+ bfd_vma next_start;
+ asection *text_sec;
+
+ if (next)
+ {
+ /* See if there is a gap (presumably a text section without unwind info)
+ between these two entries. */
+ text_sec = (asection *) elf_section_data (sec)->sec_info;
+ end = text_sec->output_section->vma + text_sec->output_offset
+ + text_sec->size;
+ text_sec = (asection *) elf_section_data (next)->sec_info;
+ next_start = text_sec->output_section->vma + text_sec->output_offset;
+ if (end == next_start)
+ return;
+ }
+
+ /* Add space for a CANTUNWIND terminator. */
+ if (!sec->rawsize)
+ sec->rawsize = sec->size;
+
+ bfd_set_section_size (sec->owner, sec, sec->size + 8);
+}
+
+/* Finish a pass over all .eh_frame_entry sections. */
+
+bfd_boolean
+_bfd_elf_end_eh_frame_parsing (struct bfd_link_info *info)
+{
+ struct eh_frame_hdr_info *hdr_info;
+ unsigned int i;
+
+ hdr_info = &elf_hash_table (info)->eh_info;
+
+ if (info->eh_frame_hdr_type != COMPACT_EH_HDR
+ || hdr_info->array_count == 0)
+ return FALSE;
+
+ bfd_elf_discard_eh_frame_entry (hdr_info);
+
+ qsort (hdr_info->u.compact.entries, hdr_info->array_count,
+ sizeof (asection *), cmp_eh_frame_hdr);
+
+ for (i = 0; i < hdr_info->array_count - 1; i++)
+ {
+ add_eh_frame_hdr_terminator (hdr_info->u.compact.entries[i],
+ hdr_info->u.compact.entries[i + 1]);
+ }
+
+ /* Add a CANTUNWIND terminator after the last entry. */
+ add_eh_frame_hdr_terminator (hdr_info->u.compact.entries[i], NULL);
+ return TRUE;
+}
+
+/* Mark all relocations against CIE or FDE ENT, which occurs in
+ .eh_frame section SEC. COOKIE describes the relocations in SEC;
+ its "rel" field can be changed freely. */
+
+static bfd_boolean
+mark_entry (struct bfd_link_info *info, asection *sec,
+ struct eh_cie_fde *ent, elf_gc_mark_hook_fn gc_mark_hook,
+ struct elf_reloc_cookie *cookie)
+{
+ /* FIXME: octets_per_byte. */
+ for (cookie->rel = cookie->rels + ent->reloc_index;
+ cookie->rel < cookie->relend
+ && cookie->rel->r_offset < ent->offset + ent->size;
+ cookie->rel++)
+ if (!_bfd_elf_gc_mark_reloc (info, sec, gc_mark_hook, cookie))
+ return FALSE;
+
+ return TRUE;
+}
+
+/* Mark all the relocations against FDEs that relate to code in input
+ section SEC. The FDEs belong to .eh_frame section EH_FRAME, whose
+ relocations are described by COOKIE. */
+
+bfd_boolean
+_bfd_elf_gc_mark_fdes (struct bfd_link_info *info, asection *sec,
+ asection *eh_frame, elf_gc_mark_hook_fn gc_mark_hook,
+ struct elf_reloc_cookie *cookie)
+{
+ struct eh_cie_fde *fde, *cie;
+
+ for (fde = elf_fde_list (sec); fde; fde = fde->u.fde.next_for_section)