An OMF object module is a run of records, read in order from the start. Each record has the same outer shape, which lets a reader skip what it doesn’t understand. A module begins with THEADR or LHEADR and ends with MODEND.
The record
+0Type1 byte+1Length, little-endian: the bytes after this field, including the checksum2 bytes+3Contents, laid out by typeLength − 1 bytes…Checksum: makes the record’s bytes add up to 0 modulo 256, or 0 if not computed1 byte
A type with an odd number is the 32-bit form of the type one below it: fields that hold offsets and lengths are 4 bytes instead of 2. Records are limited to 1,024 bytes unless a record type says otherwise.
Field encodings
| Field | Encoding |
|---|---|
| Name | A count byte, then that many characters. A count of 0 is an empty name. |
| Index | One byte for values 0 to 127. Otherwise two bytes, high byte first, the top bit of the first set: (first & 0x7F) << 8 | second. Indexes count from 1; 0 means none. |
| Offset or length | 2 bytes in a record with an even type, 4 bytes in the odd form, little-endian. |
Record types
| Type | Name | Meaning |
|---|---|---|
0x6E–0x7E | RHEADR, REGINT, REDATA, RIDATA, OVLDEF, ENDREC, BLKDEF, BLKEND, DEBSYM | Old Intel records, not written by later tools |
0x80 | THEADR | The module name |
0x82 | LHEADR | The name of a library module |
0x84, 0x86 | PEDATA, PIDATA | Old forms of data, not used |
0x88 | COMENT | A comment |
0x8A, 0x8B | MODEND | The end of a module; see below |
0x8C | EXTDEF | External names needed |
0x8E | TYPDEF | Type definitions, obsolete |
0x90, 0x91 | PUBDEF | Public names defined |
0x92 | LOCSYM | Local symbols, obsolete |
0x94, 0x95 | LINNUM | Line numbers |
0x96 | LNAMES | Names for segments, groups and classes |
0x98, 0x99 | SEGDEF | A segment |
0x9A | GRPDEF | A group of segments |
0x9C, 0x9D | FIXUPP | Fixups and threads |
0xA0, 0xA1 | LEDATA | Bytes for a segment |
0xA2, 0xA3 | LIDATA | Bytes for a segment, as repeating blocks |
0xA4–0xAA | LIBHED, LIBNAM, LIBLOC, LIBDIC | Intel library records, not used by Microsoft’s tools |
0xB0 | COMDEF | Communal names |
0xB2, 0xB3 | BAKPAT | Back-patches |
0xB4, 0xB5, 0xB6, 0xB7, 0xB8 | LEXTDEF (B4, B5), LPUBDEF (B6, B7), LCOMDEF (B8) | Names local to the module |
0xBA, 0xBB | COMFIX | Not in the TIS specification or Open Watcom’s pcobj.h; unverified here (an earlier note says it is obsolete and that Microsoft’s linker reports an error) |
0xBC | CEXTDEF | COMDAT external names |
0xC0 | SELDEF | Not in the TIS specification or Open Watcom’s pcobj.h; unverified here (an earlier note says it is obsolete and that Microsoft’s linker reports an error) |
0xC2, 0xC3 | COMDAT | A block the linker may keep one copy of |
0xC4, 0xC5 | LINSYM | Line numbers for a COMDAT |
0xC6 | ALIAS | Aliases |
0xC8, 0xC9 | NBKPAT | Back-patches to a named COMDAT |
0xCA | LLNAMES | Local names |
0xCC | VERNUM | The OMF version, as text |
0xCE | VENDEXT | A vendor number and private data |
0xF0, 0xF1 | Library header and end | Only in an OMF library |
MODEND
| Field | Meaning |
|---|---|
| Module type (1 byte) | Bit 7 (Main): the module is a main program module. Bit 6 (Start): the module has a start address, so the field below is present. Bit 5 (Segment): reserved, only 0 is supported by MS-DOS and OS/2. Bits 4 to 1: 0. Bit 0 (X): the start address is a relocatable reference that the linker must fix up. (The original Intel 8086 specification allows X = 0 for an absolute address stored as a 16-bit frame number and a 16-bit offset; some linkers, such as Microsoft LINK, do not support that, X should always be set, and its value is ignored.) |
| End data (only if bit 6 is set) | The Start Address subfield: its format is identical to the Fix Data, Frame Datum, Target Datum and Target Displacement fields of a FIXUP subrecord of a FIXUPP record. Bit 2 of the End Data byte (the P bit of a Fix Data field) must be 0. The Target Displacement is 4 bytes in a type 8B record and 2 bytes in type 8A. The value is the initial CS:(E)IP. |
MODEND can appear only as the last record of a module. With overlays the start address must be in the MODEND of the root module. The Link Pass Separator COMENT (class A2, subtype 01) is assumed not to be present in a module whose MODEND carries a start address, because with overlays the linker needs the start address in pass 1 to define $$MAIN. Example from the specification: 8A 07 00 C1 00 01 01 00 00 AC is a main module (bit 7) with a start address (bit 6) that is relocatable (bit 0); End Data 00 means frame and target are both given by a SEGDEF index, frame datum 1 and target datum 1 are the first SEGDEF, and the displacement is 0.
Order of records and indexes
Source: TIS Portable Formats Specification 1.10, “Relocatable Object Module Format”, which the page’s earlier text followed in part.
- A record that refers to another must come after it: an LNAMES record before any SEGDEF or GRPDEF that names its entries; EXTDEF and COMDEF before the FIXUPP records that reference them; PUBDEF, LINNUM after the SEGDEF and GRPDEF records they refer to.
- THEADR or LHEADR must be the first record. Recommended (not mandatory) order: identifier record; then in any order the records processed in pass 1 (COMENT records for the format and extensions, other COMENT records, LNAMES or LLNAMES, SEGDEF, GRPDEF, TYPDEF (obsolete), ALIAS, PUBDEF, LPUBDEF, COMDEF, LCOMDEF, EXTDEF, LEXTDEF, CEXTDEF); the optional Link Pass Separator (COMENT class A2); then LIDATA, LEDATA, FIXUPP, BAKPAT, INCDEF and LINNUM, which are processed in pass 2 wherever they are placed. All symbolic information is best at the start of the module for linking speed.
- Ordered collections, indexed from 1 (0 means unknown or not specified): names by occurrence in LNAMES (and LLNAMES) records and within each; logical segments by SEGDEF records; groups by GRPDEF records; external symbols by EXTDEF, COMDEF, LEXTDEF and LCOMDEF records and the symbols within each (this is the external name index of FIXUPP subrecords).
- The Type Index fields in PUBDEF, LPUBDEF, COMDEF, LCOMDEF, EXTDEF and LEXTDEF were once indexes of TYPDEF records; that use is obsolete. The field is usually one byte 0, but Microsoft’s 16-bit LINK may carry proprietary Microsoft symbol and type (CodeView) information in it, and other linkers may ignore or use it.
- Words and double words are little-endian. A record with an even type holds 2-byte offsets, lengths and displacements, which are zero-extended when applied to a Use32 segment; with an odd type they are 4 bytes. This is independent of the Use16/Use32 segment attribute, so 16-bit records can describe a 32-bit segment and the reverse. Applies to SEGDEF, PUBDEF, LPUBDEF, LINNUM, LEDATA, LIDATA, FIXUPP and MODEND.