[lld] e09f77d - [ELF] Remove support for legacy .zdebug sections
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 2 13:37:24 PDT 2022
Author: Fangrui Song
Date: 2022-06-02T13:37:19-07:00
New Revision: e09f77d39426dfd1a2cb05ac9de070220a3ef26f
URL: https://github.com/llvm/llvm-project/commit/e09f77d39426dfd1a2cb05ac9de070220a3ef26f
DIFF: https://github.com/llvm/llvm-project/commit/e09f77d39426dfd1a2cb05ac9de070220a3ef26f.diff
LOG: [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
Added:
Modified:
lld/ELF/InputSection.cpp
lld/ELF/InputSection.h
lld/docs/ReleaseNotes.rst
lld/test/ELF/compressed-debug-input.s
lld/test/ELF/strip-debug.s
Removed:
lld/test/ELF/relocatable-compressed-input.s
################################################################################
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 056119924a829..6acf4067b907e 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -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
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index e9b1ffadf44f5..c7c8f45f432db 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -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.
diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index b3751e53db55c..99d875a7ed5d7 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -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
-----------------
diff --git a/lld/test/ELF/compressed-debug-input.s b/lld/test/ELF/compressed-debug-input.s
index 70eb9d2a77b72..285f879504f90 100644
--- a/lld/test/ELF/compressed-debug-input.s
+++ b/lld/test/ELF/compressed-debug-input.s
@@ -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
diff --git a/lld/test/ELF/relocatable-compressed-input.s b/lld/test/ELF/relocatable-compressed-input.s
deleted file mode 100644
index c276a242c6f05..0000000000000
--- a/lld/test/ELF/relocatable-compressed-input.s
+++ /dev/null
@@ -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", at progbits,1
-.LASF2:
- .string "short unsigned int"
-.LASF3:
- .string "unsigned int"
-.LASF0:
- .string "long unsigned int"
-.LASF8:
- .string "char"
-.LASF1:
- .string "unsigned char"
diff --git a/lld/test/ELF/strip-debug.s b/lld/test/ELF/strip-debug.s
index 3ffd2f89de6f0..95cbe3a2c2b6c 100644
--- a/lld/test/ELF/strip-debug.s
+++ b/lld/test/ELF/strip-debug.s
@@ -11,6 +11,4 @@
# CHECK-NOT: Bar
.section .debug_Foo,"", at progbits
-.section .zdebug_Bar,"", at progbits
-.ascii "ZLIB"
.quad 0
More information about the llvm-commits
mailing list