[ELF] Remove support for legacy .zdebug sections

.zdebug is unlikely used any longer: gcc -gz switched from legacy
.zdebug to SHF_COMPRESSED with binutils 2.26 (2016), which has been
several years. clang 14 dropped -gz=zlib-gnu support. According to
Debian Code Search (`gz=zlib-gnu`), no project uses -gz=zlib-gnu.

Remove .zdebug support to (a) simplify code and (b) allow removal of llvm-mc's
--compress-debug-sections=zlib-gnu.

In case the old object file `a.o` uses .zdebug, run `objcopy --decompress-debug-sections a.o`

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D126793
This commit is contained in:
Fangrui Song 2022-06-02 13:37:19 -07:00
parent dfa9221aa7
commit e09f77d394
6 changed files with 7 additions and 102 deletions

View file

@ -70,11 +70,9 @@ InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
fatal(toString(this) + ": sh_addralign is not a power of 2");
this->alignment = v;
// In ELF, each section can be compressed by zlib, and if compressed,
// section name may be mangled by appending "z" (e.g. ".zdebug_info").
// If that's the case, demangle section name so that we can handle a
// section as if it weren't compressed.
if ((flags & SHF_COMPRESSED) || name.startswith(".zdebug")) {
// If SHF_COMPRESSED is set, parse the header. The legacy .zdebug format is no
// longer supported.
if (flags & SHF_COMPRESSED) {
if (!zlib::isAvailable())
error(toString(file) + ": contains a compressed section, " +
"but zlib is not available");
@ -204,29 +202,6 @@ OutputSection *SectionBase::getOutputSection() {
// by zlib-compressed data. This function parses a header to initialize
// `uncompressedSize` member and remove the header from `rawData`.
template <typename ELFT> void InputSectionBase::parseCompressedHeader() {
// Old-style header
if (!(flags & SHF_COMPRESSED)) {
assert(name.startswith(".zdebug"));
if (!toStringRef(rawData).startswith("ZLIB")) {
error(toString(this) + ": corrupted compressed section header");
return;
}
rawData = rawData.slice(4);
if (rawData.size() < 8) {
error(toString(this) + ": corrupted compressed section header");
return;
}
uncompressedSize = read64be(rawData.data());
rawData = rawData.slice(8);
// Restore the original section name.
// (e.g. ".zdebug_info" -> ".debug_info")
name = saver().save("." + name.substr(2));
return;
}
flags &= ~(uint64_t)SHF_COMPRESSED;
// New-style header

View file

@ -387,7 +387,7 @@ static_assert(sizeof(InputSection) <= 160, "InputSection is too big");
inline bool isDebugSection(const InputSectionBase &sec) {
return (sec.flags & llvm::ELF::SHF_ALLOC) == 0 &&
(sec.name.startswith(".debug") || sec.name.startswith(".zdebug"));
sec.name.startswith(".debug");
}
// The list of all input sections.

View file

@ -38,6 +38,9 @@ Breaking changes
* ``-d`` is now ignored.
* If a prevailing COMDAT group defines STB_WEAK symbol, having a STB_GLOBAL symbol in a non-prevailing group is now rejected with a diagnostic.
(`D120626 <https://reviews.llvm.org/D120626>`_)
* Support for the legacy ``.zdebug`` format has been removed. Run
``objcopy --decompress-debug-sections`` in case old object files use ``.zdebug``.
(`D126793 <https://reviews.llvm.org/D126793>`_)
COFF Improvements
-----------------

View file

@ -22,37 +22,11 @@
# ZLIB-NEXT: EntrySize: 1
# ZLIB-NEXT: }
# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-unknown-linux %s -o %t2
# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=powerpc64-unknown-unknown %s -o %t2-be
# RUN: llvm-readobj --sections %t2 | FileCheck -check-prefix=GNU %s
# RUN: llvm-readobj --sections %t2-be | FileCheck -check-prefix=GNU %s
# GNU: Section {
# GNU: Index: 2
# GNU: Name: .zdebug_str
# GNU-NEXT: Type: SHT_PROGBITS
# GNU-NEXT: Flags [
# GNU-NEXT: SHF_MERGE (0x10)
# GNU-NEXT: SHF_STRINGS (0x20)
# GNU-NEXT: ]
# GNU-NEXT: Address:
# GNU-NEXT: Offset:
# GNU-NEXT: Size:
# GNU-NEXT: Link:
# GNU-NEXT: Info:
# GNU-NEXT: AddressAlignment: 1
# GNU-NEXT: EntrySize: 1
# GNU-NEXT: }
# RUN: ld.lld --hash-style=sysv %t -o %t.so -shared
# RUN: llvm-readobj --sections --section-data %t.so | FileCheck -check-prefix=DATA %s
# RUN: ld.lld --hash-style=sysv %t-be -o %t-be.so -shared
# RUN: llvm-readobj --sections --section-data %t-be.so | FileCheck -check-prefix=DATA %s
# RUN: ld.lld --hash-style=sysv %t2 -o %t2.so -shared
# RUN: llvm-readobj --sections --section-data %t2.so | FileCheck -check-prefix=DATA %s
# RUN: ld.lld --hash-style=sysv %t2-be -o %t2-be.so -shared
# RUN: llvm-readobj --sections --section-data %t2-be.so | FileCheck -check-prefix=DATA %s
# DATA: Section {
# DATA: Index: 6
# DATA: Name: .debug_str

View file

@ -1,45 +0,0 @@
# REQUIRES: x86, zlib
# RUN: llvm-mc -compress-debug-sections=zlib-gnu -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
# RUN: llvm-readobj --sections %t1 | FileCheck -check-prefix=GNU %s
# GNU: Name: .zdebug_str
# RUN: ld.lld %t1 -o %t2 -r
# RUN: llvm-readobj --sections --section-data %t2 | FileCheck %s
## Check we uncompress section and remove ".z" prefix specific for zlib-gnu compression.
# CHECK: Section {
# CHECK: Index:
# CHECK: Name: .debug_str
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_MERGE
# CHECK-NEXT: SHF_STRINGS
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset:
# CHECK-NEXT: Size:
# CHECK-NEXT: Link:
# CHECK-NEXT: Info:
# CHECK-NEXT: AddressAlignment: 1
# CHECK-NEXT: EntrySize: 1
# CHECK-NEXT: SectionData (
# CHECK-NEXT: 0000: {{.*}} |unsigned int.cha|
# CHECK-NEXT: 0010: {{.*}} |r.unsigned char.|
# CHECK-NEXT: 0020: {{.*}} |short unsigned i|
# CHECK-NEXT: 0030: {{.*}} |nt.long unsigned|
# CHECK-NEXT: 0040: {{.*}} | int.|
# CHECK-NEXT: )
# CHECK-NEXT: }
.section .debug_str,"MS",@progbits,1
.LASF2:
.string "short unsigned int"
.LASF3:
.string "unsigned int"
.LASF0:
.string "long unsigned int"
.LASF8:
.string "char"
.LASF1:
.string "unsigned char"

View file

@ -11,6 +11,4 @@
# CHECK-NOT: Bar
.section .debug_Foo,"",@progbits
.section .zdebug_Bar,"",@progbits
.ascii "ZLIB"
.quad 0