aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2025-11-11 19:44:20 -0600
committerGitHub <noreply@github.com>2025-11-11 19:44:20 -0600
commit6655681cd0554f8df91bb0f7631b882f5bb13b81 (patch)
treea22a816b9648f09a7c6ac88961e2b915453ae781 /llvm/lib
parentea10026b64f66b3b69c0545db20f9daa8579f5cb (diff)
downloadllvm-6655681cd0554f8df91bb0f7631b882f5bb13b81.zip
llvm-6655681cd0554f8df91bb0f7631b882f5bb13b81.tar.gz
llvm-6655681cd0554f8df91bb0f7631b882f5bb13b81.tar.bz2
[llvm-offload-wrapper] Fix Triple and OpenMP handling (#167580)
Summary: The OpenMP handling using an offload binary should be optional, it's only used for extra metadata for llvm-objdump. Also the triple was completely wrong, it didn't let anyone correctly choose between ELF and COFF handling.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Frontend/Offloading/OffloadWrapper.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
index 45818de..86060d1 100644
--- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
+++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
@@ -147,21 +147,27 @@ GlobalVariable *createBinDesc(Module &M, ArrayRef<ArrayRef<char>> Bufs,
Image->setAlignment(Align(object::OffloadBinary::getAlignment()));
StringRef Binary(Buf.data(), Buf.size());
- assert(identify_magic(Binary) == file_magic::offload_binary &&
- "Invalid binary format");
+ uint64_t BeginOffset = 0;
+ uint64_t EndOffset = Binary.size();
+
+ // Optionally use an offload binary for its offload dumping support.
// The device image struct contains the pointer to the beginning and end of
// the image stored inside of the offload binary. There should only be one
// of these for each buffer so we parse it out manually.
- const auto *Header =
- reinterpret_cast<const object::OffloadBinary::Header *>(
- Binary.bytes_begin());
- const auto *Entry = reinterpret_cast<const object::OffloadBinary::Entry *>(
- Binary.bytes_begin() + Header->EntryOffset);
-
- auto *Begin = ConstantInt::get(getSizeTTy(M), Entry->ImageOffset);
- auto *Size =
- ConstantInt::get(getSizeTTy(M), Entry->ImageOffset + Entry->ImageSize);
+ if (identify_magic(Binary) == file_magic::offload_binary) {
+ const auto *Header =
+ reinterpret_cast<const object::OffloadBinary::Header *>(
+ Binary.bytes_begin());
+ const auto *Entry =
+ reinterpret_cast<const object::OffloadBinary::Entry *>(
+ Binary.bytes_begin() + Header->EntryOffset);
+ BeginOffset = Entry->ImageOffset;
+ EndOffset = Entry->ImageOffset + Entry->ImageSize;
+ }
+
+ auto *Begin = ConstantInt::get(getSizeTTy(M), BeginOffset);
+ auto *Size = ConstantInt::get(getSizeTTy(M), EndOffset);
Constant *ZeroBegin[] = {Zero, Begin};
Constant *ZeroSize[] = {Zero, Size};