+
+/* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the
+ current set of target sections. */
+
+void
+add_target_sections (struct target_section *sections,
+ struct target_section *sections_end)
+{
+ int count;
+ struct target_section_table *table = current_target_sections;
+
+ count = sections_end - sections;
+
+ if (count > 0)
+ {
+ int space = resize_section_table (table, count);
+ memcpy (table->sections + space,
+ sections, count * sizeof (sections[0]));
+
+ /* If these are the first file sections we can provide memory
+ from, push the file_stratum target. */
+ if (space == 0)
+ push_target (&exec_ops);
+ }
+}
+
+/* Remove all target sections taken from ABFD. */
+
+void
+remove_target_sections (bfd *abfd)
+{
+ struct target_section *src, *dest;
+
+ struct target_section_table *table = current_target_sections;
+
+ dest = table->sections;
+ for (src = table->sections; src < table->sections_end; src++)
+ if (src->bfd != abfd)
+ {
+ /* Keep this section. */
+ if (dest < src)
+ *dest = *src;
+ dest++;
+ }
+
+ /* If we've dropped any sections, resize the section table. */
+ if (dest < src)
+ {
+ int old_count;
+
+ old_count = resize_section_table (table, dest - src);
+
+ /* If we don't have any more sections to read memory from,
+ remove the file_stratum target from the stack. */
+ if (old_count + (dest - src) == 0)
+ unpush_target (&exec_ops);
+ }
+}
+