diff options
author | Michael Kruse <llvm-project@meinersbur.de> | 2022-05-06 02:43:49 -0500 |
---|---|---|
committer | Michael Kruse <llvm-project@meinersbur.de> | 2022-05-06 02:43:49 -0500 |
commit | d3460d2a890ccb4ee84ffd05d4a722ff82b5170d (patch) | |
tree | 19c511c63d14da385bc907b4aa99276b8636dc1a /llvm/lib/Object | |
parent | fdb6ddcfeb62be7dbc502a4a4ed7c5be11c1c9b6 (diff) | |
parent | 9c1085c7e20bdd7c4a487f50313ebeeb2b6683b8 (diff) | |
download | llvm-users/meinersbur/irbuilder-ompregion.zip llvm-users/meinersbur/irbuilder-ompregion.tar.gz llvm-users/meinersbur/irbuilder-ompregion.tar.bz2 |
Merge branch 'main' into irbuilder-ompregionusers/meinersbur/irbuilder-ompregion
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/Binary.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/Object/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Object/DXContainer.cpp | 44 | ||||
-rw-r--r-- | llvm/lib/Object/ObjectFile.cpp | 1 |
4 files changed, 47 insertions, 0 deletions
diff --git a/llvm/lib/Object/Binary.cpp b/llvm/lib/Object/Binary.cpp index 67ed44a..1703f76 100644 --- a/llvm/lib/Object/Binary.cpp +++ b/llvm/lib/Object/Binary.cpp @@ -84,6 +84,7 @@ Expected<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer, case file_magic::unknown: case file_magic::cuda_fatbinary: case file_magic::coff_cl_gl_object: + case file_magic::dxcontainer_object: // Unrecognized object file format. return errorCodeToError(object_error::invalid_file_type); case file_magic::minidump: diff --git a/llvm/lib/Object/CMakeLists.txt b/llvm/lib/Object/CMakeLists.txt index 0825210..ba612e3 100644 --- a/llvm/lib/Object/CMakeLists.txt +++ b/llvm/lib/Object/CMakeLists.txt @@ -6,6 +6,7 @@ add_llvm_component_library(LLVMObject COFFModuleDefinition.cpp COFFObjectFile.cpp Decompressor.cpp + DXContainer.cpp ELF.cpp ELFObjectFile.cpp Error.cpp diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp new file mode 100644 index 0000000..e1aea562 --- /dev/null +++ b/llvm/lib/Object/DXContainer.cpp @@ -0,0 +1,44 @@ +//===- DXContainer.cpp - DXContainer object file implementation -----------===// +// +// 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/Object/DXContainer.h" +#include "llvm/BinaryFormat/DXContainer.h" +#include "llvm/Object/Error.h" + +using namespace llvm; +using namespace llvm::object; + +static Error parseFailed(const Twine &Msg) { + return make_error<GenericBinaryError>(Msg.str(), object_error::parse_failed); +} + +template <typename T> +static Error readStruct(StringRef Buffer, const char *P, T &Struct) { + // Don't read before the beginning or past the end of the file + if (P < Buffer.begin() || P + sizeof(T) > Buffer.end()) + return parseFailed("Reading structure out of file bounds"); + + memcpy(&Struct, P, sizeof(T)); + // DXContainer is always BigEndian + if (sys::IsBigEndianHost) + Struct.byteSwap(); + return Error::success(); +} + +DXContainer::DXContainer(MemoryBufferRef O) : Data(O) {} + +Error DXContainer::parseHeader() { + return readStruct(Data.getBuffer(), Data.getBuffer().data(), Header); +} + +Expected<DXContainer> DXContainer::create(MemoryBufferRef Object) { + DXContainer Container(Object); + if (Error Err = Container.parseHeader()) + return std::move(Err); + return Container; +} diff --git a/llvm/lib/Object/ObjectFile.cpp b/llvm/lib/Object/ObjectFile.cpp index fed6726..609dfae 100644 --- a/llvm/lib/Object/ObjectFile.cpp +++ b/llvm/lib/Object/ObjectFile.cpp @@ -147,6 +147,7 @@ ObjectFile::createObjectFile(MemoryBufferRef Object, file_magic Type, case file_magic::minidump: case file_magic::goff_object: case file_magic::cuda_fatbinary: + case file_magic::dxcontainer_object: return errorCodeToError(object_error::invalid_file_type); case file_magic::tapi_file: return errorCodeToError(object_error::invalid_file_type); |