A segment’s bytes are not stored in one place. A compiler usually writes them in several LEDATA records of up to about a kilobyte, each followed by the FIXUPP records for its data. A reader rebuilds the segment by placing each record’s bytes at its offset.
LEDATA (0xA0, 0xA1)
+0Segment index: an index into the SEGDEFsindex…Enumerated data offset: where this data starts in the segment2 or 4 bytes…Data: bytes for the segmentto the end of the record
The segment index must be non-zero and refer to a previously defined SEGDEF. The offset is relative to the start of that segment, 2 bytes (zero-extended in a Use32 segment) in an A0 record and 4 in A1; successive data bytes occupy successively higher locations. At most 1,024 data bytes, so that the 10-bit Data Record Offset of a FIXUPP subrecord can address any of them. If the data needs a fixup, a FIXUPP record must immediately follow. The linker copies the bytes into the executable image; they need no expansion at run time. The code of functions is in LEDATA records of the code segment (usually _TEXT), instantiated C++ functions are written as COMDAT records, and initialised data is in LEDATA or LIDATA records. Example: A0 13 00 02 00 00 followed by 15 data bytes places them at offset 0 of the second SEGDEF.
LIDATA (0xA2, 0xA3)
Iterated data repeats a pattern without storing every copy. The record has a segment index and an offset, as in LEDATA, followed by iterated blocks to the end of the record.
| Field | Size | Meaning |
|---|---|---|
| Repeat count | 2 or 4 | How many times the block is repeated |
| Block count | 2 | 0 means data follows; otherwise this many nested blocks follow |
| Content | varies | If the block count is 0: a length byte and that many bytes. Otherwise: nested iterated blocks |
So 03 00, 00 00, 02, AA BB means three copies of the two bytes AA BB, six bytes in all.
The segment index (non-zero) and iterated data offset are as in LEDATA. The repeat count is 16 bits in an A2 record and 32 bits in A3 (the PharLap implementation uses a 16-bit repeat count even in 32-bit records). The block count is a 16-bit word: 0 means the content is a 1-byte count followed by that many data bytes, repeated as the repeat count says; non-zero means the content is that many data blocks of the same form (a recursive definition). A FIXUPP may follow an LIDATA, which the specification does not recommend; the fixup is applied before the iterated block is expanded, and it is a translator error for a fixup to refer to any count field. Example: an outer block with repeat 2 and block count 2, whose inner blocks are (repeat 3, data 40 41) and (repeat 2, data 50 51), expands to 40 41 40 41 40 41 50 51 50 51 repeated twice (20 bytes).
COMDAT (0xC2, 0xC3)
A block of code or data the linker keeps one copy of, like a COFF COMDAT section. Comes in the two forms as usual.
| Field | Size | Meaning |
|---|---|---|
| Flags | 1 | Bit 0 (01H): continuation: if clear this record establishes a new instance of the COMDAT variable, otherwise its data continue the previous COMDAT of the symbol. Bit 1 (02H): iterated data: if clear the Data field is enumerated, otherwise iterated as in LIDATA. Bit 2 (04H): local (effectively an “LCOMDAT”; used in preference to LLNAMES). Bit 3 (08H): data in code segment: if the application is overlaid this COMDAT must be forced into the root text, and FARCALLTRANSLATION is not applied to it (not supported by IBM LINK386) |
| Attributes | 1 | High nibble, selection criteria: 0x00 no match (only one instance allowed), 0x10 pick any instance, 0x20 same size (instances must have the same length or the linker reports an error), 0x30 exact match (the checksums of the instances must match or the linker reports an error; fixups are ignored), 0x40 to 0xF0 reserved. Low nibble, allocation type: 0 explicit (allocate in the segment given by the base fields), 1 far code (CODE16: the linker creates segments to hold all COMDATs of this type), 2 far data (DATA16), 3 Code32, 4 Data32, 5 to 0xF reserved |
| Alignment | 1 | 0 from the SEGDEF, 1 byte, 2 word, 3 paragraph (16 bytes), 4 page (256 bytes in Intel’s specification, 4096 in the IBM implementation), 5 double word, 6 and 7 not defined |
| Enumerated data offset | 2 or 4 | Where this block goes within the COMDAT |
| Type index | index | Usually 0 |
| Base group, base segment | indexes | Only when the allocation is explicit; a base frame follows if both are 0 |
| Public name | index | The COMDAT’s symbol, an index into the LNAMES |
| Data | varies | The bytes, or iterated blocks if flag bit 1 is set |
The Enumerated Data Offset is relative to the start of the COMDAT symbol (not to a segment); a C3 record has a 32-bit offset. The Type Index is as for PUBDEF (Microsoft symbol and type information or an old TYPDEF index, 0 for none; linkers do no type checking). The base fields are identical to the PUBDEF base group, base segment and base frame, and present only when the allocation type is explicit. The Public Name Index is a regular logical name index. The Data field holds up to 1,024 consecutive bytes; fixups for it go in a FIXUPP record that follows the COMDAT. A COMDAT cannot be continued across modules but can be duplicated within one; if any COMDAT record of a symbol has the local bit, all of them do. Without an explicit allocation, the linker accumulates COMDAT code and data and splits it into segments, so the total may exceed 64 KB; only the selected instance is fixed up and written to the executable (pass 2); COMDATs are allocated in file order unless an explicit order is given.
A CEXTDEF (0xBC) names a COMDAT symbol through a logical name index; it can precede the COMDAT it will resolve to, and is produced when a FIXUPP refers to a COMDAT symbol (added for Microsoft C 7.0).
BAKPAT and NBKPAT
BAKPAT (0xB2, 0xB3; a Microsoft extension added for QuickC 1.0): a segment index, a location type byte, then pairs of an offset and a value, each 2 bytes in B2 and 4 in B3: the linker adds each value (unsigned addition, ignoring overflow) to the location at that offset in the segment. The location type is 0 (8-bit low-order byte), 1 (16-bit offset), 2 (32-bit offset, B3 only, “not supported yet”) or 9 (32-bit offset per the IBM implementation); no other value is valid. The segment index is explicit, since a BAKPAT need not follow the data record it patches; it can appear anywhere after the SEGDEF it refers to. The linker buffers BAKPAT records in pass 2 until the end of the module, after applying all other fixups, and then treats them as fixups. Example use: for a self-relative forward jump the translator stores the negated offset of the next instruction, then an additive backpatch whose value is the target’s offset. NBKPAT (0xC8, 0xC9) is the same with the location type byte first and a public name index (a logical name index of the COMDAT) instead of a segment index, and the offset is within the COMDAT; it must immediately follow the COMDAT/FIXUPP block it refers to. Location type 2 is for C9 only. (The specification’s field-size sentence for NBKPAT reads “32 bits for record type C8H, 16 bits for C9H”, which contradicts the odd-type rule and the BAKPAT text; the odd type is the 32-bit one.)