Skip to content

[DirectX] Add support for remove-section of DXContainer for llvm-objcopy #153246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: users/inbelic/pr-153079
Choose a base branch
from

Conversation

inbelic
Copy link
Contributor

@inbelic inbelic commented Aug 12, 2025

This pr implements the remove-section option for a DXContainer object in llvm-objcopy.

It implements a base removeParts to the minimal object representation of a DXContainerObject.

This is the second step to implement #150275 as a compiler actions that invokes llvm-objcopy for functionality.

@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2025

@llvm/pr-subscribers-llvm-binary-utilities

Author: Finn Plummer (inbelic)

Changes

This pr implements the remove-section option for a DXContainer object in llvm-objcopy.

It implements a base removeParts to the minimal object representation of a DXContainerObject.

This is the second step to implement #150275 as a compiler actions that invokes llvm-objcopy for functionality.


Patch is 24.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153246.diff

8 Files Affected:

  • (modified) llvm/lib/ObjCopy/CMakeLists.txt (+1)
  • (modified) llvm/lib/ObjCopy/ConfigManager.cpp (+9-9)
  • (modified) llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp (+12)
  • (added) llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp (+30)
  • (modified) llvm/lib/ObjCopy/DXContainer/DXContainerObject.h (+7)
  • (added) llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test (+300)
  • (modified) llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test (+1-1)
  • (added) llvm/test/tools/llvm-objcopy/DXContainer/headers-remove.test (+50)
