A segment is a block of code or data with attributes the linker needs. SEGDEF records define them, and other records refer to them by index, counted from 1 in order of appearance.
SEGDEF (0x98, 0x99)
| Field | Size | Meaning |
|---|---|---|
| ACBP | 1 | The segment’s attributes; see below |
| Frame number | 2 | Only when the alignment is absolute: the paragraph number |
| Offset | 1 | Only when the alignment is absolute: the offset in that frame |
| Length | 2 or 4 | The size, with B set and a value of 0 meaning 64 KB, or 4 GB in the 32-bit form |
| Segment name | index | An index into the LNAMES |
| Class name | index | An index into the LNAMES, such as CODE or DATA |
| Overlay name | index | An index into the LNAMES, ignored by modern linkers |
The ACBP byte
| Bits | Name | Meaning |
|---|---|---|
| 7–5 | A | Alignment: 0 absolute segment (the Frame number and Offset fields are present; Microsoft LINK ignores the Offset); 1 relocatable, byte aligned; 2 relocatable, word (2-byte) aligned; 3 relocatable, paragraph (16-byte) aligned; 4 relocatable, aligned on a page boundary (the original Intel 8086 specification defines a page as 256 bytes; the IBM implementation of OMF uses 4096 bytes); 5 relocatable, double word (4-byte) aligned; 6 not supported by 16-bit linkers such as Microsoft LINK; 7 not defined. Values 4 and 5 are the ones added for 32-bit linkers. The original Intel 8086 specification had other values that conflict with Microsoft’s use of 5 (“unnamed absolute portion of memory address space”) and 6 (“load-time locatable, paragraph aligned if not part of any group”). |
| 4–2 | C | Combination: 0 private, do not combine with any other segment; 1 reserved, not supported by Microsoft (the original Intel specification lists 1 as common); 2 public, combine by appending at an offset that meets the alignment; 3 reserved, not supported by Microsoft; 4 same as 2 (Microsoft); 5 stack, combine as for 2 and force byte alignment; 6 common, combine by overlay using the maximum size; 7 same as 2 (Microsoft). Under MS-DOS, segments with the same name and class are either concatenated or, for common, overlapped (same start or same end). |
| 1 | B | Big: used as the high-order bit of the length. If set, the length value must be 0. In a 98 record the segment is exactly 64 KB long; in a 99 record exactly 232 bytes (4 GB). |
| 0 | P | The Use16/Use32 flag (the B bit for data segments and the D bit for code segments in Intel’s descriptors). 0: a Use16 segment, no larger than 64 KB if data and 16-bit addressing and operands by default if code; non-zero: a Use32 segment. This is the only way to define a Use32 segment in the TIS OMF. In the specification’s first example the P bit “is ignored and should be 0”. |
The length field is 2 bytes in a 98 record (0 to 64 KB; exactly 64 KB is written as length 0 with B = 1) and 4 bytes in a 99 record (0 to 4 GB, exactly 4 GB as 0 with B = 1). The name indexes must be non-zero, although the name itself may be null. The full name of a segment is its segment name plus its class name; segments of different modules with identical full names are combined according to A and C. The segment name need not be unique: other segments with the same name are concatenated onto the first. The linker places segments of the same class contiguously in the run-time map. The overlay name is ignored by many linkers, and since version 2.4 Microsoft LINK ignores it and takes overlays from the command line. A segment length does not include the sizes of COMDAT records, which are added if they are selected. Some name and class pairs are reserved for CodeView debug information: $$TYPES with class DEBTYP and $$SYMBOLS with class DEBSYM. Many linkers limit a module to 255 SEGDEF records. A problem in the Intel 80286 makes code unreliable between bytes 65,500 and 65,535 of a segment, and many linkers warn about it.
Example from the specification: 98 07 00 28 11 00 07 02 01 1E is ACBP 0x28 (A = 1 byte aligned, C = 2 public, B = 0, P = 0), length 0x0011, segment name index 7, class name index 2, overlay name index 1.
GRPDEF (0x9A)
A group lets several segments share one base address, so that a segment register can reach them all, as DGROUP does for data.
+0Group name: an index into the LNAMESindex…for each segment: 0xFF, then its SEGDEF index1 byte, index
The group name is an index into the LNAMES and must be non-zero. Groups of different modules with identical names are combined. The first byte of each component is a type; Microsoft LINK requires 0xFF (a segment index follows). The other types defined by the original Intel 8086 specification are 0xFE (external index), 0xFD (segment name index, class name index, overlay name index), 0xFB (LTL data field, maximum group length, group length) and 0xFA (frame number, offset); none is supported by Microsoft LINK or IBM LINK386. The group’s segments are collected so that, under OS/2, they are one logical segment addressed through a single selector, and under MS-DOS they lie in one 64 KB frame. The special group name FLAT (added for 32-bit linkers) is handled specially by Microsoft LINK: references to it are offsets from the Virtual Zero Address, the start of the memory image of the executable. A GRPDEF is frequently followed by a THREAD FIXUPP record, and the usual group, DGROUP, holds the default data segments (_DATA, CONST, _BSS). Microsoft LINK limits a module to 31 GRPDEF records, and the total across all modules to 31.