[llvm-branch-commits] [llvm] [Offloading] Add support for compressed OffloadBinary types (PR #222774)
James Henderson via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 29 02:09:06 PDT 2026
================
@@ -197,11 +176,53 @@ Error extractFromArchive(const Archive &Library,
return Error::success();
}
+bool isCompressed(const OffloadBinary::Header &Header) {
+ return Header.Version >= 3 && Header.InflatedSize != 0;
+}
+
+Expected<std::unique_ptr<MemoryBuffer>>
+decompressOffloadBinary(MemoryBufferRef Buf) {
+ const auto *Header =
+ reinterpret_cast<const OffloadBinary::Header *>(Buf.getBufferStart());
+ if (Header->EntriesOffset != sizeof(OffloadBinary::Header) ||
+ Header->EntriesOffset > Header->Size ||
+ Header->InflatedSize < Header->EntriesOffset)
+ return errorCodeToError(object_error::unexpected_eof);
+
+ // Get the compressed binary blob after the header.
+ StringRef Compressed = Buf.getBuffer()
+ .take_front(Header->Size)
+ .drop_front(Header->EntriesOffset);
+ uint64_t BodySize = Header->InflatedSize - Header->EntriesOffset;
+
+ ArrayRef<uint8_t> CompressedBytes = arrayRefFromStringRef(Compressed);
+ if (const char *Reason = compression::getReasonIfUnsupported(CompressedBytes))
+ return createStringError(Reason);
----------------
jh7370 wrote:
Looks like this is redundant, since `decompress` does the check internally and feeds it into the returned error?
https://github.com/llvm/llvm-project/pull/222774
More information about the llvm-branch-commits
mailing list