[llvm] [Offloading] Extend OffloadBinary format to support multiple metadata entries (PR #169425)

Yury Plyakhin via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 25 12:04:54 PST 2025


https://github.com/YuriPlyakhin updated https://github.com/llvm/llvm-project/pull/169425

>From ce7ab7652cf29469a8addea8ebe67f408b4b03af Mon Sep 17 00:00:00 2001
From: "Plyakhin, Yury" <yury.plyakhin at intel.com>
Date: Tue, 25 Nov 2025 00:40:45 +0100
Subject: [PATCH 1/2] [Offloading] Extend OffloadBinary format to support
 multiple metadata entries

---
 llvm/include/llvm/Object/OffloadBinary.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h
index f3847c1624977..cf25c02bc43fd 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -67,7 +67,7 @@ class OffloadBinary : public Binary {
   using string_iterator_range = iterator_range<string_iterator>;
 
   /// The current version of the binary used for backwards compatibility.
-  static const uint32_t Version = 1;
+  static const uint32_t Version = 2;
 
   /// The offloading metadata that will be serialized to a memory buffer.
   struct OffloadingImage {
@@ -109,9 +109,12 @@ class OffloadBinary : public Binary {
   struct Header {
     uint8_t Magic[4] = {0x10, 0xFF, 0x10, 0xAD}; // 0x10FF10AD magic bytes.
     uint32_t Version = OffloadBinary::Version;   // Version identifier.
-    uint64_t Size;        // Size in bytes of this entire binary.
-    uint64_t EntryOffset; // Offset of the metadata entry in bytes.
-    uint64_t EntrySize;   // Size of the metadata entry in bytes.
+    uint64_t Size;          // Size in bytes of this entire binary.
+    uint64_t EntriesCount;  // Number of metadata entries in the binary.
+    uint64_t EntriesOffset; // Offset in bytes to the start of entries block.
+    uint64_t EntriesSize;   // Size of the entries block in bytes.
+    uint64_t StringOffset;  // Offset in bytes to the global string map
+    uint64_t NumStrings;    // Number of entries in the global string map.
   };
 
   struct Entry {
@@ -127,6 +130,7 @@ class OffloadBinary : public Binary {
   struct StringEntry {
     uint64_t KeyOffset;
     uint64_t ValueOffset;
+    uint64_t ValueSize;   // Size of the value in bytes.
   };
 
 private:

>From f66ae8cca8d7678ba900c15eef1fa5fdb83a70dc Mon Sep 17 00:00:00 2001
From: "Plyakhin, Yury" <yury.plyakhin at intel.com>
Date: Tue, 25 Nov 2025 21:04:43 +0100
Subject: [PATCH 2/2] updated offloadbinary per discussion

---
 llvm/include/llvm/Object/OffloadBinary.h | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/Object/OffloadBinary.h b/llvm/include/llvm/Object/OffloadBinary.h
index cf25c02bc43fd..bdcacce204966 100644
--- a/llvm/include/llvm/Object/OffloadBinary.h
+++ b/llvm/include/llvm/Object/OffloadBinary.h
@@ -52,6 +52,13 @@ enum ImageKind : uint16_t {
   IMG_LAST,
 };
 
+/// Flags associated with the Entry.
+enum OffloadEntryFlags : uint32_t {
+  OIF_None = 0,
+  // Entry doesn't contain image. Used to keep metadata only entries.
+  OIF_NoImage = (1 << 0),
+};
+
 /// A simple binary serialization of an offloading file. We use this format to
 /// embed the offloading image into the host executable so it can be extracted
 /// and used by the linker.
@@ -110,17 +117,14 @@ class OffloadBinary : public Binary {
     uint8_t Magic[4] = {0x10, 0xFF, 0x10, 0xAD}; // 0x10FF10AD magic bytes.
     uint32_t Version = OffloadBinary::Version;   // Version identifier.
     uint64_t Size;          // Size in bytes of this entire binary.
-    uint64_t EntriesCount;  // Number of metadata entries in the binary.
     uint64_t EntriesOffset; // Offset in bytes to the start of entries block.
-    uint64_t EntriesSize;   // Size of the entries block in bytes.
-    uint64_t StringOffset;  // Offset in bytes to the global string map
-    uint64_t NumStrings;    // Number of entries in the global string map.
+    uint64_t EntriesCount;  // Number of metadata entries in the binary.
   };
 
   struct Entry {
     ImageKind TheImageKind;     // The kind of the image stored.
     OffloadKind TheOffloadKind; // The producer of this image.
-    uint32_t Flags;             // Additional flags associated with the image.
+    uint32_t Flags;             // Additional flags associated with the entry.
     uint64_t StringOffset;      // Offset in bytes to the string map.
     uint64_t NumStrings;        // Number of entries in the string map.
     uint64_t ImageOffset;       // Offset in bytes of the actual binary image.



More information about the llvm-commits mailing list