qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user/microblaze: Fix little-endianness binary
@ 2025-10-06 17:33 Philippe Mathieu-Daudé
  2025-10-06 17:35 ` Edgar E. Iglesias
  2025-10-16  8:34 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-06 17:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: Laurent Vivier, Philippe Mathieu-Daudé, qemu-stable,
	Edgar E. Iglesias

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 <edgar.iglesias@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 linux-user/microblaze/elfload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/linux-user/microblaze/elfload.c b/linux-user/microblaze/elfload.c
index 7eb1b26d170..bdc0a953d59 100644
--- a/linux-user/microblaze/elfload.c
+++ b/linux-user/microblaze/elfload.c
@@ -8,7 +8,8 @@
 
 const char *get_elf_cpu_model(uint32_t eflags)
 {
-    return "any";
+    return TARGET_BIG_ENDIAN ? "any,little-endian=off"
+                             : "any,little-endian=on";
 }
 
 void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user/microblaze: Fix little-endianness binary
  2025-10-06 17:33 [PATCH] linux-user/microblaze: Fix little-endianness binary Philippe Mathieu-Daudé
@ 2025-10-06 17:35 ` Edgar E. Iglesias
  2025-10-16  8:34 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Edgar E. Iglesias @ 2025-10-06 17:35 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-devel, Laurent Vivier, qemu-stable

[-- Attachment #1: Type: text/plain, Size: 2288 bytes --]

On Mon, Oct 6, 2025 at 7:33 PM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> 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 <edgar.iglesias@gmail.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>

Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com>



> ---
>  linux-user/microblaze/elfload.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/linux-user/microblaze/elfload.c
> b/linux-user/microblaze/elfload.c
> index 7eb1b26d170..bdc0a953d59 100644
> --- a/linux-user/microblaze/elfload.c
> +++ b/linux-user/microblaze/elfload.c
> @@ -8,7 +8,8 @@
>
>  const char *get_elf_cpu_model(uint32_t eflags)
>  {
> -    return "any";
> +    return TARGET_BIG_ENDIAN ? "any,little-endian=off"
> +                             : "any,little-endian=on";
>  }
>
>  void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMBState *env)
> --
> 2.51.0
>
>

[-- Attachment #2: Type: text/html, Size: 3238 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] linux-user/microblaze: Fix little-endianness binary
  2025-10-06 17:33 [PATCH] linux-user/microblaze: Fix little-endianness binary Philippe Mathieu-Daudé
  2025-10-06 17:35 ` Edgar E. Iglesias
@ 2025-10-16  8:34 ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-16  8:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, qemu-stable, Edgar E. Iglesias

On 6/10/25 19:33, Philippe Mathieu-Daudé wrote:
> 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 <edgar.iglesias@gmail.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   linux-user/microblaze/elfload.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

Patch queued.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-16  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-06 17:33 [PATCH] linux-user/microblaze: Fix little-endianness binary Philippe Mathieu-Daudé
2025-10-06 17:35 ` Edgar E. Iglesias
2025-10-16  8:34 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).