Introduction
A .beam file holds one compiled module for BEAM, the virtual machine of
Erlang/OTP. The Erlang compiler writes one file
per module, and so do the compilers of other languages that run on the same virtual
machine, such as Elixir and Gleam. The runtime loads modules from these files as the
program calls them, and can load a new version of a module while the system is
running.
Structure
A BEAM file uses the chunk layout of the IFF format. It starts with
FOR1, a 32-bit big-endian size for the rest of the file, and the form
type BEAM. Then come chunks, each a four-character ID, a 32-bit big-endian
length and that many bytes, padded to a multiple of four.
Common chunks are AtU8 (the atoms the module uses, in UTF-8;
Atom in older files), Code (the bytecode), StrT
(strings), ImpT, ExpT and LocT (imported,
exported and local functions), LitT (literals), FunT
(anonymous functions), Attr and CInf (module attributes and
compiler information), Line (line numbers) and Dbgi or
Docs for debug information and documentation. Each chunk’s layout is
on the chunks page, and the compact
encoding of instruction operands and the full opcode table on
code and opcodes. Erlang/OTP publishes no
formal specification of the file; those pages follow its documentation and source
code.
0FOR1, size, form typeBEAM12 bytes12AtU8 atom tablevaries…Code bytecodevaries…StrT, ImpT, ExpT, LocT, LitT and other chunksvaries
Not described
Known, not yet covered
- Reference: the entries of the
Typechunk, the layout ofExCk, and the meaning of each instruction’s operands, which the Erlang/OTP source documents; the chunks and code pages give the encodings and opcodes only. Opcodes 186 to 193 appear only in a development branch. - Viewer: there is no viewer for BEAM files yet, so the chunks are not decoded or shown.
Links
Software
- Erlang/OTP – the Erlang compiler and virtual machine, which compiles and runs them (Windows, macOS, Linux)
- Elixir – language that compiles to BEAM files (Windows, macOS, Linux)
- Gleam – typed language that compiles to BEAM files (Windows, macOS, Linux)
Developers
- beam_lib – the Erlang/OTP standard library module that reads chunks from BEAM files (Erlang)
Reference
- The BEAM Book – free online book on the BEAM virtual machine, with a chapter on the file format