The bcode file format

bcode is LARD's binary file format. A bcode file may be an unlinked object file, a partially linked library, or an "executable" program.

A bcode file is made up from a number of sections. The first section is a header section which describes the other sections present in the file, giving their locations within the file and their types. This document describes the formats used for the header and other section types.

There may be no more than one section of each type in each file.

The Header Section

The header section contains a number of section descriptor records:

struct section_desc
  int sect_type;
  int start;
  int end;
  int private1;
  int private2;
sect_type indicates the type of the section. The first section descriptor record describes the header section so this field has the value HEADER_SECTTYPE. Since this is the first word of the file it is also used as a magic number to identify the file as a bcode file.

start and end give the file offsets of the start of the section and the byte after the end of the section.

private1 and private2 have meanings that are specific to each section type.

The Code Section (CODE_SECTTYPE)

The code section contains compiled icode. The encoding of the instructions is not described here.

The Relocations Section (RELOC_SECTTYPE)

The relocations section describes locations in the code section which need to be changed to refer to a valid symbol during linking.

The section consists of a sequence of location-symbol pairs. The location is a word offset into the code section and the symbol is a null-terminated string. The pair is followed by further nulls to align the next pair on a word boundary.

The External Symbols Section (EXTERNSYM_SECTTYPE)

The external symbols section gives symbolic names to particular locations in the code section. These symbolic names are used during linking to resolve relocations required by other files.

The section consists of location-symbol pairs in the same form as the relocations section.

The Internal Symbols Section (INTERNSYM_SECTTYPE)

The internal symbols section describes additional symbols that are not required for linking but which may be retained for debugging. It has the same format as the external symbols section.