Introduction
A .bc file holds a module of LLVM IR, the intermediate representation of
the LLVM compiler project, in its compact binary form,
bitcode. Compilers built on LLVM, such as Clang, Rust and Swift, translate source code
into this IR before LLVM optimises it and turns it into machine code. Bitcode files
appear when a build keeps that middle stage, for example for link-time optimisation or
with clang -emit-llvm -c.
The same IR written as text uses the .ll extension. The bitcode format
changes between LLVM versions, though newer LLVM releases can usually read bitcode from
older ones.
Structure
A bitcode file starts with the bytes 42 43 C0 DE: BC
followed by 0xC0DE. Some files, notably on Apple platforms, are first
wrapped in a 20-byte header starting DE C0 17 0B (the number
0x0B17C0DE, little-endian) that gives the offset and size of the bitcode
inside.
After the magic number the file is a bitstream rather than a sequence of bytes: fields are written with as many bits as they need, and records are grouped into nested blocks, such as the module, the constants, each function and the symbol table. Each block can define abbreviations that say how its records are packed, which keeps the file small.
Links
Software
Developers
Reference
- LLVM Bitcode File Format, LLVM documentation
- LLVM Language Reference Manual, the IR the bitcode holds