From acef0da910ca9ce3e15b5dd92306f200e38a41c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 6 Oct 2025 17:36:31 +0200 Subject: [PATCH] linux-user/microblaze: Fix little-endianness binary MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit MicroBlaze CPU model has a "little-endian" property, pointing to the @endi internal field. Commit c36ec3a9655 ("hw/microblaze: Explicit CPU endianness") took care of having all MicroBlaze boards with an explicit default endianness, so later commit 415aae543ed ("target/microblaze: Consider endianness while translating code") could infer the endianness at runtime from the @endi field, and not a compile time via the TARGET_BIG_ENDIAN definition. Doing so, we forgot to make the endianness explicit on user emulation, so there all CPUs are started with the default "little-endian=off" value, leading to breaking support for little endian binaries: $ readelf -h ./hello-world-mbel ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian $ qemu-microblazeel ./hello-world-mbel qemu: uncaught target signal 11 (Segmentation fault) - core dumped Segmentation fault (core dumped) Fix by restoring the previous behavior of starting with the builtin endianness of the binary: $ qemu-microblazeel ./hello-world-mbel Hello World Cc: qemu-stable@nongnu.org Fixes: 415aae543ed ("target/microblaze: Consider endianness while translating code") Reported-by: Edgar E. Iglesias Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Edgar E. Iglesias Message-Id: <20251006173350.17455-1-philmd@linaro.org> (cherry picked from commit 91fc6d8101de97c588e0a4263cf4f6148b3e702a) (Mjt: adapt for missing v10.1.0-38-gaf880af8d4 "linux-user: Move get_elf_cpu_model to target/elfload.c") Signed-off-by: Michael Tokarev --- linux-user/microblaze/target_elf.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h index 8a8f1debff9..cab4c9187cc 100644 --- a/linux-user/microblaze/target_elf.h +++ b/linux-user/microblaze/target_elf.h @@ -9,6 +9,7 @@ #define MICROBLAZE_TARGET_ELF_H static inline const char *cpu_get_model(uint32_t eflags) { - return "any"; + return TARGET_BIG_ENDIAN ? "any,little-endian=off" + : "any,little-endian=on"; } #endif -- 2.47.3