Introduction
An assembler or compiler writes an object file; a linker joins object files, and the units of link libraries, into a load file. The blocks are the ones in a load file, with a few
more: a unit has a name, its hunks have names, and HUNK_EXT lists the symbols it defines and the ones it needs. There is no HUNK_HEADER. A load file that contains
HUNK_UNIT, HUNK_EXT, HUNK_LIB or HUNK_INDEX is refused by the loader (amiga-dev wiki).
HUNK_UNIT and HUNK_NAME
HUNK_UNIT ($3E7) starts a unit: a count of longs, then the unit’s name. The unit’s hunks follow, numbered from 0 within the unit. A file can hold several units one after another.
HUNK_NAME ($3E8), with the same layout, comes before a hunk’s own block and gives that hunk its section name. In the object file made by vasm for the tests, the one unit is named demo.s (the source file) and its
four hunks are named code, datahunk, chipdata and variables, of 76, 40, 8 and 68 bytes, the sizes vasm printed.
Each hunk is: its HUNK_NAME, the code, data or BSS block, the relocation blocks, HUNK_EXT, HUNK_SYMBOL, HUNK_DEBUG and
HUNK_END. The memory type of a hunk is in the top bits of its block id (see the header page); the chip-memory section in the test file shows as chip.
The viewer lists the external symbols per hunk (the types), and a name defined with EXT_DEF becomes a label at its offset in the disassembly.
HUNK_LIB
HUNK_LIB ($3FA) starts a link library: a size long, then the library’s units, each as an object file starting with HUNK_UNIT, and finally a
HUNK_INDEX. The size counts longs, from the long after the size to the end of the library’s last block: the amitools reader (parse_lib) multiplies it by 4 and adds the 8 bytes of
the HUNK_LIB block itself to learn which hunks belong to the library, and the vlink linker’s block skipper (skiphunk) moves forward size + 2 longs. The viewer reads the units in order and
does not depend on it. A HUNK_LIB file read by vlink’s own object reader is refused (“HUNK_LIB not yet supported” in readconv), and vlink’s identify routine treats a file that starts with HUNK_UNIT and
has the name ending .lib as a library of units too, so the first block alone does not always tell an object from a library.
HUNK_INDEX
The index lets a linker find a symbol without reading every unit. It is a size in longs, then the body in words, as the amitools reader reads it:
| Part | Layout |
|---|---|
| String table | a word with its size in bytes, then those bytes; names are given as offsets into it |
| Per unit | the offset of its name, the number of its first hunk and its hunk count (three words) |
| Per hunk of the unit | the offset of its name, its size and a type word (three words); a count of references and that many name offsets; a count of definitions and, for each, a name offset, a value and a type (three words) |
| End | when the body has two bytes left, one padding word makes it a whole number of longs; any other left-over is an error in the amitools reader |
Two details of the amitools reader (parse_index, read in full from the source file for this check). The type word of a hunk, and the type word of a definition, hold the type in the low 14 bits
(for a hunk $3E9, $3EA or $3EB; for a definition the EXT_ type, for example 1) and the memory type in the top two bits (the same chip and fast bits as in a hunk id, shifted to bits 14 and 15). A reference
is a name offset; when the name at that offset is empty, the reference is a 16-bit one and its name starts one byte further (“16 bit refs point to the previous zero byte before the string entry”, in the reader’s words),
otherwise it is a 32-bit reference. The viewer shows the type word as stored and does not split off the memory bits or tell 16-bit references apart.
The viewer lists, for every unit and hunk, the symbols the hunk defines. No real library file exists on this machine and no tool here writes one: vasm writes object files and executables only, and the vlink source on the machine
(the vbcc/vlink folder of the WinUAE toolchain) refuses HUNK_LIB in its object reader, and the vlink.exe in the same folder is a Windows program that was not run. The index layout therefore rests on the amitools source and a built index, and stays the least certain part of the format here.
Not described
Known, not yet covered
- Reference: how a linker resolves references (the order of units, common symbols), the data-relative blocks of the small-data model (
HUNK_DREL16,HUNK_DREL8and theEXT_DEXTtypes are named, their meaning for a linker is not), the PowerPC object-file extensions, and the layouts above are checked against the amitools source only, not against a real library file. - Viewer: object files and libraries were checked on assembler output and built files, not on real third-party objects or libraries; the index is listed but not used to look up anything, its type words are shown as stored and 16-bit references are not told apart.
Links
Reference
- amitools hunk reader – HUNK_UNIT, HUNK_EXT, HUNK_LIB and HUNK_INDEX as it reads them
- vasm –
output_hunk.cwrites the object form - Hunk file format – amiga-dev wiki: which blocks a load file may not contain