LoongArch: Fix disassembly on big-endian hosts
Corrects LoongArch instruction decoding on big-endian systems.
The LoongArch disassembler incorrectly read 4-byte instruction words directly into a uint32_t on big-endian hosts. This resulted in byte-swapped instructions, causing all subsequent decoding to fail. The fix reads the instruction into a byte buffer and uses bfd_getl32 to ensure it’s interpreted in little-endian order, regardless of the host’s endianness, resolving test failures observed on s390x.
In Details
The print_insn_loongarch function directly read a 4-byte instruction into an insn_t (assumed uint32_t). On big-endian hosts, this performed an implicit byte swap. The fix introduces a bfd_byte buffer and uses bfd_getl32() to read the instruction, ensuring correct interpretation regardless of host endianness. This resolves binutils, gas, and ld test failures on big-endian platforms like s390x.
- LoongArch
- A RISC-ISA (Reduced Instruction Set Computer Instruction Set Architecture) developed in China, used in servers, desktops, and embedded systems.
- big-endian
- A computer architecture where the most significant byte of a multi-byte word is stored at the lowest memory address. This is in contrast to little-endian.
- disassembler
- A program that translates machine code (binary instructions) back into human-readable assembly language.
- bfd_getl32
- A function from the BFD library that reads a 32-bit value from memory, interpreting it as little-endian, irrespective of the host system's endianness.