These are the functions exported by the section handling part of BFD.
bfd_section_list_clear
bfd_get_section_by_name
bfd_get_next_section_by_name
bfd_get_linker_section
bfd_get_section_by_name_if
bfd_get_unique_section_name
bfd_make_section_old_way
bfd_make_section_anyway_with_flags
bfd_make_section_anyway
bfd_make_section_with_flags
bfd_make_section
bfd_set_section_flags
bfd_rename_section
bfd_map_over_sections
bfd_sections_find_if
bfd_set_section_size
bfd_set_section_contents
bfd_get_section_contents
bfd_malloc_and_get_section
bfd_copy_private_section_data
bfd_generic_is_group_section
bfd_generic_group_name
bfd_generic_discard_group
_bfd_section_size_insane
bfd_section_list_clear
void
bfd_section_list_clear (bfd *);
¶Clears the section list, and also resets the section count and hash table entries.
bfd_get_section_by_name
asection
*bfd_get_section_by_name (bfd *abfd, const char *name);
¶Return the most recently created section attached to abfd named name. Return NULL if no such section exists.
bfd_get_next_section_by_name
asection
*bfd_get_next_section_by_name (bfd *ibfd, asection *sec);
¶Given sec is a section returned by bfd_get_section_by_name
,
return the next most recently created section attached to the same
BFD with the same name, or if no such section exists in the same BFD and
IBFD is non-NULL, the next section with the same name in any input
BFD following IBFD. Return NULL on finding no section.
bfd_get_linker_section
asection
*bfd_get_linker_section (bfd *abfd, const char *name);
¶Return the linker created section attached to abfd named name. Return NULL if no such section exists.
bfd_get_section_by_name_if
asection
*bfd_get_section_by_name_if (bfd *abfd, const char *name, bool (*func) (bfd *abfd, asection *sect, void *obj), void *obj);
¶Call the provided function func for each section attached to the BFD abfd whose name matches name, passing obj as an argument. The function will be called as if by
func (abfd, the_section, obj);
It returns the first section for which func returns true,
otherwise NULL
.
bfd_get_unique_section_name
char
*bfd_get_unique_section_name (bfd *abfd, const char *templat, int *count);
¶Invent a section name that is unique in abfd by tacking a dot and a digit suffix onto the original templat. If count is non-NULL, then it specifies the first number tried as a suffix to generate a unique name. The value pointed to by count will be incremented in this case.
bfd_make_section_old_way
asection
*bfd_make_section_old_way (bfd *abfd, const char *name);
¶Create a new empty section called name and attach it to the end of the chain of sections for the BFD abfd. An attempt to create a section with a name which is already in use returns its pointer without changing the section chain.
It has the funny name since this is the way it used to be before it was rewritten....
Possible errors are:
bfd_error_invalid_operation
-
If output has already started for this BFD.
bfd_error_no_memory
-
If memory allocation fails.
bfd_make_section_anyway_with_flags
asection
*bfd_make_section_anyway_with_flags (bfd *abfd, const char *name, flagword flags);
¶Create a new empty section called name and attach it to the end of the chain of sections for abfd. Create a new section even if there is already a section with that name. Also set the attributes of the new section to the value flags.
Return NULL
and set bfd_error
on error; possible errors are:
bfd_error_invalid_operation
- If output has already started for abfd.
bfd_error_no_memory
- If memory allocation fails.
bfd_make_section_anyway
asection
*bfd_make_section_anyway (bfd *abfd, const char *name);
¶Create a new empty section called name and attach it to the end of the chain of sections for abfd. Create a new section even if there is already a section with that name.
Return NULL
and set bfd_error
on error; possible errors are:
bfd_error_invalid_operation
- If output has already started for abfd.
bfd_error_no_memory
- If memory allocation fails.
bfd_make_section_with_flags
asection
*bfd_make_section_with_flags (bfd *, const char *name, flagword flags);
¶Like bfd_make_section_anyway
, but return NULL
(without calling
bfd_set_error ()) without changing the section chain if there is already a
section named name. Also set the attributes of the new section to
the value flags. If there is an error, return NULL
and set
bfd_error
.
bfd_make_section
asection
*bfd_make_section (bfd *, const char *name);
¶Like bfd_make_section_anyway
, but return NULL
(without calling
bfd_set_error ()) without changing the section chain if there is already a
section named name. If there is an error, return NULL
and set
bfd_error
.
bfd_set_section_flags
bool
bfd_set_section_flags (asection *sec, flagword flags);
¶Set the attributes of the section sec to the value flags.
Return TRUE
on success, FALSE
on error. Possible error
returns are:
bfd_error_invalid_operation
-
The section cannot have one or more of the attributes
requested. For example, a .bss section in a.out
may not
have the SEC_HAS_CONTENTS
field set.
bfd_rename_section
void
bfd_rename_section (asection *sec, const char *newname);
¶Rename section sec to newname.
bfd_map_over_sections
void
bfd_map_over_sections (bfd *abfd, void (*func) (bfd *abfd, asection *sect, void *obj), void *obj);
¶Call the provided function func for each section attached to the BFD abfd, passing obj as an argument. The function will be called as if by
func (abfd, the_section, obj);
This is the preferred method for iterating over sections; an alternative would be to use a loop:
asection *p; for (p = abfd->sections; p != NULL; p = p->next) func (abfd, p, ...)
bfd_sections_find_if
asection
*bfd_sections_find_if (bfd *abfd, bool (*operation) (bfd *abfd, asection *sect, void *obj), void *obj);
¶Call the provided function operation for each section attached to the BFD abfd, passing obj as an argument. The function will be called as if by
operation (abfd, the_section, obj);
It returns the first section for which operation returns true.
bfd_set_section_size
bool
bfd_set_section_size (asection *sec, bfd_size_type val);
¶Set sec to the size val. If the operation is
ok, then TRUE
is returned, else FALSE
.
Possible error returns:
bfd_error_invalid_operation
-
Writing has started to the BFD, so setting the size is invalid.
bfd_set_section_contents
bool
bfd_set_section_contents (bfd *abfd, asection *section, const void *data, file_ptr offset, bfd_size_type count);
¶Sets the contents of the section section in BFD abfd to the data starting in memory at location. The data is written to the output section starting at offset offset for count octets.
Normally TRUE
is returned, but FALSE
is returned if
there was an error. Possible error returns are:
bfd_error_no_contents
-
The output section does not have the SEC_HAS_CONTENTS
attribute, so nothing can be written to it.
bfd_error_bad_value
-
The section is unable to contain all of the data.
bfd_error_invalid_operation
-
The BFD is not writeable.
This routine is front end to the back end function
_bfd_set_section_contents
.
bfd_get_section_contents
bool
bfd_get_section_contents (bfd *abfd, asection *section, void *location, file_ptr offset, bfd_size_type count);
¶Read data from section in BFD abfd into memory starting at location. The data is read at an offset of offset from the start of the input section, and is read for count bytes.
If the contents of a constructor with the SEC_CONSTRUCTOR
flag set are requested or if the section does not have the
SEC_HAS_CONTENTS
flag set, then the location is filled
with zeroes. If no errors occur, TRUE
is returned, else
FALSE
.
bfd_malloc_and_get_section
bool
bfd_malloc_and_get_section (bfd *abfd, asection *section, bfd_byte **buf);
¶Read all data from section in BFD abfd
into a buffer, *buf, malloc’d by this function.
Return true
on success, false
on failure in which
case *buf will be NULL.
bfd_copy_private_section_data
bool
bfd_copy_private_section_data (bfd *ibfd, asection *isec, bfd *obfd, asection *osec);
¶Copy private section information from isec in the BFD
ibfd to the section osec in the BFD obfd.
Return TRUE
on success, FALSE
on error. Possible error
returns are:
bfd_error_no_memory
-
Not enough memory exists to create private data for osec.
#define bfd_copy_private_section_data(ibfd, isection, obfd, osection) \ BFD_SEND (obfd, _bfd_copy_private_section_data, \ (ibfd, isection, obfd, osection))
bfd_generic_is_group_section
bool
bfd_generic_is_group_section (bfd *, const asection *sec);
¶Returns TRUE if sec is a member of a group.
bfd_generic_group_name
const
char *bfd_generic_group_name (bfd *, const asection *sec);
¶Returns group name if sec is a member of a group.
bfd_generic_discard_group
bool
bfd_generic_discard_group (bfd *abfd, asection *group);
¶Remove all members of group from the output.
_bfd_section_size_insane
bool
_bfd_section_size_insane (bfd *abfd, asection *sec);
¶Returns true if the given section has a size that indicates it cannot be read from file. Return false if the size is OK or* this function can’t say one way or the other.