← New search

Other meanings of Binary File Descriptor

Computing

Binary File Descriptor

A Binary File Descriptor (BFD) is a data structure and an associated library in the GNU Binutils suite that provides a common interface for reading and writing object files in various binary formats, such as ELF, COFF, and Mach-O. It abstracts the details of each format, allowing tools like the GNU assembler, linker, and debugger to operate on binaries without knowing their specific layout. The BFD library also includes a set of routines for manipulating these descriptors, enabling operations like symbol table access, relocation processing, and section management.

1988
Initial development
Year BFD was introduced in GNU Binutils
~20
Supported formats
Approximate number of binary formats supported
libbfd
Library name
The library implementing BFD
1

Overview and Purpose

The Binary File Descriptor library, commonly referred to as libbfd, was created to unify the handling of diverse object file formats within the GNU toolchain. Before BFD, each tool had to implement its own format-specific code, leading to duplication and maintenance burdens. BFD provides a set of C functions that operate on a bfd structure, which represents an open binary file. This structure contains pointers to format-specific data and a vector of function pointers that implement the actual operations, such as reading symbols or writing sections.1

The primary consumers of BFD are the GNU assembler (as), the GNU linker (ld), and the GNU debugger (gdb). By using BFD, these tools can support new binary formats by adding a new backend to the library, without altering their core logic. This design has made BFD a cornerstone of cross-platform development, enabling the same toolchain to target multiple operating systems and architectures.2

2

Architecture and Implementation

The BFD library is organized around a central bfd structure that holds the state of an open file, including its format, architecture, and a pointer to a bfd_target structure. The bfd_target contains function pointers for all operations, such as _bfd_read_headers, _bfd_slurp_symbol_table, and _bfd_write_contents. Each supported format—ELF, COFF, a.out, Mach-O, and others—provides its own implementation of these functions, which are selected at runtime based on the file's magic number or other identifying features.

One notable aspect of BFD is its handling of relocations and symbol tables. The library abstracts these into generic structures, allowing tools to manipulate them without knowing the underlying format. However, this abstraction has been criticized for being complex and sometimes leaky, as certain format-specific features are not fully exposed. Despite this, BFD remains the standard interface for binary manipulation in the GNU ecosystem, and its design has influenced other projects like LLVM's object library.3

3

Supported Formats and Usage

BFD supports a wide range of object file formats, including ELF (used on Linux and many Unix-like systems), COFF (historically used on Windows and some Unix variants), a.out (the classic Unix format), and Mach-O (used on macOS and iOS). It also handles archive files (e.g., .a libraries) and can read and write core dumps. The library is used not only by the GNU tools but also by other projects, such as the objdump utility, which relies on BFD to disassemble binaries, and the strip command, which removes symbol tables.4

Developers can use BFD directly by including bfd.h and linking against -lbfd. The library provides functions to open a file, iterate over sections, read and write symbols, and perform relocations. While the API is stable, it is considered low-level and requires careful memory management. For higher-level operations, tools like libelf or pyelftools are sometimes preferred, but BFD remains the most portable and comprehensive option for cross-format binary manipulation.5

4

Lesser-known aspects

One lesser-known fact is that BFD was originally written by David Henkel-Wallace and Steve Chamberlain, with contributions from many others, and it was first released in 1988 as part of the GNU Binutils project. The name "BFD" is often jokingly expanded as "Big Friggin' Deal" or "Binary File Descriptor," reflecting its central role in the toolchain.

Another obscure detail is that BFD includes support for unusual formats like IEEE-695, a format used by some embedded systems, and S-record files, which are plain-text hex dumps used in microcontroller programming. Additionally, BFD can handle compressed debug sections (e.g., .zdebug), which are used to reduce the size of debug information in binaries. The library also provides a mechanism for "target vectors" that allow runtime selection of the appropriate backend, and it can even be extended with user-defined formats.6

Glossary

BFD
Binary File Descriptor; a library and data structure for handling binary object files.
ELF
Executable and Linkable Format; a common object file format on Unix-like systems.
COFF
Common Object File Format; an older format used on Windows and some Unix systems.
Mach-O
Mach Object file format; used on macOS and iOS.
Relocation
The process of adjusting addresses in a binary to reflect its final memory layout.

BFD is a foundational component of the GNU toolchain, enabling cross-platform binary manipulation.