This is an archive of the discontinued LLVM Phabricator instance.

[docs] Only LLVM IR bitstreams begin with 'BC'
ClosedPublic

Authored by modocache on Jan 12 2018, 10:33 AM.

Details

Summary

The LLVM Bitcode File Format documentation states that all bitstreams
begin with the magic number 'BC', and that generic bitstream analyzer
tools may check for this number in order to determine whether the
stream is a bitstream.

However, in practice:

  • Only LLVM IR bitcode begins with 'BC'. Other bitstreams -- Clang AST files and precompiled headers, Clang serialized diagnostics, Swift modules -- do not start with 'BC'. A tool that actually checked for 'BC' would only be able to recognize LLVM IR.
  • The llvm-bcanalyzer, arguably the most used generic bitstream analyzer tool, does not check for a magic number 'BC' (except to determine whether the file is LLVM IR).

Update the bitcode format documentation to make it clear that not all
bitstreams begin with 'BC', and that tools should not rely on that
particular magic number value.

Test Plan:
Build the docs-llvm-html target and confirm the changes render in
a Safari web browser.

Diff Detail

Repository
rL LLVM

Event Timeline

modocache created this revision.Jan 12 2018, 10:33 AM
angerman accepted this revision.Jan 12 2018, 4:05 PM
angerman added a subscriber: angerman.

LGTM. I still can't shake the feeling that this just happened organically, and that Bitcode file should have the BC magic number and containers their own.

@modocache thanks for bringing the document in sync with what's actually being used!

This revision is now accepted and ready to land.Jan 12 2018, 4:05 PM

Yup, I totally agree, it would have been nice if in practice 'BC' was used by all LLVM IR bitstream formats. I wonder if it would possible, one day, to change the magic numbers for the major formats from Clang (and Swift) such that they do begin with 'BC'? Or are there too many clients that rely on the existing magic numbers? For example, does Apple's Xcode parse the magic numbers for serialized diagnostics somehow?

For now, though, I think this change makes the docs more accurate, and so I'll land this. Thanks for the review!

This revision was automatically updated to reflect the committed changes.