[PATCH] D135744: [llvm-objcopy] Support --decompress-debug-sections when zlib is disabled

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 11 21:39:21 PDT 2022


MaskRay created this revision.
MaskRay added reviewers: mariusz-sikora-at-amd, jhenderson, leonardchan, phosek.
Herald added subscribers: StephenFan, abrachet, hiraditya, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When zlib is disabled at build time, there is a wrong diagnostic `LLVM was not
compiled with LLVM_ENABLE_ZLIB: cannot decompress` for --decompress-debug-sections.
Remove it and add a check before `compression::decompress`.

This fixes compress-debug-sections-zstd.test


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135744

Files:
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp


Index: llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -993,11 +993,6 @@
         "--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 "
Index: llvm/test/tools/llvm-objcopy/ELF/decompress-debug-sections-unsupported-zlib.test
===================================================================
--- /dev/null
+++ 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"
Index: llvm/lib/ObjCopy/ELF/ELFObject.cpp
===================================================================
--- llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -453,6 +453,11 @@
                                  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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135744.467010.patch
Type: text/x-patch
Size: 2432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221012/7822cf3b/attachment.bin>


More information about the llvm-commits mailing list