+/* Add a name to the section renaming list. */
+
+static void
+add_section_rename (const char * old_name, const char * new_name,
+ flagword flags)
+{
+ section_rename * rename;
+
+ /* Check for conflicts first. */
+ for (rename = section_rename_list; rename != NULL; rename = rename->next)
+ if (strcmp (rename->old_name, old_name) == 0)
+ {
+ /* Silently ignore duplicate definitions. */
+ if (strcmp (rename->new_name, new_name) == 0
+ && rename->flags == flags)
+ return;
+
+ fatal (_("Multiple renames of section %s"), old_name);
+ }
+
+ rename = xmalloc (sizeof (* rename));
+
+ rename->old_name = old_name;
+ rename->new_name = new_name;
+ rename->flags = flags;
+ rename->next = section_rename_list;
+
+ section_rename_list = rename;
+}
+
+/* Check the section rename list for a new name of the input section
+ ISECTION. Return the new name if one is found.
+ Also set RETURNED_FLAGS to the flags to be used for this section. */
+
+static const char *
+find_section_rename (bfd * ibfd ATTRIBUTE_UNUSED, sec_ptr isection,
+ flagword * returned_flags)
+{
+ const char * old_name = bfd_section_name (ibfd, isection);
+ section_rename * rename;
+
+ /* Default to using the flags of the input section. */
+ * returned_flags = bfd_get_section_flags (ibfd, isection);
+
+ for (rename = section_rename_list; rename != NULL; rename = rename->next)
+ if (strcmp (rename->old_name, old_name) == 0)
+ {
+ if (rename->flags != (flagword) -1)
+ * returned_flags = rename->flags;
+
+ return rename->new_name;
+ }
+
+ return old_name;
+}
+
+/* Once each of the sections is copied, we may still need to do some
+ finalization work for private section headers. Do that here. */
+
+static void
+setup_bfd_headers (bfd *ibfd, bfd *obfd)
+{
+ const char *err;
+
+ /* Allow the BFD backend to copy any private data it understands
+ from the input section to the output section. */
+ if (! bfd_copy_private_header_data (ibfd, obfd))
+ {
+ err = _("private header data");
+ goto loser;
+ }
+
+ /* All went well. */
+ return;
+
+loser:
+ non_fatal (_("%s: error in %s: %s"),
+ bfd_get_filename (ibfd),
+ err, bfd_errmsg (bfd_get_error ()));
+ status = 1;
+}
+
+/* Create a section in OBFD with the same
+ name and attributes as ISECTION in IBFD. */