A format is a BFD concept of high level file contents type. The formats supported by BFD are:
bfd_object
The BFD may contain data, symbols, relocations and debug info.
bfd_archive
The BFD contains other BFDs and an optional index.
bfd_core
The BFD contains the result of an executable core dump.
bfd_check_format
bool
bfd_check_format (bfd *abfd, bfd_format format);
¶Verify if the file attached to the BFD abfd is compatible
with the format format (i.e., one of bfd_object
,
bfd_archive
or bfd_core
).
If the BFD has been set to a specific target before the
call, only the named target and format combination is
checked. If the target has not been set, or has been set to
default
, then all the known target backends is
interrogated to determine a match. If the default target
matches, it is used. If not, exactly one target must recognize
the file, or an error results.
The function returns TRUE
on success, otherwise FALSE
with one of the following error codes:
bfd_error_invalid_operation
-
if format
is not one of bfd_object
, bfd_archive
or
bfd_core
.
bfd_error_system_call
-
if an error occured during a read - even some file mismatches
can cause bfd_error_system_calls.
file_not_recognised
-
none of the backends recognised the file format.
bfd_error_file_ambiguously_recognized
-
more than one backend recognised the file format.
When calling bfd_check_format (or bfd_check_format_matches), any underlying file descriptor will be kept open for the duration of the call. This is done to avoid races when another thread calls bfd_cache_close_all. In this scenario, the thread calling bfd_check_format must call bfd_cache_close itself.
bfd_check_format_matches
bool
bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching);
¶Like bfd_check_format
, except when it returns FALSE with
bfd_errno
set to bfd_error_file_ambiguously_recognized
. In that
case, if matching is not NULL, it will be filled in with
a NULL-terminated list of the names of the formats that matched,
allocated with malloc
.
Then the user may choose a format and try again.
When done with the list that matching points to, the caller should free it.
bfd_set_format
bool
bfd_set_format (bfd *abfd, bfd_format format);
¶This function sets the file format of the BFD abfd to the format format. If the target set in the BFD does not support the format requested, the format is invalid, or the BFD is not open for writing, then an error occurs.
bfd_format_string
const
char *bfd_format_string (bfd_format format);
¶Return a pointer to a const string
invalid
, object
, archive
, core
, or unknown
,
depending upon the value of format.