aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Object/Decompressor.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-04-14 21:41:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-06-22 18:20:56 +0000
commitbdd1243df58e60e85101c09001d9812a789b6bc4 (patch)
treea1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/llvm/lib/Object/Decompressor.cpp
parent781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff)
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Object/Decompressor.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Object/Decompressor.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/contrib/llvm-project/llvm/lib/Object/Decompressor.cpp b/contrib/llvm-project/llvm/lib/Object/Decompressor.cpp
index 3842ec92ccfc..f38c0e69e850 100644
--- a/contrib/llvm-project/llvm/lib/Object/Decompressor.cpp
+++ b/contrib/llvm-project/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());
}