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);
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)
Decompressor helps to handle decompression of compressed sections.
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.
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).
Error decompress(MutableArrayRef< char > Buffer)
Uncompress section data to raw buffer provided.
static ErrorSuccess success()
Create a success value.
bool isCompressed() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static std::vector< std::string > Flags
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.
Error uncompress(StringRef InputBuffer, char *UncompressedBuffer, size_t &UncompressedSize)
This is a value type class that represents a single section in the list of sections in the object fil...