[llvm] 45ae553 - [llvm-objcopy] Remove support for legacy .zdebug sections
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 10:42:59 PDT 2022
Author: Fangrui Song
Date: 2022-06-29T10:42:55-07:00
New Revision: 45ae553109af8e1e71ae5ddf3d92fc1bf531aea1
URL: https://github.com/llvm/llvm-project/commit/45ae553109af8e1e71ae5ddf3d92fc1bf531aea1
DIFF: https://github.com/llvm/llvm-project/commit/45ae553109af8e1e71ae5ddf3d92fc1bf531aea1.diff
LOG: [llvm-objcopy] Remove support for legacy .zdebug sections
clang 14 removed -gz=zlib-gnu support and ld.lld removed linker input support
for zlib-gnu in D126793. Now let's remove zlib-gnu from llvm-objcopy.
* .zdebug* sections are no longer recognized as debug sections. --strip* don't remove them.
They are copied like other opaque sections
* --decompress-debug-sections does not uncompress .zdebug* sections
* --compress-debug-sections=zlib-gnu is not supported
It is very rare but in case a user has object files using .zdebug . They can use
llvm-objcopy<15 or GNU objcopy for uncompression.
--compress-debug-sections=zlib-gnu is unlikely ever used by anyone, so I do not
add a custom diagnostic.
Differential Revision: https://reviews.llvm.org/D128688
Added:
llvm/test/tools/llvm-objcopy/ELF/zdebug.yaml
Modified:
llvm/docs/ReleaseNotes.rst
llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/lib/ObjCopy/ELF/ELFObject.h
llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-groups.test
llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-invalid-format.test
llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-symbols.test
llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections.test
llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
llvm/tools/llvm-objcopy/ObjcopyOpts.td
Removed:
llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-default-gnu.test
llvm/test/tools/llvm-objcopy/ELF/compress-debug-sections-zlib-gnu.test
################################################################################
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index d1c5d967be5ab..3b3345ed71e76 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -204,6 +204,7 @@ Changes to the LLVM tools
* (Experimental) :manpage:`llvm-symbolizer(1)` now has ``--filter-markup`` to
filter :doc:`Symbolizer Markup </SymbolizerMarkupFormat>` into human-readable
form.
+* :doc:`llvm-objcopy <CommandGuide/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
index 340640e2231bc..2d388f8a867ed 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
@@ -53,8 +53,7 @@ using namespace llvm::object;
using SectionPred = std::function<bool(const SectionBase &Sec)>;
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.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index d0e101e08ef3f..b241bd817ff56 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -519,27 +519,22 @@ Error BinarySectionWriter::visit(const CompressedSection &Sec) {
template <class ELFT>
Error ELFSectionWriter<ELFT>::visit(const CompressedSection &Sec) {
uint8_t *Buf = reinterpret_cast<uint8_t *>(Out.getBufferStart()) + Sec.Offset;
- if (Sec.CompressionType == DebugCompressionType::None) {
+ Elf_Chdr_Impl<ELFT> 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<ELFT> 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 @@ CompressedSection::CompressedSection(const SectionBase &Sec,
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<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>)));
- }
+ assert(CompressionType != DebugCompressionType::None);
+ 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 = ChdrSize + CompressedData.size();
Align = 8;
}
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h
index 896dae03f7398..f33bbb029c9b0 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.h
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.h
@@ -554,8 +554,7 @@ class CompressedSection : public SectionBase {
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 @@ class DecompressedSection : public SectionBase {
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/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
index 9db3d3b7f9cf4..0000000000000
--- 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
index 4eeef6e6d30fe..2e394c35faea7 100644
--- 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
index ae801dc7fbeac..862c47f438471 100644
--- 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
index 969aa5973bfd1..a3b5366cb63bd 100644
--- 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
index d2811b9ffad1e..0000000000000
--- 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
index 014303fe638f9..95513d04b5e61 100644
--- 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
index 4d7cb173c341f..3eefed2b20666 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-debug.test
@@ -98,6 +98,7 @@ Sections:
- 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 @@ Symbols:
- 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
index 0000000000000..19391979c1ef8
--- /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
index 95046d4d85ccc..5b2b4b5704d81 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -729,7 +729,6 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
Config.CompressionType =
StringSwitch<DebugCompressionType>(
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
index da6d6c4ef07de..ff73265989f36 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -32,9 +32,9 @@ defm new_symbol_visibility : Eq<"new-symbol-visibility", "Visibility of "
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
More information about the llvm-commits
mailing list