New release Ada BFD 1.2.0

By Stephane Carrez

Ada BFD is an Ada binding for the GNU Binutils BFD library. It allows to read binary ELF, COFF files by using the GNU BFD and allows your program to read ELF sections, get access to the symbol table and use the disassembler.

The new release is a cleanup and update of the library to support newer version of GNU binutils. The main changes are below:

  • Cleanup build process and use gprinstall for installation
  • Fix build with binutils > 2.34
  • Remove invalid API: Bfd.Set\_Error\_Handler
  • Remove fake API: Bfd.Symbols.Is\_Local\_Label\_Name


To use the Ada BFD library, you may either build it from the sources ada-bfd-1.2.0.tar.gz or install the Debian packages.

To build from the sources, you need to have a working GNAT Ada compiler as well as the binutils-dev Debian package installed. Then, run the following commands:

git clone
cd ada-bfd
make build check install

For the Debian package installation, use the configuration that corresponds to your setup:

deb bionic main
deb focal main
deb buster main

and then run:

sudo apt-get update
# Bionic: sudo apt-get install libbfdada1-dev
# Focal:  sudo apt-get install libbfdada2-dev
# Buster: sudo apt-get install libbfdada3-dev

Reading the ELF sections

Using the Ada BFD library in a projet is quite easy, the first step is to add the following line in your GNAT project file:

with "bfdada";

To access the information of a binary, you must first define an instance of the File\_Type and open the file. You will do this as follows:

with Bfd.Files;
  Path : constant String := "..."; --  the binary to load
  File : Bfd.Files.File_Type;
  Bfd.Files.Open (File, Path, "");

Looking at the ELF section is easily made by using the Section\_Iterator provided by the Bfd.Sections package.

with Bfd.Sections;
  Iter : Bfd.Sections.Section_Iterator := Bfd.Sections.Get_Sections (File);
  while Bfd.Sections.Has_Element (Iter) loop
       S   : constant Bfd.Sections.Section := Bfd.Sections.Element (Iter);
       Ada.Text_IO.Put_Line (Bfd.Sections.Get_Name (S));
    Bfd.Sections.Next (Iter);
  end loop;

The library contains several examples that show different features of the Ada BFD library:

bfdinfo.adb./bin/bfdinfo ./bin/bfdgenOpen BFD file, get flags, list sections and symbols
sections.adb./bin/sections ./bin/bfdgenDisplay the ELF sections with the Bfd.Sections
symbol.adb./bin/symbol ./bin/bfdgen mainRead the symbol table with Bfd.Symbols
disassemble.adb./bin/disassemble ./bin/bfdgenDisassemble the text section with Bfd.Disassemble

Add a comment

To add a comment, you must be connected. Login