[llvm] e18b7c7 - [llvm-objcopy] Support --decompress-debug-sections when zlib is disabled
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 12 11:52:13 PDT 2022
Author: Fangrui Song
Date: 2022-10-12T11:52:05-07:00
New Revision: e18b7c7ae0c13909d7f1304aee8621781a3c27a0
URL: https://github.com/llvm/llvm-project/commit/e18b7c7ae0c13909d7f1304aee8621781a3c27a0
DIFF: https://github.com/llvm/llvm-project/commit/e18b7c7ae0c13909d7f1304aee8621781a3c27a0.diff
LOG: [llvm-objcopy] Support --decompress-debug-sections when zlib is disabled
When zlib is disabled at build time, the diagnostic `LLVM was not compiled with
LLVM_ENABLE_ZLIB: cannot decompress` for --decompress-debug-sections may be
inaccurate: if zstd is enabled, we should still support zstd decompression.
It's not useful to test zlib and zstd. Just remove the diagnostic and add a new
one before `compression::decompress`.
This fixes compress-debug-sections-zstd.test
Reviewed By: mariusz-sikora-at-amd, jhenderson, phosek
Differential Revision: https://reviews.llvm.org/D135744
Added:
llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test
Modified:
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index abbced61f5f2a..2ff94baf60caf 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -453,6 +453,11 @@ Error ELFSectionWriter<ELFT>::visit(const DecompressedSection &Sec) {
Twine(Sec.ChType) + ") of section '" +
Sec.Name + "' is unsupported");
}
+ if (auto *Reason =
+ compression::getReasonIfUnsupported(compression::formatFor(Type)))
+ return createStringError(errc::invalid_argument,
+ "failed to decompress section '" + Sec.Name +
+ "': " + Reason);
if (Error E = compression::decompress(Type, Compressed, Decompressed,
static_cast<size_t>(Sec.Size)))
return createStringError(errc::invalid_argument,
diff --git a/llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test b/llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test
new file mode 100644
index 0000000000000..34ca53c270fc3
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test
@@ -0,0 +1,18 @@
+# UNSUPPORTED: zlib
+# RUN: yaml2obj %s -o %t
+# RUN: not llvm-objcopy --decompress-debug-sections %t /dev/null 2>&1 | FileCheck %s -DFILE=%t
+
+# CHECK: error: '[[FILE]]': failed to decompress section '.debug_info': LLVM was not built with LLVM_ENABLE_ZLIB or did not find zlib at build time
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Type: SHT_PROGBITS
+ Name: .debug_info
+ Flags: [ SHF_COMPRESSED ]
+ AddressAlign: 8
+ Content: "010000000000000001000000000000000100000000000000789c63040000020002"
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index b2250ca8facda..1f7321e4f4b6b 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -993,11 +993,6 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
"--decompress-debug-sections");
}
- if (Config.DecompressDebugSections && !compression::zlib::isAvailable())
- return createStringError(
- errc::invalid_argument,
- "LLVM was not compiled with LLVM_ENABLE_ZLIB: cannot decompress");
-
if (Config.ExtractPartition && Config.ExtractMainPartition)
return createStringError(errc::invalid_argument,
"cannot specify --extract-partition together with "
More information about the llvm-commits
mailing list