Use the selected ABI byte order for ELF validation and core headers, user-memory accesses, signal masks and /proc/net/route conversion.
Retain the fixed-endian paths for targets without runtime selection. Signed-off-by: Philippe Mathieu-Daudé <[email protected]> --- linux-user/qemu.h | 17 ++++++++++++++++- linux-user/syscall_defs.h | 7 ------- linux-user/elfload.c | 6 +----- linux-user/syscall.c | 6 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index ef7aed2daec6..53567a6c0363 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -254,7 +254,22 @@ static inline bool access_ok(CPUState *cpu, int type, } while (0) -#if TARGET_BIG_ENDIAN +#ifdef TARGET_RUNTIME_ENDIAN +# define __put_user(x, hptr) do { \ + if (target_big_endian()) { \ + __put_user_e(x, hptr, be); \ + } else { \ + __put_user_e(x, hptr, le); \ + } \ +} while (0) +# define __get_user(x, hptr) do { \ + if (target_big_endian()) { \ + __get_user_e(x, hptr, be); \ + } else { \ + __get_user_e(x, hptr, le); \ + } \ +} while (0) +#elif TARGET_BIG_ENDIAN # define __put_user(x, hptr) __put_user_e(x, hptr, be) # define __get_user(x, hptr) __get_user_e(x, hptr, be) #else diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index f5831a6baddc..c9a1853c9e90 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -462,19 +462,12 @@ typedef struct { abi_ulong sig[TARGET_NSIG_WORDS]; } target_sigset_t; -#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s) { int i; for(i = 0;i < TARGET_NSIG_WORDS; i++) d->sig[i] = tswapal(s->sig[i]); } -#else -static inline void tswap_sigset(target_sigset_t *d, const target_sigset_t *s) -{ - *d = *s; -} -#endif static inline void target_siginitset(target_sigset_t *d, abi_ulong set) { diff --git a/linux-user/elfload.c b/linux-user/elfload.c index c188fa03c31f..c76afb77bbdc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -102,11 +102,7 @@ int info_is_fdpic(struct image_info *info) return info->personality == PER_LINUX_FDPIC; } -#if TARGET_BIG_ENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif +#define ELF_DATA (target_big_endian() ? ELFDATA2MSB : ELFDATA2LSB) #ifdef USE_UID16 typedef abi_ushort target_uid_t; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2fc61b3eabcc..9dec129e1d4f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8778,7 +8778,7 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code) #include "target_proc.h" -#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ +#if defined(TARGET_RUNTIME_ENDIAN) || HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN || \ defined(HAVE_ARCH_PROC_CPUINFO) || \ defined(HAVE_ARCH_PROC_HARDWARE) static int is_proc(const char *filename, const char *entry) @@ -8787,7 +8787,7 @@ static int is_proc(const char *filename, const char *entry) } #endif -#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN +#if defined(TARGET_RUNTIME_ENDIAN) || HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN static int open_net_route(CPUArchState *cpu_env, int fd) { FILE *fp; @@ -8850,7 +8850,7 @@ static int maybe_do_fake_open(CPUArchState *cpu_env, int dirfd, { "stat", open_self_stat, is_proc_myself }, { "auxv", open_self_auxv, is_proc_myself }, { "cmdline", open_self_cmdline, is_proc_myself }, -#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN +#if defined(TARGET_RUNTIME_ENDIAN) || HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN { "/proc/net/route", open_net_route, is_proc }, #endif #if defined(HAVE_ARCH_PROC_CPUINFO) -- 2.55.0
