[llvm] [Object] Fix offload bundle decompression on big endian (PR #205822)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 07:17:25 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/205822

tools/llvm-objdump/Offloading/fatbin-coff-compress.test was crashing on s390x because the header fields read from the object were misinterpreted as big-endian. Fix this by using ulittleN_t types.

>From d6c1160e06708ce5b915e5e4b0d5695e0467d929 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 25 Jun 2026 16:12:05 +0200
Subject: [PATCH] [Object] Fix offload bundle decompression on big endian

tools/llvm-objdump/Offloading/fatbin-coff-compress.test was
crashing on s390x because the header fields read from the object
were misinterpreted as big-endian. Fix this by using ulittleN_t types.
---
 llvm/lib/Object/OffloadBundle.cpp | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/llvm/lib/Object/OffloadBundle.cpp b/llvm/lib/Object/OffloadBundle.cpp
index 93fb2ab1affc7..edd017b99331a 100644
--- a/llvm/lib/Object/OffloadBundle.cpp
+++ b/llvm/lib/Object/OffloadBundle.cpp
@@ -432,29 +432,29 @@ CompressedOffloadBundle::compress(compression::Params P,
 LLVM_PACKED_START
 union RawCompressedBundleHeader {
   struct CommonFields {
-    uint32_t Magic;
-    uint16_t Version;
-    uint16_t Method;
+    support::ulittle32_t Magic;
+    support::ulittle16_t Version;
+    support::ulittle16_t Method;
   };
 
   struct V1Header {
     CommonFields Common;
-    uint32_t UncompressedFileSize;
-    uint64_t Hash;
+    support::ulittle32_t UncompressedFileSize;
+    support::ulittle64_t Hash;
   };
 
   struct V2Header {
     CommonFields Common;
-    uint32_t FileSize;
-    uint32_t UncompressedFileSize;
-    uint64_t Hash;
+    support::ulittle32_t FileSize;
+    support::ulittle32_t UncompressedFileSize;
+    support::ulittle64_t Hash;
   };
 
   struct V3Header {
     CommonFields Common;
-    uint64_t FileSize;
-    uint64_t UncompressedFileSize;
-    uint64_t Hash;
+    support::ulittle64_t FileSize;
+    support::ulittle64_t UncompressedFileSize;
+    support::ulittle64_t Hash;
   };
 
   CommonFields Common;
@@ -518,7 +518,7 @@ CompressedOffloadBundle::CompressedBundleHeader::tryParse(StringRef Blob) {
   case static_cast<uint16_t>(compression::Format::Zlib):
   case static_cast<uint16_t>(compression::Format::Zstd):
     Normalized.CompressionFormat =
-        static_cast<compression::Format>(Header.Common.Method);
+        static_cast<compression::Format>(Header.Common.Method.value());
     break;
   default:
     return createStringError("unknown compressing method");



More information about the llvm-commits mailing list