diff --git a/devel/spirv-llvm-translator/files.llvm12/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm12/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..1cb047892798 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm12/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:46:07 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2112,8 +2112,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- auto Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm12/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm12/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..b59f934d58c1 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm12/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:46:07 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -97,10 +97,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -185,6 +195,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm13/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm13/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..bde4136fb858 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm13/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:46:59 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2131,8 +2131,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- auto Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm13/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm13/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..350661393ead --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm13/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:46:59 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -97,10 +97,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -185,6 +195,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm14/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm14/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..d2e0457e68d0 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm14/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:47:51 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2313,8 +2313,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- auto Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm14/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm14/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..0105a50a0bc6 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm14/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:47:51 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm15/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm15/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..56342ec5b7bf --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm15/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:48:43 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2487,8 +2487,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- auto Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm15/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm15/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..810564cb9449 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm15/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:48:43 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm16/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm16/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..4724c61b36cb --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm16/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:49:59 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2487,8 +2487,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- auto Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm16/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm16/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..f2e96147d3f9 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm16/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:49:59 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm17/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm17/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..2746df544dff --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm17/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:52:28 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2483,8 +2483,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- auto Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm17/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm17/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..013056110381 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm17/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:52:28 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm18/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm18/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..afd3231f2fc8 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm18/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,13 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:53:20 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2474,8 +2474,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- const auto *Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm18/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm18/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..951f07b93944 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm18/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:53:20 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm19/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm19/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..adcccd88b6ec --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm19/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,33 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:42:18 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2544,7 +2544,8 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + MI.setAutoAddExtensions(false); + + SPIRVWord Header[5] = {0}; +- I.read(reinterpret_cast(&Header), sizeof(Header)); ++ for (auto &H : Header) ++ H = readSPIRVWord(I); + + SPIRVErrorLog &ErrorLog = MI.getErrorLog(); + if (!ErrorLog.checkError(!I.eof(), SPIRVEC_InvalidModule, +@@ -2581,8 +2582,7 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + + SPIRVEntry *Scope = nullptr; + while (true) { +- SPIRVWord WordCountAndOpCode = 0; +- I.read(reinterpret_cast(&WordCountAndOpCode), sizeof(SPIRVWord)); ++ SPIRVWord WordCountAndOpCode = readSPIRVWord(I); + SPIRVDBG(spvdbgs() << "Read word: W = " << WordCountAndOpCode + << " V = 0\n"); + SPIRVWord WordCount = WordCountAndOpCode >> 16; +@@ -2705,8 +2705,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- const auto *Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm19/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm19/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..00485a529f42 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm19/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:42:18 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm20/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm20/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..0c7eab2f5aac --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm20/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,33 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:54:13 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2584,7 +2584,8 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + MI.setAutoAddExtensions(false); + + SPIRVWord Header[5] = {0}; +- I.read(reinterpret_cast(&Header), sizeof(Header)); ++ for (auto &H : Header) ++ H = readSPIRVWord(I); + + SPIRVErrorLog &ErrorLog = MI.getErrorLog(); + if (!ErrorLog.checkError(!I.eof(), SPIRVEC_InvalidModule, +@@ -2621,8 +2622,7 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + + SPIRVEntry *Scope = nullptr; + while (true) { +- SPIRVWord WordCountAndOpCode = 0; +- I.read(reinterpret_cast(&WordCountAndOpCode), sizeof(SPIRVWord)); ++ SPIRVWord WordCountAndOpCode = readSPIRVWord(I); + SPIRVDBG(spvdbgs() << "Read word: W = " << WordCountAndOpCode + << " V = 0\n"); + SPIRVWord WordCount = WordCountAndOpCode >> 16; +@@ -2745,8 +2745,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- const auto *Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm20/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm20/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..1b27426f8574 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm20/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:54:13 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm21/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm21/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..524dc16c9ff6 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm21/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,33 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:55:06 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2583,7 +2583,8 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + MI.setAutoAddExtensions(false); + + SPIRVWord Header[5] = {0}; +- I.read(reinterpret_cast(&Header), sizeof(Header)); ++ for (auto &H : Header) ++ H = readSPIRVWord(I); + + SPIRVErrorLog &ErrorLog = MI.getErrorLog(); + if (!ErrorLog.checkError(!I.eof(), SPIRVEC_InvalidModule, +@@ -2620,8 +2621,7 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + + SPIRVEntry *Scope = nullptr; + while (true) { +- SPIRVWord WordCountAndOpCode = 0; +- I.read(reinterpret_cast(&WordCountAndOpCode), sizeof(SPIRVWord)); ++ SPIRVWord WordCountAndOpCode = readSPIRVWord(I); + SPIRVDBG(spvdbgs() << "Read word: W = " << WordCountAndOpCode + << " V = 0\n"); + SPIRVWord WordCount = WordCountAndOpCode >> 16; +@@ -2744,8 +2744,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- const auto *Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm21/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm21/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..145e958fd0db --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm21/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:55:06 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/devel/spirv-llvm-translator/files.llvm22/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp b/devel/spirv-llvm-translator/files.llvm22/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp new file mode 100644 index 000000000000..af6a04e1a865 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm22/patch-lib_SPIRV_libSPIRV_SPIRVModule.cpp @@ -0,0 +1,33 @@ +--- lib/SPIRV/libSPIRV/SPIRVModule.cpp.orig 2026-09-02 08:55:58 UTC ++++ lib/SPIRV/libSPIRV/SPIRVModule.cpp +@@ -2623,7 +2623,8 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + MI.setAutoAddExtensions(false); + + SPIRVWord Header[5] = {0}; +- I.read(reinterpret_cast(&Header), sizeof(Header)); ++ for (auto &H : Header) ++ H = readSPIRVWord(I); + + SPIRVErrorLog &ErrorLog = MI.getErrorLog(); + if (!ErrorLog.checkError(!I.eof(), SPIRVEC_InvalidModule, +@@ -2660,8 +2661,7 @@ std::istream &SPIRVModuleImpl::parseSPIRV(std::istream + + SPIRVEntry *Scope = nullptr; + while (true) { +- SPIRVWord WordCountAndOpCode = 0; +- I.read(reinterpret_cast(&WordCountAndOpCode), sizeof(SPIRVWord)); ++ SPIRVWord WordCountAndOpCode = readSPIRVWord(I); + SPIRVDBG(spvdbgs() << "Read word: W = " << WordCountAndOpCode + << " V = 0\n"); + SPIRVWord WordCount = WordCountAndOpCode >> 16; +@@ -2784,8 +2784,8 @@ bool isSpirvBinary(const std::string &Img) { + bool isSpirvBinary(const std::string &Img) { + if (Img.size() < sizeof(unsigned)) + return false; +- const auto *Magic = reinterpret_cast(Img.data()); +- return *Magic == MagicNumber; ++ std::istringstream IS(Img); ++ return readSPIRVWord(IS) == MagicNumber; + } + + #ifdef _SPIRV_SUPPORT_TEXT_FMT diff --git a/devel/spirv-llvm-translator/files.llvm22/patch-lib_SPIRV_libSPIRV_SPIRVStream.h b/devel/spirv-llvm-translator/files.llvm22/patch-lib_SPIRV_libSPIRV_SPIRVStream.h new file mode 100644 index 000000000000..310ca8092630 --- /dev/null +++ b/devel/spirv-llvm-translator/files.llvm22/patch-lib_SPIRV_libSPIRV_SPIRVStream.h @@ -0,0 +1,36 @@ +--- lib/SPIRV/libSPIRV/SPIRVStream.h.orig 2026-09-02 08:55:58 UTC ++++ lib/SPIRV/libSPIRV/SPIRVStream.h +@@ -98,10 +98,20 @@ class SPIRVNL { + friend spv_ostream &operator<<(spv_ostream &O, const SPIRVNL &E); + }; + ++/// Read a single SPIR-V word from a binary stream, byte-swapping from ++/// little-endian on big-endian hosts. ++inline uint32_t readSPIRVWord(std::istream &IS) { ++ uint32_t W; ++ IS.read(reinterpret_cast(&W), sizeof(W)); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ W = __builtin_bswap32(W); ++#endif ++ return W; ++} ++ + template + const SPIRVDecoder &decodeBinary(const SPIRVDecoder &I, T &V) { +- uint32_t W; +- I.IS.read(reinterpret_cast(&W), sizeof(W)); ++ uint32_t W = readSPIRVWord(I.IS); + V = static_cast(W); + SPIRVDBG(spvdbgs() << "Read word: W = " << W << " V = " << V << '\n'); + return I; +@@ -186,6 +196,10 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, + } + #endif + uint32_t W = static_cast(V); ++#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ ++ // SPIR-V binary format is little-endian; byte-swap on big-endian hosts. ++ W = __builtin_bswap32(W); ++#endif + O.OS.write(reinterpret_cast(&W), sizeof(W)); + return O; + } diff --git a/graphics/spirv-tools/files/patch-source_binary.cpp b/graphics/spirv-tools/files/patch-source_binary.cpp new file mode 100644 index 000000000000..3c52f8fb80e1 --- /dev/null +++ b/graphics/spirv-tools/files/patch-source_binary.cpp @@ -0,0 +1,69 @@ +--- source/binary.cpp.orig 2026-07-08 19:46:47 UTC ++++ source/binary.cpp +@@ -181,7 +181,7 @@ class Parser { + // Returns the endian-corrected word at the given position. + uint32_t peekAt(size_t index) const { + assert(index < _.num_words); +- return spvFixWord(_.words[index], _.endian); ++ return _.native_words[index]; + } + + // Data members +@@ -230,6 +230,7 @@ class Parser { + // Is the SPIR-V binary in a different endianness from the host native + // endianness? + bool requires_endian_conversion; ++ std::unique_ptr native_words; + // Set by parseOperand when LookupOperand fails for an enum operand and + // handle_unknown_opcodes_ is set. Signals parseInstruction to discard + // the partially-decoded instruction and re-emit it as raw OpUnknown data. +@@ -279,6 +280,9 @@ spv_result_t Parser::parseModule() { + << _.words[0] << "'."; + } + _.requires_endian_conversion = !spvIsHostEndian(_.endian); ++ _.native_words = std::make_unique(_.num_words); ++ for (size_t i = 0; i < _.num_words; i++) ++ _.native_words[i] = _.requires_endian_conversion ? spvFixWord(_.words[i], _.endian) : _.words[i]; + + // Process the header. + spv_header_t header; +@@ -495,10 +499,6 @@ spv_result_t Parser::parseOperand(size_t inst_offset, + + const uint32_t word = peek(); + +- // Do the words in this operand have to be converted to native endianness? +- // True for all but literal strings. +- bool convert_operand_endianness = true; +- + switch (type) { + case SPV_OPERAND_TYPE_TYPE_ID: + if (!word) +@@ -664,7 +664,7 @@ spv_result_t Parser::parseOperand(size_t inst_offset, + case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING: { + const size_t max_words = _.num_words - _.word_index; + std::string string = +- spvtools::utils::MakeString(_.words + _.word_index, max_words, false); ++ spvtools::utils::MakeString(_.native_words.get() + _.word_index, max_words, false); + + if (string.length() == max_words * 4) + return exhaustedInputDiagnostic(inst_offset, opcode, type); +@@ -870,17 +870,8 @@ spv_result_t Parser::parseOperand(size_t inst_offset, + + if (_.requires_endian_conversion) { + // Copy instruction words. Translate to native endianness as needed. +- if (convert_operand_endianness) { +- const spv_endianness_t endianness = _.endian; +- std::transform(_.words + _.word_index, _.words + index_after_operand, +- std::back_inserter(*words), +- [endianness](const uint32_t raw_word) { +- return spvFixWord(raw_word, endianness); +- }); +- } else { +- words->insert(words->end(), _.words + _.word_index, +- _.words + index_after_operand); +- } ++ words->insert(words->end(), _.native_words.get() + _.word_index, ++ _.native_words.get() + index_after_operand); + } + + // Advance past the operand. diff --git a/graphics/spirv-tools/files/patch-tools_objdump_extract__source.cpp b/graphics/spirv-tools/files/patch-tools_objdump_extract__source.cpp new file mode 100644 index 000000000000..3133faf18832 --- /dev/null +++ b/graphics/spirv-tools/files/patch-tools_objdump_extract__source.cpp @@ -0,0 +1,93 @@ +--- tools/objdump/extract_source.cpp.orig 2026-07-08 19:46:47 UTC ++++ tools/objdump/extract_source.cpp +@@ -23,45 +23,12 @@ + #include "source/opt/log.h" + #include "spirv-tools/libspirv.hpp" + #include "tools/util/cli_consumer.h" ++#include "source/binary.h" + + namespace { + + constexpr auto kDefaultEnvironment = SPV_ENV_UNIVERSAL_1_6; + +-// Extract a string literal from a given range. +-// Copies all the characters from `begin` to the first '\0' it encounters, while +-// removing escape patterns. +-// Not finding a '\0' before reaching `end` fails the extraction. +-// +-// Returns `true` if the extraction succeeded. +-// `output` value is undefined if false is returned. +-spv_result_t ExtractStringLiteral(const spv_position_t& loc, const char* begin, +- const char* end, std::string* output) { +- size_t sourceLength = std::distance(begin, end); +- std::string escapedString; +- escapedString.resize(sourceLength); +- +- size_t writeIndex = 0; +- size_t readIndex = 0; +- for (; readIndex < sourceLength; writeIndex++, readIndex++) { +- const char read = begin[readIndex]; +- if (read == '\0') { +- escapedString.resize(writeIndex); +- output->append(escapedString); +- return SPV_SUCCESS; +- } +- +- if (read == '\\') { +- ++readIndex; +- } +- escapedString[writeIndex] = begin[readIndex]; +- } +- +- spvtools::Error(spvtools::utils::CLIMessageConsumer, "", loc, +- "Missing NULL terminator for literal string."); +- return SPV_ERROR_INVALID_BINARY; +-} +- + spv_result_t extractOpString(const spv_position_t& loc, + const spv_parsed_instruction_t& instruction, + std::string* output) { +@@ -73,12 +40,8 @@ spv_result_t extractOpString(const spv_position_t& loc + return SPV_ERROR_INVALID_BINARY; + } + +- const auto& operand = instruction.operands[1]; +- const char* stringBegin = +- reinterpret_cast(instruction.words + operand.offset); +- const char* stringEnd = reinterpret_cast( +- instruction.words + operand.offset + operand.num_words); +- return ExtractStringLiteral(loc, stringBegin, stringEnd, output); ++ *output = spvDecodeLiteralStringOperand(instruction, 1); ++ return SPV_SUCCESS; + } + + spv_result_t extractOpSourceContinued( +@@ -93,12 +56,8 @@ spv_result_t extractOpSourceContinued( + return SPV_ERROR_INVALID_BINARY; + } + +- const auto& operand = instruction.operands[0]; +- const char* stringBegin = +- reinterpret_cast(instruction.words + operand.offset); +- const char* stringEnd = reinterpret_cast( +- instruction.words + operand.offset + operand.num_words); +- return ExtractStringLiteral(loc, stringBegin, stringEnd, output); ++ *output = *output + spvDecodeLiteralStringOperand(instruction, 0); ++ return SPV_SUCCESS; + } + + spv_result_t extractOpSource(const spv_position_t& loc, +@@ -124,11 +83,8 @@ spv_result_t extractOpSource(const spv_position_t& loc + return SPV_SUCCESS; + } + +- const char* stringBegin = +- reinterpret_cast(instruction.words + 4); +- const char* stringEnd = +- reinterpret_cast(instruction.words + instruction.num_words); +- return ExtractStringLiteral(loc, stringBegin, stringEnd, code); ++ *code = spvDecodeLiteralStringOperand(instruction, 3); ++ return SPV_SUCCESS; + } + + } // namespace