Skip to content
Surf Wiki
Save to docs
general/c-programming-language-libraries

From Surf Wiki (app.surf) — the open knowledge base

Binary File Descriptor library

GNU support for multiple executable file formats


GNU support for multiple executable file formats

FieldValue
nameBinary File Descriptor library
logo
screenshot
authorCygnus Solutions
released
latest release date
latest preview date
programming languageC
platform
genreLibrary
licenseGNU General Public License

The Binary File Descriptor library (BFD) is the GNU Project's main mechanism for the portable manipulation of object files in a variety of formats. , it supports approximately 50 file formats and 25 instruction set architectures.

History

When David Henkel-Wallace of Cygnus Support proposed developing the library as a way to open up new business opportunities for the company, Richard Stallman said that it would be difficult; David's response was that it wasn't such a "Big Fucking Deal". Abbreviated to "BFD", this became the library name. | access-date = 2011-11-11

Design

BFD works by presenting a common abstract view of object files. An object file has a "header" with descriptive info; a variable number of "sections" that each has a name, some attributes, and a block of data; a symbol table; relocation entries; and so forth.

Internally, BFD translates the data from the abstract view into the details of the bit/byte layout required by the target processor and file format. Its key services include handling byte order differences, such as between a little-endian host and big-endian target, correct conversion between 32-bit and 64-bit data, and details of address arithmetic specified by relocation entries.

BFD library can be logically divided into two parts. The front-end and the back-end. The front-end gives a common interface independent of underlying object file view. Users will be interacting with the object files with this interface. Even if the layout of the object files are not known to the user, the user would still be able to use the interface. This hiding of the detail is done with the help of the back-end. The back-end implements how the front-end interface interacts with the object files layout. Whenever a new object files type is introduced the back-end needs to register the type and implement it if it needs to be supported by the BFD application.

Although BFD was originally designed to be a generic library usable by a wide variety of tools, the frequent need to tinker with the API to accommodate new systems' capabilities has tended to limit its use; BFD's main clients are the GNU Assembler (GAS), GNU Linker (GLD), and other GNU Binary Utilities ("binutils") tools, and the GNU Debugger (GDB). As a result, BFD is not distributed separately, but is always included with releases of binutils and GDB. Nevertheless, BFD is a critical component in the use of GNU tools for embedded systems development.

The BFD library can be used to read the structured data out of a core dump.

BFD library usage

Eg: Print object file size using bfd library APIs.

#include "bfd.h"
#include <stdio.h>

int main()
{
  bfd* abfd = bfd_openr("a.o", NULL); 
  printf("%llu\n", bfd_get_size(abfd));
  return 0;
}

Build command: gcc main.c -lbfd -o output ./output # prints the size

References

References

  1. [https://ftp.gnu.org/old-gnu/Manuals/bfd-2.9.1/html_chapter/bfd_1.html BFD specification]
  2. Langasek, Steve. (2005-05-22). "Re: depending on shared libbfd from binutils-dev".
  3. Kuratomi, Toshio. (2010-06-04). "binutils once more".
  4. Taylor, Ian. (2003-09-12). "Re: FreeBSD 4.6 - binutils 2.14 installs useless libbfd".
  5. "GNU ld manual - 1. Overview". [[GNU Project]]}} See also: {{cite web.
Info: Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about Binary File Descriptor library — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report