[llvm] 966c40a - [Object][DX] Identify DXBC file magic
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Mon May 2 14:47:39 PDT 2022
Author: Chris Bieneman
Date: 2022-05-02T16:24:36-05:00
New Revision: 966c40aea663fa2cb575614518fc1b7c528bbae9
URL: https://github.com/llvm/llvm-project/commit/966c40aea663fa2cb575614518fc1b7c528bbae9
DIFF: https://github.com/llvm/llvm-project/commit/966c40aea663fa2cb575614518fc1b7c528bbae9.diff
LOG: [Object][DX] Identify DXBC file magic
This adds support to llvm::identify_magic to detect DXBC and classify
it as the dxcontainer format.
Added:
Modified:
llvm/include/llvm/BinaryFormat/Magic.h
llvm/lib/BinaryFormat/Magic.cpp
llvm/unittests/Object/DXContainerTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/BinaryFormat/Magic.h b/llvm/include/llvm/BinaryFormat/Magic.h
index e91f0fdcc8cd8..b6bc4e9b2a7a3 100644
--- a/llvm/include/llvm/BinaryFormat/Magic.h
+++ b/llvm/include/llvm/BinaryFormat/Magic.h
@@ -52,6 +52,7 @@ struct file_magic {
pdb, ///< Windows PDB debug info file
tapi_file, ///< Text-based Dynamic Library Stub file
cuda_fatbinary, ///< CUDA Fatbinary object file
+ dxcontainer_object, ///< DirectX container file
};
bool is_object() const { return V != unknown; }
diff --git a/llvm/lib/BinaryFormat/Magic.cpp b/llvm/lib/BinaryFormat/Magic.cpp
index 5d999a907fd2b..d48adb1121fee 100644
--- a/llvm/lib/BinaryFormat/Magic.cpp
+++ b/llvm/lib/BinaryFormat/Magic.cpp
@@ -225,6 +225,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
if (startswith(Magic, "--- !tapi") || startswith(Magic, "---\narchs:"))
return file_magic::tapi_file;
break;
+
+ case 'D': // DirectX container file - DXBC
+ if (startswith(Magic, "DXBC") && Magic.size() == 4)
+ return file_magic::dxcontainer_object;
+ break;
default:
break;
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 06d006506c63d..95bafe8da894b 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -21,6 +21,11 @@ template <std::size_t X> MemoryBufferRef getMemoryBuffer(uint8_t Data[X]) {
return MemoryBufferRef(Obj, "");
}
+TEST(DXCFile, IdentifyMagic) {
+ StringRef Buffer("DXBC");
+ EXPECT_EQ(identify_magic(Buffer), file_magic::dxcontainer_object);
+}
+
TEST(DXCFile, ParseHeaderErrors) {
uint8_t Buffer[] = {0x44, 0x58, 0x42, 0x43};
EXPECT_THAT_EXPECTED(
More information about the llvm-commits
mailing list