asection *bfd_get_section_by_name (bfd *abfd, const char *name);
DESCRIPTION
- Run through @var{abfd} and return the one of the
- <<asection>>s whose name matches @var{name}, otherwise <<NULL>>.
- @xref{Sections}, for more information.
-
- This should only be used in special cases; the normal way to process
- all sections of a given name is to use <<bfd_map_over_sections>> and
- <<strcmp>> on the name (or better yet, base it on the section flags
- or something else) for each section.
+ Return the most recently created section attached to @var{abfd}
+ named @var{name}. Return NULL if no such section exists.
*/
asection *
return NULL;
}
+/*
+FUNCTION
+ bfd_get_next_section_by_name
+
+SYNOPSIS
+ asection *bfd_get_next_section_by_name (asection *sec);
+
+DESCRIPTION
+ Given @var{sec} is a section returned by @code{bfd_get_section_by_name},
+ return the next most recently created section attached to the same
+ BFD with the same name. Return NULL if no such section exists.
+*/
+
+asection *
+bfd_get_next_section_by_name (asection *sec)
+{
+ struct section_hash_entry *sh;
+ const char *name;
+ unsigned long hash;
+
+ sh = ((struct section_hash_entry *)
+ ((char *) sec - offsetof (struct section_hash_entry, section)));
+
+ hash = sh->root.hash;
+ name = sec->name;
+ for (sh = (struct section_hash_entry *) sh->root.next;
+ sh != NULL;
+ sh = (struct section_hash_entry *) sh->root.next)
+ if (sh->root.hash == hash
+ && strcmp (sh->root.string, name) == 0)
+ return &sh->section;
+
+ return NULL;
+}
+
+/*
+FUNCTION
+ bfd_get_linker_section
+
+SYNOPSIS
+ asection *bfd_get_linker_section (bfd *abfd, const char *name);
+
+DESCRIPTION
+ Return the linker created section attached to @var{abfd}
+ named @var{name}. Return NULL if no such section exists.
+*/
+
+asection *
+bfd_get_linker_section (bfd *abfd, const char *name)
+{
+ asection *sec = bfd_get_section_by_name (abfd, name);
+
+ while (sec != NULL && (sec->flags & SEC_LINKER_CREATED) == 0)
+ sec = bfd_get_next_section_by_name (sec);
+ return sec;
+}
+
/*
FUNCTION
bfd_get_section_by_name_if
This is the preferred method for iterating over sections; an
alternative would be to use a loop:
-| section *p;
+| asection *p;
| for (p = abfd->sections; p != NULL; p = p->next)
| func (abfd, p, ...)