diff options
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index e2e98d3..0b4e986 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -144,7 +144,7 @@ struct ELFWriter { uint64_t align(unsigned Alignment); - bool maybeWriteCompression(uint64_t Size, + bool maybeWriteCompression(uint32_t ChType, uint64_t Size, SmallVectorImpl<uint8_t> &CompressedContents, unsigned Alignment); @@ -819,8 +819,8 @@ MCSectionELF *ELFWriter::createRelocationSection(MCContext &Ctx, // Include the debug info compression header. bool ELFWriter::maybeWriteCompression( - uint64_t Size, SmallVectorImpl<uint8_t> &CompressedContents, - unsigned Alignment) { + uint32_t ChType, uint64_t Size, + SmallVectorImpl<uint8_t> &CompressedContents, unsigned Alignment) { uint64_t HdrSize = is64Bit() ? sizeof(ELF::Elf32_Chdr) : sizeof(ELF::Elf64_Chdr); if (Size <= HdrSize + CompressedContents.size()) @@ -828,13 +828,13 @@ bool ELFWriter::maybeWriteCompression( // Platform specific header is followed by compressed data. if (is64Bit()) { // Write Elf64_Chdr header. - write(static_cast<ELF::Elf64_Word>(ELF::ELFCOMPRESS_ZLIB)); + write(static_cast<ELF::Elf64_Word>(ChType)); write(static_cast<ELF::Elf64_Word>(0)); // ch_reserved field. write(static_cast<ELF::Elf64_Xword>(Size)); write(static_cast<ELF::Elf64_Xword>(Alignment)); } else { // Write Elf32_Chdr header otherwise. - write(static_cast<ELF::Elf32_Word>(ELF::ELFCOMPRESS_ZLIB)); + write(static_cast<ELF::Elf32_Word>(ChType)); write(static_cast<ELF::Elf32_Word>(Size)); write(static_cast<ELF::Elf32_Word>(Alignment)); } @@ -856,38 +856,31 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec, return; } - assert((MAI->compressDebugSections() == DebugCompressionType::Z || - MAI->compressDebugSections() == DebugCompressionType::GNU) && - "expected zlib or zlib-gnu style compression"); + assert(MAI->compressDebugSections() == DebugCompressionType::Z && + "expected zlib style compression"); SmallVector<char, 128> UncompressedData; raw_svector_ostream VecOS(UncompressedData); Asm.writeSectionData(VecOS, &Section, Layout); - SmallVector<uint8_t, 128> CompressedContents; + SmallVector<uint8_t, 128> Compressed; + const uint32_t ChType = ELF::ELFCOMPRESS_ZLIB; compression::zlib::compress( makeArrayRef(reinterpret_cast<uint8_t *>(UncompressedData.data()), UncompressedData.size()), - CompressedContents); + Compressed); - bool ZlibStyle = MAI->compressDebugSections() == DebugCompressionType::Z; - if (!maybeWriteCompression(UncompressedData.size(), CompressedContents, + if (!maybeWriteCompression(ChType, UncompressedData.size(), Compressed, Sec.getAlignment())) { W.OS << UncompressedData; return; } - if (ZlibStyle) { - // Set the compressed flag. That is zlib style. - Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED); - // Alignment field should reflect the requirements of - // the compressed section header. - Section.setAlignment(is64Bit() ? Align(8) : Align(4)); - } else { - // Add "z" prefix to section name. This is zlib-gnu style. - MC.renameELFSection(&Section, (".z" + SectionName.drop_front(1)).str()); - } - W.OS << toStringRef(CompressedContents); + Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED); + // Alignment field should reflect the requirements of + // the compressed section header. + Section.setAlignment(is64Bit() ? Align(8) : Align(4)); + W.OS << toStringRef(Compressed); } void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags, |