diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/Object/Decompressor.cpp | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'llvm/lib/Object/Decompressor.cpp')
-rw-r--r-- | llvm/lib/Object/Decompressor.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/llvm/lib/Object/Decompressor.cpp b/llvm/lib/Object/Decompressor.cpp index 3842ec92ccfc..f38c0e69e850 100644 --- a/llvm/lib/Object/Decompressor.cpp +++ b/llvm/lib/Object/Decompressor.cpp @@ -19,11 +19,8 @@ using namespace object; Expected<Decompressor> Decompressor::create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit) { - if (!compression::zlib::isAvailable()) - return createError("zlib is not available"); - Decompressor D(Data); - if (Error Err = D.consumeCompressedZLibHeader(Is64Bit, IsLE)) + if (Error Err = D.consumeCompressedHeader(Is64Bit, IsLE)) return std::move(Err); return D; } @@ -31,8 +28,7 @@ Expected<Decompressor> Decompressor::create(StringRef Name, StringRef Data, Decompressor::Decompressor(StringRef Data) : SectionData(Data), DecompressedSize(0) {} -Error Decompressor::consumeCompressedZLibHeader(bool Is64Bit, - bool IsLittleEndian) { +Error Decompressor::consumeCompressedHeader(bool Is64Bit, bool IsLittleEndian) { using namespace ELF; uint64_t HdrSize = Is64Bit ? sizeof(Elf64_Chdr) : sizeof(Elf32_Chdr); if (SectionData.size() < HdrSize) @@ -40,10 +36,21 @@ Error Decompressor::consumeCompressedZLibHeader(bool Is64Bit, DataExtractor Extractor(SectionData, IsLittleEndian, 0); uint64_t Offset = 0; - if (Extractor.getUnsigned(&Offset, Is64Bit ? sizeof(Elf64_Word) - : sizeof(Elf32_Word)) != - ELFCOMPRESS_ZLIB) - return createError("unsupported compression type"); + auto ChType = Extractor.getUnsigned(&Offset, Is64Bit ? sizeof(Elf64_Word) + : sizeof(Elf32_Word)); + switch (ChType) { + case ELFCOMPRESS_ZLIB: + CompressionType = DebugCompressionType::Zlib; + break; + case ELFCOMPRESS_ZSTD: + CompressionType = DebugCompressionType::Zstd; + break; + default: + return createError("unsupported compression type (" + Twine(ChType) + ")"); + } + if (const char *Reason = llvm::compression::getReasonIfUnsupported( + compression::formatFor(CompressionType))) + return createError(Reason); // Skip Elf64_Chdr::ch_reserved field. if (Is64Bit) @@ -55,8 +62,8 @@ Error Decompressor::consumeCompressedZLibHeader(bool Is64Bit, return Error::success(); } -Error Decompressor::decompress(MutableArrayRef<uint8_t> Buffer) { - size_t Size = Buffer.size(); - return compression::zlib::uncompress(arrayRefFromStringRef(SectionData), - Buffer.data(), Size); +Error Decompressor::decompress(MutableArrayRef<uint8_t> Output) { + return compression::decompress(CompressionType, + arrayRefFromStringRef(SectionData), + Output.data(), Output.size()); } |