[llvm] [ObjCopy] Reject compress-debug-sections for non-ELF (PR #191314)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 9 15:26:09 PDT 2026
https://github.com/nataliakokoromyti updated https://github.com/llvm/llvm-project/pull/191314
>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 1/2] [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
>From f7270e1917e57e5fae8a442a7da6be57f1daf7c9 Mon Sep 17 00:00:00 2001
From: nataliakokoromyti <nataliakokoromyti at gmail.com>
Date: Thu, 9 Apr 2026 15:25:59 -0700
Subject: [PATCH 2/2] Format fix
---
llvm/lib/ObjCopy/ConfigManager.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp
index 9f375f6bb664a..66acefd84bb6e 100644
--- a/llvm/lib/ObjCopy/ConfigManager.cpp
+++ b/llvm/lib/ObjCopy/ConfigManager.cpp
@@ -107,9 +107,8 @@ Expected<const XCOFFConfig &> ConfigManager::getXCOFFConfig() const {
Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
Common.Weaken || Common.StripUnneeded ||
Common.CompressionType != DebugCompressionType::None ||
- Common.DecompressDebugSections ||
- Common.GapFill != 0 || Common.PadTo != 0 ||
- Common.ChangeSectionLMAValAll != 0 ||
+ Common.DecompressDebugSections || Common.GapFill != 0 ||
+ Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
!Common.ChangeSectionAddress.empty() || !Common.ExtractSection.empty()) {
return createStringError(
llvm::errc::invalid_argument,
@@ -133,9 +132,8 @@ ConfigManager::getDXContainerConfig() const {
Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
Common.StripUnneeded ||
Common.CompressionType != DebugCompressionType::None ||
- Common.DecompressDebugSections ||
- Common.GapFill != 0 || Common.PadTo != 0 ||
- Common.ChangeSectionLMAValAll != 0 ||
+ Common.DecompressDebugSections || Common.GapFill != 0 ||
+ Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
!Common.ChangeSectionAddress.empty()) {
return createStringError(llvm::errc::invalid_argument,
"option is not supported for DXContainer");
More information about the llvm-commits
mailing list