[PATCH] D86847: [Bitcode] Add BITCODE_SIZE_BLOCK_ID to encode the size of the bitcode

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 29 21:35:47 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: mehdi_amini, pcc, steven_wu.
Herald added subscribers: llvm-commits, danielkiss, dexonsmith, hiraditya.
Herald added a project: LLVM.
MaskRay requested review of this revision.

Currently a bitcode file has no terminator. If several bitcode files are
concatenated, there is no suitable tool splitting them. For example:

  clang -fembed-bitcode=all -c a.c b.c
  ld a.o b.o
  objcopy --dump-section=.llvmbc=a.bc a.out /dev/null
  llvm-dis a.bc  # LLVM ERROR: Invalid encoding

This is because llvm-dis does not terminate after reaching the end of the first
stream, and decodes the start of the second bitcode file as the continuation
instead, and fail.

This patch introduces an optional BITCODE_SIZE_BLOCK_ID block to encode the size
of the stream. The block can be placed anywhere in the stream. For a streaming
writer, BITCODE_SIZE_BLOCK_ID can be placed at the end as a terminator. If
random access is supported, BITCODE_SIZE_BLOCK_ID can be placed earlier to allow
fast filtering (according to IDENTIFICATION_BLOCK_ID).

llvm-dis is taught to handle concatenated streams.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86847

Files:
  llvm/include/llvm/Bitcode/BitcodeAnalyzer.h
  llvm/include/llvm/Bitcode/BitcodeReader.h
  llvm/include/llvm/Bitcode/BitcodeWriter.h
  llvm/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/include/llvm/Bitstream/BitstreamWriter.h
  llvm/lib/Bitcode/Reader/BitcodeAnalyzer.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/Assembler/multi-mod-disassemble.ll
  llvm/tools/llvm-dis/llvm-dis.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86847.288834.patch
Type: text/x-patch
Size: 16033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200830/147d68ea/attachment.bin>


More information about the llvm-commits mailing list