18 using namespace llvm::support::endian;
19 using namespace object;
22 bool IsLE,
bool Is64Bit) {
27 Error Err = isGnuStyle(Name) ? D.consumeCompressedGnuHeader()
28 : D.consumeCompressedZLibHeader(Is64Bit, IsLE);
30 return std::move(Err);
34 Decompressor::Decompressor(
StringRef Data)
35 : SectionData(Data), DecompressedSize(0) {}
37 Error Decompressor::consumeCompressedGnuHeader() {
39 return createError(
"corrupted compressed section header");
41 SectionData = SectionData.
substr(4);
44 if (SectionData.
size() < 8)
45 return createError(
"corrupted uncompressed section size");
47 SectionData = SectionData.
substr(8);
52 Error Decompressor::consumeCompressedZLibHeader(
bool Is64Bit,
53 bool IsLittleEndian) {
55 uint64_t HdrSize = Is64Bit ?
sizeof(Elf64_Chdr) :
sizeof(Elf32_Chdr);
56 if (SectionData.size() < HdrSize)
57 return createError(
"corrupted compressed section header");
70 DecompressedSize = Extractor.getUnsigned(
72 SectionData = SectionData.substr(HdrSize);
92 Out.
resize(DecompressedSize);
97 size_t Size = Buffer.
size();
static bool isCompressed(const object::SectionRef &Section)
Return true if section is compressed, including gnu-styled case.
static bool isGnuStyle(StringRef Name)
Return true if section name matches gnu style compressed one.
static Error createError(StringRef Err)
uint64_t read64be(const void *P)
Error decompress(SmallString< 32 > &Out)
Resize the buffer and uncompress section data into it.
Decompressor helps to handle decompression of compressed sections.
struct fuzzer::@269 Flags
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
Tagged union holding either a T or a Error.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
std::error_code getName(StringRef &Result) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array size.
Status uncompress(StringRef InputBuffer, char *UncompressedBuffer, size_t &UncompressedSize)
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
static ErrorSuccess success()
Create a success value.
bool isCompressed() const
pointer data()
Return a pointer to the vector's buffer, even if empty().
Lightweight error class with error context and mandatory checking.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
static bool isCompressedELFSection(uint64_t Flags, StringRef Name)
Return true if section is a ELF compressed one.
This is a value type class that represents a single section in the list of sections in the object fil...
static Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.