Obj, isCompressable,
[&Config, &Obj](const SectionBase *S) -> Expected<SectionBase *> {
return &Obj.addSection<CompressedSection>(
- CompressedSection(*S, Config.CompressionType));
+ CompressedSection(*S, Config.CompressionType, Obj.Is64Bits));
}))
return Err;
} else if (Config.DecompressDebugSections) {
}
CompressedSection::CompressedSection(const SectionBase &Sec,
- DebugCompressionType CompressionType)
+ DebugCompressionType CompressionType,
+ bool Is64Bits)
: SectionBase(Sec), CompressionType(CompressionType),
DecompressedSize(Sec.OriginalData.size()), DecompressedAlign(Sec.Align) {
compression::compress(compression::Params(CompressionType), OriginalData,
CompressedData);
Flags |= ELF::SHF_COMPRESSED;
- size_t ChdrSize =
- std::max(std::max(sizeof(object::Elf_Chdr_Impl<object::ELF64LE>),
- sizeof(object::Elf_Chdr_Impl<object::ELF64BE>)),
- std::max(sizeof(object::Elf_Chdr_Impl<object::ELF32LE>),
- sizeof(object::Elf_Chdr_Impl<object::ELF32BE>)));
+ size_t ChdrSize = Is64Bits ? sizeof(object::Elf_Chdr_Impl<object::ELF64LE>)
+ : sizeof(object::Elf_Chdr_Impl<object::ELF32LE>);
Size = ChdrSize + CompressedData.size();
Align = 8;
}
return HeadersFile.takeError();
const typename ELFFile<ELFT>::Elf_Ehdr &Ehdr = HeadersFile->getHeader();
+ Obj.Is64Bits = Ehdr.e_ident[EI_CLASS] == ELFCLASS64;
Obj.OSABI = Ehdr.e_ident[EI_OSABI];
Obj.ABIVersion = Ehdr.e_ident[EI_ABIVERSION];
Obj.Type = Ehdr.e_type;
public:
CompressedSection(const SectionBase &Sec,
- DebugCompressionType CompressionType);
+ DebugCompressionType CompressionType, bool Is64Bits);
CompressedSection(ArrayRef<uint8_t> CompressedData, uint32_t ChType,
uint64_t DecompressedSize, uint64_t DecompressedAlign);
Segment ElfHdrSegment;
Segment ProgramHdrSegment;
+ bool Is64Bits;
uint8_t OSABI;
uint8_t ABIVersion;
uint64_t Entry;
# 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 %}
+## Test roundtrip for ELFCLASS32.
+# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t32 && llvm-objcopy %t32
+# RUN: llvm-objcopy --compress-debug-sections=zstd %t32 %t32-zstd
+# RUN: llvm-objcopy --decompress-debug-sections %t32-zstd %t32-de
+# RUN: cmp %t32 %t32-de
+
# 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