Introduction
LX, the Linear eXecutable format, is the format of 32-bit programs
(.exe) and libraries (.dll) on IBM’s OS/2, from OS/2 2.0 in
1992 onwards, and on its successors eComStation and
ArcaOS. OS/2’s device drivers use it too. Some
DOS programs load LX modules as well: the sound drivers that Miles Design shipped with
the DOS game System Shock are LX libraries.
LX is a close relative of LE, the format of Windows VxDs and DOS extender programs, and shares most of its layout. But it changes fields LE has: each page now has its own offset and size in the file, so pages can be any length and stored anywhere, or compacted as iterated data, and the header word that held the size of the last page holds a shift for the page offsets instead. So the two are separate formats. Earlier 16-bit OS/2 programs use NE. All the variations are on the .EXE page.
IBM published the format in its “LX – Linear eXecutable Module Format Description”. The code is x86, described in the x86 instruction reference.
A program or library dropped on any page opens in the explorer, which shows its structure, field by field, its resources, and its code: an instruction decoded at every byte, laid out in columns, so that a jump into the middle of another instruction can be followed.
Structure
An LX file begins with an MS-DOS MZ header and a DOS program, the stub, which usually
prints a message and exits. The 32-bit word at 0x3C points to the LX header,
which starts with LX. The header says which processor and system the module
is for, what kind of module it is, where it starts, and where each of its tables is.
Most table offsets are from the start of the LX header; the data pages, the
non-resident names and the debug information are found by file offsets.
Code and data are held in objects, the 32-bit successors of segments, each cut into pages, usually of 4,096 bytes. The object page table says where each page is stored and how much of it is stored; the rest of the page is zeros. Fixups say which places in each page to adjust when the page is loaded.
0x00DOS header and stub, withe_lfanewat0x3Cvariese_lfanewLX headerLX, the processor and system, module flags, entry point, page size, page offset shift and the table offsets196 bytes…Loader section: the object table, the object page table, the resource table, the resident names and the entry tablevaries…Fixup section: the fixup page table, the fixup records, and the imported module and procedure namesvariesdata pagesPages the code and data of each object, where the page table saysvaries…Non-resident names and debug informationoptional
The code
Executable objects hold the code. The explorer disassembles each one as 32-bit code
when the object’s big/default flag (0x2000) is set, and as 16-bit code
otherwise. A 32-bit object’s addresses count from its relocation base, the address it
was linked for; a 16-bit object’s count from 0. Exported entry points and the entry
point are named, and places that fixups patch with an imported procedure are labelled
with its module and name or ordinal. See the
x86 instruction reference.
Reference pages
- The DOS and LX headers – the DOS header and stub, every field of the LX header, module directives and debug information
- The object table – each object’s size, address, flags and pages
- Object pages – the 8-byte page entries, page types, iterated pages and where each page is
- The resource table – resource entries and how they are found
- Resident and non-resident names – the module name, its description and exported names
- The entry table – exported entry points and forwarders in bundles
- Fixups – the fixup page table and fixup records, field by field
- Imports – imported module and procedure names
Telling it apart
MS-DOS, Windows and OS/2 programs all start with MZ. The newer formats put
the file offset of a second header in the 32-bit word at 0x3C,
e_lfanew. The explorer takes a file as LX when, at that offset:
- the signature is
LX, and the 196-byte header is inside the file; - the byte order and the word order are both 0 (little-endian), and the format level is 0;
- the CPU type is a known one, such as 2 for the 80386;
- the page size is a power of two, not 0 and at most 1 MB;
- the page offset shift is 24 or less;
- there are fewer than 65,536 objects, and the object table is inside the file.
An LE header passes the same checks, but has the
signature LE, 4-byte page entries, and the size of the last page where LX
has the shift. A file with LX at e_lfanew that fails the
checks is shown as a plain MS-DOS program, with a
note.
Not described
The gaps are those on the EXE overview. For the LX format, some header fields are not confirmed by any source.
Also used for
- .NET assembly – .NET assemblies and modules: a PE file with ECMA-335 metadata tables, heaps and signatures.
Variants
- MS-DOS executable (MZ) – 16-bit DOS programs: an MZ header, relocations and the code
- 16-bit Windows executable (NE) – Windows 3.x and early OS/2 programs and DLLs, in movable segments
- Linear Executable (LE) – 32-bit Windows VxD drivers and DOS extender programs, in paged objects
- OS/2 executable (LX) – 32-bit OS/2 programs and DLLs, in paged objects
- Windows executable (PE32) – 32-bit Windows programs and DLLs: an MZ stub, a PE header with a 32-bit optional header, and sections
- Windows 64-bit executable (PE32+) – 64-bit Windows programs and DLLs (x64, ARM64, Itanium): the PE format with a 64-bit optional header
Links
Software
- ArcaOS – the current OS/2 distribution, which runs them
- Open Watcom – compiler suite whose linker writes LX files and whose
wdumptool lists them (Windows, Linux, DOS, OS/2) - IDA Pro – commercial disassembler and decompiler (Windows, macOS, Linux)
Reference
- LX – Linear eXecutable Module Format Description – IBM’s description of the format, on EDM2
- Open Watcom source – its
exeflat.hgives the whole 196-byte header and the object, page and fixup constants