librel -- the Microsoft REL object format
=========================================

librel is the one implementation of the Microsoft REL (LINK-80 compatible)
object format in this project.  Everything that reads or writes a .REL file
links against it: the assembler mz80, the linker mlink, the system generator
gen, and the reconstruction tools relmap, relir, relcmp, relfix, serial,
package and disasm.

There is exactly one copy of the item table, which is the point.  A second
copy could drift, and a symmetric error in a reader and a writer -- both
consuming a field the format does not have -- is precisely the failure a
round-trip test cannot catch.


Three layers

    rel.h, relread.c, relwrite.c
        The codec.  REL is a BIT stream, not a byte stream: bits are
        consumed most-significant first, nothing is aligned to a byte, and
        16-bit values are low byte first but not byte aligned, so they
        cannot be read with a cast.  The reader returns one decoded item at
        a time; the writer is its strict inverse over the same field table.

    irload.h, irload.c
        The loader.  It turns an item stream into a structured module:
        segment images at nominal base zero, a relocation map, a map of the
        space that was RESERVED and never written, the COMMON block each
        common-relative word points into, the publics, and each external
        with its chain already walked into a list of sites.

    rellink.h, rellink.c
        The linking core.  A global symbol table, a 64K image, segment
        placement, relocation, external resolution, and writers for raw
        binary, CP/M .COM, Intel HEX and .SYM.

Layout POLICY is deliberately not here, and the omission is the design.
rl_place() is told where a segment goes and does as it is told.  LINK-80
interleaves data and program per module from one origin; TurboDOS's GEN sorts
six segment classes around a boundary and can build downward.  A library that
chose between them could serve only one, so this one follows NEITHER: it
supplies the mechanism and no policy at all.

mlink is currently the only consumer of the linking core.  gen(1) links from
the same codec and the same loader but has its own placement and its own
image, written before rellink existed and left alone because it passes a
byte-identical acceptance test.


Building and installing

    make ; sudo make install

installs librel.a, the three headers and the manual page.


Testing

    make test

The unit tests cover the codec's round trip over every item the format
defines, and the linking core's arithmetic.  What the library is for is
tested where it is used: mz80 against the real MACRO-80, mlink against the
real LINK-80, and gen against the original GEN, each over a corpus of real
object files.


Provenance

The item table is transcribed in docs/RELFORMAT.md of the TurboDOS
reconstruction, from Microsoft's LINK-80 manual, and corroborated against
440 files, 1,144 modules and 552,241 items with zero decode errors.  Note in
particular that item 4 carries a B field ONLY: the project brief says A+B,
and consuming an A field there would desynchronise the whole stream.


Licence

BSD 2-Clause; see the head of any source file.
