forked from OSchip/llvm-project
[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
This commit is contained in:
parent
dd48d3ad0e
commit
45ae553109
|
@ -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
|
||||
---------------------------------
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -554,8 +554,7 @@ public:
|
|||
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 @@ public:
|
|||
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;
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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: ]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: ]
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
...
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue