[llvm] 6977ff4 - [MC] Delete dead zlib-gnu code and simplify writeSectionData

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 24 01:17:43 PDT 2022


Author: Fangrui Song
Date: 2022-07-24T01:17:34-07:00
New Revision: 6977ff40064d2f1891d3fd62cb6db2835c46d91e

URL: https://github.com/llvm/llvm-project/commit/6977ff40064d2f1891d3fd62cb6db2835c46d91e
DIFF: https://github.com/llvm/llvm-project/commit/6977ff40064d2f1891d3fd62cb6db2835c46d91e.diff

LOG: [MC] Delete dead zlib-gnu code and simplify writeSectionData

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCTargetOptions.h
    llvm/lib/MC/ELFObjectWriter.cpp
    llvm/lib/ObjCopy/ELF/ELFObject.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCTargetOptions.h b/llvm/include/llvm/MC/MCTargetOptions.h
index 9c906cdc90d02..ae305564a3536 100644
--- a/llvm/include/llvm/MC/MCTargetOptions.h
+++ b/llvm/include/llvm/MC/MCTargetOptions.h
@@ -27,7 +27,6 @@ enum class ExceptionHandling {
 
 enum class DebugCompressionType {
   None, ///< No compression
-  GNU,  ///< zlib-gnu style compression
   Z,    ///< zlib style complession
 };
 

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index e2e98d38289d7..0b4e9866d50af 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,

diff  --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index f0e4f91cd347b..8b44c09023f19 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -523,9 +523,6 @@ Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
   case DebugCompressionType::None:
     std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), Buf);
     return Error::success();
-  case DebugCompressionType::GNU:
-    llvm_unreachable("unexpected zlib-gnu");
-    break;
   case DebugCompressionType::Z:
     Chdr.ch_type = ELF::ELFCOMPRESS_ZLIB;
     break;


        


More information about the llvm-commits mailing list