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 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. The container, its encodings and the wrapper header are on the bitstream page.
A current file holds an identification block, the module block and a string table with the names. The block IDs, module records, linkage and other codes, attributes and the type table are on the module blocks page; every constant and instruction record on functions and constants; and debug metadata and ThinLTO summaries on metadata and summaries. The operands of each record, in order, with the checks LLVM’s reader makes, are on module records, types, attributes, constants, instructions and name tables (value symbol table, string table, symbol table, operand bundle tags and synchronisation scope names).
Not described
Known, not yet covered
- Viewer: function bodies are decoded and checked when the file is opened until 400,000 records have been read. A body past that is decoded when it is opened (in the Code tab or in the tree); a problem found then joins the Problems list, marked as found when that function body was opened, and the “Problems” count on the first tab does not change.
- Reference: the rules for the symbols that inline assembly defines are given only in outline on the symbol table page (the states of the assembler’s record streamer are not listed). The block-info abbreviations and the symbol flag rules for global values are described there, from the main branch’s
BitcodeWriter.cpp,IRSymtab.cpp,ModuleSymbolTable.cppandGlobals.cpp. - Reference: the records that exist only on LLVM’s main branch (
INST_BITINSERT,INST_BITEXTRACT, METADATA 50 to 52, the IR-layers operand of a debug location) are described fromLLVMBitCodes.h, the reader, the writer andAsmWriter.cpp/LLParser.cppof 2026-11-19. No file made by a released LLVM holds them; the samples that do were written by hand (llvm-bcanalyzerreads their records,llvm-dis22 cannot read the instructions and metadata), so their text is checked against the source and not against a second program. The attribute kinds, cast and binary operators, RMW operations and other value enumerations ofLLVMBitCodes.hare not compared one by one by a script; the record codes and block IDs are (241 record codes and 19 block IDs: every one named in the viewer and on a page, with the code the header gives). - Reference: older record forms are given from the reader’s code, not from a file: version 0 function bodies (absolute operand numbers), the old typed-pointer forms,
FUNC_CODE_INST_LANDINGPAD_OLD,INST_CMPXCHG_OLDand the case-rangeSWITCHare described on the instructions page as the reader takes them, with no sample file that holds them. - Reference: the summary-block section of metadata and summaries follows the main branch (summary version 14) and states every difference from LLVM 22 (version 12): global value flags bit 11, call-edge bit 4, index flags bit 11, version 13 (MemProf records after their function summary), version 14 (CFI triples), and the speculative devirtualisation resolution kind. The operand order of each FS record is given from the 22.x reader and was compared with main’s reader through the differences between the two files (every difference in
parseEntireSummaryis on the page); it was not re-read record by record against main a second time, and no file written by main holds a version 13 or 14 summary, so the viewer’s reading of those versions is tested on records made by hand (test-bc-built.mjs, round 4), not against a second reader. - Reference: the reader’s error messages are listed with their conditions for
MetadataLoader.cpp(metadata page) and, forBitcodeReader.cpp, on the page of the record each belongs to (module records, types, attributes, constants, instructions, function and tables). The “operand unreadable” conditions are stated in general (getValueTypePair,popValueandgetValuefail for a missing operand, a value number that does not exist or a wrong type) and not worked out value by value; messages whose text is built from an LLVM class (BitInsertInst::areInvalidOperands) are not listed one by one. - Reference:
ValueEnumerator.cpp(how the writer numbers values, types and metadata, andpredictUseListOrder),BitstreamReader.hand the LangRef are not read line by line; the USELIST reader is described fromparseUseListsonly (function blocks). - Viewer: METADATA records are shown as named fields in the tree, in the operand order of main’s
MetadataLoader.cpp(operands that only main has, such as a basic type’s file and line, a string type’s character type and a compile unit’s dialect, are read when present), with the textllvm-disprints for the node (!DISubprogram(name: "push", …)), version flags unpacked, DWARF tags, encodings, languages, flags and expression operations by name, and every reference followed to what it points to. A reference is shown by the file’s own metadata ID, which is not the numberllvm-disgives the node. The older layouts (a subprogram before the SP flags, a global variable of version 0, expressions of versions 0 to 2, the old node forms) are read as the loader reads them, but the upgrades the loader makes afterwards are not made, and expressions of versions below 3 are shown as stored. A value used as metadata inside a function (a debug record’s operand) shows by its number where the function’s own names are not at hand. No sample holds aSTRING_OLD,OLD_NODEorOLD_FN_NODErecord, so those three are decoded from the loader’s source and not checked against a file. The same holds for METADATA records 50 to 52 (DIProperty,DILayerLoc,DILayerLocList) and the IR-layers operand of a location: they are shown as named fields in the text ofAsmWriter.cpp, and the only files that hold them are hand-written. The atom group and rank of a debug location are checked againstllvm-dison a file made withclang -gkey-instructions. - Viewer: the records of the summary blocks (ThinLTO summaries), MODULE_STRTAB, METADATA_ATTACHMENT and USELIST are shown as named fields (flags unpacked, references and call edges resolved to names, an attachment’s instruction and metadata resolved). The per-module function, variable and alias summaries are checked against the summary
llvm-disprints; the other summary records are decoded fromparseEntireSummarywith every operand named, but no sample file lets them be compared with a second reader:FS_PERMODULE(the legacy form),FS_PERMODULE_RELBF,FS_COMBINED, the combined and per-module alias records,FS_TYPE_CHECKED_LOAD_VCALLSand the const-call form, the CFI function lists,FS_TYPE_ID,FS_TYPE_ID_METADATA, the vtable records,FS_PARAM_ACCESSand the memory-profile records (call sites, allocations, stack IDs, the radix tree). - Viewer: the function listing matches
llvm-dison the samples (1,163 lines, instruction by instruction: opcode, types, operands, flags, parameter and return attributes,#Nnumbers of function attributes, operand bundles, metadata attachments, debug records) apart from five differences made on purpose: white space (llvm-disputs a switch’s cases, an invoke’s destinations and a landingpad’s clauses on lines of their own), a;between a switch’s cases, an instruction’s!dbgwritten in full as the DILocation wherellvm-diswrites the number of a node, metadata numbers that are file IDs, and a debug record kept in file order (after the instruction it belongs to;llvm-disprints it before). Approximated: function bodies of module version 0 (absolute operand numbers, before LLVM 3.3) are listed by the version 1 rules, so their operand numbers can be wrong; the old case-rangeswitchencoding is shown as a count of operands, not decoded; the pre-opaque-pointer records that depend on pointee types are listed by the version 1 rules or as raw operands, so their operand numbers can be wrong; ablockaddressconstant names its block%bbN, wherellvm-disuses the block’s own name or number; constant expressions that LLVM removed (compare, select, vector operations) are written by the old reader’s form; widex86_fp80,fp128andppc_fp128constants are written as hexadecimal. A function-local metadata value shows as%Nin the metadata text (the listing resolves it by name).bitinsertandbitextractare listed by the rules ofAsmWriter.cpp(no releasedllvm-disreads them; see the first item). ATYPE_CODE_X86_MMXtype is shown as<1 x i64>, as LLVM’s reader makes it (checked againstllvm-dis22), with a note that the file stores X86_MMX; the oldINST_SELECT(code 5) is listed by the rules ofINST_VSELECT. - Viewer: the bitcode a Mach-O object keeps in its
__LLVM,__bitcodesection opens as bitcode from the section’s node in the Mach-O viewer. The__LLVM,__bundlesection is a xar archive of such files and is not offered, because there is no xar viewer yet. A file that does not start with the magic number or the wrapper number and whose next bytes start no block, a file cut inside the wrapper header, and a wrapper that points past the end of the file are shown as a partial tree (the wrapper’s fields as far as they exist, the bytes after them, each with its problem); a file whose magic number alone is damaged is read on. - Viewer: a damaged METADATA_STRINGS record (count, offset or length table) is reported with the messages of
MetadataLoader.cpp(“metadata strings bad length”, “truncated chars”, “corrupt offset”, “with no strings”, “layout”); the length table that ends inside a length is reported as a bad length wherellvm-bcanalyzersays “Unexpected end of file reading 8 of 8 bytes”. A damaged magic number is counted in the problem total as well as marked in the tree. - Viewer: the listing of older streams (typed pointers, module version 0) is largely wrong: for
GLByteCodes.x86_64.bcfrom macOS, 69 of 244,060 lines matchedllvm-diseven with metadata numbers blanked (a typed GEP is shown asgetelementptr inbounds %"" zeroinitializer). The viewer now says so: a Pointers row on the first tab and “approximate” in the title of the Code tab. The listing itself is not made right for typed pointers (LLVM 22 reads those files as opaque pointers, which the viewer does not emulate). - Viewer: metadata numbers in the listing (
!tbaa !25,!dbg_declare(.., !171, ..)) are the file’s own metadata IDs, whichllvm-disnumbers again in its own order (!9,!66); the Code tab’s title says so. The mapping tollvm-dis’s numbering (itsSlotTrackerorder) is not made, so the numbers are never compared:scripts/bc/compare-listing.mjsneeds--blankfor them. The script now reads files of several modules (thin-cfi-linux.bc,thin-vcalls-linux.bc: all lines match with the numbers blanked) and writesllvm-dis’s output to a scratch folder only;combined-index.bcholds no function bodies.
Links
Software
Developers
Reference
- LLVM Bitcode File Format – LLVM’s documentation of the bitstream
- LLVM Language Reference Manual – the IR the bitcode holds