diff --git a/llvm/lib/ObjCopy/CMakeLists.txt b/llvm/lib/ObjCopy/CMakeLists.txt
index 54d0ea99fbc28..960f1d1fae2d0 100644
--- a/llvm/lib/ObjCopy/CMakeLists.txt
+++ b/llvm/lib/ObjCopy/CMakeLists.txt
@@ -44,6 +44,7 @@ source_group("Source Files\\DXContainer" REGULAR_EXPRESSION
 add_llvm_component_library(LLVMObjCopy
   Archive.cpp
   DXContainer/DXContainerObjcopy.cpp
+  DXContainer/DXContainerObject.cpp
   DXContainer/DXContainerReader.cpp
   DXContainer/DXContainerWriter.cpp
   CommonConfig.cpp
diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp
index afbf42f4f1feb..c598795d4c006 100644
--- a/llvm/lib/ObjCopy/ConfigManager.cpp
+++ b/llvm/lib/ObjCopy/ConfigManager.cpp
@@ -117,14 +117,14 @@ ConfigManager::getDXContainerConfig() const {
       !Common.AllocSectionsPrefix.empty() ||
       Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
       !Common.DumpSection.empty() || !Common.KeepSection.empty() ||
-      !Common.OnlySection.empty() || !Common.ToRemove.empty() ||
-      !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
-      !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
-      Common.ExtractDWO || Common.OnlyKeepDebug || Common.StripAllGNU ||
-      Common.StripDWO || Common.StripDebug || Common.StripNonAlloc ||
-      Common.StripSections || Common.StripUnneeded ||
-      Common.DecompressDebugSections || Common.GapFill != 0 ||
-      Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
+      !Common.OnlySection.empty() || !Common.SectionsToRename.empty() ||
+      !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
+      !Common.SetSectionType.empty() || Common.ExtractDWO ||
+      Common.OnlyKeepDebug || Common.StripAllGNU || Common.StripDWO ||
+      Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
+      Common.StripUnneeded || Common.DecompressDebugSections ||
+      Common.GapFill != 0 || Common.PadTo != 0 ||
+      Common.ChangeSectionLMAValAll != 0 ||
       !Common.ChangeSectionAddress.empty()) {
     return createStringError(
         llvm::errc::invalid_argument,
@@ -132,6 +132,6 @@ ConfigManager::getDXContainerConfig() const {
   }
 
   // If a flag is listed here, then it has support for DXContainer:
-  // Common.PreserveDates
+  // Common.PreserveDates, Common.ToRemove
   return DXContainer;
 }
diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp
index 38155f0a84498..a6a978d969255 100644
--- a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp
+++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp
@@ -19,6 +19,18 @@ namespace dxbc {
 using namespace object;
 
 static Error handleArgs(const CommonConfig &Config, Object &Obj) {
+  std::function<bool(const Part &)> RemovePred = [](const Part &) {
+    return false;
+  };
+
+  if (!Config.ToRemove.empty())
+    RemovePred = [&Config](const Part &P) {
+      return Config.ToRemove.matches(P.Name);
+    };
+
+  if (auto E = Obj.removeParts(RemovePred))
+    return E;
+
   return Error::success();
 }
 
diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp
new file mode 100644
index 0000000000000..d7c2462d803c9
--- /dev/null
+++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp
@@ -0,0 +1,30 @@
+//===- DXContainerObject.cpp ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DXContainerObject.h"
+
+namespace llvm {
+namespace objcopy {
+namespace dxbc {
+
+Error Object::removeParts(PartPred ToRemove) {
+  erase_if(Parts, ToRemove);
+  recomputeHeader();
+  return Error::success();
+}
+
+void Object::recomputeHeader() {
+  Header.FileSize = headerSize();
+  Header.PartCount = Parts.size();
+  for (const Part &P : Parts)
+    Header.FileSize += P.size();
+}
+
+} // end namespace dxbc
+} // end namespace objcopy
+} // end namespace llvm
diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h
index 160a235bbc1ff..9dcf01e3a3a2a 100644
--- a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h
+++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h
@@ -30,6 +30,8 @@ struct Part {
   }
 };
 
+using PartPred = llvm::function_ref<bool(const Part &)>;
+
 struct Object {
   ::llvm::dxbc::Header Header;
   SmallVector<Part> Parts;
@@ -38,6 +40,11 @@ struct Object {
     return sizeof(::llvm::dxbc::Header)       // base header
            + sizeof(uint32_t) * Parts.size(); // part offset values
   }
+
+  Error removeParts(PartPred ToRemove);
+
+private:
+  void recomputeHeader();
 };
 
 } // end namespace dxbc
diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test
new file mode 100644
index 0000000000000..3af18d256fabc
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test
@@ -0,0 +1,300 @@
+## Tests that the RTS0 (root signature) part is correctly removed from the
+## copied DXContainer
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objcopy --remove-section=RTS0 %t %t.out
+# RUN: obj2yaml %t.out | FileCheck %s
+
+## The DXContainer described below was generated with:
+
+## `clang-dxc -T cs_6_7 test.hlsl /Fo temp.dxo`
+## `obj2yaml temp.dxo`
+
+## ``` test.hlsl
+## [RootSignature("")]
+## [numthreads(1,1,1)]
+## void main() {}
+## ```
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+## FileSize = 1984 - 24 (RTS0 content) - 4 (1 part offset) - 8 (1 part header)
+##          = 1948
+## CHECK: FileSize:       1948
+  FileSize:        1984
+## CHECK: PartCount:      6
+  PartCount:       7
+  PartOffsets:     [ 60, 1792, 1808, 1836, 1852, 1868, 1900 ]
+Parts:
+## CHECK-NOT: RTS0
+  - Name:            DXIL
+    Size:            1724
+    Program:
+      MajorVersion:    6
+      MinorVersion:    7
+      ShaderKind:      5
+      Size:            431
+      DXILMajorVersion: 1
+      DXILMinorVersion: 7
+      DXILSize:        1700
+      DXIL:            [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0xA6,
+                         0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
+                         0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23,
+                         0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32,
+                         0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19,
+                         0x1E, 0x4, 0x8B, 0x62, 0x80, 0x10, 0x45, 0x2,
+                         0x42, 0x92, 0xB, 0x42, 0x84, 0x10, 0x32, 0x14,
+                         0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x42, 0x88,
+                         0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5,
+                         0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90,
+                         0x11, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C,
+                         0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x21, 0x46, 0x6,
+                         0x51, 0x18, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1B,
+                         0x90, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x7, 0xC0,
+                         0x1, 0x24, 0x80, 0x2, 0x0, 0x0, 0x0, 0x49, 0x18,
+                         0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x13, 0x82, 0x0,
+                         0x0, 0x89, 0x20, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0,
+                         0x32, 0x22, 0x8, 0x9, 0x20, 0x64, 0x85, 0x4, 0x13,
+                         0x22, 0xA4, 0x84, 0x4, 0x13, 0x22, 0xE3, 0x84,
+                         0xA1, 0x90, 0x14, 0x12, 0x4C, 0x88, 0x8C, 0xB,
+                         0x84, 0x84, 0x4C, 0x10, 0x20, 0x73, 0x4, 0x8,
+                         0xC1, 0x65, 0xC3, 0x85, 0x2C, 0xE8, 0x3, 0x40,
+                         0x14, 0x91, 0x4E, 0xD1, 0x4A, 0x48, 0x44, 0x54,
+                         0x11, 0xC3, 0x9, 0x30, 0xC4, 0x18, 0x1, 0x30,
+                         0x2, 0x50, 0x82, 0x21, 0x1A, 0x8, 0x98, 0x23,
+                         0x0, 0x3, 0x0, 0x13, 0x14, 0x72, 0xC0, 0x87, 0x74,
+                         0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x3,
+                         0x72, 0xC0, 0x87, 0xD, 0xAE, 0x50, 0xE, 0x6D,
+                         0xD0, 0xE, 0x7A, 0x50, 0xE, 0x6D, 0x0, 0xF, 0x7A,
+                         0x30, 0x7, 0x72, 0xA0, 0x7, 0x73, 0x20, 0x7, 0x6D,
+                         0x90, 0xE, 0x71, 0xA0, 0x7, 0x73, 0x20, 0x7, 0x6D,
+                         0x90, 0xE, 0x78, 0xA0, 0x7, 0x78, 0xD0, 0x6, 0xE9,
+                         0x10, 0x7, 0x76, 0xA0, 0x7, 0x71, 0x60, 0x7, 0x6D,
+                         0x90, 0xE, 0x73, 0x20, 0x7, 0x7A, 0x30, 0x7, 0x72,
+                         0xD0, 0x6, 0xE9, 0x60, 0x7, 0x74, 0xA0, 0x7, 0x76,
+                         0x40, 0x7, 0x6D, 0x60, 0xE, 0x71, 0x60, 0x7, 0x7A,
+                         0x10, 0x7, 0x76, 0xD0, 0x6, 0xE6, 0x30, 0x7, 0x72,
+                         0xA0, 0x7, 0x73, 0x20, 0x7, 0x6D, 0x60, 0xE, 0x76,
+                         0x40, 0x7, 0x7A, 0x60, 0x7, 0x74, 0xD0, 0x6, 0xEE,
+                         0x80, 0x7, 0x7A, 0x10, 0x7, 0x76, 0xA0, 0x7, 0x73,
+                         0x20, 0x7, 0x7A, 0x60, 0x7, 0x74, 0x30, 0xE4,
+                         0x21, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x2, 0x0,
+                         0x0, 0x0, 0x20, 0xB, 0x4, 0x7, 0x0, 0x0, 0x0,
+                         0x32, 0x1E, 0x98, 0xC, 0x19, 0x11, 0x4C, 0x90,
+                         0x8C, 0x9, 0x26, 0x47, 0xC6, 0x4, 0x43, 0xBA,
+                         0x12, 0x28, 0x88, 0x62, 0x28, 0x87, 0x42, 0x28,
+                         0x2, 0x0, 0x0, 0x0, 0x79, 0x18, 0x0, 0x0, 0xE2,
+                         0x0, 0x0, 0x0, 0x33, 0x8, 0x80, 0x1C, 0xC4, 0xE1,
+                         0x1C, 0x66, 0x14, 0x1, 0x3D, 0x88, 0x43, 0x38,
+                         0x84, 0xC3, 0x8C, 0x42, 0x80, 0x7, 0x79, 0x78,
+                         0x7, 0x73, 0x98, 0x71, 0xC, 0xE6, 0x0, 0xF, 0xED,
+                         0x10, 0xE, 0xF4, 0x80, 0xE, 0x33, 0xC, 0x42, 0x1E,
+                         0xC2, 0xC1, 0x1D, 0xCE, 0xA1, 0x1C, 0x66, 0x30,
+                         0x5, 0x3D, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1B,
+                         0xCC, 0x3, 0x3D, 0xC8, 0x43, 0x3D, 0x8C, 0x3,
+                         0x3D, 0xCC, 0x78, 0x8C, 0x74, 0x70, 0x7, 0x7B,
+                         0x8, 0x7, 0x79, 0x48, 0x87, 0x70, 0x70, 0x7, 0x7A,
+                         0x70, 0x3, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87,
+                         0x19, 0xCC, 0x11, 0xE, 0xEC, 0x90, 0xE, 0xE1,
+                         0x30, 0xF, 0x6E, 0x30, 0xF, 0xE3, 0xF0, 0xE, 0xF0,
+                         0x50, 0xE, 0x33, 0x10, 0xC4, 0x1D, 0xDE, 0x21,
+                         0x1C, 0xD8, 0x21, 0x1D, 0xC2, 0x61, 0x1E, 0x66,
+                         0x30, 0x89, 0x3B, 0xBC, 0x83, 0x3B, 0xD0, 0x43,
+                         0x39, 0xB4, 0x3, 0x3C, 0xBC, 0x83, 0x3C, 0x84,
+                         0x3, 0x3B, 0xCC, 0xF0, 0x14, 0x76, 0x60, 0x7,
+                         0x7B, 0x68, 0x7, 0x37, 0x68, 0x87, 0x72, 0x68,
+                         0x7, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70,
+                         0x60, 0x7, 0x76, 0x28, 0x7, 0x76, 0xF8, 0x5, 0x76,
+                         0x78, 0x87, 0x77, 0x80, 0x87, 0x5F, 0x8, 0x87,
+                         0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98,
+                         0x81, 0x2C, 0xEE, 0xF0, 0xE, 0xEE, 0xE0, 0xE,
+                         0xF5, 0xC0, 0xE, 0xEC, 0x30, 0x3, 0x62, 0xC8,
+                         0xA1, 0x1C, 0xE4, 0xA1, 0x1C, 0xCC, 0xA1, 0x1C,
+                         0xE4, 0xA1, 0x1C, 0xDC, 0x61, 0x1C, 0xCA, 0x21,
+                         0x1C, 0xC4, 0x81, 0x1D, 0xCA, 0x61, 0x6, 0xD6,
+                         0x90, 0x43, 0x39, 0xC8, 0x43, 0x39, 0x98, 0x43,
+                         0x39, 0xC8, 0x43, 0x39, 0xB8, 0xC3, 0x38, 0x94,
+                         0x43, 0x38, 0x88, 0x3, 0x3B, 0x94, 0xC3, 0x2F,
+                         0xBC, 0x83, 0x3C, 0xFC, 0x82, 0x3B, 0xD4, 0x3,
+                         0x3B, 0xB0, 0xC3, 0xC, 0xC7, 0x69, 0x87, 0x70,
+                         0x58, 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x7,
+                         0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xA0,
+                         0x87, 0x19, 0xCE, 0x53, 0xF, 0xEE, 0x0, 0xF, 0xF2,
+                         0x50, 0xE, 0xE4, 0x90, 0xE, 0xE3, 0x40, 0xF, 0xE1,
+                         0x20, 0xE, 0xEC, 0x50, 0xE, 0x33, 0x20, 0x28,
+                         0x1D, 0xDC, 0xC1, 0x1E, 0xC2, 0x41, 0x1E, 0xD2,
+                         0x21, 0x1C, 0xDC, 0x81, 0x1E, 0xDC, 0xE0, 0x1C,
+                         0xE4, 0xE1, 0x1D, 0xEA, 0x1, 0x1E, 0x66, 0x18,
+                         0x51, 0x38, 0xB0, 0x43, 0x3A, 0x9C, 0x83, 0x3B,
+                         0xCC, 0x50, 0x24, 0x76, 0x60, 0x7, 0x7B, 0x68,
+                         0x7, 0x37, 0x60, 0x87, 0x77, 0x78, 0x7, 0x78,
+                         0x98, 0x51, 0x4C, 0xF4, 0x90, 0xF, 0xF0, 0x50,
+                         0xE, 0x33, 0x1E, 0x6A, 0x1E, 0xCA, 0x61, 0x1C,
+                         0xE8, 0x21, 0x1D, 0xDE, 0xC1, 0x1D, 0x7E, 0x1,
+                         0x1E, 0xE4, 0xA1, 0x1C, 0xCC, 0x21, 0x1D, 0xF0,
+                         0x61, 0x6, 0x54, 0x85, 0x83, 0x38, 0xCC, 0xC3,
+                         0x3B, 0xB0, 0x43, 0x3D, 0xD0, 0x43, 0x39, 0xFC,
+                         0xC2, 0x3C, 0xE4, 0x43, 0x3B, 0x88, 0xC3, 0x3B,
+                         0xB0, 0xC3, 0x8C, 0xC5, 0xA, 0x87, 0x79, 0x98,
+                         0x87, 0x77, 0x18, 0x87, 0x74, 0x8, 0x7, 0x7A,
+                         0x28, 0x7, 0x72, 0x98, 0x81, 0x5C, 0xE3, 0x10,
+                         0xE, 0xEC, 0xC0, 0xE, 0xE5, 0x50, 0xE, 0xF3, 0x30,
+                         0x23, 0xC1, 0xD2, 0x41, 0x1E, 0xE4, 0xE1, 0x17,
+                         0xD8, 0xE1, 0x1D, 0xDE, 0x1, 0x1E, 0x66, 0x48,
+                         0x19, 0x3B, 0xB0, 0x83, 0x3D, 0xB4, 0x83, 0x1B,
+                         0x84, 0xC3, 0x38, 0x8C, 0x43, 0x39, 0xCC, 0xC3,
+                         0x3C, 0xB8, 0xC1, 0x39, 0xC8, 0xC3, 0x3B, 0xD4,
+                         0x3, 0x3C, 0xCC, 0x48, 0xB4, 0x71, 0x8, 0x7, 0x76,
+                         0x60, 0x7, 0x71, 0x8, 0x87, 0x71, 0x58, 0x87,
+                         0x19, 0xDB, 0xC6, 0xE, 0xEC, 0x60, 0xF, 0xED,
+                         0xE0, 0x6, 0xF0, 0x20, 0xF, 0xE5, 0x30, 0xF, 0xE5,
+                         0x20, 0xF, 0xF6, 0x50, 0xE, 0x6E, 0x10, 0xE, 0xE3,
+                         0x30, 0xE, 0xE5, 0x30, 0xF, 0xF3, 0xE0, 0x6, 0xE9,
+                         0xE0, 0xE, 0xE4, 0x50, 0xE, 0xF8, 0x30, 0x23,
+                         0xE2, 0xEC, 0x61, 0x1C, 0xC2, 0x81, 0x1D, 0xD8,
+                         0xE1, 0x17, 0xEC, 0x21, 0x1D, 0xE6, 0x21, 0x1D,
+                         0xC4, 0x21, 0x1D, 0xD8, 0x21, 0x1D, 0xE8, 0x21,
+                         0x1F, 0x66, 0x20, 0x9D, 0x3B, 0xBC, 0x43, 0x3D,
+                         0xB8, 0x3, 0x39, 0x94, 0x83, 0x39, 0xCC, 0x58,
+                         0xBC, 0x70, 0x70, 0x7, 0x77, 0x78, 0x7, 0x7A,
+                         0x8, 0x7, 0x7A, 0x48, 0x87, 0x77, 0x70, 0x87,
+                         0x19, 0xCB, 0xE7, 0xE, 0xEF, 0x30, 0xF, 0xE1,
+                         0xE0, 0xE, 0xE9, 0x40, 0xF, 0xE9, 0xA0, 0xF, 0xE5,
+                         0x30, 0xC3, 0x1, 0x3, 0x73, 0xA8, 0x7, 0x77, 0x18,
+                         0x87, 0x5F, 0x98, 0x87, 0x70, 0x70, 0x87, 0x74,
+                         0xA0, 0x87, 0x74, 0xD0, 0x87, 0x72, 0x98, 0x81,
+                         0x84, 0x41, 0x39, 0xE0, 0xC3, 0x38, 0xB0, 0x43,
+                         0x3D, 0x90, 0x43, 0x39, 0xCC, 0x40, 0xC4, 0xA0,
+                         0x1D, 0xCA, 0xA1, 0x1D, 0xE0, 0x41, 0x1E, 0xDE,
+                         0xC1, 0x1C, 0x66, 0x24, 0x63, 0x30, 0xE, 0xE1,
+                         0xC0, 0xE, 0xEC, 0x30, 0xF, 0xE9, 0x40, 0xF, 0xE5,
+                         0x30, 0x43, 0x21, 0x83, 0x75, 0x18, 0x7, 0x73,
+                         0x48, 0x87, 0x5F, 0xA0, 0x87, 0x7C, 0x80, 0x87,
+                         0x72, 0x98, 0xB1, 0x94, 0x1, 0x3C, 0x8C, 0xC3,
+                         0x3C, 0x94, 0xC3, 0x38, 0xD0, 0x43, 0x3A, 0xBC,
+                         0x83, 0x3B, 0xCC, 0xC3, 0x8C, 0xC5, 0xC, 0x48,
+                         0x21, 0x15, 0x42, 0x61, 0x1E, 0xE6, 0x21, 0x1D,
+                         0xCE, 0xC1, 0x1D, 0x52, 0x81, 0x14, 0x66, 0x4C,
+                         0x67, 0x30, 0xE, 0xEF, 0x20, 0xF, 0xEF, 0xE0,
+                         0x6, 0xEF, 0x50, 0xF, 0xF4, 0x30, 0xF, 0xE9, 0x40,
+                         0xE, 0xE5, 0xE0, 0x6, 0xE6, 0x20, 0xF, 0xE1, 0xD0,
+                         0xE, 0xE5, 0x30, 0xA3, 0x40, 0x83, 0x76, 0x68,
+                         0x7, 0x79, 0x8, 0x87, 0x19, 0x52, 0x1A, 0xB8,
+                         0xC3, 0x3B, 0x84, 0x3, 0x3B, 0xA4, 0x43, 0x38,
+                         0xCC, 0x83, 0x1B, 0x84, 0x3, 0x39, 0x90, 0x83,
+                         0x3C, 0xCC, 0x3, 0x3C, 0x84, 0xC3, 0x38, 0x94,
+                         0xC3, 0xC, 0x46, 0xD, 0xC6, 0x21, 0x1C, 0xD8,
+                         0x81, 0x1D, 0xCA, 0xA1, 0x1C, 0x7E, 0x81, 0x1E,
+                         0xF2, 0x1, 0x1E, 0xCA, 0x61, 0x86, 0xB3, 0x6,
+                         0xE4, 0x80, 0xF, 0x6E, 0xE0, 0xE, 0xEF, 0xE0,
+                         0xE, 0xF5, 0xE0, 0xE, 0xE9, 0x60, 0xE, 0xEF, 0x20,
+                         0xF, 0xED, 0x30, 0xA3, 0x62, 0x3, 0x72, 0xC0,
+                         0x7, 0x37, 0x18, 0x87, 0x77, 0x70, 0x7, 0x7A,
+                         0x90, 0x87, 0x77, 0x60, 0x7, 0x73, 0x60, 0x87,
+                         0x77, 0xB8, 0x7, 0x37, 0x40, 0x87, 0x74, 0x70,
+                         0x7, 0x7A, 0x98, 0x87, 0x19, 0x4B, 0x1B, 0x90,
+                         0x3, 0x3E, 0xB8, 0x1, 0x3C, 0xC8, 0x43, 0x39,
+                         0x8C, 0x43, 0x3A, 0xCC, 0x43, 0x39, 0x0, 0x0,
+                         0x79, 0x28, 0x0, 0x0, 0x53, 0x0, 0x0, 0x0, 0xC2,
+                         0x3C, 0x90, 0x40, 0x86, 0x10, 0x19, 0x32, 0xE2,
+                         0x64, 0x90, 0x40, 0x46, 0x2, 0x19, 0x23, 0x23,
+                         0x46, 0x2, 0x13, 0x24, 0xC6, 0x0, 0x13, 0x74,
+                         0xD4, 0x61, 0x8C, 0x2D, 0xCC, 0xED, 0xC, 0xC4,
+                         0xAE, 0x4C, 0x6E, 0x2E, 0xED, 0xCD, 0xD, 0x44,
+                         0x46, 0xC6, 0x5, 0xC6, 0x5, 0xE6, 0x2C, 0x8D,
+                         0xE, 0x4, 0xE5, 0x2C, 0x8D, 0xE, 0xE8, 0x2C, 0x8D,
+                         0xE, 0xAD, 0x4E, 0xCC, 0x65, 0xEC, 0xAD, 0x4D,
+                         0x27, 0xCD, 0x4D, 0xAC, 0x8C, 0x2D, 0x6D, 0xEC,
+                         0x85, 0x8D, 0xCD, 0xAE, 0xAD, 0x5, 0x4E, 0xEE,
+                         0x4D, 0xAD, 0x6C, 0x8C, 0xCE, 0xE5, 0x2C, 0x8D,
+                         0xE, 0x84, 0x86, 0xC6, 0xCC, 0xC6, 0x86, 0x4C,
+                         0xC, 0x87, 0x6C, 0xEC, 0x26, 0x67, 0x46, 0x26,
+                         0x67, 0x6C, 0xA6, 0xCC, 0x66, 0x8C, 0xC6, 0x2C,
+                         0xEC, 0x26, 0xC, 0x26, 0x2C, 0xEC, 0x26, 0xCC,
+                         0xCC, 0x86, 0x6, 0xE6, 0x6, 0x26, 0xE7, 0x86,
+                         0xE6, 0x26, 0xE5, 0x8, 0x63, 0x73, 0x87, 0x68,
+                         0xB, 0x4B, 0x73, 0x3B, 0xCA, 0xDD, 0x18, 0x5A,
+                         0x98, 0xDC, 0xD7, 0x5C, 0x9A, 0x5E, 0xD9, 0x69,
+                         0xCC, 0xE4, 0xC2, 0xDA, 0xCA, 0x5A, 0xE0, 0xDE,
+                         0xD2, 0xDC, 0xE8, 0xCA, 0xE4, 0x86, 0x20, 0x1C,
+                         0xC1, 0x10, 0x84, 0x43, 0x18, 0x82, 0x70, 0xC,
+                         0x43, 0x10, 0xE, 0x62, 0x8, 0x42, 0x1, 0xC, 0x41,
+                         0x38, 0x8A, 0x21, 0x8, 0x87, 0x31, 0x6, 0xC1,
+                         0x38, 0xC6, 0x10, 0x4, 0x63, 0x18, 0x4, 0x24,
+                         0x19, 0x83, 0x60, 0x24, 0x63, 0x18, 0xC, 0xC3,
+                         0x18, 0x83, 0xB0, 0x44, 0x63, 0x28, 0x94, 0x1,
+                         0x0, 0xA4, 0x31, 0xC, 0x6, 0xB1, 0x8C, 0x61, 0x60,
+                         0xA, 0xC6, 0x24, 0x64, 0x78, 0x2E, 0x76, 0x61,
+                         0x6C, 0x76, 0x65, 0x72, 0x43, 0x9, 0x18, 0xA3,
+                         0xB0, 0x...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Aug 12, 2025

@llvm/pr-subscribers-backend-directx

Author: Finn Plummer (inbelic)

Changes

This pr implements the remove-section option for a DXContainer object in llvm-objcopy.

It implements a base removeParts to the minimal object representation of a DXContainerObject.

This is the second step to implement #150275 as a compiler actions that invokes llvm-objcopy for functionality.


Patch is 24.72 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153246.diff

8 Files Affected:

  • (modified) llvm/lib/ObjCopy/CMakeLists.txt (+1)
  • (modified) llvm/lib/ObjCopy/ConfigManager.cpp (+9-9)
  • (modified) llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp (+12)
  • (added) llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp (+30)
  • (modified) llvm/lib/ObjCopy/DXContainer/DXContainerObject.h (+7)
  • (added) llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test (+300)
  • (modified) llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test (+1-1)
  • (added) llvm/test/tools/llvm-objcopy/DXContainer/headers-remove.test (+50)
diff --git a/llvm/lib/ObjCopy/CMakeLists.txt b/llvm/lib/ObjCopy/CMakeLists.txt
index 54d0ea99fbc28..960f1d1fae2d0 100644
--- a/llvm/lib/ObjCopy/CMakeLists.txt
+++ b/llvm/lib/ObjCopy/CMakeLists.txt
@@ -44,6 +44,7 @@ source_group("Source Files\\DXContainer" REGULAR_EXPRESSION
 add_llvm_component_library(LLVMObjCopy
   Archive.cpp
   DXContainer/DXContainerObjcopy.cpp
+  DXContainer/DXContainerObject.cpp
   DXContainer/DXContainerReader.cpp
   DXContainer/DXContainerWriter.cpp
   CommonConfig.cpp
diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp
index afbf42f4f1feb..c598795d4c006 100644
--- a/llvm/lib/ObjCopy/ConfigManager.cpp
+++ b/llvm/lib/ObjCopy/ConfigManager.cpp
@@ -117,14 +117,14 @@ ConfigManager::getDXContainerConfig() const {
       !Common.AllocSectionsPrefix.empty() ||
       Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
       !Common.DumpSection.empty() || !Common.KeepSection.empty() ||
-      !Common.OnlySection.empty() || !Common.ToRemove.empty() ||
-      !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
-      !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
-      Common.ExtractDWO || Common.OnlyKeepDebug || Common.StripAllGNU ||
-      Common.StripDWO || Common.StripDebug || Common.StripNonAlloc ||
-      Common.StripSections || Common.StripUnneeded ||
-      Common.DecompressDebugSections || Common.GapFill != 0 ||
-      Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
+      !Common.OnlySection.empty() || !Common.SectionsToRename.empty() ||
+      !Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
+      !Common.SetSectionType.empty() || Common.ExtractDWO ||
+      Common.OnlyKeepDebug || Common.StripAllGNU || Common.StripDWO ||
+      Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
+      Common.StripUnneeded || Common.DecompressDebugSections ||
+      Common.GapFill != 0 || Common.PadTo != 0 ||
+      Common.ChangeSectionLMAValAll != 0 ||
       !Common.ChangeSectionAddress.empty()) {
     return createStringError(
         llvm::errc::invalid_argument,
@@ -132,6 +132,6 @@ ConfigManager::getDXContainerConfig() const {
   }
 
   // If a flag is listed here, then it has support for DXContainer:
-  // Common.PreserveDates
+  // Common.PreserveDates, Common.ToRemove
   return DXContainer;
 }
diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp
index 38155f0a84498..a6a978d969255 100644
--- a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp
+++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp
@@ -19,6 +19,18 @@ namespace dxbc {
 using namespace object;
 
 static Error handleArgs(const CommonConfig &Config, Object &Obj) {
+  std::function<bool(const Part &)> RemovePred = [](const Part &) {
+    return false;
+  };
+
+  if (!Config.ToRemove.empty())
+    RemovePred = [&Config](const Part &P) {
+      return Config.ToRemove.matches(P.Name);
+    };
+
+  if (auto E = Obj.removeParts(RemovePred))
+    return E;
+
   return Error::success();
 }
 
diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp
new file mode 100644
index 0000000000000..d7c2462d803c9
--- /dev/null
+++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.cpp
@@ -0,0 +1,30 @@
+//===- DXContainerObject.cpp ----------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "DXContainerObject.h"
+
+namespace llvm {
+namespace objcopy {
+namespace dxbc {
+
+Error Object::removeParts(PartPred ToRemove) {
+  erase_if(Parts, ToRemove);
+  recomputeHeader();
+  return Error::success();
+}
+
+void Object::recomputeHeader() {
+  Header.FileSize = headerSize();
+  Header.PartCount = Parts.size();
+  for (const Part &P : Parts)
+    Header.FileSize += P.size();
+}
+
+} // end namespace dxbc
+} // end namespace objcopy
+} // end namespace llvm
diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h
index 160a235bbc1ff..9dcf01e3a3a2a 100644
--- a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h
+++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h
@@ -30,6 +30,8 @@ struct Part {
   }
 };
 
+using PartPred = llvm::function_ref<bool(const Part &)>;
+
 struct Object {
   ::llvm::dxbc::Header Header;
   SmallVector<Part> Parts;
@@ -38,6 +40,11 @@ struct Object {
     return sizeof(::llvm::dxbc::Header)       // base header
            + sizeof(uint32_t) * Parts.size(); // part offset values
   }
+
+  Error removeParts(PartPred ToRemove);
+
+private:
+  void recomputeHeader();
 };
 
 } // end namespace dxbc
diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test
new file mode 100644
index 0000000000000..3af18d256fabc
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-remove.test
@@ -0,0 +1,300 @@
+## Tests that the RTS0 (root signature) part is correctly removed from the
+## copied DXContainer
+
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objcopy --remove-section=RTS0 %t %t.out
+# RUN: obj2yaml %t.out | FileCheck %s
+
+## The DXContainer described below was generated with:
+
+## `clang-dxc -T cs_6_7 test.hlsl /Fo temp.dxo`
+## `obj2yaml temp.dxo`
+
+## ``` test.hlsl
+## [RootSignature("")]
+## [numthreads(1,1,1)]
+## void main() {}
+## ```
+
+--- !dxcontainer
+Header:
+  Hash:            [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+                     0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+  Version:
+    Major:           1
+    Minor:           0
+## FileSize = 1984 - 24 (RTS0 content) - 4 (1 part offset) - 8 (1 part header)
+##          = 1948
+## CHECK: FileSize:       1948
+  FileSize:        1984
+## CHECK: PartCount:      6
+  PartCount:       7
+  PartOffsets:     [ 60, 1792, 1808, 1836, 1852, 1868, 1900 ]
+Parts:
+## CHECK-NOT: RTS0
+  - Name:            DXIL
+    Size:            1724
+    Program:
+      MajorVersion:    6
+      MinorVersion:    7
+      ShaderKind:      5
+      Size:            431
+      DXILMajorVersion: 1
+      DXILMinorVersion: 7
+      DXILSize:        1700
+      DXIL:            [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0xA6,
+                         0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
+                         0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23,
+                         0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32,
+                         0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19,
+                         0x1E, 0x4, 0x8B, 0x62, 0x80, 0x10, 0x45, 0x2,
+                         0x42, 0x92, 0xB, 0x42, 0x84, 0x10, 0x32, 0x14,
+                         0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x42, 0x88,
+                         0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5,
+                         0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90,
+                         0x11, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C,
+                         0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x21, 0x46, 0x6,
+                         0x51, 0x18, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1B,
+                         0x90, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x7, 0xC0,
+                         0x1, 0x24, 0x80, 0x2, 0x0, 0x0, 0x0, 0x49, 0x18,
+                         0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x13, 0x82, 0x0,
+                         0x0, 0x89, 0x20, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0,
+                         0x32, 0x22, 0x8, 0x9, 0x20, 0x64, 0x85, 0x4, 0x13,
+                         0x22, 0xA4, 0x84, 0x4, 0x13, 0x22, 0xE3, 0x84,
+                         0xA1, 0x90, 0x14, 0x12, 0x4C, 0x88, 0x8C, 0xB,
+                         0x84, 0x84, 0x4C, 0x10, 0x20, 0x73, 0x4, 0x8,
+                         0xC1, 0x65, 0xC3, 0x85, 0x2C, 0xE8, 0x3, 0x40,
+                         0x14, 0x91, 0x4E, 0xD1, 0x4A, 0x48, 0x44, 0x54,
+                         0x11, 0xC3, 0x9, 0x30, 0xC4, 0x18, 0x1, 0x30,
+                         0x2, 0x50, 0x82, 0x21, 0x1A, 0x8, 0x98, 0x23,
+                         0x0, 0x3, 0x0, 0x13, 0x14, 0x72, 0xC0, 0x87, 0x74,
+                         0x60, 0x87, 0x36, 0x68, 0x87, 0x79, 0x68, 0x3,
+                         0x72, 0xC0, 0x87, 0xD, 0xAE, 0x50, 0xE, 0x6D,
+                         0xD0, 0xE, 0x7A, 0x50, 0xE, 0x6D, 0x0, 0xF, 0x7A,
+                         0x30, 0x7, 0x72, 0xA0, 0x7, 0x73, 0x20, 0x7, 0x6D,
+                         0x90, 0xE, 0x71, 0xA0, 0x7, 0x73, 0x20, 0x7, 0x6D,
+                         0x90, 0xE, 0x78, 0xA0, 0x7, 0x78, 0xD0, 0x6, 0xE9,
+                         0x10, 0x7, 0x76, 0xA0, 0x7, 0x71, 0x60, 0x7, 0x6D,
+                         0x90, 0xE, 0x73, 0x20, 0x7, 0x7A, 0x30, 0x7, 0x72,
+                         0xD0, 0x6, 0xE9, 0x60, 0x7, 0x74, 0xA0, 0x7, 0x76,
+                         0x40, 0x7, 0x6D, 0x60, 0xE, 0x71, 0x60, 0x7, 0x7A,
+                         0x10, 0x7, 0x76, 0xD0, 0x6, 0xE6, 0x30, 0x7, 0x72,
+                         0xA0, 0x7, 0x73, 0x20, 0x7, 0x6D, 0x60, 0xE, 0x76,
+                         0x40, 0x7, 0x7A, 0x60, 0x7, 0x74, 0xD0, 0x6, 0xEE,
+                         0x80, 0x7, 0x7A, 0x10, 0x7, 0x76, 0xA0, 0x7, 0x73,
+                         0x20, 0x7, 0x7A, 0x60, 0x7, 0x74, 0x30, 0xE4,
+                         0x21, 0x0, 0x0, 0x8, 0x0, 0x0, 0x0, 0x2, 0x0,
+                         0x0, 0x0, 0x20, 0xB, 0x4, 0x7, 0x0, 0x0, 0x0,
+                         0x32, 0x1E, 0x98, 0xC, 0x19, 0x11, 0x4C, 0x90,
+                         0x8C, 0x9, 0x26, 0x47, 0xC6, 0x4, 0x43, 0xBA,
+                         0x12, 0x28, 0x88, 0x62, 0x28, 0x87, 0x42, 0x28,
+                         0x2, 0x0, 0x0, 0x0, 0x79, 0x18, 0x0, 0x0, 0xE2,
+                         0x0, 0x0, 0x0, 0x33, 0x8, 0x80, 0x1C, 0xC4, 0xE1,
+                         0x1C, 0x66, 0x14, 0x1, 0x3D, 0x88, 0x43, 0x38,
+                         0x84, 0xC3, 0x8C, 0x42, 0x80, 0x7, 0x79, 0x78,
+                         0x7, 0x73, 0x98, 0x71, 0xC, 0xE6, 0x0, 0xF, 0xED,
+                         0x10, 0xE, 0xF4, 0x80, 0xE, 0x33, 0xC, 0x42, 0x1E,
+                         0xC2, 0xC1, 0x1D, 0xCE, 0xA1, 0x1C, 0x66, 0x30,
+                         0x5, 0x3D, 0x88, 0x43, 0x38, 0x84, 0x83, 0x1B,
+                         0xCC, 0x3, 0x3D, 0xC8, 0x43, 0x3D, 0x8C, 0x3,
+                         0x3D, 0xCC, 0x78, 0x8C, 0x74, 0x70, 0x7, 0x7B,
+                         0x8, 0x7, 0x79, 0x48, 0x87, 0x70, 0x70, 0x7, 0x7A,
+                         0x70, 0x3, 0x76, 0x78, 0x87, 0x70, 0x20, 0x87,
+                         0x19, 0xCC, 0x11, 0xE, 0xEC, 0x90, 0xE, 0xE1,
+                         0x30, 0xF, 0x6E, 0x30, 0xF, 0xE3, 0xF0, 0xE, 0xF0,
+                         0x50, 0xE, 0x33, 0x10, 0xC4, 0x1D, 0xDE, 0x21,
+                         0x1C, 0xD8, 0x21, 0x1D, 0xC2, 0x61, 0x1E, 0x66,
+                         0x30, 0x89, 0x3B, 0xBC, 0x83, 0x3B, 0xD0, 0x43,
+                         0x39, 0xB4, 0x3, 0x3C, 0xBC, 0x83, 0x3C, 0x84,
+                         0x3, 0x3B, 0xCC, 0xF0, 0x14, 0x76, 0x60, 0x7,
+                         0x7B, 0x68, 0x7, 0x37, 0x68, 0x87, 0x72, 0x68,
+                         0x7, 0x37, 0x80, 0x87, 0x70, 0x90, 0x87, 0x70,
+                         0x60, 0x7, 0x76, 0x28, 0x7, 0x76, 0xF8, 0x5, 0x76,
+                         0x78, 0x87, 0x77, 0x80, 0x87, 0x5F, 0x8, 0x87,
+                         0x71, 0x18, 0x87, 0x72, 0x98, 0x87, 0x79, 0x98,
+                         0x81, 0x2C, 0xEE, 0xF0, 0xE, 0xEE, 0xE0, 0xE,
+                         0xF5, 0xC0, 0xE, 0xEC, 0x30, 0x3, 0x62, 0xC8,
+                         0xA1, 0x1C, 0xE4, 0xA1, 0x1C, 0xCC, 0xA1, 0x1C,
+                         0xE4, 0xA1, 0x1C, 0xDC, 0x61, 0x1C, 0xCA, 0x21,
+                         0x1C, 0xC4, 0x81, 0x1D, 0xCA, 0x61, 0x6, 0xD6,
+                         0x90, 0x43, 0x39, 0xC8, 0x43, 0x39, 0x98, 0x43,
+                         0x39, 0xC8, 0x43, 0x39, 0xB8, 0xC3, 0x38, 0x94,
+                         0x43, 0x38, 0x88, 0x3, 0x3B, 0x94, 0xC3, 0x2F,
+                         0xBC, 0x83, 0x3C, 0xFC, 0x82, 0x3B, 0xD4, 0x3,
+                         0x3B, 0xB0, 0xC3, 0xC, 0xC7, 0x69, 0x87, 0x70,
+                         0x58, 0x87, 0x72, 0x70, 0x83, 0x74, 0x68, 0x7,
+                         0x78, 0x60, 0x87, 0x74, 0x18, 0x87, 0x74, 0xA0,
+                         0x87, 0x19, 0xCE, 0x53, 0xF, 0xEE, 0x0, 0xF, 0xF2,
+                         0x50, 0xE, 0xE4, 0x90, 0xE, 0xE3, 0x40, 0xF, 0xE1,
+                         0x20, 0xE, 0xEC, 0x50, 0xE, 0x33, 0x20, 0x28,
+                         0x1D, 0xDC, 0xC1, 0x1E, 0xC2, 0x41, 0x1E, 0xD2,
+                         0x21, 0x1C, 0xDC, 0x81, 0x1E, 0xDC, 0xE0, 0x1C,
+                         0xE4, 0xE1, 0x1D, 0xEA, 0x1, 0x1E, 0x66, 0x18,
+                         0x51, 0x38, 0xB0, 0x43, 0x3A, 0x9C, 0x83, 0x3B,
+                         0xCC, 0x50, 0x24, 0x76, 0x60, 0x7, 0x7B, 0x68,
+                         0x7, 0x37, 0x60, 0x87, 0x77, 0x78, 0x7, 0x78,
+                         0x98, 0x51, 0x4C, 0xF4, 0x90, 0xF, 0xF0, 0x50,
+                         0xE, 0x33, 0x1E, 0x6A, 0x1E, 0xCA, 0x61, 0x1C,
+                         0xE8, 0x21, 0x1D, 0xDE, 0xC1, 0x1D, 0x7E, 0x1,
+                         0x1E, 0xE4, 0xA1, 0x1C, 0xCC, 0x21, 0x1D, 0xF0,
+                         0x61, 0x6, 0x54, 0x85, 0x83, 0x38, 0xCC, 0xC3,
+                         0x3B, 0xB0, 0x43, 0x3D, 0xD0, 0x43, 0x39, 0xFC,
+                         0xC2, 0x3C, 0xE4, 0x43, 0x3B, 0x88, 0xC3, 0x3B,
+                         0xB0, 0xC3, 0x8C, 0xC5, 0xA, 0x87, 0x79, 0x98,
+                         0x87, 0x77, 0x18, 0x87, 0x74, 0x8, 0x7, 0x7A,
+                         0x28, 0x7, 0x72, 0x98, 0x81, 0x5C, 0xE3, 0x10,
+                         0xE, 0xEC, 0xC0, 0xE, 0xE5, 0x50, 0xE, 0xF3, 0x30,
+                         0x23, 0xC1, 0xD2, 0x41, 0x1E, 0xE4, 0xE1, 0x17,
+                         0xD8, 0xE1, 0x1D, 0xDE, 0x1, 0x1E, 0x66, 0x48,
+                         0x19, 0x3B, 0xB0, 0x83, 0x3D, 0xB4, 0x83, 0x1B,
+                         0x84, 0xC3, 0x38, 0x8C, 0x43, 0x39, 0xCC, 0xC3,
+                         0x3C, 0xB8, 0xC1, 0x39, 0xC8, 0xC3, 0x3B, 0xD4,
+                         0x3, 0x3C, 0xCC, 0x48, 0xB4, 0x71, 0x8, 0x7, 0x76,
+                         0x60, 0x7, 0x71, 0x8, 0x87, 0x71, 0x58, 0x87,
+                         0x19, 0xDB, 0xC6, 0xE, 0xEC, 0x60, 0xF, 0xED,
+                         0xE0, 0x6, 0xF0, 0x20, 0xF, 0xE5, 0x30, 0xF, 0xE5,
+                         0x20, 0xF, 0xF6, 0x50, 0xE, 0x6E, 0x10, 0xE, 0xE3,
+                         0x30, 0xE, 0xE5, 0x30, 0xF, 0xF3, 0xE0, 0x6, 0xE9,
+                         0xE0, 0xE, 0xE4, 0x50, 0xE, 0xF8, 0x30, 0x23,
+                         0xE2, 0xEC, 0x61, 0x1C, 0xC2, 0x81, 0x1D, 0xD8,
+                         0xE1, 0x17, 0xEC, 0x21, 0x1D, 0xE6, 0x21, 0x1D,
+                         0xC4, 0x21, 0x1D, 0xD8, 0x21, 0x1D, 0xE8, 0x21,
+                         0x1F, 0x66, 0x20, 0x9D, 0x3B, 0xBC, 0x43, 0x3D,
+                         0xB8, 0x3, 0x39, 0x94, 0x83, 0x39, 0xCC, 0x58,
+                         0xBC, 0x70, 0x70, 0x7, 0x77, 0x78, 0x7, 0x7A,
+                         0x8, 0x7, 0x7A, 0x48, 0x87, 0x77, 0x70, 0x87,
+                         0x19, 0xCB, 0xE7, 0xE, 0xEF, 0x30, 0xF, 0xE1,
+                         0xE0, 0xE, 0xE9, 0x40, 0xF, 0xE9, 0xA0, 0xF, 0xE5,
+                         0x30, 0xC3, 0x1, 0x3, 0x73, 0xA8, 0x7, 0x77, 0x18,
+                         0x87, 0x5F, 0x98, 0x87, 0x70, 0x70, 0x87, 0x74,
+                         0xA0, 0x87, 0x74, 0xD0, 0x87, 0x72, 0x98, 0x81,
+                         0x84, 0x41, 0x39, 0xE0, 0xC3, 0x38, 0xB0, 0x43,
+                         0x3D, 0x90, 0x43, 0x39, 0xCC, 0x40, 0xC4, 0xA0,
+                         0x1D, 0xCA, 0xA1, 0x1D, 0xE0, 0x41, 0x1E, 0xDE,
+                         0xC1, 0x1C, 0x66, 0x24, 0x63, 0x30, 0xE, 0xE1,
+                         0xC0, 0xE, 0xEC, 0x30, 0xF, 0xE9, 0x40, 0xF, 0xE5,
+                         0x30, 0x43, 0x21, 0x83, 0x75, 0x18, 0x7, 0x73,
+                         0x48, 0x87, 0x5F, 0xA0, 0x87, 0x7C, 0x80, 0x87,
+                         0x72, 0x98, 0xB1, 0x94, 0x1, 0x3C, 0x8C, 0xC3,
+                         0x3C, 0x94, 0xC3, 0x38, 0xD0, 0x43, 0x3A, 0xBC,
+                         0x83, 0x3B, 0xCC, 0xC3, 0x8C, 0xC5, 0xC, 0x48,
+                         0x21, 0x15, 0x42, 0x61, 0x1E, 0xE6, 0x21, 0x1D,
+                         0xCE, 0xC1, 0x1D, 0x52, 0x81, 0x14, 0x66, 0x4C,
+                         0x67, 0x30, 0xE, 0xEF, 0x20, 0xF, 0xEF, 0xE0,
+                         0x6, 0xEF, 0x50, 0xF, 0xF4, 0x30, 0xF, 0xE9, 0x40,
+                         0xE, 0xE5, 0xE0, 0x6, 0xE6, 0x20, 0xF, 0xE1, 0xD0,
+                         0xE, 0xE5, 0x30, 0xA3, 0x40, 0x83, 0x76, 0x68,
+                         0x7, 0x79, 0x8, 0x87, 0x19, 0x52, 0x1A, 0xB8,
+                         0xC3, 0x3B, 0x84, 0x3, 0x3B, 0xA4, 0x43, 0x38,
+                         0xCC, 0x83, 0x1B, 0x84, 0x3, 0x39, 0x90, 0x83,
+                         0x3C, 0xCC, 0x3, 0x3C, 0x84, 0xC3, 0x38, 0x94,
+                         0xC3, 0xC, 0x46, 0xD, 0xC6, 0x21, 0x1C, 0xD8,
+                         0x81, 0x1D, 0xCA, 0xA1, 0x1C, 0x7E, 0x81, 0x1E,
+                         0xF2, 0x1, 0x1E, 0xCA, 0x61, 0x86, 0xB3, 0x6,
+                         0xE4, 0x80, 0xF, 0x6E, 0xE0, 0xE, 0xEF, 0xE0,
+                         0xE, 0xF5, 0xE0, 0xE, 0xE9, 0x60, 0xE, 0xEF, 0x20,
+                         0xF, 0xED, 0x30, 0xA3, 0x62, 0x3, 0x72, 0xC0,
+                         0x7, 0x37, 0x18, 0x87, 0x77, 0x70, 0x7, 0x7A,
+                         0x90, 0x87, 0x77, 0x60, 0x7, 0x73, 0x60, 0x87,
+                         0x77, 0xB8, 0x7, 0x37, 0x40, 0x87, 0x74, 0x70,
+                         0x7, 0x7A, 0x98, 0x87, 0x19, 0x4B, 0x1B, 0x90,
+                         0x3, 0x3E, 0xB8, 0x1, 0x3C, 0xC8, 0x43, 0x39,
+                         0x8C, 0x43, 0x3A, 0xCC, 0x43, 0x39, 0x0, 0x0,
+                         0x79, 0x28, 0x0, 0x0, 0x53, 0x0, 0x0, 0x0, 0xC2,
+                         0x3C, 0x90, 0x40, 0x86, 0x10, 0x19, 0x32, 0xE2,
+                         0x64, 0x90, 0x40, 0x46, 0x2, 0x19, 0x23, 0x23,
+                         0x46, 0x2, 0x13, 0x24, 0xC6, 0x0, 0x13, 0x74,
+                         0xD4, 0x61, 0x8C, 0x2D, 0xCC, 0xED, 0xC, 0xC4,
+                         0xAE, 0x4C, 0x6E, 0x2E, 0xED, 0xCD, 0xD, 0x44,
+                         0x46, 0xC6, 0x5, 0xC6, 0x5, 0xE6, 0x2C, 0x8D,
+                         0xE, 0x4, 0xE5, 0x2C, 0x8D, 0xE, 0xE8, 0x2C, 0x8D,
+                         0xE, 0xAD, 0x4E, 0xCC, 0x65, 0xEC, 0xAD, 0x4D,
+                         0x27, 0xCD, 0x4D, 0xAC, 0x8C, 0x2D, 0x6D, 0xEC,
+                         0x85, 0x8D, 0xCD, 0xAE, 0xAD, 0x5, 0x4E, 0xEE,
+                         0x4D, 0xAD, 0x6C, 0x8C, 0xCE, 0xE5, 0x2C, 0x8D,
+                         0xE, 0x84, 0x86, 0xC6, 0xCC, 0xC6, 0x86, 0x4C,
+                         0xC, 0x87, 0x6C, 0xEC, 0x26, 0x67, 0x46, 0x26,
+                         0x67, 0x6C, 0xA6, 0xCC, 0x66, 0x8C, 0xC6, 0x2C,
+                         0xEC, 0x26, 0xC, 0x26, 0x2C, 0xEC, 0x26, 0xCC,
+                         0xCC, 0x86, 0x6, 0xE6, 0x6, 0x26, 0xE7, 0x86,
+                         0xE6, 0x26, 0xE5, 0x8, 0x63, 0x73, 0x87, 0x68,
+                         0xB, 0x4B, 0x73, 0x3B, 0xCA, 0xDD, 0x18, 0x5A,
+                         0x98, 0xDC, 0xD7, 0x5C, 0x9A, 0x5E, 0xD9, 0x69,
+                         0xCC, 0xE4, 0xC2, 0xDA, 0xCA, 0x5A, 0xE0, 0xDE,
+                         0xD2, 0xDC, 0xE8, 0xCA, 0xE4, 0x86, 0x20, 0x1C,
+                         0xC1, 0x10, 0x84, 0x43, 0x18, 0x82, 0x70, 0xC,
+                         0x43, 0x10, 0xE, 0x62, 0x8, 0x42, 0x1, 0xC, 0x41,
+                         0x38, 0x8A, 0x21, 0x8, 0x87, 0x31, 0x6, 0xC1,
+                         0x38, 0xC6, 0x10, 0x4, 0x63, 0x18, 0x4, 0x24,
+                         0x19, 0x83, 0x60, 0x24, 0x63, 0x18, 0xC, 0xC3,
+                         0x18, 0x83, 0xB0, 0x44, 0x63, 0x28, 0x94, 0x1,
+                         0x0, 0xA4, 0x31, 0xC, 0x6, 0xB1, 0x8C, 0x61, 0x60,
+                         0xA, 0xC6, 0x24, 0x64, 0x78, 0x2E, 0x76, 0x61,
+                         0x6C, 0x76, 0x65, 0x72, 0x43, 0x9, 0x18, 0xA3,
+                         0xB0, 0x...
[truncated]

@@ -12,7 +12,7 @@ Header:
Version:
Major: 1
Minor: 0
FileSize: 3548
FileSize: 1996
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this different if the remove section arg wasn't passed to llvm-objcopy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, this commit was meant to be pushed to #153079.

In any case, the yaml here incorrectly specified the FileSize as 3548 instead of 1996. Since we now invoke recomputeHeader as part of removeParts it was failing this test case, because the (correctly) computed size was different than the original specified.

Copy link
Contributor

@bob80905 bob80905 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, assuming you don't intend to take back the commit you made to llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test

@jh7370
Copy link
Collaborator

jh7370 commented Aug 13, 2025

Please hold off merging until I've had a chance to review (probably tomorrow).

Copy link
Member

@hekota hekota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few comments.


Error Object::removeParts(PartPred ToRemove) {
erase_if(Parts, ToRemove);
recomputeHeader();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking ahead to when other options are added, should this be done outside removeParts, in handleArgs or similar? If, for example, you add the ability to add a section, you'll presumably need to recompute and you should probably only do that once after all the changes have been made.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point, thanks.

@@ -0,0 +1,300 @@
## Tests that the RTS0 (root signature) part is correctly removed from the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the basic- part of the test name be dropped and the name updated to something more specific to what is being removed (e.g. remove-section.test or remove-root-signature.test)?

@@ -0,0 +1,50 @@
## Tests that the copied DXContainer correctly has the specified headers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd invert the name to remove-headers.test, so that all "remove" tests are grouped together (see also my other comment).

@inbelic inbelic force-pushed the inbelic/dx-objcopy-rm branch from 91ecc92 to 74ca962 Compare August 14, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HLSL][RootSignature] Add support for Qstrip_rootsignature compiler flag
5 participants