Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
Decompressor.cpp
Go to the documentation of this file.
1//===-- Decompressor.cpp --------------------------------------------------===//
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#include "llvm/Object/Decompressor.h"
10#include "llvm/ADT/StringExtras.h"
11#include "llvm/BinaryFormat/ELF.h"
12#include "llvm/Object/ObjectFile.h"
13#include "llvm/Support/Compression.h"
14#include "llvm/Support/DataExtractor.h"
15#include "llvm/Support/Endian.h"
16
17using namespacellvm;
18using namespacellvm::support::endian;
19using namespaceobject;
20
21Expected<Decompressor>Decompressor::create(StringRefName,StringRef Data,
22bool IsLE,bool Is64Bit) {
23DecompressorD(Data);
24if (Error Err =D.consumeCompressedHeader(Is64Bit, IsLE))
25return std::move(Err);
26returnD;
27}
28
29Decompressor::Decompressor(StringRefData)
30 : SectionData(Data), DecompressedSize(0) {}
31
32Error Decompressor::consumeCompressedHeader(bool Is64Bit,bool IsLittleEndian) {
33using namespaceELF;
34uint64_t HdrSize = Is64Bit ?sizeof(Elf64_Chdr) :sizeof(Elf32_Chdr);
35if (SectionData.size() < HdrSize)
36returncreateError("corrupted compressed section header");
37
38DataExtractor Extractor(SectionData, IsLittleEndian, 0);
39uint64_tOffset = 0;
40auto ChType = Extractor.getUnsigned(&Offset, Is64Bit ?sizeof(Elf64_Word)
41 :sizeof(Elf32_Word));
42switch (ChType) {
43case ELFCOMPRESS_ZLIB:
44 CompressionType =DebugCompressionType::Zlib;
45break;
46case ELFCOMPRESS_ZSTD:
47 CompressionType =DebugCompressionType::Zstd;
48break;
49default:
50returncreateError("unsupported compression type (" +Twine(ChType) +")");
51 }
52if (constchar *Reason =llvm::compression::getReasonIfUnsupported(
53compression::formatFor(CompressionType)))
54returncreateError(Reason);
55
56// Skip Elf64_Chdr::ch_reserved field.
57if (Is64Bit)
58Offset +=sizeof(Elf64_Word);
59
60 DecompressedSize = Extractor.getUnsigned(
61 &Offset, Is64Bit ?sizeof(Elf64_Xword) :sizeof(Elf32_Word));
62 SectionData = SectionData.substr(HdrSize);
63returnError::success();
64}
65
66ErrorDecompressor::decompress(MutableArrayRef<uint8_t> Output) {
67returncompression::decompress(CompressionType,
68 arrayRefFromStringRef(SectionData),
69 Output.data(), Output.size());
70}
ELF.h
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Compression.h
DataExtractor.h
Decompressor.h
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Endian.h
ObjectFile.h
StringExtras.h
This file contains some functions that are useful when dealing with strings.
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::DataExtractor
Definition:DataExtractor.h:41
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition:Error.h:337
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::MutableArrayRef
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition:ArrayRef.h:310
llvm::MutableArrayRef::data
T * data() const
Definition:ArrayRef.h:357
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::substr
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition:StringRef.h:571
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition:StringRef.h:150
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition:Twine.h:81
llvm::object::Decompressor
Decompressor helps to handle decompression of compressed sections.
Definition:Decompressor.h:21
llvm::object::Decompressor::decompress
Error decompress(MutableArrayRef< uint8_t > Output)
Uncompress section data to raw buffer provided.
Definition:Decompressor.cpp:66
llvm::object::Decompressor::create
static Expected< Decompressor > create(StringRef Name, StringRef Data, bool IsLE, bool Is64Bit)
Create decompressor object.
Definition:Decompressor.cpp:21
uint64_t
llvm::compression::getReasonIfUnsupported
const char * getReasonIfUnsupported(Format F)
Definition:Compression.cpp:30
llvm::compression::decompress
Error decompress(DebugCompressionType T, ArrayRef< uint8_t > Input, uint8_t *Output, size_t UncompressedSize)
Definition:Compression.cpp:58
llvm::compression::formatFor
Format formatFor(DebugCompressionType Type)
Definition:Compression.h:81
llvm::object::createError
Error createError(const Twine &Err)
Definition:Error.h:84
llvm::support::endian
Definition:Endian.h:41
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::Offset
@ Offset
Definition:DWP.cpp:480
llvm::DebugCompressionType::Zstd
@ Zstd
Zstandard.
llvm::DebugCompressionType::Zlib
@ Zlib
zlib
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55

Generated on Thu Jul 17 2025 12:34:26 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp