[PATCH 06/16] hw/core/loader: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check

Philippe Mathieu-Daudé posted 16 patches 1 month ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, Gerd Hoffmann <kraxel@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Stefano Garzarella <sgarzare@redhat.com>, Laurent Vivier <laurent@vivier.eu>, Jason Wang <jasowang@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <arikalo@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Paolo Bonzini <pbonzini@redhat.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
[PATCH 06/16] hw/core/loader: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check
Posted by Philippe Mathieu-Daudé 1 month ago
Replace compile-time #ifdef with a runtime check to ensure all code
paths are built and tested. This reduces build-time configuration
complexity and improves maintainability.

No functional change intended.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/loader.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/core/loader.c b/hw/core/loader.c
index 477661a0255..aef10cb3f2b 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -491,7 +491,9 @@ ssize_t load_elf_ram_sym(const char *filename,
 
 static void bswap_uboot_header(uboot_image_header_t *hdr)
 {
-#if !HOST_BIG_ENDIAN
+    if (HOST_BIG_ENDIAN) {
+        return;
+    }
     bswap32s(&hdr->ih_magic);
     bswap32s(&hdr->ih_hcrc);
     bswap32s(&hdr->ih_time);
@@ -499,7 +501,6 @@ static void bswap_uboot_header(uboot_image_header_t *hdr)
     bswap32s(&hdr->ih_load);
     bswap32s(&hdr->ih_ep);
     bswap32s(&hdr->ih_dcrc);
-#endif
 }
 
 
-- 
2.51.0


Re: [PATCH 06/16] hw/core/loader: Replace HOST_BIG_ENDIAN #ifdef with runtime if() check
Posted by Alistair Francis 1 month ago
On Fri, Oct 10, 2025 at 11:46 PM Philippe Mathieu-Daudé
<philmd@linaro.org> wrote:
>
> Replace compile-time #ifdef with a runtime check to ensure all code
> paths are built and tested. This reduces build-time configuration
> complexity and improves maintainability.
>
> No functional change intended.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/core/loader.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 477661a0255..aef10cb3f2b 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -491,7 +491,9 @@ ssize_t load_elf_ram_sym(const char *filename,
>
>  static void bswap_uboot_header(uboot_image_header_t *hdr)
>  {
> -#if !HOST_BIG_ENDIAN
> +    if (HOST_BIG_ENDIAN) {
> +        return;
> +    }
>      bswap32s(&hdr->ih_magic);
>      bswap32s(&hdr->ih_hcrc);
>      bswap32s(&hdr->ih_time);
> @@ -499,7 +501,6 @@ static void bswap_uboot_header(uboot_image_header_t *hdr)
>      bswap32s(&hdr->ih_load);
>      bswap32s(&hdr->ih_ep);
>      bswap32s(&hdr->ih_dcrc);
> -#endif
>  }
>
>
> --
> 2.51.0
>
>