From 44f66db8dc79329c3e6c4fa7a0aa7af640709747 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Thu, 7 Aug 2025 18:42:27 +0000 Subject: [PATCH 01/17] boiler plate to add dxcontainer to objcopy --- llvm/include/llvm/ObjCopy/ConfigManager.h | 4 ++ .../ObjCopy/DXContainer/DXContainerConfig.h | 21 ++++++++ .../ObjCopy/DXContainer/DXContainerObjcopy.h | 36 +++++++++++++ llvm/include/llvm/ObjCopy/MultiFormatConfig.h | 2 + llvm/include/llvm/Object/DXContainer.h | 2 + llvm/lib/ObjCopy/CMakeLists.txt | 11 ++++ llvm/lib/ObjCopy/ConfigManager.cpp | 32 ++++++++++++ .../DXContainer/DXContainerObjcopy.cpp | 47 +++++++++++++++++ .../ObjCopy/DXContainer/DXContainerObject.h | 38 ++++++++++++++ .../ObjCopy/DXContainer/DXContainerReader.cpp | 38 ++++++++++++++ .../ObjCopy/DXContainer/DXContainerReader.h | 34 +++++++++++++ .../ObjCopy/DXContainer/DXContainerWriter.cpp | 50 +++++++++++++++++++ .../ObjCopy/DXContainer/DXContainerWriter.h | 39 +++++++++++++++ llvm/lib/ObjCopy/ObjCopy.cpp | 12 +++++ 14 files changed, 366 insertions(+) create mode 100644 llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h create mode 100644 llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h create mode 100644 llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp create mode 100644 llvm/lib/ObjCopy/DXContainer/DXContainerObject.h create mode 100644 llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp create mode 100644 llvm/lib/ObjCopy/DXContainer/DXContainerReader.h create mode 100644 llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp create mode 100644 llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h diff --git a/llvm/include/llvm/ObjCopy/ConfigManager.h b/llvm/include/llvm/ObjCopy/ConfigManager.h index e7b3775f0e9f1..4b596c604ea3a 100644 --- a/llvm/include/llvm/ObjCopy/ConfigManager.h +++ b/llvm/include/llvm/ObjCopy/ConfigManager.h @@ -11,6 +11,7 @@ #include "llvm/ObjCopy/COFF/COFFConfig.h" #include "llvm/ObjCopy/CommonConfig.h" +#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h" #include "llvm/ObjCopy/ELF/ELFConfig.h" #include "llvm/ObjCopy/MachO/MachOConfig.h" #include "llvm/ObjCopy/MultiFormatConfig.h" @@ -36,6 +37,8 @@ struct LLVM_ABI ConfigManager : public MultiFormatConfig { Expected getXCOFFConfig() const override; + Expected getDXContainerConfig() const override; + // All configs. CommonConfig Common; ELFConfig ELF; @@ -43,6 +46,7 @@ struct LLVM_ABI ConfigManager : public MultiFormatConfig { MachOConfig MachO; WasmConfig Wasm; XCOFFConfig XCOFF; + DXContainerConfig DXContainer; }; } // namespace objcopy diff --git a/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h new file mode 100644 index 0000000000000..1ce4f2bb370eb --- /dev/null +++ b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h @@ -0,0 +1,21 @@ +//===- DXContainerConfig.h --------------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJCOPY_DXCONTAINER_DXCONTAINERCONFIG_H +#define LLVM_OBJCOPY_DXCONTAINER_DXCONTAINERCONFIG_H + +namespace llvm { +namespace objcopy { + +// DXContainer specific configuration for copying/stripping a single file. +struct DXContainerConfig {}; + +} // namespace objcopy +} // namespace llvm + +#endif // LLVM_OBJCOPY_DXCONTAINER_DXCONTAINERCONFIG_H diff --git a/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h new file mode 100644 index 0000000000000..d27a955b9afab --- /dev/null +++ b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h @@ -0,0 +1,36 @@ +//===- DXContainerObjcopy.h -------------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_OBJCOPY_DXCONTAINER_DXCONTAINEROBJCOPY_H +#define LLVM_OBJCOPY_DXCONTAINER_DXCONTAINEROBJCOPY_H + +namespace llvm { +class Error; +class raw_ostream; + +namespace object { +class DXContainerObjectFile; +} // end namespace object + +namespace objcopy { +struct CommonConfig; +struct DXContainerConfig; + +namespace dxc { +/// Apply the transformations described by \p Config and \p DXContainerConfig +/// to \p In and writes the result into \p Out. +/// \returns any Error encountered whilst performing the operation. +Error executeObjcopyOnBinary(const CommonConfig &Config, + const DXContainerConfig &, + object::DXContainerObjectFile &In, + raw_ostream &Out); +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm + +#endif // LLVM_OBJCOPY_DXCONTAINER_DXCONTAINEROBJCOPY_H diff --git a/llvm/include/llvm/ObjCopy/MultiFormatConfig.h b/llvm/include/llvm/ObjCopy/MultiFormatConfig.h index 180f2f82a908b..bb93f64aa2788 100644 --- a/llvm/include/llvm/ObjCopy/MultiFormatConfig.h +++ b/llvm/include/llvm/ObjCopy/MultiFormatConfig.h @@ -20,6 +20,7 @@ struct COFFConfig; struct MachOConfig; struct WasmConfig; struct XCOFFConfig; +struct DXContainerConfig; class MultiFormatConfig { public: @@ -31,6 +32,7 @@ class MultiFormatConfig { virtual Expected getMachOConfig() const = 0; virtual Expected getWasmConfig() const = 0; virtual Expected getXCOFFConfig() const = 0; + virtual Expected getDXContainerConfig() const = 0; }; } // namespace objcopy diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h index 3c8cd174afede..54cfd35b35fe8 100644 --- a/llvm/include/llvm/Object/DXContainer.h +++ b/llvm/include/llvm/Object/DXContainer.h @@ -605,6 +605,8 @@ class DXContainerObjectFile : public ObjectFile { public: static bool classof(const Binary *v) { return v->isDXContainer(); } + const dxbc::Header &getHeader() const { return Container.getHeader(); } + Expected getSymbolName(DataRefImpl) const override; Expected getSymbolAddress(DataRefImpl Symb) const override; uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; diff --git a/llvm/lib/ObjCopy/CMakeLists.txt b/llvm/lib/ObjCopy/CMakeLists.txt index 2d6bee94875f0..54d0ea99fbc28 100644 --- a/llvm/lib/ObjCopy/CMakeLists.txt +++ b/llvm/lib/ObjCopy/CMakeLists.txt @@ -16,6 +16,9 @@ source_group("Header Files\\wasm" REGULAR_EXPRESSION source_group("Header Files\\XCOFF" REGULAR_EXPRESSION XCOFF/.*[.]h ) +source_group("Header Files\\DXContainer" REGULAR_EXPRESSION + DXContainer/.*[.]h +) source_group("Source Files" REGULAR_EXPRESSION .*[.]cpp ) @@ -34,9 +37,15 @@ source_group("Source Files\\wasm" REGULAR_EXPRESSION source_group("Source Files\\XCOFF" REGULAR_EXPRESSION XCOFF/.*[.]cpp ) +source_group("Source Files\\DXContainer" REGULAR_EXPRESSION + DXContainer/.*[.]cpp +) add_llvm_component_library(LLVMObjCopy Archive.cpp + DXContainer/DXContainerObjcopy.cpp + DXContainer/DXContainerReader.cpp + DXContainer/DXContainerWriter.cpp CommonConfig.cpp ObjCopy.cpp ConfigManager.cpp @@ -62,11 +71,13 @@ add_llvm_component_library(LLVMObjCopy ADDITIONAL_HEADER_DIRS ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy/COFF + ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy/DXContainer ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy/ELF ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy/MachO ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy/wasm ${LLVM_MAIN_INCLUDE_DIR}/llvm/ObjCopy/XCOFF COFF + DXContainer ELF MachO wasm diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp index 9a81b51c4d277..fd82a7f60477f 100644 --- a/llvm/lib/ObjCopy/ConfigManager.cpp +++ b/llvm/lib/ObjCopy/ConfigManager.cpp @@ -107,3 +107,35 @@ Expected ConfigManager::getXCOFFConfig() const { return XCOFF; } + +Expected +ConfigManager::getDXContainerConfig() const { + if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition || + !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || + !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() || + !Common.AllocSectionsPrefix.empty() || + Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() || + !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() || + !Common.KeepSection.empty() || !Common.OnlySection.empty() || + !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() || + !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() || + !Common.SymbolsToRemove.empty() || + !Common.UnneededSymbolsToRemove.empty() || + !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() || + !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() || + !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() || + !Common.SymbolsToRename.empty() || Common.ExtractDWO || + Common.ExtractMainPartition || Common.OnlyKeepDebug || + Common.PreserveDates || Common.StripAllGNU || Common.StripDWO || + Common.StripDebug || Common.StripNonAlloc || Common.StripSections || + Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections || + Common.GapFill != 0 || Common.PadTo != 0 || + Common.ChangeSectionLMAValAll != 0 || + !Common.ChangeSectionAddress.empty()) { + return createStringError( + llvm::errc::invalid_argument, + "no flags are supported yet, only basic copying is allowed"); + } + + return DXContainer; +} diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp new file mode 100644 index 0000000000000..9629555b38a1b --- /dev/null +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp @@ -0,0 +1,47 @@ +//===- DXContainerObjcopy.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 "llvm/ObjCopy/DXContainer/DXContainerObjcopy.h" +#include "llvm/ObjCopy/CommonConfig.h" +#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h" + +#include "DXContainerReader.h" +#include "DXContainerWriter.h" + +namespace llvm { +namespace objcopy { +namespace dxc { + +using namespace object; + +static Error handleArgs(const CommonConfig &Config, Object &Obj) { + return Error::success(); +} + +Error executeObjcopyOnBinary(const CommonConfig &Config, + const DXContainerConfig &, + DXContainerObjectFile &In, raw_ostream &Out) { + DXContainerReader Reader(In); + Expected> ObjOrErr = Reader.create(); + if (!ObjOrErr) + return createFileError(Config.InputFilename, ObjOrErr.takeError()); + Object *Obj = ObjOrErr->get(); + assert(Obj && "Unable to deserialize DXContainer object"); + + if (Error E = handleArgs(Config, *Obj)) + return E; + + DXContainerWriter Writer(*Obj, Out); + if (Error E = Writer.write()) + return createFileError(Config.OutputFilename, std::move(E)); + return Error::success(); +} + +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h new file mode 100644 index 0000000000000..14f948df0ad9a --- /dev/null +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h @@ -0,0 +1,38 @@ +//===- DXContainerObject.h --------------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_OBJCOPY_DXContainer_DXContainerOBJECT_H +#define LLVM_LIB_OBJCOPY_DXContainer_DXContainerOBJECT_H + +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Object/DXContainer.h" +#include + +namespace llvm { +namespace objcopy { +namespace dxc { + +using namespace object; + +struct Part { + StringRef Name; + uint32_t Offset; + ArrayRef Data; +}; + +struct Object { + dxbc::Header Header; + SmallVector Parts; +}; + +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm + +#endif // LLVM_LIB_OBJCOPY_DXContainer_DXContainerOBJECT_H diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp new file mode 100644 index 0000000000000..d6e7a2a6a200c --- /dev/null +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp @@ -0,0 +1,38 @@ +//===- DXContainerReader.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 "DXContainerReader.h" + +namespace llvm { +namespace objcopy { +namespace dxc { + +using namespace object; + +Expected> DXContainerReader::create() const { + auto Obj = std::make_unique(); + Obj->Header = DXContainerObj.getHeader(); + for (const SectionRef &Part : DXContainerObj.sections()) { + DataRefImpl PartDRI = Part.getRawDataRefImpl(); + Expected Name = DXContainerObj.getSectionName(PartDRI); + if (auto E = Name.takeError()) + return createStringError(inconvertibleErrorCode(), "Missing Part Name"); + uint32_t Offset = DXContainerObj.getSectionAddress(PartDRI); + Expected> Data = + DXContainerObj.getSectionContents(PartDRI); + if (auto E = Data.takeError()) + return createStringError(inconvertibleErrorCode(), + "Missing Part Contents"); + Obj->Parts.push_back({*Name, Offset, *Data}); + } + return std::move(Obj); +} + +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h new file mode 100644 index 0000000000000..32128d0b6df0c --- /dev/null +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h @@ -0,0 +1,34 @@ +//===- DXContainerReader.h --------------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERREADER_H +#define LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERREADER_H + +#include "DXContainerObject.h" + +namespace llvm { +namespace objcopy { +namespace dxc { + +using namespace object; + +class DXContainerReader { +public: + explicit DXContainerReader(const DXContainerObjectFile &Obj) + : DXContainerObj(Obj) {} + Expected> create() const; + +private: + const DXContainerObjectFile &DXContainerObj; +}; + +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm + +#endif // LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERREADER_H diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp new file mode 100644 index 0000000000000..8c7759c9ebe13 --- /dev/null +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp @@ -0,0 +1,50 @@ +//===- DXContainerWriter.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 "DXContainerWriter.h" + +namespace llvm { +namespace objcopy { +namespace dxc { + +using namespace object; + +size_t DXContainerWriter::finalize() { + size_t ObjectSize = sizeof(dxbc::Header); + ObjectSize += Obj.Parts.size() * sizeof(uint32_t); + Offsets.reserve(Obj.Parts.size()); + for (const Part &P : Obj.Parts) { + Offsets.push_back(ObjectSize); + assert(P.Name.size() == 4 && + "Valid DXIL Part name consists of 4 characters"); + ObjectSize += 4 + sizeof(uint32_t) + P.Data.size(); + } + return ObjectSize; +} + +Error DXContainerWriter::write() { + size_t TotalSize = finalize(); + Out.reserveExtraSpace(TotalSize); + + Out.write(reinterpret_cast(&Obj.Header), sizeof(dxbc::Header)); + Out.write(reinterpret_cast(Offsets.data()), + Offsets.size() * sizeof(uint32_t)); + + for (const Part &P : Obj.Parts) { + Out.write(reinterpret_cast(P.Name.data()), P.Name.size()); + uint32_t Size = P.Data.size(); + Out.write(reinterpret_cast(&Size), sizeof(uint32_t)); + Out.write(reinterpret_cast(P.Data.data()), P.Data.size()); + } + + return Error::success(); +} + +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h new file mode 100644 index 0000000000000..f330edd75b421 --- /dev/null +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h @@ -0,0 +1,39 @@ +//===- DXContainerWriter.h --------------------------------------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERWRITER_H +#define LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERWRITER_H + +#include "DXContainerObject.h" + +namespace llvm { +namespace objcopy { +namespace dxc { + +using namespace object; + +class DXContainerWriter { +public: + explicit DXContainerWriter(const Object &Obj, raw_ostream &Out) + : Obj(Obj), Out(Out) {} + Error write(); + +private: + const Object &Obj; + raw_ostream &Out; + + SmallVector Offsets; + + size_t finalize(); +}; + +} // end namespace dxc +} // end namespace objcopy +} // end namespace llvm + +#endif // LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINERWRITER_H diff --git a/llvm/lib/ObjCopy/ObjCopy.cpp b/llvm/lib/ObjCopy/ObjCopy.cpp index d9a190d1a2ad1..e8e8067c9518d 100644 --- a/llvm/lib/ObjCopy/ObjCopy.cpp +++ b/llvm/lib/ObjCopy/ObjCopy.cpp @@ -9,6 +9,8 @@ #include "llvm/ObjCopy/ObjCopy.h" #include "llvm/ObjCopy/COFF/COFFConfig.h" #include "llvm/ObjCopy/COFF/COFFObjcopy.h" +#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h" +#include "llvm/ObjCopy/DXContainer/DXContainerObjcopy.h" #include "llvm/ObjCopy/ELF/ELFConfig.h" #include "llvm/ObjCopy/ELF/ELFObjcopy.h" #include "llvm/ObjCopy/MachO/MachOConfig.h" @@ -19,6 +21,7 @@ #include "llvm/ObjCopy/wasm/WasmConfig.h" #include "llvm/ObjCopy/wasm/WasmObjcopy.h" #include "llvm/Object/COFF.h" +#include "llvm/Object/DXContainer.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/Error.h" #include "llvm/Object/MachO.h" @@ -78,6 +81,15 @@ Error objcopy::executeObjcopyOnBinary(const MultiFormatConfig &Config, return xcoff::executeObjcopyOnBinary(Config.getCommonConfig(), *XCOFFConfig, *XCOFFBinary, Out); } + if (auto *DXContainerBinary = dyn_cast(&In)) { + Expected DXContainerConfig = + Config.getDXContainerConfig(); + if (!DXContainerConfig) + return DXContainerConfig.takeError(); + + return dxc::executeObjcopyOnBinary( + Config.getCommonConfig(), *DXContainerConfig, *DXContainerBinary, Out); + } return createStringError(object_error::invalid_file_type, "unsupported object file format"); } From 648d0fc2fcc02ac74c5406706f0e77f14c8f1bb9 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 11 Aug 2025 19:56:19 +0000 Subject: [PATCH 02/17] add basic tests --- .../llvm-objcopy/DXContainer/basic-copy.test | 292 ++++++++++++++++++ .../DXContainer/headers-copy.test | 39 +++ 2 files changed, 331 insertions(+) create mode 100644 llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test create mode 100644 llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test new file mode 100644 index 0000000000000..1958b0ff18ac3 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test @@ -0,0 +1,292 @@ +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy %t %t.out +# RUN: cmp %t %t.out + +# The following DXContainer to copied 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 + PartCount: 7 + PartOffsets: [ 60, 1792, 1808, 1836, 1852, 1868, 1900 ] +Parts: + - 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, 0xB1, 0xD9, 0xB5, 0xB9, 0xA4, 0x91, 0x95, + 0xB9, 0xD1, 0xD, 0x25, 0x68, 0x8C, 0x43, 0x86, + 0xE7, 0x32, 0x87, 0x16, 0x46, 0x56, 0x26, 0xD7, + 0xF4, 0x46, 0x56, 0xC6, 0x36, 0x94, 0xC0, 0x31, + 0xA, 0x19, 0x9E, 0x8B, 0x5D, 0x99, 0xDC, 0x5C, + 0xDA, 0x9B, 0xDB, 0x50, 0x82, 0xC7, 0x38, 0x64, + 0x78, 0x2E, 0x65, 0x6E, 0x74, 0x72, 0x79, 0x50, + 0x6F, 0x69, 0x6E, 0x74, 0x73, 0x43, 0x9, 0x24, + 0x13, 0xB1, 0xB1, 0xD9, 0xB5, 0xB9, 0xB4, 0xBD, + 0x91, 0xD5, 0xB1, 0x95, 0xB9, 0x98, 0xB1, 0x85, + 0x9D, 0xCD, 0xD, 0x45, 0x98, 0x28, 0x0, 0x0, 0x71, + 0x20, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x6, 0x40, + 0x30, 0x0, 0xD2, 0x0, 0x0, 0x0, 0x61, 0x20, 0x0, + 0x0, 0x6, 0x0, 0x0, 0x0, 0x13, 0x4, 0x1, 0x86, + 0x3, 0x1, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x7, 0x50, + 0x10, 0xCD, 0x14, 0x61, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0 ] + - Name: SFI0 + Size: 8 + - Name: HASH + Size: 20 + Hash: + IncludesSource: false + Digest: [ 0x9F, 0xD1, 0xD9, 0xE2, 0x49, 0xFB, 0x3A, 0x6C, + 0x8C, 0x14, 0x8A, 0x96, 0x1C, 0x7D, 0x85, 0xA9 ] + - Name: ISG1 + Size: 8 + Signature: + Parameters: [] + - Name: OSG1 + Size: 8 + Signature: + Parameters: [] + - Name: RTS0 + Size: 24 + RootSignature: + Version: 2 + NumRootParameters: 0 + RootParametersOffset: 24 + NumStaticSamplers: 0 + StaticSamplersOffset: 0 + Parameters: [] + - Name: PSV0 + Size: 76 + PSVInfo: + Version: 3 + ShaderStage: 5 + MinimumWaveLaneCount: 0 + MaximumWaveLaneCount: 4294967295 + UsesViewID: 0 + SigInputVectors: 0 + SigOutputVectors: [ 0, 0, 0, 0 ] + NumThreadsX: 1 + NumThreadsY: 1 + NumThreadsZ: 1 + EntryName: main + ResourceStride: 24 + Resources: [] + SigInputElements: [] + SigOutputElements: [] + SigPatchOrPrimElements: [] + InputOutputMap: + - [ ] + - [ ] + - [ ] + - [ ] +... diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test new file mode 100644 index 0000000000000..b2248edfad5ad --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test @@ -0,0 +1,39 @@ +# RUN: yaml2obj %s -o %t +# RUN: llvm-objcopy %t %t.out +# RUN: cmp %t %t.out + +--- !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: 3548 + PartCount: 7 + PartOffsets: [ 60, 76, 92, 108, 236, 1932, 1960 ] +Parts: + - Name: FKE0 + Size: 8 + - Name: FKE1 + Size: 8 + - Name: FKE2 + Size: 8 + - Name: FKE3 + Size: 120 + - Name: FKE4 + Size: 1688 + - Name: FKE5 + Size: 20 + - Name: DXIL + Size: 28 + Program: + MajorVersion: 6 + MinorVersion: 5 + ShaderKind: 5 + Size: 8 + DXILMajorVersion: 1 + DXILMinorVersion: 5 + DXILSize: 4 + DXIL: [ 0x42, 0x43, 0xC0, 0xDE, ] +... From c4b10967eee0e5269c76816aba6a849fe0cd7df3 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 11 Aug 2025 21:44:21 +0000 Subject: [PATCH 03/17] self-review: recompute offsets instead of storing them --- llvm/lib/ObjCopy/DXContainer/DXContainerObject.h | 11 ++++++++++- llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp | 5 +++-- llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp | 11 ++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h index 14f948df0ad9a..362210b92dcaf 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h @@ -22,13 +22,22 @@ using namespace object; struct Part { StringRef Name; - uint32_t Offset; ArrayRef Data; + + size_t size() const { + return sizeof(dxbc::PartHeader) // base header + + Data.size(); // contents size + } }; struct Object { dxbc::Header Header; SmallVector Parts; + + size_t headerSize() const { + return sizeof(dxbc::Header) // base header + + sizeof(uint32_t) * Parts.size(); // part offset values + } }; } // end namespace dxc diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp index d6e7a2a6a200c..2a1a202d402ea 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp @@ -22,13 +22,14 @@ Expected> DXContainerReader::create() const { Expected Name = DXContainerObj.getSectionName(PartDRI); if (auto E = Name.takeError()) return createStringError(inconvertibleErrorCode(), "Missing Part Name"); - uint32_t Offset = DXContainerObj.getSectionAddress(PartDRI); + assert(Name->size() == 4 && + "Valid DXIL Part name consists of 4 characters"); Expected> Data = DXContainerObj.getSectionContents(PartDRI); if (auto E = Data.takeError()) return createStringError(inconvertibleErrorCode(), "Missing Part Contents"); - Obj->Parts.push_back({*Name, Offset, *Data}); + Obj->Parts.push_back({*Name, *Data}); } return std::move(Obj); } diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp index 8c7759c9ebe13..6dfc6908fe6e4 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp @@ -15,16 +15,13 @@ namespace dxc { using namespace object; size_t DXContainerWriter::finalize() { - size_t ObjectSize = sizeof(dxbc::Header); - ObjectSize += Obj.Parts.size() * sizeof(uint32_t); Offsets.reserve(Obj.Parts.size()); + size_t Offset = Obj.headerSize(); for (const Part &P : Obj.Parts) { - Offsets.push_back(ObjectSize); - assert(P.Name.size() == 4 && - "Valid DXIL Part name consists of 4 characters"); - ObjectSize += 4 + sizeof(uint32_t) + P.Data.size(); + Offsets.push_back(Offset); + Offset += P.size(); } - return ObjectSize; + return Obj.Header.FileSize; } Error DXContainerWriter::write() { From a3229ee009351d3afec14dbdbaec1f19914c7485 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 11 Aug 2025 21:51:33 +0000 Subject: [PATCH 04/17] review: use dxbc instead of dxc --- .../llvm/ObjCopy/DXContainer/DXContainerObjcopy.h | 4 ++-- llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp | 4 ++-- llvm/lib/ObjCopy/DXContainer/DXContainerObject.h | 12 ++++++------ llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp | 4 ++-- llvm/lib/ObjCopy/DXContainer/DXContainerReader.h | 4 ++-- llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp | 7 ++++--- llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h | 4 ++-- llvm/lib/ObjCopy/ObjCopy.cpp | 2 +- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h index d27a955b9afab..a410cfec18ea4 100644 --- a/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h +++ b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerObjcopy.h @@ -21,7 +21,7 @@ namespace objcopy { struct CommonConfig; struct DXContainerConfig; -namespace dxc { +namespace dxbc { /// Apply the transformations described by \p Config and \p DXContainerConfig /// to \p In and writes the result into \p Out. /// \returns any Error encountered whilst performing the operation. @@ -29,7 +29,7 @@ Error executeObjcopyOnBinary(const CommonConfig &Config, const DXContainerConfig &, object::DXContainerObjectFile &In, raw_ostream &Out); -} // end namespace dxc +} // end namespace dxbc } // end namespace objcopy } // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp index 9629555b38a1b..e94058959bd33 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp @@ -15,7 +15,7 @@ namespace llvm { namespace objcopy { -namespace dxc { +namespace dxbc { using namespace object; @@ -42,6 +42,6 @@ Error executeObjcopyOnBinary(const CommonConfig &Config, return Error::success(); } -} // end namespace dxc +} // 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 362210b92dcaf..8f54084caeca7 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h @@ -16,7 +16,7 @@ namespace llvm { namespace objcopy { -namespace dxc { +namespace dxbc { using namespace object; @@ -25,22 +25,22 @@ struct Part { ArrayRef Data; size_t size() const { - return sizeof(dxbc::PartHeader) // base header - + Data.size(); // contents size + return sizeof(::llvm::dxbc::PartHeader) // base header + + Data.size(); // contents size } }; struct Object { - dxbc::Header Header; + ::llvm::dxbc::Header Header; SmallVector Parts; size_t headerSize() const { - return sizeof(dxbc::Header) // base header + return sizeof(::llvm::dxbc::Header) // base header + sizeof(uint32_t) * Parts.size(); // part offset values } }; -} // end namespace dxc +} // end namespace dxbc } // end namespace objcopy } // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp index 2a1a202d402ea..770576dbce57f 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp @@ -10,7 +10,7 @@ namespace llvm { namespace objcopy { -namespace dxc { +namespace dxbc { using namespace object; @@ -34,6 +34,6 @@ Expected> DXContainerReader::create() const { return std::move(Obj); } -} // end namespace dxc +} // end namespace dxbc } // end namespace objcopy } // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h index 32128d0b6df0c..54058ff133adb 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.h @@ -13,7 +13,7 @@ namespace llvm { namespace objcopy { -namespace dxc { +namespace dxbc { using namespace object; @@ -27,7 +27,7 @@ class DXContainerReader { const DXContainerObjectFile &DXContainerObj; }; -} // end namespace dxc +} // end namespace dxbc } // end namespace objcopy } // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp index 6dfc6908fe6e4..8beb896dd7de4 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp @@ -10,7 +10,7 @@ namespace llvm { namespace objcopy { -namespace dxc { +namespace dxbc { using namespace object; @@ -28,7 +28,8 @@ Error DXContainerWriter::write() { size_t TotalSize = finalize(); Out.reserveExtraSpace(TotalSize); - Out.write(reinterpret_cast(&Obj.Header), sizeof(dxbc::Header)); + Out.write(reinterpret_cast(&Obj.Header), + sizeof(::llvm::dxbc::Header)); Out.write(reinterpret_cast(Offsets.data()), Offsets.size() * sizeof(uint32_t)); @@ -42,6 +43,6 @@ Error DXContainerWriter::write() { return Error::success(); } -} // end namespace dxc +} // end namespace dxbc } // end namespace objcopy } // end namespace llvm diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h index f330edd75b421..c785c1663b39c 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.h @@ -13,7 +13,7 @@ namespace llvm { namespace objcopy { -namespace dxc { +namespace dxbc { using namespace object; @@ -32,7 +32,7 @@ class DXContainerWriter { size_t finalize(); }; -} // end namespace dxc +} // end namespace dxbc } // end namespace objcopy } // end namespace llvm diff --git a/llvm/lib/ObjCopy/ObjCopy.cpp b/llvm/lib/ObjCopy/ObjCopy.cpp index e8e8067c9518d..152600f4f243f 100644 --- a/llvm/lib/ObjCopy/ObjCopy.cpp +++ b/llvm/lib/ObjCopy/ObjCopy.cpp @@ -87,7 +87,7 @@ Error objcopy::executeObjcopyOnBinary(const MultiFormatConfig &Config, if (!DXContainerConfig) return DXContainerConfig.takeError(); - return dxc::executeObjcopyOnBinary( + return dxbc::executeObjcopyOnBinary( Config.getCommonConfig(), *DXContainerConfig, *DXContainerBinary, Out); } return createStringError(object_error::invalid_file_type, From 7ca8df7351b88744b8d0ad18e79739e372feba07 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 11 Aug 2025 22:23:40 +0000 Subject: [PATCH 05/17] review: account for endianness on non-copy values --- llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp index 8beb896dd7de4..c453f4be4aae0 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp @@ -28,14 +28,22 @@ Error DXContainerWriter::write() { size_t TotalSize = finalize(); Out.reserveExtraSpace(TotalSize); - Out.write(reinterpret_cast(&Obj.Header), + llvm::dxbc::Header Header = Obj.Header; + if (sys::IsBigEndianHost) + Header.swapBytes(); + Out.write(reinterpret_cast(&Header), sizeof(::llvm::dxbc::Header)); + if (sys::IsBigEndianHost) + for (auto &O : Offsets) + sys::swapByteOrder(O); Out.write(reinterpret_cast(Offsets.data()), Offsets.size() * sizeof(uint32_t)); for (const Part &P : Obj.Parts) { - Out.write(reinterpret_cast(P.Name.data()), P.Name.size()); + Out.write(reinterpret_cast(P.Name.data()), 4); uint32_t Size = P.Data.size(); + if (sys::IsBigEndianHost) + sys::swapByteOrder(Size); Out.write(reinterpret_cast(&Size), sizeof(uint32_t)); Out.write(reinterpret_cast(P.Data.data()), P.Data.size()); } From 56cbd57532902533960887ffa9d341ed0810c29f Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Tue, 12 Aug 2025 16:42:04 +0000 Subject: [PATCH 06/17] review: address LLVM/objcopy guideline comments --- .../ObjCopy/DXContainer/DXContainerObjcopy.cpp | 5 ++--- .../ObjCopy/DXContainer/DXContainerObject.h | 6 +++--- .../ObjCopy/DXContainer/DXContainerReader.cpp | 5 ++--- .../llvm-objcopy/DXContainer/basic-copy.test | 18 ++++++++++-------- .../llvm-objcopy/DXContainer/headers-copy.test | 3 +++ 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp index e94058959bd33..38155f0a84498 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp @@ -7,11 +7,10 @@ //===----------------------------------------------------------------------===// #include "llvm/ObjCopy/DXContainer/DXContainerObjcopy.h" -#include "llvm/ObjCopy/CommonConfig.h" -#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h" - #include "DXContainerReader.h" #include "DXContainerWriter.h" +#include "llvm/ObjCopy/CommonConfig.h" +#include "llvm/ObjCopy/DXContainer/DXContainerConfig.h" namespace llvm { namespace objcopy { diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h index 8f54084caeca7..160a235bbc1ff 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerObject.h @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIB_OBJCOPY_DXContainer_DXContainerOBJECT_H -#define LLVM_LIB_OBJCOPY_DXContainer_DXContainerOBJECT_H +#ifndef LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINEROBJECT_H +#define LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINEROBJECT_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" @@ -44,4 +44,4 @@ struct Object { } // end namespace objcopy } // end namespace llvm -#endif // LLVM_LIB_OBJCOPY_DXContainer_DXContainerOBJECT_H +#endif // LLVM_LIB_OBJCOPY_DXCONTAINER_DXCONTAINEROBJECT_H diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp index 770576dbce57f..61ee94c5cae95 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerReader.cpp @@ -21,14 +21,13 @@ Expected> DXContainerReader::create() const { DataRefImpl PartDRI = Part.getRawDataRefImpl(); Expected Name = DXContainerObj.getSectionName(PartDRI); if (auto E = Name.takeError()) - return createStringError(inconvertibleErrorCode(), "Missing Part Name"); + return E; assert(Name->size() == 4 && "Valid DXIL Part name consists of 4 characters"); Expected> Data = DXContainerObj.getSectionContents(PartDRI); if (auto E = Data.takeError()) - return createStringError(inconvertibleErrorCode(), - "Missing Part Contents"); + return E; Obj->Parts.push_back({*Name, *Data}); } return std::move(Obj); diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test index 1958b0ff18ac3..54c87dc4d2c23 100644 --- a/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test +++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test @@ -1,17 +1,19 @@ +## Tests that the copied DXContainer is identical to the original + # RUN: yaml2obj %s -o %t # RUN: llvm-objcopy %t %t.out # RUN: cmp %t %t.out -# The following DXContainer to copied was generated with: +## The DXContainer described below was generated with: -# `clang-dxc -T cs_6_7 test.hlsl /Fo temp.dxo` -# `obj2yaml temp.dxo` +## `clang-dxc -T cs_6_7 test.hlsl /Fo temp.dxo` +## `obj2yaml temp.dxo` -# ``` test.hlsl -# [RootSignature("")] -# [numthreads(1,1,1)] -# void main() {} -# ``` +## ``` test.hlsl +## [RootSignature("")] +## [numthreads(1,1,1)] +## void main() {} +## ``` --- !dxcontainer Header: diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test index b2248edfad5ad..5a681a6a7b28f 100644 --- a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test +++ b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test @@ -1,3 +1,6 @@ +## Tests that the copied DXContainer is identical to the original, ensuring all +## the different headers are correctly handled + # RUN: yaml2obj %s -o %t # RUN: llvm-objcopy %t %t.out # RUN: cmp %t %t.out From c78cc588f41879ef37ec0a910bb16d9dfbd3d533 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Tue, 12 Aug 2025 16:56:39 +0000 Subject: [PATCH 07/17] review: allow PreserveDates --- llvm/lib/ObjCopy/ConfigManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp index fd82a7f60477f..918daf8292f54 100644 --- a/llvm/lib/ObjCopy/ConfigManager.cpp +++ b/llvm/lib/ObjCopy/ConfigManager.cpp @@ -110,6 +110,9 @@ Expected ConfigManager::getXCOFFConfig() const { Expected ConfigManager::getDXContainerConfig() const { + // If a flag is listed below, then it may be implemented in the future. All + // other flags are not applicable and will be silently ignored for the + // DXContainer object file if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition || !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() || @@ -126,7 +129,7 @@ ConfigManager::getDXContainerConfig() const { !Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() || !Common.SymbolsToRename.empty() || Common.ExtractDWO || Common.ExtractMainPartition || Common.OnlyKeepDebug || - Common.PreserveDates || Common.StripAllGNU || Common.StripDWO || + Common.StripAllGNU || Common.StripDWO || Common.StripDebug || Common.StripNonAlloc || Common.StripSections || Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections || Common.GapFill != 0 || Common.PadTo != 0 || @@ -137,5 +140,7 @@ ConfigManager::getDXContainerConfig() const { "no flags are supported yet, only basic copying is allowed"); } + // If a flag is listed here, then it has support for DXContainer: + // Common.PreserveDates return DXContainer; } From 152c383f8b94a8b646bcacf205cae83f05d24ba2 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Tue, 12 Aug 2025 17:01:59 +0000 Subject: [PATCH 08/17] review: remove symbol related options --- llvm/lib/ObjCopy/ConfigManager.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp index 918daf8292f54..c0825f7f8095a 100644 --- a/llvm/lib/ObjCopy/ConfigManager.cpp +++ b/llvm/lib/ObjCopy/ConfigManager.cpp @@ -114,24 +114,16 @@ ConfigManager::getDXContainerConfig() const { // other flags are not applicable and will be silently ignored for the // DXContainer object file if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition || - !Common.SplitDWO.empty() || !Common.SymbolsPrefix.empty() || - !Common.SymbolsPrefixRemove.empty() || !Common.SymbolsToSkip.empty() || - !Common.AllocSectionsPrefix.empty() || + !Common.SplitDWO.empty() || !Common.AllocSectionsPrefix.empty() || Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() || - !Common.DumpSection.empty() || !Common.SymbolsToAdd.empty() || - !Common.KeepSection.empty() || !Common.OnlySection.empty() || - !Common.ToRemove.empty() || !Common.SymbolsToGlobalize.empty() || - !Common.SymbolsToKeep.empty() || !Common.SymbolsToLocalize.empty() || - !Common.SymbolsToRemove.empty() || - !Common.UnneededSymbolsToRemove.empty() || - !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.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.SymbolsToRename.empty() || Common.ExtractDWO || - Common.ExtractMainPartition || Common.OnlyKeepDebug || - Common.StripAllGNU || Common.StripDWO || + Common.ExtractDWO || Common.ExtractMainPartition || + Common.OnlyKeepDebug || Common.StripAllGNU || Common.StripDWO || Common.StripDebug || Common.StripNonAlloc || Common.StripSections || - Common.Weaken || Common.StripUnneeded || Common.DecompressDebugSections || + Common.StripUnneeded || Common.DecompressDebugSections || Common.GapFill != 0 || Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 || !Common.ChangeSectionAddress.empty()) { From 99e3b41a983e9a88e94b3c7384728c0b753283fe Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Tue, 12 Aug 2025 17:05:44 +0000 Subject: [PATCH 09/17] review: remove partition related options --- llvm/lib/ObjCopy/ConfigManager.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp index c0825f7f8095a..afbf42f4f1feb 100644 --- a/llvm/lib/ObjCopy/ConfigManager.cpp +++ b/llvm/lib/ObjCopy/ConfigManager.cpp @@ -113,19 +113,18 @@ ConfigManager::getDXContainerConfig() const { // If a flag is listed below, then it may be implemented in the future. All // other flags are not applicable and will be silently ignored for the // DXContainer object file - if (!Common.AddGnuDebugLink.empty() || Common.ExtractPartition || - !Common.SplitDWO.empty() || !Common.AllocSectionsPrefix.empty() || + if (!Common.AddGnuDebugLink.empty() || !Common.SplitDWO.empty() || + !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.ExtractMainPartition || - 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.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, From dc8e3c2a6c16d8556d6835ece05486ad4717a5a7 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Tue, 12 Aug 2025 18:05:54 +0000 Subject: [PATCH 10/17] self-review: correct header filesize --- llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test index 5a681a6a7b28f..fa90f263eead2 100644 --- a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test +++ b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test @@ -12,7 +12,7 @@ Header: Version: Major: 1 Minor: 0 - FileSize: 3548 + FileSize: 1996 PartCount: 7 PartOffsets: [ 60, 76, 92, 108, 236, 1932, 1960 ] Parts: From 364681aae3eb56256a51759b142c94461fff6c71 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Wed, 13 Aug 2025 17:38:27 +0000 Subject: [PATCH 11/17] review: fix up comments --- llvm/lib/ObjCopy/ConfigManager.cpp | 8 ++------ llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test | 2 +- .../test/tools/llvm-objcopy/DXContainer/headers-copy.test | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp index afbf42f4f1feb..bfa94ba778c76 100644 --- a/llvm/lib/ObjCopy/ConfigManager.cpp +++ b/llvm/lib/ObjCopy/ConfigManager.cpp @@ -110,9 +110,8 @@ Expected ConfigManager::getXCOFFConfig() const { Expected ConfigManager::getDXContainerConfig() const { - // If a flag is listed below, then it may be implemented in the future. All - // other flags are not applicable and will be silently ignored for the - // DXContainer object file + // All other flags are either supported or not applicable for DXContainer + // object files and will be silently ignored. if (!Common.AddGnuDebugLink.empty() || !Common.SplitDWO.empty() || !Common.AllocSectionsPrefix.empty() || Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() || @@ -130,8 +129,5 @@ ConfigManager::getDXContainerConfig() const { llvm::errc::invalid_argument, "no flags are supported yet, only basic copying is allowed"); } - - // If a flag is listed here, then it has support for DXContainer: - // Common.PreserveDates return DXContainer; } diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test index 54c87dc4d2c23..16ac30f059487 100644 --- a/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test +++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test @@ -1,4 +1,4 @@ -## Tests that the copied DXContainer is identical to the original +## Tests that the copied DXContainer is identical to the original. # RUN: yaml2obj %s -o %t # RUN: llvm-objcopy %t %t.out diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test index fa90f263eead2..b7720c8d57fbb 100644 --- a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test +++ b/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test @@ -1,5 +1,5 @@ ## Tests that the copied DXContainer is identical to the original, ensuring all -## the different headers are correctly handled +## the different headers are correctly handled. # RUN: yaml2obj %s -o %t # RUN: llvm-objcopy %t %t.out From 4fa61af3c5c79e2f3b9c52875fa43671166bbe9e Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Wed, 13 Aug 2025 17:38:44 +0000 Subject: [PATCH 12/17] review: ensure reader errors are surfaced --- .../llvm-objcopy/DXContainer/basic-errs.test | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test new file mode 100644 index 0000000000000..54b288f31863a --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test @@ -0,0 +1,46 @@ +## Check that llvm-objcopy reports a suitable error when it +## encounters an invalid input during reading. The purpose is not to have +## extensive of all read errors, that should be done in DXContainerTest.cpp, +## instead this is a sanity check that the error is produced when using the +## reader in llvm-objcopy. + +## We can't have multiple DXIL parts. +# RUN: yaml2obj %s --docnum=1 -o %t1 +# RUN: not llvm-objcopy %t1 %t1.out 2>&1 | FileCheck %s -DFILE=%t1 --check-prefix=ERROR1 + +# ERROR1: error: '[[FILE]]': More than one DXIL part is present in the file + +--- !dxcontainer +Header: + Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] + Version: + Major: 1 + Minor: 0 + PartCount: 2 +Parts: + - Name: DXIL + Size: 28 + - Name: DXIL + Size: 28 +... + +## The first part offset is out of file bound. +# RUN: yaml2obj %s --docnum=2 -o %t2 +# RUN: not llvm-objcopy %t2 %t2.out 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=ERROR2 + +# ERROR2: error: '[[FILE]]': Reading structure out of file bounds + +--- !dxcontainer +Header: + Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] + Version: + Major: 2 + Minor: 0 + PartCount: 1 + PartOffsets: [ 48 ] +Parts: + - Name: DXIL + Size: 28 +... From 9a60220815404feb4eb5e5221d5f456ea38d382b Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Thu, 14 Aug 2025 16:41:03 +0000 Subject: [PATCH 13/17] review: fix up comments --- llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test b/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test index 54b288f31863a..32099552a4525 100644 --- a/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test +++ b/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test @@ -1,8 +1,5 @@ ## Check that llvm-objcopy reports a suitable error when it -## encounters an invalid input during reading. The purpose is not to have -## extensive of all read errors, that should be done in DXContainerTest.cpp, -## instead this is a sanity check that the error is produced when using the -## reader in llvm-objcopy. +## encounters an invalid input during reading. ## We can't have multiple DXIL parts. # RUN: yaml2obj %s --docnum=1 -o %t1 @@ -25,7 +22,7 @@ Parts: Size: 28 ... -## The first part offset is out of file bound. +## The first part offset is out of file bounds. # RUN: yaml2obj %s --docnum=2 -o %t2 # RUN: not llvm-objcopy %t2 %t2.out 2>&1 | FileCheck %s -DFILE=%t2 --check-prefix=ERROR2 From 79c043e7d3e02e8593e32924f476c364fc381030 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Thu, 14 Aug 2025 16:42:56 +0000 Subject: [PATCH 14/17] review: rename files --- .../llvm-objcopy/DXContainer/{basic-copy.test => copy-basic.test} | 0 .../DXContainer/{headers-copy.test => copy-headers.test} | 0 .../DXContainer/{basic-errs.test => errs-reading.test} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename llvm/test/tools/llvm-objcopy/DXContainer/{basic-copy.test => copy-basic.test} (100%) rename llvm/test/tools/llvm-objcopy/DXContainer/{headers-copy.test => copy-headers.test} (100%) rename llvm/test/tools/llvm-objcopy/DXContainer/{basic-errs.test => errs-reading.test} (100%) diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test similarity index 100% rename from llvm/test/tools/llvm-objcopy/DXContainer/basic-copy.test rename to llvm/test/tools/llvm-objcopy/DXContainer/copy-basic.test diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test b/llvm/test/tools/llvm-objcopy/DXContainer/copy-headers.test similarity index 100% rename from llvm/test/tools/llvm-objcopy/DXContainer/headers-copy.test rename to llvm/test/tools/llvm-objcopy/DXContainer/copy-headers.test diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test b/llvm/test/tools/llvm-objcopy/DXContainer/errs-reading.test similarity index 100% rename from llvm/test/tools/llvm-objcopy/DXContainer/basic-errs.test rename to llvm/test/tools/llvm-objcopy/DXContainer/errs-reading.test From 40d4594edb19375786a4d63a314834978d177201 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 18 Aug 2025 14:47:46 -0700 Subject: [PATCH 15/17] review: rename test --- .../DXContainer/{errs-reading.test => reading-errs.test} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename llvm/test/tools/llvm-objcopy/DXContainer/{errs-reading.test => reading-errs.test} (100%) diff --git a/llvm/test/tools/llvm-objcopy/DXContainer/errs-reading.test b/llvm/test/tools/llvm-objcopy/DXContainer/reading-errs.test similarity index 100% rename from llvm/test/tools/llvm-objcopy/DXContainer/errs-reading.test rename to llvm/test/tools/llvm-objcopy/DXContainer/reading-errs.test From c0aec7a3c7c5d8ad0744e107fbc195d1e7b6de9f Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 18 Aug 2025 14:52:39 -0700 Subject: [PATCH 16/17] review: assert offsets --- llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp index c453f4be4aae0..6c26ec4cff646 100644 --- a/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp +++ b/llvm/lib/ObjCopy/DXContainer/DXContainerWriter.cpp @@ -15,6 +15,8 @@ namespace dxbc { using namespace object; size_t DXContainerWriter::finalize() { + assert(Offsets.empty() && + "Attempted to finalize writer with already computed offsets"); Offsets.reserve(Obj.Parts.size()); size_t Offset = Obj.headerSize(); for (const Part &P : Obj.Parts) { From b4c17fb824e1d8f508c6ea33852092777e96f800 Mon Sep 17 00:00:00 2001 From: Finn Plummer Date: Mon, 18 Aug 2025 14:59:25 -0700 Subject: [PATCH 17/17] review: add comment --- llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h index 1ce4f2bb370eb..953e0d7189708 100644 --- a/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h +++ b/llvm/include/llvm/ObjCopy/DXContainer/DXContainerConfig.h @@ -12,7 +12,9 @@ namespace llvm { namespace objcopy { -// DXContainer specific configuration for copying/stripping a single file. +// DXContainer specific configuration for copying/stripping a single file. This +// is defined, following convention elsewhere, as the return type of +// `getDXContainerConfig`, which reports an error for an unsupported option. struct DXContainerConfig {}; } // namespace objcopy