Revert "[Support] Add llvm::compression::{getReasonIfUnsupported,compress,decompress}"
This reverts commit19dc3cff0f
. This reverts commit5b19a1f8e8
. This reverts commit9397648ac8
. This reverts commit10842b4475
. Breaks the GCC build, as reported here: https://reviews.llvm.org/D130506#3776415
This commit is contained in:
parent
10842b4475
commit
0444b40ed3
|
@ -299,7 +299,7 @@ them.
|
|||
.. option:: --compress-debug-sections [<format>]
|
||||
|
||||
Compress DWARF debug sections in the output, using the specified format.
|
||||
Supported formats are ``zlib`` and ``zstd``. Use ``zlib`` if ``<format>`` is omitted.
|
||||
Supported formats are ``zlib``. Use ``zlib`` if ``<format>`` is omitted.
|
||||
|
||||
.. option:: --decompress-debug-sections
|
||||
|
||||
|
|
|
@ -1800,7 +1800,6 @@ struct Elf64_Nhdr {
|
|||
// Legal values for ch_type field of compressed section header.
|
||||
enum {
|
||||
ELFCOMPRESS_ZLIB = 1, // ZLIB/DEFLATE algorithm.
|
||||
ELFCOMPRESS_ZSTD = 2, // Zstandard algorithm
|
||||
ELFCOMPRESS_LOOS = 0x60000000, // Start of OS-specific.
|
||||
ELFCOMPRESS_HIOS = 0x6fffffff, // End of OS-specific.
|
||||
ELFCOMPRESS_LOPROC = 0x70000000, // Start of processor-specific.
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#define LLVM_MC_MCTARGETOPTIONS_H
|
||||
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/Support/Compression.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -26,6 +25,11 @@ enum class ExceptionHandling {
|
|||
AIX, ///< AIX Exception Handling
|
||||
};
|
||||
|
||||
enum class DebugCompressionType {
|
||||
None, ///< No compression
|
||||
Z, ///< zlib style complession
|
||||
};
|
||||
|
||||
enum class EmitDwarfUnwindType {
|
||||
Always, // Always emit dwarf unwind
|
||||
NoCompactUnwind, // Only emit if compact unwind isn't available
|
||||
|
|
|
@ -20,16 +20,6 @@ namespace llvm {
|
|||
template <typename T> class SmallVectorImpl;
|
||||
class Error;
|
||||
|
||||
// None indicates no compression. The other members are a subset of
|
||||
// compression::Format, which is used for compressed debug sections in some
|
||||
// object file formats (e.g. ELF). This is a separate class as we may add new
|
||||
// compression::Format members for non-debugging purposes.
|
||||
enum class DebugCompressionType {
|
||||
None, ///< No compression
|
||||
Z, ///< zlib
|
||||
Zstd, ///< Zstandard
|
||||
};
|
||||
|
||||
namespace compression {
|
||||
namespace zlib {
|
||||
|
||||
|
@ -75,52 +65,6 @@ Error uncompress(ArrayRef<uint8_t> Input,
|
|||
|
||||
} // End of namespace zstd
|
||||
|
||||
enum class Format {
|
||||
Zlib,
|
||||
Zstd,
|
||||
};
|
||||
|
||||
inline Format formatFor(DebugCompressionType Type) {
|
||||
switch (Type) {
|
||||
case DebugCompressionType::None:
|
||||
llvm_unreachable("not a compression type");
|
||||
case DebugCompressionType::Z:
|
||||
return Format::Zlib;
|
||||
case DebugCompressionType::Zstd:
|
||||
return Format::Zstd;
|
||||
}
|
||||
llvm_unreachable("invalid type");
|
||||
}
|
||||
|
||||
struct Params {
|
||||
constexpr Params(Format F)
|
||||
: Format(F), Level(F == Format::Zlib ? zlib::DefaultCompression
|
||||
: zstd::DefaultCompression) {}
|
||||
Params(DebugCompressionType Type) : Params(formatFor(Type)) {}
|
||||
|
||||
Format Format;
|
||||
int Level;
|
||||
// This may support multi-threading for zstd in the future. Note that
|
||||
// different threads may produce different output, so be careful if certain
|
||||
// output determinism is desired.
|
||||
};
|
||||
|
||||
// Return nullptr if LLVM was built with support (LLVM_ENABLE_ZLIB,
|
||||
// LLVM_ENABLE_ZSTD) for the specified compression format; otherwise
|
||||
// return a string literal describing the reason.
|
||||
const char *getReasonIfUnsupported(Format F);
|
||||
|
||||
// Compress Input with the specified format P.Format. If Level is -1, use
|
||||
// *::DefaultCompression for the format.
|
||||
void compress(Params P, ArrayRef<uint8_t> Input,
|
||||
SmallVectorImpl<uint8_t> &Output);
|
||||
|
||||
// Decompress Input. The uncompressed size must be available.
|
||||
Error decompress(Format F, ArrayRef<uint8_t> Input,
|
||||
SmallVectorImpl<uint8_t> &Output, size_t UncompressedSize);
|
||||
Error decompress(DebugCompressionType T, ArrayRef<uint8_t> Input,
|
||||
SmallVectorImpl<uint8_t> &Output, size_t UncompressedSize);
|
||||
|
||||
} // End of namespace compression
|
||||
|
||||
} // End of namespace llvm
|
||||
|
|
|
@ -848,34 +848,27 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
|
|||
auto &MC = Asm.getContext();
|
||||
const auto &MAI = MC.getAsmInfo();
|
||||
|
||||
const DebugCompressionType CompressionType = MAI->compressDebugSections();
|
||||
if (CompressionType == DebugCompressionType::None ||
|
||||
!SectionName.startswith(".debug_")) {
|
||||
bool CompressionEnabled =
|
||||
MAI->compressDebugSections() != DebugCompressionType::None;
|
||||
if (!CompressionEnabled || !SectionName.startswith(".debug_")) {
|
||||
Asm.writeSectionData(W.OS, &Section, Layout);
|
||||
return;
|
||||
}
|
||||
|
||||
assert(MAI->compressDebugSections() == DebugCompressionType::Z &&
|
||||
"expected zlib style compression");
|
||||
|
||||
SmallVector<char, 128> UncompressedData;
|
||||
raw_svector_ostream VecOS(UncompressedData);
|
||||
Asm.writeSectionData(VecOS, &Section, Layout);
|
||||
ArrayRef<uint8_t> Uncompressed =
|
||||
makeArrayRef(reinterpret_cast<uint8_t *>(UncompressedData.data()),
|
||||
UncompressedData.size());
|
||||
|
||||
SmallVector<uint8_t, 128> Compressed;
|
||||
uint32_t ChType;
|
||||
switch (CompressionType) {
|
||||
case DebugCompressionType::None:
|
||||
llvm_unreachable("has been handled");
|
||||
case DebugCompressionType::Z:
|
||||
ChType = ELF::ELFCOMPRESS_ZLIB;
|
||||
break;
|
||||
case DebugCompressionType::Zstd:
|
||||
ChType = ELF::ELFCOMPRESS_ZSTD;
|
||||
break;
|
||||
}
|
||||
compression::compress(compression::Params(CompressionType), Uncompressed,
|
||||
Compressed);
|
||||
const uint32_t ChType = ELF::ELFCOMPRESS_ZLIB;
|
||||
compression::zlib::compress(
|
||||
makeArrayRef(reinterpret_cast<uint8_t *>(UncompressedData.data()),
|
||||
UncompressedData.size()),
|
||||
Compressed);
|
||||
|
||||
if (!maybeWriteCompression(ChType, UncompressedData.size(), Compressed,
|
||||
Sec.getAlignment())) {
|
||||
W.OS << UncompressedData;
|
||||
|
|
|
@ -438,29 +438,14 @@ template <class ELFT>
|
|||
Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) {
|
||||
ArrayRef<uint8_t> Compressed =
|
||||
Sec.OriginalData.slice(sizeof(Elf_Chdr_Impl<ELFT>));
|
||||
SmallVector<uint8_t, 128> Decompressed;
|
||||
DebugCompressionType Type;
|
||||
switch (Sec.ChType) {
|
||||
case ELFCOMPRESS_ZLIB:
|
||||
Type = DebugCompressionType::Z;
|
||||
break;
|
||||
case ELFCOMPRESS_ZSTD:
|
||||
Type = DebugCompressionType::Zstd;
|
||||
break;
|
||||
default:
|
||||
SmallVector<uint8_t, 128> DecompressedContent;
|
||||
if (Error Err = compression::zlib::uncompress(Compressed, DecompressedContent,
|
||||
static_cast<size_t>(Sec.Size)))
|
||||
return createStringError(errc::invalid_argument,
|
||||
"--decompress-debug-sections: ch_type (" +
|
||||
Twine(Sec.ChType) + ") of section '" +
|
||||
Sec.Name + "' is unsupported");
|
||||
}
|
||||
if (Error E = compression::decompress(Type, Compressed, Decompressed,
|
||||
static_cast<size_t>(Sec.Size)))
|
||||
return createStringError(errc::invalid_argument,
|
||||
"failed to decompress section '" + Sec.Name +
|
||||
"': " + toString(std::move(E)));
|
||||
"'" + Sec.Name + "': " + toString(std::move(Err)));
|
||||
|
||||
uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset;
|
||||
std::copy(Decompressed.begin(), Decompressed.end(), Buf);
|
||||
std::copy(DecompressedContent.begin(), DecompressedContent.end(), Buf);
|
||||
|
||||
return Error::success();
|
||||
}
|
||||
|
@ -513,9 +498,6 @@ Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
|
|||
case DebugCompressionType::Z:
|
||||
Chdr.ch_type = ELF::ELFCOMPRESS_ZLIB;
|
||||
break;
|
||||
case DebugCompressionType::Zstd:
|
||||
Chdr.ch_type = ELF::ELFCOMPRESS_ZSTD;
|
||||
break;
|
||||
}
|
||||
Chdr.ch_size = Sec.DecompressedSize;
|
||||
Chdr.ch_addralign = Sec.DecompressedAlign;
|
||||
|
@ -530,9 +512,9 @@ CompressedSection::CompressedSection(const SectionBase &Sec,
|
|||
DebugCompressionType CompressionType)
|
||||
: SectionBase(Sec), CompressionType(CompressionType),
|
||||
DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) {
|
||||
compression::compress(compression::Params(CompressionType), OriginalData,
|
||||
CompressedData);
|
||||
compression::zlib::compress(OriginalData, CompressedData);
|
||||
|
||||
assert(CompressionType != DebugCompressionType::None);
|
||||
Flags |= ELF::SHF_COMPRESSED;
|
||||
size_t ChdrSize =
|
||||
std::max(std::max(sizeof(object::Elf_Chdr_Impl<object::ELF64LE>),
|
||||
|
@ -544,9 +526,9 @@ CompressedSection::CompressedSection(const SectionBase &Sec,
|
|||
}
|
||||
|
||||
CompressedSection::CompressedSection(ArrayRef<uint8_t> CompressedData,
|
||||
uint32_t ChType, uint64_t DecompressedSize,
|
||||
uint64_t DecompressedSize,
|
||||
uint64_t DecompressedAlign)
|
||||
: ChType(ChType), CompressionType(DebugCompressionType::None),
|
||||
: CompressionType(DebugCompressionType::None),
|
||||
DecompressedSize(DecompressedSize), DecompressedAlign(DecompressedAlign) {
|
||||
OriginalData = CompressedData;
|
||||
}
|
||||
|
@ -1724,8 +1706,8 @@ Expected<SectionBase &> ELFBuilder<ELFT>::makeSection(const Elf_Shdr &Shdr) {
|
|||
if (!(Shdr.sh_flags & ELF::SHF_COMPRESSED))
|
||||
return Obj.addSection<Section>(*Data);
|
||||
auto *Chdr = reinterpret_cast<const Elf_Chdr_Impl<ELFT> *>(Data->data());
|
||||
return Obj.addSection<CompressedSection>(CompressedSection(
|
||||
*Data, Chdr->ch_type, Chdr->ch_size, Chdr->ch_addralign));
|
||||
return Obj.addSection<CompressedSection>(
|
||||
CompressedSection(*Data, Chdr->ch_size, Chdr->ch_addralign));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -536,7 +536,6 @@ public:
|
|||
class CompressedSection : public SectionBase {
|
||||
MAKE_SEC_WRITER_FRIEND
|
||||
|
||||
uint32_t ChType = 0;
|
||||
DebugCompressionType CompressionType;
|
||||
uint64_t DecompressedSize;
|
||||
uint64_t DecompressedAlign;
|
||||
|
@ -545,12 +544,11 @@ class CompressedSection : public SectionBase {
|
|||
public:
|
||||
CompressedSection(const SectionBase &Sec,
|
||||
DebugCompressionType CompressionType);
|
||||
CompressedSection(ArrayRef<uint8_t> CompressedData, uint32_t ChType,
|
||||
uint64_t DecompressedSize, uint64_t DecompressedAlign);
|
||||
CompressedSection(ArrayRef<uint8_t> CompressedData, uint64_t DecompressedSize,
|
||||
uint64_t DecompressedAlign);
|
||||
|
||||
uint64_t getDecompressedSize() const { return DecompressedSize; }
|
||||
uint64_t getDecompressedAlign() const { return DecompressedAlign; }
|
||||
uint64_t getChType() const { return ChType; }
|
||||
|
||||
Error accept(SectionVisitor &Visitor) const override;
|
||||
Error accept(MutableSectionVisitor &Visitor) override;
|
||||
|
@ -564,9 +562,8 @@ class DecompressedSection : public SectionBase {
|
|||
MAKE_SEC_WRITER_FRIEND
|
||||
|
||||
public:
|
||||
uint32_t ChType;
|
||||
explicit DecompressedSection(const CompressedSection &Sec)
|
||||
: SectionBase(Sec), ChType(Sec.getChType()) {
|
||||
: SectionBase(Sec) {
|
||||
Size = Sec.getDecompressedSize();
|
||||
Align = Sec.getDecompressedAlign();
|
||||
Flags = OriginalFlags = (Flags & ~ELF::SHF_COMPRESSED);
|
||||
|
|
|
@ -27,50 +27,6 @@
|
|||
using namespace llvm;
|
||||
using namespace llvm::compression;
|
||||
|
||||
const char *compression::getReasonIfUnsupported(compression::Format F) {
|
||||
switch (F) {
|
||||
case compression::Format::Zlib:
|
||||
if (zlib::isAvailable())
|
||||
return nullptr;
|
||||
return "LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at "
|
||||
"build time";
|
||||
case compression::Format::Zstd:
|
||||
if (zstd::isAvailable())
|
||||
return nullptr;
|
||||
return "LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at "
|
||||
"build time";
|
||||
}
|
||||
}
|
||||
|
||||
void compression::compress(Params P, ArrayRef<uint8_t> Input,
|
||||
SmallVectorImpl<uint8_t> &Output) {
|
||||
switch (P.Format) {
|
||||
case compression::Format::Zlib:
|
||||
zlib::compress(Input, Output, P.Level);
|
||||
break;
|
||||
case compression::Format::Zstd:
|
||||
zstd::compress(Input, Output, P.Level);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Error compression::decompress(compression::Format F, ArrayRef<uint8_t> Input,
|
||||
SmallVectorImpl<uint8_t> &Output,
|
||||
size_t UncompressedSize) {
|
||||
switch (F) {
|
||||
case compression::Format::Zlib:
|
||||
return zlib::uncompress(Input, Output, UncompressedSize);
|
||||
case compression::Format::Zstd:
|
||||
return zstd::uncompress(Input, Output, UncompressedSize);
|
||||
}
|
||||
}
|
||||
|
||||
Error compression::decompress(DebugCompressionType T, ArrayRef<uint8_t> Input,
|
||||
SmallVectorImpl<uint8_t> &Output,
|
||||
size_t UncompressedSize) {
|
||||
return decompress(formatFor(T), Input, Output, UncompressedSize);
|
||||
}
|
||||
|
||||
#if LLVM_ENABLE_ZLIB
|
||||
|
||||
static StringRef convertZlibCodeToString(int Code) {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
// REQUIRES: !zlib
|
||||
// RUN: not llvm-mc -filetype=obj -compress-debug-sections=zlib -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s
|
||||
|
||||
// CHECK: llvm-mc{{[^:]*}}: error: build tools with LLVM_ENABLE_ZLIB to enable --compress-debug-sections=zlib
|
||||
// CHECK-NOT: {{.}}
|
||||
// CHECK: llvm-mc{{[^:]*}}: error: build tools with zlib to enable -compress-debug-sections
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# UNSUPPORTED: zstd
|
||||
# RUN: not llvm-mc -filetype=obj -compress-debug-sections=zstd -triple x86_64 %s 2>&1 | FileCheck %s
|
||||
|
||||
# CHECK: error: --compress-debug-sections: LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at build time
|
||||
# CHECK-NOT: {{.}}
|
|
@ -1,115 +0,0 @@
|
|||
# REQUIRES: zstd
|
||||
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64 -compress-debug-sections=zstd %s -o %t
|
||||
# RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SEC
|
||||
# RUN: llvm-objdump -s %t | FileCheck %s
|
||||
|
||||
## Check that the large debug sections .debug_line and .debug_frame are compressed
|
||||
## and have the SHF_COMPRESSED flag.
|
||||
# SEC: .nonalloc PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 0 0 1
|
||||
# SEC: .debug_line PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 C 0 0 8
|
||||
# SEC: .debug_abbrev PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 0 0 1
|
||||
# SEC: .debug_info PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 0 0 1
|
||||
# SEC: .debug_str PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 01 MSC 0 0 8
|
||||
# SEC: .debug_frame PROGBITS [[#%x,]] [[#%x,]] [[#%x,]] 00 C 0 0 8
|
||||
|
||||
# CHECK: Contents of section .debug_line
|
||||
## ch_type == ELFCOMPRESS_ZSTD (2)
|
||||
# CHECK-NEXT: 0000 02000000 00000000 55010000 00000000
|
||||
# CHECK-NEXT: 0010 01000000 00000000 {{.*}}
|
||||
|
||||
## The compress/decompress round trip should be identical to the uncompressed output.
|
||||
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.uncom
|
||||
# RUN: llvm-objcopy --decompress-debug-sections %t %t.decom
|
||||
# RUN: cmp %t.uncom %t.decom
|
||||
|
||||
## Don't compress a section not named .debug_*.
|
||||
.section .nonalloc,"",@progbits
|
||||
.rept 50
|
||||
.asciz "aaaaaaaaaa"
|
||||
.endr
|
||||
|
||||
.section .debug_line,"",@progbits
|
||||
|
||||
.section .debug_abbrev,"",@progbits
|
||||
.Lsection_abbrev:
|
||||
.byte 1 # Abbreviation Code
|
||||
.byte 17 # DW_TAG_compile_unit
|
||||
.byte 0 # DW_CHILDREN_no
|
||||
.byte 27 # DW_AT_comp_dir
|
||||
.byte 14 # DW_FORM_strp
|
||||
.byte 0 # EOM(1)
|
||||
.byte 0 # EOM(2)
|
||||
|
||||
.section .debug_info,"",@progbits
|
||||
.long 12 # Length of Unit
|
||||
.short 4 # DWARF version number
|
||||
.long .Lsection_abbrev # Offset Into Abbrev. Section
|
||||
.byte 8 # Address Size (in bytes)
|
||||
.byte 1 # Abbrev [1] DW_TAG_compile_unit
|
||||
.long .Linfo_string0 # DW_AT_comp_dir
|
||||
|
||||
.text
|
||||
foo:
|
||||
.cfi_startproc
|
||||
.file 1 "Driver.ii"
|
||||
|
||||
.rept 3
|
||||
.ifdef I386
|
||||
pushl %ebp
|
||||
.cfi_def_cfa_offset 8
|
||||
.cfi_offset %ebp, -8
|
||||
movl %esp, %ebp
|
||||
.cfi_def_cfa_register %ebp
|
||||
pushl %ebx
|
||||
pushl %edi
|
||||
pushl %esi
|
||||
.cfi_offset %esi, -20
|
||||
.cfi_offset %edi, -16
|
||||
.cfi_offset %ebx, -12
|
||||
.loc 1 1 1 prologue_end
|
||||
popl %esi
|
||||
popl %edi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
.cfi_def_cfa %esp, 4
|
||||
.else
|
||||
pushq %rbp
|
||||
.cfi_def_cfa_offset 16
|
||||
.cfi_offset %rbp, -16
|
||||
movq %rsp, %rbp
|
||||
.cfi_def_cfa_register %rbp
|
||||
pushq %r15
|
||||
pushq %r14
|
||||
pushq %r13
|
||||
pushq %r12
|
||||
pushq %rbx
|
||||
.cfi_offset %rbx, -56
|
||||
.cfi_offset %r12, -48
|
||||
.cfi_offset %r13, -40
|
||||
.cfi_offset %r14, -32
|
||||
.cfi_offset %r15, -24
|
||||
.loc 1 1 1 prologue_end
|
||||
popq %rbx
|
||||
popq %r12
|
||||
popq %r13
|
||||
popq %r14
|
||||
popq %r15
|
||||
popq %rbp
|
||||
.cfi_def_cfa %rsp, 8
|
||||
.endif
|
||||
.endr
|
||||
|
||||
# pad out the line table to make sure it's big enough to warrant compression
|
||||
.irpc i, 123456789
|
||||
.irpc j, 0123456789
|
||||
.loc 1 \i\j \j
|
||||
nop
|
||||
.endr
|
||||
.endr
|
||||
.cfi_endproc
|
||||
.cfi_sections .debug_frame
|
||||
|
||||
.section .debug_str,"MS",@progbits,1
|
||||
.Linfo_string0:
|
||||
.asciz "perfectly compressable data sample *****************************************"
|
|
@ -2,15 +2,12 @@
|
|||
|
||||
# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t.o
|
||||
# RUN: llvm-objcopy --compress-debug-sections %t.o %t-compressed.o
|
||||
# RUN: llvm-readobj -S --sd %t-compressed.o | FileCheck %s
|
||||
# RUN: llvm-readobj -S %t-compressed.o | FileCheck %s
|
||||
|
||||
# CHECK: Name: .debug_foo
|
||||
# CHECK-NEXT: Type: SHT_PROGBITS
|
||||
# CHECK-NEXT: Flags [
|
||||
# CHECK-NEXT: SHF_COMPRESSED
|
||||
# CHECK-NEXT: ]
|
||||
# CHECK: SectionData (
|
||||
## ch_type = ELFCOMPRESS_ZLIB (1)
|
||||
# CHECK-NEXT: 0000: 01000000 {{.*}}
|
||||
# CHECK-NOT: Name: .debug_foo
|
||||
|
||||
|
|
|
@ -28,21 +28,3 @@
|
|||
## --compress-debug-sections does not update a compressed section.
|
||||
# RUN: llvm-objcopy --compress-debug-sections=zlib %t-zlib.o %t-zlib-zlib.o
|
||||
# RUN: cmp %t-zlib.o %t-zlib-zlib.o
|
||||
|
||||
# RUN: yaml2obj %s -o %t-corrupted
|
||||
# RUN: not llvm-objcopy --decompress-debug-sections %t-corrupted /dev/null 2>&1 | FileCheck %s -DFILE=%t-corrupted --check-prefix=ERR
|
||||
|
||||
# ERR: error: '[[FILE]]': failed to decompress section '.debug_info': zlib error: Z_DATA_ERROR
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Type: SHT_PROGBITS
|
||||
Name: .debug_info
|
||||
Flags: [ SHF_COMPRESSED ]
|
||||
AddressAlign: 8
|
||||
Content: "010000000000000004000000000000000100000000000000ffffffff"
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# UNSUPPORTED: zstd
|
||||
# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t
|
||||
# RUN: not llvm-objcopy --compress-debug-sections=zstd %t /dev/null 2>&1 | FileCheck %s
|
||||
|
||||
# CHECK: error: LLVM was not built with LLVM_ENABLE_ZSTD or did not find zstd at build time
|
|
@ -1,51 +0,0 @@
|
|||
# REQUIRES: zstd
|
||||
## Test --compress-debug-sections=zstd and decompression.
|
||||
|
||||
# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t && llvm-objcopy %t
|
||||
# RUN: llvm-objcopy --compress-debug-sections=zstd %t %t-zstd
|
||||
# RUN: llvm-objcopy --decompress-debug-sections %t-zstd %t-de
|
||||
# RUN: cmp %t %t-de
|
||||
|
||||
# RUN: llvm-readelf -S -r -x .debug_foo %t-zstd | FileCheck %s --check-prefixes=CHECK,COMPRESSED
|
||||
# RUN: llvm-readelf -S -r -x .debug_foo %t-de | FileCheck %s --check-prefixes=CHECK,DECOMPRESSED
|
||||
|
||||
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
|
||||
# COMPRESSED: .debug_foo PROGBITS 0000000000000000 000040 {{.*}} 00 C 0 0 8
|
||||
# COMPRESSED-NEXT: .notdebug_foo PROGBITS 0000000000000000 {{.*}} 000008 00 0 0 0
|
||||
# DECOMPRESSED: .debug_foo PROGBITS 0000000000000000 000040 000008 00 0 0 0
|
||||
# DECOMPRESSED-NEXT: .notdebug_foo PROGBITS 0000000000000000 {{.*}} 000008 00 0 0 0
|
||||
|
||||
## Relocations do not change.
|
||||
# CHECK: Relocation section '.rela.debug_foo' at offset {{.*}} contains 2 entries:
|
||||
# CHECK-NEXT: Offset
|
||||
# CHECK-NEXT: 0000000000000001 000000010000000a R_X86_64_32 0000000000000000 .debug_foo + 0
|
||||
# CHECK-NEXT: 0000000000000002 000000020000000a R_X86_64_32 0000000000000000 .notdebug_foo + 0
|
||||
|
||||
# COMPRESSED: Hex dump of section '.debug_foo':
|
||||
## ch_type == ELFCOMPRESS_ZSTD (2)
|
||||
# COMPRESSED-NEXT: 0x00000000 02000000 00000000 08000000 00000000
|
||||
# COMPRESSED-NEXT: 0x00000010 00000000 00000000 {{.*}}
|
||||
|
||||
## --compress-debug-sections does not update a compressed section. Its compression
|
||||
## type does not change.
|
||||
# RUN: llvm-objcopy --compress-debug-sections=zstd %t-zstd %t-zstd-zstd
|
||||
# RUN: cmp %t-zstd %t-zstd-zstd
|
||||
# RUN: %if zlib %{ llvm-objcopy --compress-debug-sections=zlib %t-zstd %t-zstd-zlib && cmp %t-zstd %t-zstd-zlib %}
|
||||
|
||||
# RUN: yaml2obj %s -o %t-corrupted
|
||||
# RUN: not llvm-objcopy --decompress-debug-sections %t-corrupted /dev/null 2>&1 | FileCheck %s -DFILE=%t-corrupted --check-prefix=ERR
|
||||
|
||||
# ERR: error: '[[FILE]]': failed to decompress section '.debug_info': Src size is incorrect
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Type: SHT_PROGBITS
|
||||
Name: .debug_info
|
||||
Flags: [ SHF_COMPRESSED ]
|
||||
AddressAlign: 8
|
||||
Content: "020000000000000004000000000000000100000000000000ffffffff"
|
|
@ -1,24 +0,0 @@
|
|||
# REQUIRES: zlib
|
||||
# RUN: yaml2obj %s -o %t
|
||||
# RUN: not llvm-objcopy --decompress-debug-sections %t /dev/null 2>&1 | FileCheck %s -DFILE=%t
|
||||
|
||||
# CHECK: error: '[[FILE]]': --decompress-debug-sections: ch_type (3) of section '.debug_info' is unsupported
|
||||
# CHECK-EMPTY:
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_REL
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .debug_info
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_COMPRESSED ]
|
||||
Content: 030000000000000004000000000000000000000000000000789c6360
|
||||
AddressAlign: 8
|
||||
- Name: .debug_str
|
||||
Type: SHT_PROGBITS
|
||||
Flags: [ SHF_COMPRESSED ]
|
||||
Content: 030000000000000004000000000000000000000000000000789c6360
|
||||
AddressAlign: 8
|
|
@ -76,8 +76,8 @@ static cl::opt<DebugCompressionType> CompressDebugSections(
|
|||
cl::init(DebugCompressionType::None),
|
||||
cl::desc("Choose DWARF debug sections compression:"),
|
||||
cl::values(clEnumValN(DebugCompressionType::None, "none", "No compression"),
|
||||
clEnumValN(DebugCompressionType::Z, "zlib", "Use zlib"),
|
||||
clEnumValN(DebugCompressionType::Zstd, "zstd", "Use zstd")),
|
||||
clEnumValN(DebugCompressionType::Z, "zlib",
|
||||
"Use zlib compression")),
|
||||
cl::cat(MCCategory));
|
||||
|
||||
static cl::opt<bool>
|
||||
|
@ -399,15 +399,15 @@ int main(int argc, char **argv) {
|
|||
assert(MAI && "Unable to create target asm info!");
|
||||
|
||||
MAI->setRelaxELFRelocations(RelaxELFRel);
|
||||
|
||||
if (CompressDebugSections != DebugCompressionType::None) {
|
||||
if (const char *Reason = compression::getReasonIfUnsupported(
|
||||
compression::formatFor(CompressDebugSections))) {
|
||||
if (!compression::zlib::isAvailable()) {
|
||||
WithColor::error(errs(), ProgName)
|
||||
<< "--compress-debug-sections: " << Reason;
|
||||
<< "build tools with zlib to enable -compress-debug-sections";
|
||||
return 1;
|
||||
}
|
||||
MAI->setCompressDebugSections(CompressDebugSections);
|
||||
}
|
||||
MAI->setCompressDebugSections(CompressDebugSections);
|
||||
MAI->setPreserveAsmComments(PreserveComments);
|
||||
|
||||
// Package up features to be passed to target/subtarget
|
||||
|
|
|
@ -721,17 +721,16 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
|
|||
if (const auto *A = InputArgs.getLastArg(OBJCOPY_compress_debug_sections)) {
|
||||
Config.CompressionType = StringSwitch<DebugCompressionType>(A->getValue())
|
||||
.Case("zlib", DebugCompressionType::Z)
|
||||
.Case("zstd", DebugCompressionType::Zstd)
|
||||
.Default(DebugCompressionType::None);
|
||||
if (Config.CompressionType == DebugCompressionType::None) {
|
||||
if (Config.CompressionType == DebugCompressionType::None)
|
||||
return createStringError(
|
||||
errc::invalid_argument,
|
||||
"invalid or unsupported --compress-debug-sections format: %s",
|
||||
A->getValue());
|
||||
}
|
||||
if (const char *Reason = compression::getReasonIfUnsupported(
|
||||
compression::formatFor(Config.CompressionType)))
|
||||
return createStringError(errc::invalid_argument, Reason);
|
||||
if (!compression::zlib::isAvailable())
|
||||
return createStringError(
|
||||
errc::invalid_argument,
|
||||
"LLVM was not compiled with LLVM_ENABLE_ZLIB: can not compress");
|
||||
}
|
||||
|
||||
Config.AddGnuDebugLink = InputArgs.getLastArgValue(OBJCOPY_add_gnu_debuglink);
|
||||
|
|
|
@ -33,7 +33,7 @@ def compress_debug_sections
|
|||
: Joined<["--"], "compress-debug-sections=">,
|
||||
MetaVarName<"format">,
|
||||
HelpText<"Compress DWARF debug sections using specified format. Supported "
|
||||
"formats: zlib, zstd. Select zlib if <format> is omitted">;
|
||||
"formats: zlib">;
|
||||
def : Flag<["--"], "compress-debug-sections">, Alias<compress_debug_sections>,
|
||||
AliasArgs<["zlib"]>;
|
||||
def decompress_debug_sections : Flag<["--"], "decompress-debug-sections">,
|
||||
|
|
|
@ -30,15 +30,9 @@ static void testZlibCompression(StringRef Input, int Level) {
|
|||
|
||||
// Check that uncompressed buffer is the same as original.
|
||||
Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
|
||||
EXPECT_FALSE(std::move(E));
|
||||
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
||||
consumeError(std::move(E));
|
||||
|
||||
// decompress with Z dispatches to zlib::uncompress.
|
||||
E = compression::decompress(DebugCompressionType::Z, Compressed, Uncompressed,
|
||||
Input.size());
|
||||
EXPECT_FALSE(std::move(E));
|
||||
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
||||
|
||||
if (Input.size() > 0) {
|
||||
// Uncompression fails if expected length is too short.
|
||||
E = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
|
||||
|
@ -75,15 +69,9 @@ static void testZstdCompression(StringRef Input, int Level) {
|
|||
|
||||
// Check that uncompressed buffer is the same as original.
|
||||
Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
|
||||
EXPECT_FALSE(std::move(E));
|
||||
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
||||
consumeError(std::move(E));
|
||||
|
||||
// uncompress with Zstd dispatches to zstd::uncompress.
|
||||
E = compression::decompress(DebugCompressionType::Zstd, Compressed,
|
||||
Uncompressed, Input.size());
|
||||
EXPECT_FALSE(std::move(E));
|
||||
EXPECT_EQ(Input, toStringRef(Uncompressed));
|
||||
|
||||
if (Input.size() > 0) {
|
||||
// Uncompression fails if expected length is too short.
|
||||
E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
|
||||
|
|
|
@ -112,9 +112,6 @@ class LLVMConfig(object):
|
|||
have_zlib = getattr(config, 'have_zlib', None)
|
||||
if have_zlib:
|
||||
features.add('zlib')
|
||||
have_zstd = getattr(config, 'have_zstd', None)
|
||||
if have_zstd:
|
||||
features.add('zstd')
|
||||
|
||||
# Check if we should run long running tests.
|
||||
long_tests = lit_config.params.get('run_long_tests', None)
|
||||
|
|
Loading…
Reference in New Issue