SkipBitcodeWrapperHeader - Some systems wrap bc files with a special header for padding or other reasons. The format of this header is: struct bc_header { uint32_t Magic; // 0x0B17C0DE uint32_t Version; // Version, currently always 0. uint32_t BitcodeOffset; // Offset to traditional bitcode file. uint32_t BitcodeSize; // Size of traditional bitcode file. ... potentially other gun
| 238 | /// If 'VerifyBufferSize' is true, check that the buffer is large enough to |
| 239 | /// contain the whole bitcode file. |
| 240 | inline bool SkipBitcodeWrapperHeader(const unsigned char *&BufPtr, |
| 241 | const unsigned char *&BufEnd, |
| 242 | bool VerifyBufferSize) { |
| 243 | // Must contain the offset and size field! |
| 244 | if (unsigned(BufEnd - BufPtr) < BWH_SizeField + 4) |
| 245 | return true; |
| 246 | |
| 247 | unsigned Offset = support::endian::read32le(&BufPtr[BWH_OffsetField]); |
| 248 | unsigned Size = support::endian::read32le(&BufPtr[BWH_SizeField]); |
| 249 | uint64_t BitcodeOffsetEnd = (uint64_t)Offset + (uint64_t)Size; |
| 250 | |
| 251 | // Verify that Offset+Size fits in the file. |
| 252 | if (VerifyBufferSize && BitcodeOffsetEnd > uint64_t(BufEnd-BufPtr)) |
| 253 | return true; |
| 254 | BufPtr += Offset; |
| 255 | BufEnd = BufPtr+Size; |
| 256 | return false; |
| 257 | } |
| 258 | |
| 259 | const std::error_category &BitcodeErrorCategory(); |
| 260 | enum class BitcodeError { CorruptedBitcode = 1 }; |
no test coverage detected