Object format

Compiled code is stored in a different format then the usual ELF format. A new format is used, coined ‘oj’. It is valid json and contains all the information that is also in ELF, but then in more plain text format. You can open and even edit an oj-object file with a text editor.

Object files are used to store assembled code.

Information contained is code, symbol table and relocation information.

The hierarchy is as follows:

  • an object file contains zero or more sections.
  • an object file may contains memory definitions, which contain a sequence of contained sections.
  • a section contains a name and data.
  • relocations are offset into a section, refer a symbol and have a type
  • symbols are offset into a section and have a name
  • debug data have an offset into a section and contain data.
  • sections cannot overlap
class ppci.binutils.objectfile.Image(name: str, address: int)

Memory image.

A memory image is a piece that can be loaded into memory.


Add a section to this memory image


Get the data of this memory


Determine the size of this memory

class ppci.binutils.objectfile.ObjectFile(arch)

Container for sections with compiled code or data. Also contains symbols and relocation entries. Also contains debug information.


Add an image


Add a relocation entry


Add a section

add_symbol(id, name, binding, value, section, typ, size)

Define a new symbol


Get the size in bytes of this object file


Create and add a section with the given name.


Remove a symbol with a given name


Get a list of defined symbols.


Get a memory image

get_section(name, create=False)

Get or create a section with the given name


Get a symbol


Lookup a symbol and determine its value


Get a list of undefined symbols.


Check if the object file has a section with the given name


Check if this object file has a symbol with name ‘name’


Test if this object file is executable by checking the entry point.

static load(input_file)

Load object file from file


Save object file to a file like object


Serialize the object into a dictionary structure suitable for json.

class ppci.binutils.objectfile.RelocationEntry(reloc_type, symbol_id, section, offset, addend)

A relocation entry.

While it mich be confusing to have Relocation here, and RelocationType in arch.encoding, this is cleaner, since the relocation here is a record indicating a relocation, while the relocation type is emitted by instructions and can actually apply the relocation.

This class is a record holding information on where to a apply which relocation. Not how to do the actual relocation.

class ppci.binutils.objectfile.Section(name)

A defined region of data in the object file


Append data to the end of this section

class ppci.binutils.objectfile.Symbol(id, name, binding, value, section, typ, size)

A symbol definition in an object file


Test if this symbol is a function.


Test if this symbol is undefined.


Create an object file from dict-like data


Try hard to load an object

ppci.binutils.objectfile.merge_memories(mem1, mem2, name)

Merge two memories into a new one


Display an object in a user friendly manner


Serialize an object so it can be json-ified, or serialized