LLVM  15.0.0git
Decompressor.h
Go to the documentation of this file.
1 //===-- Decompressor.h ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===/
8 
9 #ifndef LLVM_OBJECT_DECOMPRESSOR_H
10 #define LLVM_OBJECT_DECOMPRESSOR_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Error.h"
15 
16 namespace llvm {
17 namespace object {
18 
19 class SectionRef;
20 
21 /// Decompressor helps to handle decompression of compressed sections.
22 class Decompressor {
23 public:
24  /// Create decompressor object.
25  /// @param Name Section name.
26  /// @param Data Section content.
27  /// @param IsLE Flag determines if Data is in little endian form.
28  /// @param Is64Bit Flag determines if object is 64 bit.
30  bool IsLE, bool Is64Bit);
31 
32  /// Resize the buffer and uncompress section data into it.
33  /// @param Out Destination buffer.
34  template <class T> Error resizeAndDecompress(T &Out) {
35  Out.resize(DecompressedSize);
36  return decompress({Out.data(), (size_t)DecompressedSize});
37  }
38 
39  /// Uncompress section data to raw buffer provided.
40  /// @param Buffer Destination buffer.
42 
43  /// Return memory buffer size required for decompression.
44  uint64_t getDecompressedSize() { return DecompressedSize; }
45 
46  /// Return true if section is compressed, including gnu-styled case.
47  static bool isCompressed(const object::SectionRef &Section);
48 
49  /// Return true if section is a ELF compressed one.
50  static bool isCompressedELFSection(uint64_t Flags, StringRef Name);
51 
52  /// Return true if section name matches gnu style compressed one.
53  static bool isGnuStyle(StringRef Name);
54 
55 private:
56  Decompressor(StringRef Data);
57 
58  Error consumeCompressedGnuHeader();
59  Error consumeCompressedZLibHeader(bool Is64Bit, bool IsLittleEndian);
60 
61  StringRef SectionData;
62  uint64_t DecompressedSize;
63 };
64 
65 } // end namespace object
66 } // end namespace llvm
67 
68 #endif // LLVM_OBJECT_DECOMPRESSOR_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
StringRef.h
Error.h
llvm::object::Decompressor::decompress
Error decompress(MutableArrayRef< char > Buffer)
Uncompress section data to raw buffer provided.
Definition: Decompressor.cpp:95
llvm::object::Decompressor::isCompressed
static bool isCompressed(const object::SectionRef &Section)
Return true if section is compressed, including gnu-styled case.
Definition: Decompressor.cpp:79
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::object::Decompressor::resizeAndDecompress
Error resizeAndDecompress(T &Out)
Resize the buffer and uncompress section data into it.
Definition: Decompressor.h:34
llvm::MutableArrayRef< char >
llvm::object::SectionRef
This is a value type class that represents a single section in the list of sections in the object fil...
Definition: ObjectFile.h:80
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
uint64_t
llvm::object::Decompressor::create
static Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.
Definition: Decompressor.cpp:20
llvm::object::Decompressor::isGnuStyle
static bool isGnuStyle(StringRef Name)
Return true if section name matches gnu style compressed one.
Definition: Decompressor.cpp:75
ArrayRef.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::object::Decompressor::getDecompressedSize
uint64_t getDecompressedSize()
Return memory buffer size required for decompression.
Definition: Decompressor.h:44
llvm::object::Decompressor
Decompressor helps to handle decompression of compressed sections.
Definition: Decompressor.h:22
llvm::object::Decompressor::isCompressedELFSection
static bool isCompressedELFSection(uint64_t Flags, StringRef Name)
Return true if section is a ELF compressed one.
Definition: Decompressor.cpp:91