[llvm] [ObjCopy] Reject compress-debug-sections for non-ELF (PR #191314)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 9 15:23:44 PDT 2026
https://github.com/nataliakokoromyti created https://github.com/llvm/llvm-project/pull/191314
`--compress-debug-sections` is currently an ELF-only option in the [docs](https://llvm.org/docs/CommandGuide/llvm-objcopy.html#cmdoption-llvm-objcopy-compress-debug-sections) but in `llvm-objcopy`, non-ELF backends were silently ignoring it, while `--decompress-debug-sections` already [reports](https://github.com/llvm/llvm-project/blob/89446086eaed6f07e2c122396570f2985cec62e5/llvm/lib/ObjCopy/ConfigManager.cpp#L32) unsupported-option error.
This PR makes behavior consistent by treating `--compress-debug-sections` as unsupported for non-ELF formats too (via `Common.CompressionType != DebugCompressionType::None`) in:
- `getCOFFConfig()`
- `getMachOConfig()`
- `getXCOFFConfig()`
- `getDXContainerConfig()`
>From c44ea334a75d9cccc7569f2bf011b39c3a2f1a5d Mon Sep 17 00:00:00 2001
From: nataliakokoromyti <nataliakokoromyti at gmail.com>
Date: Thu, 9 Apr 2026 14:42:55 -0700
Subject: [PATCH] [ObjCopy] Reject compress-debug-sections for non-ELF
---
llvm/lib/ObjCopy/ConfigManager.cpp | 13 ++++++++++---
.../COFF/compress-debug-sections-unsupported.test | 7 +++++++
2 files changed, 17 insertions(+), 3 deletions(-)
create mode 100644 llvm/test/tools/llvm-objcopy/COFF/compress-debug-sections-unsupported.test
diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp
index 7424865a2e5e2..9f375f6bb664a 100644
--- a/llvm/lib/ObjCopy/ConfigManager.cpp
+++ b/llvm/lib/ObjCopy/ConfigManager.cpp
@@ -29,7 +29,9 @@ Expected<const COFFConfig &> ConfigManager::getCOFFConfig() const {
!Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() ||
!Common.SetSectionAlignment.empty() || !Common.SetSectionType.empty() ||
Common.ExtractDWO || Common.StripDWO || Common.StripNonAlloc ||
- Common.StripSections || Common.Weaken || Common.DecompressDebugSections ||
+ Common.StripSections || Common.Weaken ||
+ Common.CompressionType != DebugCompressionType::None ||
+ Common.DecompressDebugSections ||
Common.DiscardMode == DiscardType::Locals ||
!Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
@@ -50,6 +52,7 @@ Expected<const MachOConfig &> ConfigManager::getMachOConfig() const {
!Common.SetSectionType.empty() || Common.ExtractDWO ||
Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
Common.StripNonAlloc || Common.StripSections ||
+ Common.CompressionType != DebugCompressionType::None ||
Common.DecompressDebugSections || Common.StripUnneeded ||
Common.DiscardMode == DiscardType::Locals ||
!Common.SymbolsToAdd.empty() || Common.GapFill != 0 ||
@@ -102,7 +105,9 @@ Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
Common.ExtractMainPartition || Common.OnlyKeepDebug ||
Common.PreserveDates || Common.StripAllGNU || Common.StripDWO ||
Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
- Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections ||
+ Common.Weaken || Common.StripUnneeded ||
+ Common.CompressionType != DebugCompressionType::None ||
+ Common.DecompressDebugSections ||
Common.GapFill != 0 || Common.PadTo != 0 ||
Common.ChangeSectionLMAValAll != 0 ||
!Common.ChangeSectionAddress.empty() || !Common.ExtractSection.empty()) {
@@ -126,7 +131,9 @@ ConfigManager::getDXContainerConfig() const {
!Common.SetSectionType.empty() || Common.ExtractDWO ||
Common.OnlyKeepDebug || Common.StripAllGNU || Common.StripDWO ||
Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
- Common.StripUnneeded || Common.DecompressDebugSections ||
+ Common.StripUnneeded ||
+ Common.CompressionType != DebugCompressionType::None ||
+ Common.DecompressDebugSections ||
Common.GapFill != 0 || Common.PadTo != 0 ||
Common.ChangeSectionLMAValAll != 0 ||
!Common.ChangeSectionAddress.empty()) {
diff --git a/llvm/test/tools/llvm-objcopy/COFF/compress-debug-sections-unsupported.test b/llvm/test/tools/llvm-objcopy/COFF/compress-debug-sections-unsupported.test
new file mode 100644
index 0000000000000..4a1aa40478778
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/COFF/compress-debug-sections-unsupported.test
@@ -0,0 +1,7 @@
+## --compress-debug-sections is ELF-only and should be rejected for COFF.
+# REQUIRES: zlib
+
+# RUN: yaml2obj %p/Inputs/x86_64-obj.yaml -o %t.in.o
+# RUN: not llvm-objcopy --compress-debug-sections %t.in.o %t.out.o 2>&1 | FileCheck %s
+
+# CHECK: error: option is not supported for COFF
More information about the llvm-commits
mailing list