aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2023-12-13 20:39:50 -0600
committerGitHub <noreply@github.com>2023-12-13 20:39:50 -0600
commitedc83886d479e110c87d104e7241ce67ee1b6316 (patch)
treece15637d5de410009c79867441d3c1c8b86d50d3 /llvm/lib/Object
parent1f3d13c415a2a92e5a3811740ed55c4bcff3f539 (diff)
downloadllvm-edc83886d479e110c87d104e7241ce67ee1b6316.zip
llvm-edc83886d479e110c87d104e7241ce67ee1b6316.tar.gz
llvm-edc83886d479e110c87d104e7241ce67ee1b6316.tar.bz2
[LLVM] Add file magic detection for SPIR-V files. (#75363)
Summary: More SPIR-V related patches are being upstreamed. We should add support to detect when a binary file is SPIR-V. This will be used in the future when support for SPIR-V is added to the offloading runtime or more support for bundling. The magic number is described in the official documentation: https://registry.khronos.org/SPIR-V/specs/1.0/SPIRV.html#Magic. Notably, SPIR-V files are streams of 32-bit words. This means that the magic numbers differ depending on the endianness. Here we simply check the strandard and byte-reversed versions.
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r--llvm/lib/Object/Binary.cpp1
-rw-r--r--llvm/lib/Object/ObjectFile.cpp1
2 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp
index 0ee9f7f..0b9d954 100644
--- a/llvm/lib/Object/Binary.cpp
+++ b/llvm/lib/Object/Binary.cpp
@@ -89,6 +89,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
case file_magic::dxcontainer_object:
case file_magic::offload_bundle:
case file_magic::offload_bundle_compressed:
+ case file_magic::spirv_object:
// Unrecognized object file format.
return errorCodeToError(object_error::invalid_file_type);
case file_magic::offload_binary:
diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp
index 428166f..ca92183 100644
--- a/llvm/lib/Object/ObjectFile.cpp
+++ b/llvm/lib/Object/ObjectFile.cpp
@@ -160,6 +160,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type,
case file_magic::dxcontainer_object:
case file_magic::offload_bundle:
case file_magic::offload_bundle_compressed:
+ case file_magic::spirv_object:
return errorCodeToError(object_error::invalid_file_type);
case file_magic::tapi_file:
return errorCodeToError(object_error::invalid_file_type);