+\f
+/* Returns TRUE if the specified section should be dumped. */
+
+static bfd_boolean
+process_section_p (asection * section)
+{
+ struct only * only;
+
+ if (only_list == NULL)
+ return TRUE;
+
+ for (only = only_list; only; only = only->next)
+ if (strcmp (only->name, section->name) == 0)
+ {
+ only->seen = TRUE;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* Add an entry to the 'only' list. */
+
+static void
+add_only (char * name)
+{
+ struct only * only;
+
+ /* First check to make sure that we do not
+ already have an entry for this name. */
+ for (only = only_list; only; only = only->next)
+ if (strcmp (only->name, name) == 0)
+ return;
+
+ only = xmalloc (sizeof * only);
+ only->name = name;
+ only->seen = FALSE;
+ only->next = only_list;
+ only_list = only;
+}
+
+/* Release the memory used by the 'only' list.
+ PR 11225: Issue a warning message for unseen sections.
+ Only do this if none of the sections were seen. This is mainly to support
+ tools like the GAS testsuite where an object file is dumped with a list of
+ generic section names known to be present in a range of different file
+ formats. */
+
+static void
+free_only_list (void)
+{
+ bfd_boolean at_least_one_seen = FALSE;
+ struct only * only;
+ struct only * next;
+
+ if (only_list == NULL)
+ return;
+
+ for (only = only_list; only; only = only->next)
+ if (only->seen)
+ {
+ at_least_one_seen = TRUE;
+ break;
+ }
+
+ for (only = only_list; only; only = next)
+ {
+ if (! at_least_one_seen)
+ {
+ non_fatal (_("Section '%s' mentioned in a -j option, but not found in any input file"),
+ only->name);
+ exit_status = 1;
+ }
+ next = only->next;
+ free (only);
+ }
+}
+