|
From: Pranav P <pra...@ib...> - 2026-08-11 09:37:22
|
Hi Christian and the LinuxSampler team, I have put together a patch to port libgig to big-endian architectures (testing happend on s390x). This was based on the bug report in Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1116657 While the existing code works well on little-endian systems (like x86_64), it contained several assumptions that caused data corruption, CRC mismatches, and crashes (due to unaligned memory access) on big-endian systems. Changes made in this patch: 1. RIFF.cpp (Chunk Size IO): Fixed read() and write() calls that were attempting to read/write 4 bytes directly into a 64-bit uint64_t variable. This caused silent memory corruption on big-endian systems. The patch uses a 32-bit temp variable to handle this safely. 2. RIFF.cpp (Buffer Restoration): Added logic to revertpData to its native endianness after writing, as the write operation modifies the buffer in place for byte-swapping. 3. gig.cpp (CRC Calculation): The CRC must be calculated on the serialized little-endian byte stream (as it exists on disk). On big-endian systems, the code now creates a temporary little-endian buffer to calculate the CRC correctly, ensuring checksums match across architectures. 4. gig.cpp (Memory Alignment & Aliasing): Replaced raw uint32_t* pointer arithmetic with uint8_t* combined with load32/store32. This prevents unaligned memory access faults and ensures correct little-endian parsing of chunk data. The patch applies cleanly to SVN revision 4650. Please find the patch attached to this email. The code was tested in both x86 and s390x. Testing involved: Running test cases on both architectures, generating files .riff and .gig files on s390x and reading them from an x86 machine and generating .riff and .gig files on x86 and reading them from an s390x. Let me know if you need any modifications, have questions about the approach, or need further testing on other architectures. Best regards, Pranav |