diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -204,6 +204,7 @@ * (Experimental) :manpage:`llvm-symbolizer(1)` now has ``--filter-markup`` to filter :doc:`Symbolizer Markup ` into human-readable form. +* :doc:`llvm-objcopy ` has removed support for the legacy ``zlib-gnu`` format. Changes to LLDB --------------------------------- diff --git a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp --- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp @@ -53,8 +53,7 @@ using SectionPred = std::function; static bool isDebugSection(const SectionBase &Sec) { - return StringRef(Sec.Name).startswith(".debug") || - StringRef(Sec.Name).startswith(".zdebug") || Sec.Name == ".gdb_index"; + return StringRef(Sec.Name).startswith(".debug") || Sec.Name == ".gdb_index"; } static bool isDWOSection(const SectionBase &Sec) { diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h --- a/llvm/lib/ObjCopy/ELF/ELFObject.h +++ b/llvm/lib/ObjCopy/ELF/ELFObject.h @@ -554,8 +554,7 @@ Error accept(MutableSectionVisitor &Visitor) override; static bool classof(const SectionBase *S) { - return (S->OriginalFlags & ELF::SHF_COMPRESSED) || - (StringRef(S->Name).startswith(".zdebug")); + return S->OriginalFlags & ELF::SHF_COMPRESSED; } }; @@ -568,8 +567,6 @@ Size = Sec.getDecompressedSize(); Align = Sec.getDecompressedAlign(); Flags = OriginalFlags = (Flags & ~ELF::SHF_COMPRESSED); - if (StringRef(Name).startswith(".zdebug")) - Name = "." + Name.substr(2); } Error accept(SectionVisitor &Visitor) const override; diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp --- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp +++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp @@ -519,27 +519,22 @@ template Error ELFSectionWriter::visit(const CompressedSection &Sec) { uint8_t *Buf = reinterpret_cast(Out.getBufferStart()) + Sec.Offset; - if (Sec.CompressionType == DebugCompressionType::None) { + Elf_Chdr_Impl Chdr; + switch (Sec.CompressionType) { + case DebugCompressionType::None: std::copy(Sec.OriginalData.begin(), Sec.OriginalData.end(), Buf); return Error::success(); - } - - if (Sec.CompressionType == DebugCompressionType::GNU) { - const char *Magic = "ZLIB"; - memcpy(Buf, Magic, strlen(Magic)); - Buf += strlen(Magic); - const uint64_t DecompressedSize = - support::endian::read64be(&Sec.DecompressedSize); - memcpy(Buf, &DecompressedSize, sizeof(DecompressedSize)); - Buf += sizeof(DecompressedSize); - } else { - Elf_Chdr_Impl Chdr; + case DebugCompressionType::GNU: + llvm_unreachable("unexpected zlib-gnu"); + break; + case DebugCompressionType::Z: Chdr.ch_type = ELF::ELFCOMPRESS_ZLIB; - Chdr.ch_size = Sec.DecompressedSize; - Chdr.ch_addralign = Sec.DecompressedAlign; - memcpy(Buf, &Chdr, sizeof(Chdr)); - Buf += sizeof(Chdr); + break; } + Chdr.ch_size = Sec.DecompressedSize; + Chdr.ch_addralign = Sec.DecompressedAlign; + memcpy(Buf, &Chdr, sizeof(Chdr)); + Buf += sizeof(Chdr); std::copy(Sec.CompressedData.begin(), Sec.CompressedData.end(), Buf); return Error::success(); @@ -553,18 +548,13 @@ OriginalData.size()), CompressedData); - size_t ChdrSize; - if (CompressionType == DebugCompressionType::GNU) { - Name = ".z" + Sec.Name.substr(1); - ChdrSize = sizeof("ZLIB") - 1 + sizeof(uint64_t); - } else { - Flags |= ELF::SHF_COMPRESSED; - ChdrSize = - std::max(std::max(sizeof(object::Elf_Chdr_Impl), - sizeof(object::Elf_Chdr_Impl)), - std::max(sizeof(object::Elf_Chdr_Impl), - sizeof(object::Elf_Chdr_Impl))); - } + assert(CompressionType != DebugCompressionType::None); + Flags |= ELF::SHF_COMPRESSED; + size_t ChdrSize = + std::max(std::max(sizeof(object::Elf_Chdr_Impl), + sizeof(object::Elf_Chdr_Impl)), + std::max(sizeof(object::Elf_Chdr_Impl), + sizeof(object::Elf_Chdr_Impl))); Size = ChdrSize + CompressedData.size(); Align = 8; } diff --git a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-default-gnu.test b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-default-gnu.test deleted file mode 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-default-gnu.test +++ /dev/null @@ -1,9 +0,0 @@ -# REQUIRES: zlib - -# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t.o -# RUN: llvm-objcopy --compress-debug-sections --compress-debug-sections=zlib-gnu %t.o %t-compressed.o -# RUN: llvm-objdump -s %t-compressed.o | FileCheck %s - -# CHECK: .zdebug_foo: -# CHECK: ZLIB - diff --git a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-groups.test b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-groups.test --- a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-groups.test +++ b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-groups.test @@ -10,27 +10,11 @@ # RUN: llvm-readobj -S --section-groups %t-compressed.o | \ # RUN: FileCheck %s --check-prefixes=CHECK,COMPRESS -## Check zlib-gnu compression of debug sections. -# RUN: llvm-objcopy --compress-debug-sections=zlib-gnu %t.o %t-compressed-gnu.o -# RUN: llvm-readobj -S --section-groups %t-compressed-gnu.o | \ -# RUN: FileCheck %s --check-prefixes=CHECK,COMPRESSZLIB - ## Check decompression of debug sections. # RUN: llvm-objcopy --decompress-debug-sections %t-compressed.o %t-decompressed.o # RUN: llvm-readobj --section-groups %t-decompressed.o | \ # RUN: FileCheck %s --check-prefixes=CHECK,DECOMPRESS -## Check decompression of zlib-gnu debug sections. -# RUN: llvm-objcopy --decompress-debug-sections %t-compressed-gnu.o %t-decompressed-gnu.o -# RUN: llvm-readobj --section-groups %t-decompressed-gnu.o | \ -# RUN: FileCheck %s --check-prefixes=CHECK,DECOMPRESS - -# COMPRESSZLIB: Name: .zdebug_in_group -# COMPRESSZLIB-NEXT: Type: SHT_PROGBITS -# COMPRESSZLIB-NEXT: Flags [ -# COMPRESSZLIB-NEXT: SHF_GROUP -# COMPRESSZLIB-NEXT: ] - # COMPRESS: Name: .debug_in_group # COMPRESS-NEXT: Type: SHT_PROGBITS # COMPRESS-NEXT: Flags [ @@ -47,7 +31,6 @@ # CHECK-NEXT: Signature: groupname # CHECK-NEXT: Section(s) in group [ # CHECK-NEXT: .text.in.group -# COMPRESSZLIB-NEXT: .zdebug_in_group # COMPRESS-NEXT: .debug_in_group # DECOMPRESS-NEXT: .debug_in_group # CHECK-NEXT: ] diff --git a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-invalid-format.test b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-invalid-format.test --- a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-invalid-format.test +++ b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-invalid-format.test @@ -1,5 +1,6 @@ # RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t.o # RUN: not llvm-objcopy --compress-debug-sections=zlib-fake %t.o 2>&1 | FileCheck %s +# RUN: not llvm-objcopy --compress-debug-sections=zlib-gnu %t.o 2>&1 | FileCheck %s --check-prefix=GNU # CHECK: invalid or unsupported --compress-debug-sections format: zlib-fake - +# GNU: invalid or unsupported --compress-debug-sections format: zlib-gnu diff --git a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-symbols.test b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-symbols.test --- a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-symbols.test +++ b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-symbols.test @@ -6,10 +6,7 @@ ## and it is placed into the right section. # RUN: llvm-objcopy --compress-debug-sections %t.o %t-compressed1.o -# RUN: llvm-readobj --symbols %t-compressed1.o | FileCheck %s --check-prefixes=CHECK,ZLIB - -# RUN: llvm-objcopy --compress-debug-sections=zlib-gnu %t.o %t-compressed2.o -# RUN: llvm-readobj --symbols %t-compressed2.o | FileCheck %s --check-prefixes=CHECK,ZLIBGNU +# RUN: llvm-readobj --symbols %t-compressed1.o | FileCheck %s # CHECK: Name: .Linfo_string0 # CHECK-NEXT: Value: 0x0 @@ -17,5 +14,4 @@ # CHECK-NEXT: Binding: Global # CHECK-NEXT: Type: None # CHECK-NEXT: Other: 0 -# ZLIB-NEXT: Section: .debug_bar -# ZLIBGNU-NEXT: Section: .zdebug_bar +# CHECK-NEXT: Section: .debug_bar diff --git a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-zlib-gnu.test b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-zlib-gnu.test deleted file mode 100644 --- a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-zlib-gnu.test +++ /dev/null @@ -1,57 +0,0 @@ -# REQUIRES: zlib - -# RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t.o -# RUN: llvm-objcopy --compress-debug-sections=zlib-gnu %t.o %t-compressed.o -# RUN: llvm-objcopy --decompress-debug-sections %t-compressed.o %t-decompressed.o - -# RUN: llvm-objdump -s %t.o --section=.debug_foo | FileCheck %s -# RUN: llvm-objdump -s %t-compressed.o | FileCheck %s --check-prefix=CHECK-COMPRESSED -# RUN: llvm-readobj --relocations -S %t-compressed.o | FileCheck %s --check-prefix=CHECK-FLAGS -# RUN: llvm-readobj --relocations -S %t-decompressed.o | FileCheck %s --check-prefix=CHECK-HEADER -# RUN: llvm-readobj --relocations -S %t.o | FileCheck %s --check-prefix=CHECK-HEADER -# RUN: llvm-objdump -s %t-decompressed.o --section=.debug_foo | FileCheck %s - -# CHECK: .debug_foo: -# CHECK-NEXT: 0000 00000000 00000000 - -# CHECK-HEADER: Name: .debug_foo -# CHECK-HEADER-NEXT: Type: SHT_PROGBITS -# CHECK-HEADER-NEXT: Flags [ -# CHECK-HEADER-NEXT: ] -# CHECK-HEADER-NEXT: Address: -# CHECK-HEADER-NEXT: Offset: -# CHECK-HEADER-NEXT: Size: 8 - -# CHECK-COMPRESSED: .zdebug_foo: -# CHECK-COMPRESSED: ZLIB -# CHECK-COMPRESSED: .notdebug_foo: - -# CHECK-FLAGS-NOT: Name: .debug_foo -# CHECK-FLAGS: Name: .zdebug_foo -# CHECK-FLAGS-NEXT: Type: SHT_PROGBITS -# CHECK-FLAGS-NEXT: Flags [ -# CHECK-FLAGS-NEXT: ] -# CHECK-FLAGS-NEXT: Address: -# CHECK-FLAGS-NEXT: Offset: -# CHECK-FLAGS-NEXT: Size: 23 - -# CHECK-FLAGS: Name: .notdebug_foo -# CHECK-FLAGS-NEXT: Type: SHT_PROGBITS -# CHECK-FLAGS-NEXT: Flags [ -# CHECK-FLAGS-NEXT: ] -# CHECK-FLAGS-NEXT: Address: -# CHECK-FLAGS-NEXT: Offset: -# CHECK-FLAGS-NEXT: Size: 8 - -# CHECK-FLAGS: Name: .rela.debug_foo -# CHECK-FLAGS-NEXT: Type: SHT_RELA -# CHECK-FLAGS-NEXT: Flags [ -# CHECK-FLAGS-NEXT: ] - -# CHECK-FLAGS: Relocations [ -# CHECK-FLAGS-NEXT: .rela.debug_foo { -# CHECK-FLAGS-NEXT: 0x1 R_X86_64_32 .zdebug_foo 0x0 -# CHECK-FLAGS-NEXT: 0x2 R_X86_64_32 .notdebug_foo 0x0 -# CHECK-FLAGS-NEXT: } -# CHECK-FLAGS-NEXT: ] - diff --git a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections.test b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections.test --- a/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections.test +++ b/llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections.test @@ -4,21 +4,15 @@ # RUN: cp %t.o %t.copy.o # RUN: llvm-objcopy --compress-debug-sections=zlib %t.o %tz.o -# RUN: llvm-objcopy --compress-debug-sections=zlib-gnu %t.o %tzg.o # RUN: cp %tz.o %tz.copy.o -# RUN: cp %tzg.o %tzg.copy.o # RUN: llvm-objcopy --decompress-debug-sections %tz.o %t2.o -# RUN: llvm-objcopy --decompress-debug-sections %tzg.o %t3.o # Using redirects to avoid llvm-objdump from printing the filename. # RUN: llvm-objdump -s --section=.debug_str - < %t.o > %t.txt # RUN: llvm-objdump -s --section=.debug_str - < %t2.o > %t2.txt -# RUN: llvm-objdump -s --section=.debug_str - < %t3.o > %t3.txt # RUN: diff %t.txt %t2.txt -# RUN: diff %t.txt %t3.txt # RUN: cmp %t.o %t.copy.o # RUN: cmp %tz.o %tz.copy.o -# RUN: cmp %tzg.o %tzg.copy.o diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test b/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test --- a/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test +++ b/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test @@ -98,6 +98,7 @@ - Name: .debugfoo Type: SHT_PROGBITS Content: "00000000" + ## .zdebug is no longer recognized as a debug section. - Name: .zdebugfoo Type: SHT_PROGBITS Content: "00000000" @@ -119,8 +120,9 @@ - Name: filesymbol Type: STT_FILE -# CHECK: SectionHeaderCount: 5 +# CHECK: SectionHeaderCount: 6 +# CHECK: Name: .zdebugfoo # CHECK: Name: .text # CHECK: Name: .symtab # CHECK: Name: .strtab diff --git a/llvm/test/tools/llvm-objcopy/ELF/zdebug.yaml b/llvm/test/tools/llvm-objcopy/ELF/zdebug.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/zdebug.yaml @@ -0,0 +1,24 @@ +## .zdebug is no longer recognized as zlib-gnu compressed sections. It's treated +## as an opaque non-debug section. +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy --decompress-debug-sections %t %t.copy +# RUN: llvm-readelf -S %t.copy | FileCheck %s + +# CHECK: .zdebug_str + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Content: '00' + - Name: .zdebug_str + Type: SHT_PROGBITS + Content: 5a4c49420000000000000002789c4b64000000c40062 + AddressAlign: 8 +... diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -729,7 +729,6 @@ Config.CompressionType = StringSwitch( InputArgs.getLastArgValue(OBJCOPY_compress_debug_sections_eq)) - .Case("zlib-gnu", DebugCompressionType::GNU) .Case("zlib", DebugCompressionType::Z) .Default(DebugCompressionType::None); if (Config.CompressionType == DebugCompressionType::None) diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td --- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -32,9 +32,9 @@ def compress_debug_sections : Flag<["--"], "compress-debug-sections">; def compress_debug_sections_eq : Joined<["--"], "compress-debug-sections=">, - MetaVarName<"[ zlib | zlib-gnu ]">, + MetaVarName<"[ zlib ]">, HelpText<"Compress DWARF debug sections using specified style. Supported " - "styles: 'zlib-gnu' and 'zlib'">; + "formats: 'zlib'">; def decompress_debug_sections : Flag<["--"], "decompress-debug-sections">, HelpText<"Decompress DWARF debug sections.">; defm split_dwo