linux-user/aarch64: Support both endianness at runtime
v2 cover linux-user/aarch64: Support both endianness at runtime
Since v1:
- add ./configure error msg
- cover ARM32
This series lets qemu-aarch64 run both little- and big-endian ELF binaries, retaining qemu-aarch64_be as a compatibility alias.
The ELF loader selects the target byte order once, before execution. AArch64 CPU, signal, ABI and vDSO handling then use that selection. Fixed-endian targets and system emulation retain their existing accessors.
Runtime-endian TargetInfo data is exposed const to readers, allowing target_big_endian() to be inlined without a separate boolean cache. The writable initializer remains outside LTO, preserving the boundary between ELF initialization and subsequent reads.
I compared the complete series against its baseline, with normal and LTO builds and LE/BE guests and did not notice significative speed down.
The inspiration comes from previous optimization intent from Richard:
https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (12):
tests/tcg/aarch64_be: Check data byte order in hello tests/tcg/arm: Add BE8 and BE32 hello tests linux-user/aarch64: Move ELF/vDSO endian checks to runtime linux-user/aarch64: Move CPU/signal endian checks to runtime linux-user/arm: Move ELF/vDSO endian checks to runtime linux-user/arm: Move CPU endian checks to runtime
target-info: Support runtime-endian Linux-user targets
linux-user: Honor runtime byte order in ABI accesses
linux-user: Select target byte order from the ELF header
meson: Support Linux-user executable aliases linux-user/aarch64: Unify both endianness under qemu-aarch64 linux-user/arm: Unify both endianness under qemu-arm
docs/about/deprecated.rst | 23 +++++++++++++ docs/user/main.rst | 18 +++++++++-- configure | 12 ++++++- configs/targets/aarch64-linux-user.mak | 2 ++ configs/targets/aarch64_be-linux-user.mak | 10 ------ configs/targets/arm-linux-user.mak | 2 ++ configs/targets/armeb-linux-user.mak | 9 ------ meson.build | 39 +++++++++++++++++++++-- include/exec/tswap.h | 11 ++++--- include/qemu/target-info-def.h | 14 ++++++++ include/qemu/target-info.h | 20 ++++++++++++ linux-user/aarch64/target_elf.h | 6 +--- linux-user/aarch64/target_syscall.h | 6 +--- linux-user/arm/target_proc.h | 20 ++++-------- linux-user/arm/target_syscall.h | 6 +--- linux-user/qemu.h | 17 +++++++++- linux-user/syscall_defs.h | 7 ---- target/arm/cpu.h | 10 ++++-- target/arm/internals.h | 2 +- linux-user/aarch64/cpu_loop.c | 12 +++---- linux-user/aarch64/elfload.c | 10 +++++- linux-user/aarch64/signal.c | 20 ++++-------- linux-user/arm/cpu_loop.c | 2 +- linux-user/arm/elfload.c | 36 +++++++-------------- linux-user/elfload.c | 6 +--- linux-user/main.c | 26 +++++++++++++++ linux-user/syscall.c | 6 ++-- linux-user/uname.c | 13 ++------ target-info-def.c | 19 +++++++++++ target/arm/gdbstub64.c | 4 +-- target/arm/tcg/translate-sve.c | 2 +- tests/tcg/aarch64_be/hello.c | 16 ++++++---- tests/tcg/arm/hello-arm-be.c | 34 ++++++++++++++++++++ tests/tcg/arm/hello-arm-be32.c | 4 +++ .gitlab-ci.d/buildtest.yml | 2 +- .gitlab-ci.d/crossbuild-template.yml | 4 +-- linux-user/aarch64/meson.build | 10 +++--- linux-user/arm/meson.build | 4 --- tests/tcg/aarch64_be/meson.build | 4 +-- tests/tcg/arm/hello-arm.ref | 1 + tests/tcg/arm/meson.build | 11 +++++++ 41 files changed, 323 insertions(+), 157 deletions(-) delete mode 100644 configs/targets/aarch64_be-linux-user.mak delete mode 100644 configs/targets/armeb-linux-user.mak create mode 100644 tests/tcg/arm/hello-arm-be.c create mode 100644 tests/tcg/arm/hello-arm-be32.c create mode 100644 tests/tcg/arm/hello-arm.ref
Signature · 1 line
2.55.0
PATCH v2 1/12 tests/tcg/aarch64_be: Check data byte order in hello
Load the write length from guest data instead of an immediate, and fail unless the syscall writes exactly 12 bytes. This detects incorrect CPU data byte order rather than merely accepting the ELF header.
--- tests/tcg/aarch64_be/hello.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tests/tcg/aarch64_be/hello.c +10 -6
@@ -7,16 +7,17 @@#define __NR_write 64#define __NR_exit 93 -int write (int fd,char *buf,int len) +int write (int fd,const char *buf,int len) { register int x0 __asm__("x0") = fd; - register char *x1 __asm__("x1") = buf; + register const char *x1 __asm__("x1") = buf; register int x2 __asm__("x2") = len; register int x8 __asm__("x8") = __NR_write; - asmvolatile ("svc #0" : :"r" (x0),"r" (x1),"r" (x2),"r" (x8)); + asmvolatile ("svc #0" :"+r" (x0) :"r" (x1),"r" (x2),"r" (x8) + :"memory" ); -return len; +return x0; }void exit (int ret)
@@ -30,6 +31,9 @@ void exit(int ret)void _start (void ) { -write (1 ,"Hello World\n" ,12 ); -exit (0 ); +/* Force a data load to check CPU data byte order. */ +static const char hello[] ="Hello World\n" ; +static volatile int len =sizeof (hello) -1 ; + +exit (write (1 , hello, len) != len); }
Signature · 1 line
2.55.0
PATCH v2 2/12 tests/tcg/arm: Add BE8 and BE32 hello tests
In reply to Philippe Mathieu-Daudéarm-linux-user had no big-endian test coverage. Build the non-libc hello world with -mbig-endian (BE8 by default) and again with -mbe32 for legacy BE32 code/data ordering. The volatile length forces a data load, checking the CPU data byte order. Plumb both tests with the meson machinery.
--- tests/tcg/arm/hello-arm-be.c | 34 ++++++++++++++++++++++++++++++++++ tests/tcg/arm/hello-arm-be32.c | 4 ++++ tests/tcg/arm/hello-arm.ref | 1 + tests/tcg/arm/meson.build | 11 +++++++++++ 4 files changed, 50 insertions(+) create mode 100644 tests/tcg/arm/hello-arm-be.c create mode 100644 tests/tcg/arm/hello-arm-be32.c create mode 100644 tests/tcg/arm/hello-arm.ref
tests/tcg/arm/hello-arm-be.c new file +34 -0
@@ -0,0 +1,34 @@ +/* +* Non-libc syscall hello world to exercise big-endian ARM Linux-user. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#define __NR_exit 1 +#define __NR_write 4 + +static const char hello[] ="Hello World\n" ; +/* Volatile forces a data load to check the CPU data byte order. */ +static volatile int len =sizeof (hello) -1 ; + +static inline int write (int fd,const char *buf,int len) +{ + register int r0 __asm__("r0") = fd; + register const char *r1 __asm__("r1") = buf; + register int r2 __asm__("r2") = len; + register int r7 __asm__("r7") = __NR_write; + + __asm__volatile ("svc 0" :"+r" (r0) :"r" (r1),"r" (r2),"r" (r7) + :"memory" ); + +return r0; +} + +void _start (void ) +{ + register int r0 __asm__("r0") = write(1, hello, len) != len; + register int r7 __asm__("r7") = __NR_exit; + + __asm__volatile ("svc 0" : :"r" (r0),"r" (r7) :"memory" ); +__builtin_unreachable (); +}
tests/tcg/arm/hello-arm-be32.c new file +4 -0
@@ -0,0 +1,4 @@ +/* Rebuild the big-endian hello test with legacy BE32 code/data ordering. */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "hello-arm-be.c"
tests/tcg/arm/hello-arm.ref new file +1 -0
@@ -0,0 +1 @@ +Hello World
tests/tcg/arm/meson.build +11 -0
@@ -30,6 +30,17 @@ tests += { 'hello-arm.c': { 'cflags': ['-marm', '-nostdlib', '-ffreestanding', '-fno-stack-protector'], }, + # The cross compiler emits BE8 for -mbig-endian; test legacy BE32 too. + 'hello-arm-be.c': { + 'cflags': ['-marm', '-mbig-endian', '-nostdlib', '-static', '-ffreestanding', + '-fno-stack-protector'], + 'expected_output': 'hello-arm.ref', + }, + 'hello-arm-be32.c': { + 'cflags': ['-marm', '-mbig-endian', '-mbe32', '-nostdlib', '-static', + '-ffreestanding', '-fno-stack-protector'], + 'expected_output': 'hello-arm.ref', + }, 'fcvt.c': { 'cflags': ['-lm', '-march=armv8.2-a+fp16', '-mfpu=neon-fp-armv8'], 'expected_output': 'fcvt.ref',
Signature · 1 line
2.55.0
PATCH v2 3/12 linux-user/aarch64: Move ELF/vDSO endian checks to runtime
In reply to Philippe Mathieu-DaudéUse target_big_endian() for the platform name, uname machine, /proc/cpuinfo suffix and vDSO selection. Give the generated vDSOs distinct symbols so both can be included.
Preserve the behavior of the existing fixed-endian targets.
--- linux-user/aarch64/target_elf.h | 6 +----- linux-user/aarch64/target_syscall.h | 6 +----- linux-user/arm/target_proc.h | 2 +- linux-user/aarch64/elfload.c | 10 +++++++++- linux-user/aarch64/meson.build | 10 ++++------ 5 files changed, 16 insertions(+), 18 deletions(-)
linux-user/aarch64/target_elf.h +1 -5
@@ -27,10 +27,6 @@ typedef struct target_elf_gregset_t { struct target_user_pt_regs pt; } target_elf_gregset_t; -#if TARGET_BIG_ENDIAN -# define VDSO_HEADER "vdso-be.c.inc" -#else -# define VDSO_HEADER "vdso-le.c.inc" -#endif +#define HAVE_VDSO_IMAGE_INFO 1#endif
linux-user/aarch64/target_syscall.h +1 -5
@@ -1,11 +1,7 @@#ifndef AARCH64_TARGET_SYSCALL_H #define AARCH64_TARGET_SYSCALL_H -#if TARGET_BIG_ENDIAN -#define UNAME_MACHINE "aarch64_be" -#else -#define UNAME_MACHINE "aarch64" -#endif +#define UNAME_MACHINE (target_big_endian() ? "aarch64_be" : "aarch64")#define UNAME_MINIMUM_RELEASE "3.8.0"#define TARGET_CLONE_BACKWARDS #define TARGET_MCL_CURRENT 1
linux-user/arm/target_proc.h +1 -1
@@ -25,7 +25,7 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)#endif arch =8 ; - elf_name ="v8" END_SUFFIX ; + elf_name =target_big_endian () ?"v8b" :"v8l" ; midr_rev =FIELD_EX32 (midr,MIDR_EL1 ,REVISION ); midr_part =FIELD_EX32 (midr,MIDR_EL1 ,PARTNUM ); midr_var =FIELD_EX32 (midr,MIDR_EL1 ,VARIANT );
linux-user/aarch64/elfload.c +9 -1
@@ -379,7 +379,15 @@ const char *elf_hwcap2_str(uint32_t bit)const char *get_elf_platform (CPUState *cs) { -return TARGET_BIG_ENDIAN ?"aarch64_be" :"aarch64" ; +return target_big_endian () ?"aarch64_be" :"aarch64" ; +} + +#include "vdso-be.c.inc" +#include "vdso-le.c.inc" + +const VdsoImageInfo *get_vdso_image_info (uint32_t elf_flags) +{ +return target_big_endian () ? &vdso_be_image_info : &vdso_le_image_info; } bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
linux-user/aarch64/meson.build +4 -6
@@ -1,12 +1,10 @@ -# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it -# is always true as far as source_set.apply() is concerned. Always build -# both header files and include the right one via #if. - vdso_be_inc = gen_vdso.process('vdso-be.so', - extra_args: ['-r', '__kernel_rt_sigreturn']) + extra_args: ['-r', '__kernel_rt_sigreturn', + '-p', 'vdso_be']) vdso_le_inc = gen_vdso.process('vdso-le.so', - extra_args: ['-r', '__kernel_rt_sigreturn']) + extra_args: ['-r', '__kernel_rt_sigreturn', + '-p', 'vdso_le']) linux_user_ss.add(when: 'TARGET_AARCH64', if_true: [vdso_be_inc, vdso_le_inc])
Signature · 1 line
2.55.0
PATCH v2 4/12 linux-user/aarch64: Move CPU/signal endian checks to runtime
In reply to Philippe Mathieu-DaudéUse target_big_endian() for CPU endian initialization, FPSIMD signal-frame ordering and CPU-versus-ABI byte-order checks.
Preserve the behavior of the existing fixed-endian targets.
--- target/arm/internals.h | 2 +- linux-user/aarch64/cpu_loop.c | 12 ++++++------ linux-user/aarch64/signal.c | 20 ++++++-------------- target/arm/gdbstub64.c | 4 ++-- target/arm/tcg/translate-sve.c | 2 +- 5 files changed, 16 insertions(+), 24 deletions(-)
target/arm/internals.h +1 -1
@@ -588,7 +588,7 @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env)#ifdef CONFIG_USER_ONLY static inline bool arm_cpu_bswap_data (CPUARMState *env) { -return TARGET_BIG_ENDIAN ^arm_cpu_data_is_big_endian (env); +return target_big_endian () ^arm_cpu_data_is_big_endian (env); }#endif
linux-user/aarch64/cpu_loop.c +6 -6
@@ -242,13 +242,13 @@ void init_main_thread(CPUState *cs, struct image_info *info) env->pc = info->entry & ~0x3ULL ; env->xregs[31 ] = info->start_stack; -#if TARGET_BIG_ENDIAN - env->cp15.sctlr_el[1 ] |=SCTLR_E0E ; -for (int i =1 ; i <4 ; ++i) { - env->cp15.sctlr_el[i] |=SCTLR_EE ; +if (target_big_endian ()) { + env->cp15.sctlr_el[1 ] |=SCTLR_E0E ; +for (int i =1 ; i <4 ; ++i) { + env->cp15.sctlr_el[i] |=SCTLR_EE ; + } +arm_rebuild_hflags (env); } -arm_rebuild_hflags (env); -#endif if (cpu_isar_feature (aa64_pauth, cpu)) {qemu_guest_getrandom_nofail (&env->keys,sizeof (env->keys));
linux-user/aarch64/signal.c +6 -14
@@ -208,6 +208,7 @@ static void target_setup_fpsimd_record(struct target_fpsimd_context *fpsimd, CPUARMState *env) {int i; +int big_endian =target_big_endian ();__put_user (TARGET_FPSIMD_MAGIC , &fpsimd->head.magic);__put_user (sizeof (struct target_fpsimd_context ), &fpsimd->head.size);
@@ -216,13 +217,8 @@ static void target_setup_fpsimd_record(struct target_fpsimd_context *fpsimd,for (i =0 ; i <32 ; i++) {uint64_t *q =aa64_vfp_qreg (env, i); -#if TARGET_BIG_ENDIAN -__put_user (q[0 ], &fpsimd->vregs[i *2 +1 ]); -__put_user (q[1 ], &fpsimd->vregs[i *2 ]); -#else -__put_user (q[0 ], &fpsimd->vregs[i *2 ]); -__put_user (q[1 ], &fpsimd->vregs[i *2 +1 ]); -#endif +__put_user (q[0 ], &fpsimd->vregs[i *2 + big_endian]); +__put_user (q[1 ], &fpsimd->vregs[i *2 + !big_endian]); } }
@@ -402,6 +398,7 @@ static void target_restore_fpsimd_record(CPUARMState *env, {uint32_t fpsr, fpcr;int i; +int big_endian =target_big_endian ();__get_user (fpsr, &fpsimd->fpsr);vfp_set_fpsr (env, fpsr);
@@ -410,13 +407,8 @@ static void target_restore_fpsimd_record(CPUARMState *env,for (i =0 ; i <32 ; i++) {uint64_t *q =aa64_vfp_qreg (env, i); -#if TARGET_BIG_ENDIAN -__get_user (q[0 ], &fpsimd->vregs[i *2 +1 ]); -__get_user (q[1 ], &fpsimd->vregs[i *2 ]); -#else -__get_user (q[0 ], &fpsimd->vregs[i *2 ]); -__get_user (q[1 ], &fpsimd->vregs[i *2 +1 ]); -#endif +__get_user (q[0 ], &fpsimd->vregs[i *2 + big_endian]); +__get_user (q[1 ], &fpsimd->vregs[i *2 + !big_endian]); } }
target/arm/gdbstub64.c +2 -2
@@ -122,8 +122,8 @@ int aarch64_gdb_set_fpu_reg(CPUState *cs, uint8_t *buf, int reg)* On the wire these are target-endian 128 bit values. * In the CPU state these are host-order uint64_t values * with the least-significant one first. This means they're -* the other way around for target_big_endian() (which is -* only true for us for aarch64_be-linux-user). +* the other way around for target_big_endian(), which reflects +* the executable's byte order in Linux-user emulation. */ if (target_big_endian ()) { q[1 ] =ldq_p (buf);
target/arm/tcg/translate-sve.c +1 -1
@@ -5165,7 +5165,7 @@ void gen_sve_str(DisasContext *s, TCGv_ptr base, int vofs,/* Note that unpredicated load/store of vector/predicate registers * are defined as a stream of bytes, which equates to little-endian * operations on larger quantities. There is no nice way to force -* a little-endian store for aarch64_be-linux-user out of line. +* a little-endian store for big-endian Linux-user guests out of line. * * Attempt to keep code expansion to a minimum by limiting the * amount of unrolling done.
Signature · 1 line
2.55.0
PATCH v2 5/12 linux-user/arm: Move ELF/vDSO endian checks to runtime
In reply to Philippe Mathieu-DaudéUse target_big_endian() for the platform name, uname machine, /proc/cpuinfo suffix and vDSO selection.
Preserve the behavior of the existing fixed-endian targets.
--- linux-user/arm/target_proc.h | 18 +++++------------ linux-user/arm/target_syscall.h | 6 +----- linux-user/arm/elfload.c | 36 +++++++++++---------------------- linux-user/uname.c | 13 +++--------- linux-user/arm/meson.build | 4 ---- 5 files changed, 21 insertions(+), 56 deletions(-)
linux-user/arm/target_proc.h +5 -13
@@ -18,12 +18,6 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)const char *elf_name;int num_cpus, len_part, len_var; -#if TARGET_BIG_ENDIAN -# define END_SUFFIX "b" -#else -# define END_SUFFIX "l" -#endif - arch =8 ; elf_name =target_big_endian () ?"v8b" :"v8l" ; midr_rev =FIELD_EX32 (midr,MIDR_EL1 ,REVISION );
@@ -41,29 +35,27 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd) midr_var = (midr >>16 ) &0x7f ; len_var =2 ;if (arm_feature (&cpu->env,ARM_FEATURE_M )) { - elf_name ="armv7m" END_SUFFIX ; + elf_name =target_big_endian () ?"armv7mb" :"armv7ml" ; }else { - elf_name ="armv7" END_SUFFIX ; + elf_name =target_big_endian () ?"armv7b" :"armv7l" ; } }else { midr_part = midr >>4 ; len_part =7 ;if (arm_feature (&cpu->env,ARM_FEATURE_V6 )) { arch =6 ; - elf_name ="armv6" END_SUFFIX ; + elf_name =target_big_endian () ?"armv6b" :"armv6l" ; }else if (arm_feature (&cpu->env,ARM_FEATURE_V5 )) { arch =5 ; - elf_name ="armv5t" END_SUFFIX ; + elf_name =target_big_endian () ?"armv5tb" :"armv5tl" ; }else { arch =4 ; - elf_name ="armv4" END_SUFFIX ; + elf_name =target_big_endian () ?"armv4b" :"armv4l" ; } } }#endif -#undef END_SUFFIX - num_cpus =sysconf (_SC_NPROCESSORS_ONLN);for (int i =0 ; i < num_cpus; i++) { dprintf(fd,
linux-user/arm/target_syscall.h +1 -5
@@ -10,11 +10,7 @@#define ARM_NR_set_tls (ARM_NR_BASE + 5)#define ARM_NR_get_tls (ARM_NR_BASE + 6) -#if TARGET_BIG_ENDIAN -#define UNAME_MACHINE "armv5teb" -#else -#define UNAME_MACHINE "armv5tel" -#endif +#define UNAME_MACHINE (target_big_endian() ? "armv5teb" : "armv5tel")#define UNAME_MINIMUM_RELEASE "2.6.32"#define TARGET_CLONE_BACKWARDS
linux-user/arm/elfload.c +12 -24
@@ -179,29 +179,21 @@ const char *get_elf_platform(CPUState *cs) {CPUARMState *env =cpu_env (cs); -#if TARGET_BIG_ENDIAN -# define END "b" -#else -# define END "l" -#endif -if (arm_feature (env,ARM_FEATURE_V8 )) { -return "v8" END ; +return target_big_endian () ?"v8b" :"v8l" ; }else if (arm_feature (env,ARM_FEATURE_V7 )) {if (arm_feature (env,ARM_FEATURE_M )) { -return "v7m" END ; +return target_big_endian () ?"v7mb" :"v7ml" ; }else { -return "v7" END ; +return target_big_endian () ?"v7b" :"v7l" ; } }else if (arm_feature (env,ARM_FEATURE_V6 )) { -return "v6" END ; +return target_big_endian () ?"v6b" :"v6l" ; }else if (arm_feature (env,ARM_FEATURE_V5 )) { -return "v5" END ; +return target_big_endian () ?"v5b" :"v5l" ; }else { -return "v4" END ; +return target_big_endian () ?"v4b" :"v4l" ; } - -#undef END }bool init_guest_commpage (void )
@@ -257,21 +249,17 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env) r->pt.orig_r0 =tswapal (env->regs[0 ]);/* FIXME */ } -#if TARGET_BIG_ENDIAN # include "vdso-be8.c.inc" # include "vdso-be32.c.inc" -#else # include "vdso-le.c.inc" -#endif const VdsoImageInfo *get_vdso_image_info (uint32_t elf_flags) { -#if TARGET_BIG_ENDIAN -return (EF_ARM_EABI_VERSION (elf_flags) >=EF_ARM_EABI_VER4 - && (elf_flags &EF_ARM_BE8 ) - ? &vdso_be8_image_info - : &vdso_be32_image_info); -#else +if (target_big_endian ()) { +return (EF_ARM_EABI_VERSION (elf_flags) >=EF_ARM_EABI_VER4 + && (elf_flags &EF_ARM_BE8 ) + ? &vdso_be8_image_info + : &vdso_be32_image_info); + }return &vdso_image_info; -#endif }
linux-user/uname.c +3 -10
@@ -38,20 +38,13 @@ const char *cpu_to_uname_machine(CPUArchState *cpu_env)* see arch/arm/kernel/setup.c: setup_processor() */ -/* in theory, endianness is configurable on some ARM CPUs, but this isn't -* used in user mode emulation */ -#if TARGET_BIG_ENDIAN -#define utsname_suffix "b" -#else -#define utsname_suffix "l" -#endif if (arm_feature (cpu_env,ARM_FEATURE_V7 )) -return "armv7" utsname_suffix; +return target_big_endian () ?"armv7b" :"armv7l" ;if (arm_feature (cpu_env,ARM_FEATURE_V6 )) -return "armv6" utsname_suffix; +return target_big_endian () ?"armv6b" :"armv6l" ;/* earliest emulated CPU is ARMv5TE; qemu can emulate the 1026, but not its * Jazelle support */ -return "armv5te" utsname_suffix; +return target_big_endian () ?"armv5teb" :"armv5tel" ;#elif defined(TARGET_I386 ) && !defined(TARGET_X86_64 )/* see arch/x86/kernel/cpu/bugs.c: check_bugs(), 386, 486, 586, 686 */ CPUState *cpu =env_cpu (cpu_env);
linux-user/arm/meson.build +0 -4
@@ -6,10 +6,6 @@ syscall_nr_generators += { output: '@BASENAME@_nr.h') } -# TARGET_BIG_ENDIAN is defined to 'n' for little-endian; which means it -# is always true as far as source_set.apply() is concerned. Always build -# both header files and include the right one via #if. - vdso_be8_inc = gen_vdso.process('vdso-be8.so', extra_args: ['-s', 'sigreturn_codes', '-p', 'vdso_be8'])
Signature · 1 line
2.55.0
PATCH v2 6/12 linux-user/arm: Move CPU endian checks to runtime
In reply to Philippe Mathieu-DaudéUse target_big_endian() for BE8 code-order handling.
Preserve the behavior of the existing fixed-endian targets.
--- target/arm/cpu.h | 10 ++++++++-- linux-user/arm/cpu_loop.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-)
target/arm/cpu.h +8 -2
@@ -22,6 +22,7 @@#include "kvm-consts.h" #include "qemu/cpu-float.h" +#include "qemu/target-info.h" #include "hw/core/registerfields.h" #include "cpu-qom.h" #include "exec/cpu-common.h"
@@ -2660,11 +2661,16 @@ static inline int sme_vq(CPUARMState *env)static inline bool bswap_code (bool sctlr_b) {#ifdef CONFIG_USER_ONLY -/* BE8 (SCTLR.B = 0, TARGET_BIG_ENDIAN = 1) is mixed endian. -* The invalid combination SCTLR.B=1/CPSR.E=1/TARGET_BIG_ENDIAN=0 +/* +* BE8 (SCTLR.B = 0, big-endian target) is mixed endian. +* The invalid combination SCTLR.B=1/CPSR.E=1/little-endian target * would also end up as a mixed-endian mode with BE code, LE data. */ +#ifdef TARGET_RUNTIME_ENDIAN +return target_big_endian () ^ sctlr_b; +#else return TARGET_BIG_ENDIAN ^ sctlr_b; +#endif #else /* All code access in ARM is little endian, and there are no loaders * doing swaps that need to be reversed
linux-user/arm/cpu_loop.c +1 -1
@@ -505,7 +505,7 @@ void init_main_thread(CPUState *cs, struct image_info *info) } } -if (TARGET_BIG_ENDIAN ) { +if (target_big_endian ()) {/* Enable BE8. */ if (EF_ARM_EABI_VERSION (info->elf_flags) >=EF_ARM_EABI_VER4 && (info->elf_flags &EF_ARM_BE8 )) {
Signature · 1 line
2.55.0
PATCH v2 7/12 target-info: Support runtime-endian Linux-user targets
In reply to Philippe Mathieu-DaudéAdd a write-once ABI byte-order setter for runtime-endian Linux-user targets.
Expose const data to readers and inline runtime endian checks, keeping its writable initializer outside LTO.
Retain immutable data and compile-time byte swapping for fixed-endian targets. Restrict TARGET_RUNTIME_ENDIAN to Linux-user configurations.
--- meson.build | 26 ++++++++++++++++++++++++-- include/exec/tswap.h | 11 +++++++---- include/qemu/target-info-def.h | 14 ++++++++++++++ include/qemu/target-info.h | 20 ++++++++++++++++++++ target-info-def.c | 19 +++++++++++++++++++ 5 files changed, 84 insertions(+), 6 deletions(-)
meson.build +24 -2
@@ -3342,6 +3342,11 @@ foreach target : target_dirs config_target += keyval.load('configs/targets' / target + '.mak') + if 'TARGET_RUNTIME_ENDIAN' in config_target + assert(target.endswith('linux-user'), + 'Runtime target endianness is only supported for Linux-user') + endif + target_kconfig = [] foreach sym: accelerators if sym == 'CONFIG_TCG' or target in accelerator_targets.get(sym, [])
@@ -4400,8 +4405,6 @@ foreach target : target_dirs endif endif - arch_srcs += files('target-info-def.c') - if target_base_arch in target_arch t = target_arch[target_base_arch].apply(config_target, strict: false) arch_srcs += t.sources()
@@ -4470,6 +4473,25 @@ foreach target : target_dirs lib_deps += dep.partial_dependency(compile_args: true, includes: true) endforeach + # Keep the writable runtime-endian definition opaque to const readers, + # as for page-vary-common.c above. + target_info = files('target-info-def.c') + if get_option('b_lto') and 'TARGET_RUNTIME_ENDIAN' in config_target + target_info_flags = ['-fno-lto'] + if get_option('cfi') + target_info_flags += '-fno-sanitize=cfi-icall' + endif + target_info = static_library('target-info-' + target, + sources: target_info + genh + config_target_h[target], + dependencies: lib_deps, + include_directories: target_inc, + c_args: c_args + target_info_flags, + build_by_default: false) + objects += target_info.extract_all_objects(recursive: false) + else + arch_srcs += target_info + endif + lib = static_library('qemu-' + target, sources: arch_srcs + genh, dependencies: lib_deps,
include/exec/tswap.h +7 -4
@@ -13,14 +13,17 @@#include "hw/core/cpu.h" /* -* If we're in target-specific code, we can hard-code the swapping -* condition, otherwise we have to do (slower) run-time checks. +* For fixed-endian target-specific code, hard-code the swapping condition. +* Otherwise use run-time checks. */ #ifdef COMPILING_PER_TARGET +#ifndef TARGET_RUNTIME_ENDIAN #define target_needs_bswap () (HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN) -#else +#endif +#endif +#ifndef target_needs_bswap#define target_needs_bswap () (HOST_BIG_ENDIAN != target_big_endian()) -#endif /* COMPILING_PER_TARGET */ +#endif #if defined(CONFIG_USER_ONLY ) \ || !defined(TARGET_NOT_USING_LEGACY_NATIVE_ENDIAN_API )
include/qemu/target-info-def.h +14 -0
@@ -32,6 +32,20 @@ typedef struct TargetInfo {bool page_bits_vary; } TargetInfo; +#ifdef COMPILING_PER_TARGET +#ifdef TARGET_RUNTIME_ENDIAN +/* +* Linux-user selects the ELF byte order before creating CPUs or guest threads. +* The data is then immutable; its writable definition must stay outside LTO. +*/ +#ifdef IN_TARGET_INFO_DEF +extern TargetInfo target_info_stub; +#else +extern const TargetInfo target_info_stub; +#endif +#endif +#endif +/** * target_info: *
include/qemu/target-info.h +20 -0
@@ -9,6 +9,12 @@#ifndef QEMU_TARGET_INFO_H #define QEMU_TARGET_INFO_H +#ifdef COMPILING_PER_TARGET +#ifdef TARGET_RUNTIME_ENDIAN +#include "qemu/target-info-def.h" +#endif +#endif +/** * target_name: *
@@ -40,7 +46,21 @@ const char *target_cpu_type(void);* the target, so please do *not* use this function unless you know very * well what you are doing! */ +#ifdef COMPILING_PER_TARGET +#ifdef TARGET_RUNTIME_ENDIAN +static inline bool target_big_endian (void ) +{ +return target_info_stub.endianness ==ENDIAN_MODE_BIG ; +} + +/* Select the Linux-user ABI byte order once, before CPUs or guest threads. */ +void target_set_big_endian (bool big_endian); +#else bool target_big_endian (void ); +#endif +#else +bool target_big_endian (void ); +#endif /** * target_heterogeneous:
target-info-def.c +19 -0
@@ -6,6 +6,8 @@* SPDX-License-Identifier: GPL-2.0-or-later */ +#define IN_TARGET_INFO_DEF 1 +#include "qemu/osdep.h" #include "qemu/target-info.h" #include "qemu/target-info-def.h"
@@ -24,7 +26,12 @@ QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));QEMU_BUILD_BUG_ON (TARGET_PAGE_BITS <TARGET_PAGE_BITS_MIN );#endif +#ifdef TARGET_RUNTIME_ENDIAN +/* This writable definition must not be compiled with -flto. */ +TargetInfo target_info_stub = { +#else static const TargetInfo target_info_stub = { +#endif .target_name = TARGET_NAME, .target_arch = glue(SYS_EMU_TARGET_, TARGET_ARCH_VARIANT), .long_bits = TARGET_LONG_BITS,
@@ -42,3 +49,15 @@ static const TargetInfo target_info_stub = { }; target_info_init(target_info_stub) + +#ifdef TARGET_RUNTIME_ENDIAN +void target_set_big_endian (bool big_endian) +{ +static bool endian_decided; + +assert (!endian_decided); + endian_decided = true; + target_info_stub.endianness = big_endian ?ENDIAN_MODE_BIG + :ENDIAN_MODE_LITTLE ; +} +#endif
Signature · 1 line
2.55.0
PATCH v2 8/12 linux-user: Honor runtime byte order in ABI accesses
In reply to Philippe Mathieu-Daudé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.
--- 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(-)
linux-user/qemu.h +16 -1
@@ -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
linux-user/syscall_defs.h +0 -7
@@ -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) {
linux-user/elfload.c +1 -5
@@ -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 ;
linux-user/syscall.c +3 -3
@@ -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)
Signature · 1 line
2.55.0
PATCH v2 9/12 linux-user: Select target byte order from the ELF header
In reply to Philippe Mathieu-DaudéRead EI_DATA from the executable descriptor before selecting the CPU and loading the image. This also covers binfmt open-binary execution and an explicitly selected CPU model.
Reject invalid ELF byte-order encodings without using the invoked emulator name to select an ABI.
--- linux-user/main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
linux-user/main.c +26 -0
@@ -22,6 +22,7 @@#include "qemu/units.h" #include "qemu/accel.h" #include "qemu/version.h" +#include "elf.h" #include <sys/syscall.h> #include <sys/resource.h> #include <sys/shm.h>
@@ -769,6 +770,31 @@ int main(int argc, char **argv, char **envp) } } +#ifdef TARGET_RUNTIME_ENDIAN + { +unsigned char ident[EI_NIDENT ]; +ssize_t len =pread (execfd, ident,sizeof (ident),0 ); + +if (len <0 ) { +error_report ("Error reading %s: %s" , exec_path,strerror (errno)); +exit (EXIT_FAILURE ); + } +if (len ==sizeof (ident) &&memcmp (ident,ELFMAG ,SELFMAG ) ==0 ) { +switch (ident[EI_DATA ]) { +case ELFDATA2LSB : +target_set_big_endian (false); +break ; +case ELFDATA2MSB : +target_set_big_endian (true); +break ; +default : +error_report ("%s: Invalid ELF byte order" , exec_path); +exit (EXIT_FAILURE ); + } + } + } +#endif +/* Resolve executable file name to full path name */ /* Keep how we started the program in exec_path, e.g. "./my_program" */ /* Store real path in real_exec_path, e.g. "/usr/local/bin/my_program" */
Signature · 1 line
2.55.0
PATCH v2 10/12 meson: Support Linux-user executable aliases
In reply to Philippe Mathieu-DaudéAccept TARGET_USER_ALIASES in target configurations and create relative symlinks in both the build and install trees. Depend on the canonical emulator instead of linking a second binary.
--- meson.build | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
meson.build +12 -1
@@ -3297,7 +3297,7 @@ host_kconfig = \ (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=y'] : []) + \ (have_rust ? ['CONFIG_HAVE_RUST=y'] : []) -ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR' ] +ignored = [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR', 'TARGET_USER_ALIASES' ] default_targets = 'CONFIG_DEFAULT_TARGETS' in config_host actual_target_dirs = []
@@ -4580,6 +4580,17 @@ foreach target : target_dirs emulators += {exe['name']: emulator} endif + foreach alias : config_target.get('TARGET_USER_ALIASES', '').split() + alias_name = 'qemu-' + alias + custom_target(alias_name, + output: alias_name, + depends: emulator, + build_by_default: true, + command: [find_program('ln'), '-sf', exe['name'], '@OUTPUT@']) + install_symlink(alias_name, pointing_to: exe['name'], + install_dir: get_option('bindir')) + endforeach + traceable += [{ 'exe': exe['name'], 'probe-prefix': 'qemu.' + target_type + '.' + target_name,
Signature · 1 line
2.55.0
PATCH v2 11/12 linux-user/aarch64: Unify both endianness under qemu-aarch64
In reply to Philippe Mathieu-DaudéEnable runtime byte-order selection for aarch64-linux-user and retain qemu-aarch64_be as a compatibility symlink. Deprecate the symlink since 12.0 and recommend qemu-aarch64 for both ELF byte orders.
Remove the separate aarch64_be-linux-user build target and obsolete CI exclusions.
Run the existing big-endian hello test through qemu-aarch64 while retaining its big-endian fixture toolchain. Document that executable name compatibility does not preserve the removed target-list spelling.
--- docs/about/deprecated.rst | 13 +++++++++++++ docs/user/main.rst | 8 ++++++++ configure | 9 ++++++++- configs/targets/aarch64-linux-user.mak | 2 ++ configs/targets/aarch64_be-linux-user.mak | 10 ---------- .gitlab-ci.d/buildtest.yml | 2 +- .gitlab-ci.d/crossbuild-template.yml | 4 ++-- tests/tcg/aarch64_be/meson.build | 4 ++-- 8 files changed, 36 insertions(+), 16 deletions(-) delete mode 100644 configs/targets/aarch64_be-linux-user.mak
docs/about/deprecated.rst +13 -0
@@ -438,6 +438,19 @@ It was implemented as a no-op instruction in TCG up to QEMU 9.0, but only with ``-cpu max`` (which does not guarantee migration compatibility across versions). +linux-user mode executables +--------------------------- + +.. _deprecated-qemu-aarch64-be: + +``qemu-aarch64_be`` executable name (since 12.0) +'''''''''''''''''''''''''''''''''''''''''''''''' + +The ``qemu-aarch64_be`` compatibility symlink is deprecated. +Use ``qemu-aarch64`` instead for both little- and big-endian +Linux ELF executables. The emulator selects the endianness from +the ELF header, regardless of the executable name used to invoke it. + linux-user mode CPUs --------------------
docs/user/main.rst +8 -0
@@ -65,6 +65,14 @@ emulator. Linux User space emulator ------------------------- +For AArch64, ``qemu-aarch64`` runs both little- and big-endian Linux ELF +executables, selecting the byte order from the ELF header. ``qemu-aarch64_be`` +is a :ref:`deprecated compatibility symlink <deprecated-qemu-aarch64-be>` +to the same emulator; its name does not override the ELF byte order. +Build both names with ``--target-list=aarch64-linux-user``; the separate +``aarch64_be-linux-user`` build target is no longer supported. +For bFLT, which has no byte-order marker, QEMU uses the little-endian default. + Command line options ~~~~~~~~~~~~~~~~~~~~
configure +8 -1
@@ -1107,7 +1107,14 @@ else *" $target "*) ;; *) - error_exit "Unknown target name '$target'" + case "$target" in + aarch64_be-linux-user) + error_exit "Target '$target' is no longer supported; use 'aarch64-linux-user' instead" + ;; + *) + error_exit "Unknown target name '$target'" + ;; + esac ;; esac done
configs/targets/aarch64-linux-user.mak +2 -0
@@ -1,5 +1,7 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm +TARGET_RUNTIME_ENDIAN=y +TARGET_USER_ALIASES=aarch64_be TARGET_XML_FILES= aarch64-core.xml aarch64-fpu.xml aarch64-pauth.xml aarch64-mte.xml aarch64-sme2.xml TARGET_HAS_BFLT=y CONFIG_SEMIHOSTING=y
configs/targets/aarch64_be-linux-user.mak deleted +0 -10
@@ -1,10 +0,0 @@ -TARGET_ARCH=aarch64 -TARGET_BASE_ARCH=arm -TARGET_BIG_ENDIAN=y -TARGET_XML_FILES= aarch64-core.xml aarch64-fpu.xml aarch64-pauth.xml aarch64-mte.xml aarch64-sme2.xml -TARGET_HAS_BFLT=y -CONFIG_SEMIHOSTING=y -CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y -TARGET_SYSTBL_ABI=common,64,renameat,rlimit,memfd_secret -TARGET_SYSTBL=syscall_64.tbl -TARGET_LONG_BITS=64
.gitlab-ci.d/buildtest.yml +1 -1
@@ -451,7 +451,7 @@ clang-user: variables: IMAGE: debian-all-test-cross CONFIGURE_ARGS: --cc=clang --cxx=clang++ --disable-system --enable-ubsan - --target-list-exclude=alpha-linux-user,microblazeel-linux-user,aarch64_be-linux-user,i386-linux-user,m68k-linux-user,mipsn32el-linux-user,xtensaeb-linux-user + --target-list-exclude=alpha-linux-user,microblazeel-linux-user,i386-linux-user,m68k-linux-user,mipsn32el-linux-user,xtensaeb-linux-user --extra-cflags=-fno-sanitize-recover=undefined MAKE_CHECK_ARGS: check-unit check-tcg
.gitlab-ci.d/crossbuild-template.yml +2 -2
@@ -70,8 +70,8 @@ - cd build - section_start configure "Running configure" - ../configure --enable-werror --disable-docs $QEMU_CONFIGURE_OPTS - --disable-system --target-list-exclude="aarch64_be-linux-user - alpha-linux-user m68k-linux-user microblazeel-linux-user + --disable-system --target-list-exclude="alpha-linux-user + m68k-linux-user microblazeel-linux-user or1k-linux-user ppc-linux-user sparc-linux-user xtensa-linux-user $CROSS_SKIP_TARGETS" - section_end configure
tests/tcg/aarch64_be/meson.build +2 -2
@@ -6,7 +6,7 @@ tests += { 'hello.c': {'cflags': ['-mbig-endian', '-ffreestanding', '-nostdlib']}, } -if 'qemu-aarch64_be' in emulators +if 'qemu-aarch64' in emulators tcg_tests += { 'aarch64_be-linux-user': { 'cc': 'aarch64-linux-gnu-gcc',
@@ -14,7 +14,7 @@ if 'qemu-aarch64_be' in emulators 'cc_dockerfile': 'debian-all-test-cross', 'folder': 'aarch64_be', 'gdb_arch': 'aarch64_be', - 'qemu': emulators['qemu-aarch64_be'], + 'qemu': emulators['qemu-aarch64'], 'tests': tests, } }
Signature · 1 line
2.55.0
PATCH v2 12/12 linux-user/arm: Unify both endianness under qemu-arm
In reply to Philippe Mathieu-DaudéEnable runtime byte-order selection for arm-linux-user and retain qemu-armeb as a compatibility symlink. Deprecate the symlink since 12.0 and recommend qemu-arm for both ELF byte orders.
Remove the separate armeb-linux-user build target and obsolete CI exclusions.
Run the existing big-endian hello test through qemu-arm while retaining its big-endian fixture toolchain. Document that executable name compatibility does not preserve the removed target-list spelling.
--- docs/about/deprecated.rst | 10 ++++++++++ docs/user/main.rst | 10 ++++++++-- configure | 3 +++ configs/targets/arm-linux-user.mak | 2 ++ configs/targets/armeb-linux-user.mak | 9 --------- 5 files changed, 23 insertions(+), 11 deletions(-) delete mode 100644 configs/targets/armeb-linux-user.mak
docs/about/deprecated.rst +10 -0
@@ -451,6 +451,16 @@ Use ``qemu-aarch64`` instead for both little- and big-endian Linux ELF executables. The emulator selects the endianness from the ELF header, regardless of the executable name used to invoke it. +.. _deprecated-qemu-armeb: + +``qemu-armeb`` executable name (since 12.0) +''''''''''''''''''''''''''''''''''''''''''' + +The ``qemu-armeb`` compatibility symlink is deprecated. +Use ``qemu-arm`` instead for both little- and big-endian Linux +ELF executables. The emulator selects the endianness from the +ELF header, regardless of the executable name used to invoke it. + linux-user mode CPUs --------------------
docs/user/main.rst +8 -2
@@ -152,11 +152,17 @@ Other binaries - user mode (Arm) - * ``qemu-armeb`` TODO. + ``qemu-arm`` runs both little- and big-endian Linux ELF executables, + selecting the byte order from the ELF header. ``qemu-armeb`` is a + :ref:`deprecated compatibility symlink <deprecated-qemu-armeb>` to the + same emulator; its name does not override the ELF byte order. Build both + names with ``--target-list=arm-linux-user``; the separate + ``armeb-linux-user`` build target is no longer supported. * ``qemu-arm`` is also capable of running Arm \"Angel\" semihosted ELF binaries (as implemented by the arm-elf and arm-eabi Newlib/GDB - configurations), and arm-uclinux bFLT format binaries. + configurations), and arm-uclinux bFLT format binaries. bFLT has no + byte-order marker and uses the little-endian default. - user mode (ColdFire)
configure +3 -0
@@ -1111,6 +1111,9 @@ else aarch64_be-linux-user) error_exit "Target '$target' is no longer supported; use 'aarch64-linux-user' instead" ;; + armeb-linux-user) + error_exit "Target '$target' is no longer supported; use 'arm-linux-user' instead" + ;; *) error_exit "Unknown target name '$target'" ;;
configs/targets/arm-linux-user.mak +2 -0
@@ -1,6 +1,8 @@ TARGET_ARCH=arm TARGET_SYSTBL_ABI=common,oabi TARGET_SYSTBL=syscall.tbl +TARGET_RUNTIME_ENDIAN=y +TARGET_USER_ALIASES=armeb TARGET_XML_FILES= arm-core.xml arm-vfp.xml arm-vfp3.xml arm-vfp-sysregs.xml arm-neon.xml arm-m-profile.xml arm-m-profile-mve.xml TARGET_HAS_BFLT=y CONFIG_SEMIHOSTING=y
configs/targets/armeb-linux-user.mak deleted +0 -9
@@ -1,9 +0,0 @@ -TARGET_ARCH=arm -TARGET_SYSTBL_ABI=common,oabi -TARGET_SYSTBL=syscall.tbl -TARGET_BIG_ENDIAN=y -TARGET_XML_FILES= arm-core.xml arm-vfp.xml arm-vfp3.xml arm-vfp-sysregs.xml arm-neon.xml arm-m-profile.xml arm-m-profile-mve.xml -TARGET_HAS_BFLT=y -CONFIG_SEMIHOSTING=y -CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y -TARGET_LONG_BITS=32
Signature · 1 line
2.55.0
Quoted 6 lines · Philippe Mathieu-Daudé
Since v1:
- add ./configure error msg
- cover ARM32This series lets qemu-aarch64 run both little- and big-endian ELF binaries, retaining qemu-aarch64_be as a compatibility alias.
Why would we want to do this? qemu-aarch64_be exists, but is essentially unused. It's certainly not supported by upstream Linux.
Having runtime selection of endianness seems silly within that context.
r~
Quoted 11 lines · Richard Henderson
Quoted 6 lines · Philippe Mathieu-Daudé
Since v1:
- add ./configure error msg
- cover ARM32This series lets qemu-aarch64 run both little- and big-endian ELF binaries, retaining qemu-aarch64_be as a compatibility alias.
Why would we want to do this? qemu-aarch64_be exists, but is essentially unused. It's certainly not supported by upstream Linux.
I know the kernel just dropped big-endian kernel support recently, but did that also extend to userspace ?
(We should check with the kernel and gcc folks about whether/when it makes sense to deprecate qemu-aarch64_be.)
Quoted 1 line
Having runtime selection of endianness seems silly within that context.
As a more general question, is this something we would want for architectures where both endiannesses are relevant (e.g. mips, ppc64)? At the moment we consistently for all targets handle big vs little endian as "it's a separate target with its own executable". That's convenient because you can at compile time hardwire in things like variations in struct layout between the two. We could switch to doing that kind of thing at runtime, but what is the benefit we're aiming for by doing that?
thanks
-- PMM
Quoted 22 lines · Peter Maydell
Quoted 11 lines · Richard Henderson
Quoted 6 lines · Philippe Mathieu-Daudé
Since v1:
- add ./configure error msg
- cover ARM32This series lets qemu-aarch64 run both little- and big-endian ELF binaries, retaining qemu-aarch64_be as a compatibility alias.
Why would we want to do this? qemu-aarch64_be exists, but is essentially unused. It's certainly not supported by upstream Linux.
I know the kernel just dropped big-endian kernel support recently, but did that also extend to userspace ?
(We should check with the kernel and gcc folks about whether/when it makes sense to deprecate qemu-aarch64_be.)
Quoted 1 line
Having runtime selection of endianness seems silly within that context.
Quoted 9 lines
As a more general question, is this something we would want for architectures where both endiannesses are relevant (e.g. mips, ppc64)? At the moment we consistently for all targets handle big vs little endian as "it's a separate target with its own executable". That's convenient because you can at compile time hardwire in things like variations in struct layout between the two. We could switch to doing that kind of thing at runtime, but what is the benefit we're aiming for by doing that?
I did the other conversions (Microblaze, Xtensa, PPC, MIPS, SH4) and wanted to test the water first where this would get more attention, with the series involving less changes.
My motivation is MIPS where we currently have 6 binaries and I'd like to add binaries to cover more ABIs without having a combinatory explosion and have 18 linux-user MIPS binaries. With this approach I reduced the current MIPS set to 3 binaries and add 2 more, ending with 5 covering more ABIs instead of currently 6.
In order to get there I need the few core changes introduced in this series, which affect all user binaries. I have the idea ARM users are the first ones interested by no performance change thus is where I started the benchmark to prove this approach have no impact in emulation.
The TargetInfo structure change (one initializer LTO-protected and all accessors via read-only exposed structure) is also what Richard was very keen to have (page size support planned) instead of the current approach.
I'm thus returning the question as: why would we not want to do this?
Regards,
Phil.
Quoted 27 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Peter Maydell
As a more general question, is this something we would want for architectures where both endiannesses are relevant (e.g. mips, ppc64)? At the moment we consistently for all targets handle big vs little endian as "it's a separate target with its own executable". That's convenient because you can at compile time hardwire in things like variations in struct layout between the two. We could switch to doing that kind of thing at runtime, but what is the benefit we're aiming for by doing that?
I did the other conversions (Microblaze, Xtensa, PPC, MIPS, SH4) and wanted to test the water first where this would get more attention, with the series involving less changes.
My motivation is MIPS where we currently have 6 binaries and I'd like to add binaries to cover more ABIs without having a combinatory explosion and have 18 linux-user MIPS binaries. With this approach I reduced the current MIPS set to 3 binaries and add 2 more, ending with 5 covering more ABIs instead of currently 6.
In order to get there I need the few core changes introduced in this series, which affect all user binaries. I have the idea ARM users are the first ones interested by no performance change thus is where I started the benchmark to prove this approach have no impact in emulation.
Quoted 6 lines
The TargetInfo structure change (one initializer LTO-protected and all accessors via read-only exposed structure) is also what Richard was very keen to have (page size support planned) instead of the current approach.
I'm thus returning the question as: why would we not want to do this?
Mostly because what we have today works, and the idea of "the target ABI is known at compile-time" is quite deeply embedded in the way the linux-user code is written (both in terms of ifdefs and also C types being defined appropriately for one specific ABI).
The idea of not having to have 18 different MIPS linux-user binaries is pretty tempting, though.
thanks
-- PMM
Quoted 34 lines · Peter Maydell
Quoted 32 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Peter Maydell
As a more general question, is this something we would want for architectures where both endiannesses are relevant (e.g. mips, ppc64)? At the moment we consistently for all targets handle big vs little endian as "it's a separate target with its own executable". That's convenient because you can at compile time hardwire in things like variations in struct layout between the two. We could switch to doing that kind of thing at runtime, but what is the benefit we're aiming for by doing that?
I did the other conversions (Microblaze, Xtensa, PPC, MIPS, SH4) and wanted to test the water first where this would get more attention, with the series involving less changes.
My motivation is MIPS where we currently have 6 binaries and I'd like to add binaries to cover more ABIs without having a combinatory explosion and have 18 linux-user MIPS binaries. With this approach I reduced the current MIPS set to 3 binaries and add 2 more, ending with 5 covering more ABIs instead of currently 6.
In order to get there I need the few core changes introduced in this series, which affect all user binaries. I have the idea ARM users are the first ones interested by no performance change thus is where I started the benchmark to prove this approach have no impact in emulation.
The TargetInfo structure change (one initializer LTO-protected and all accessors via read-only exposed structure) is also what Richard was very keen to have (page size support planned) instead of the current approach.
Quoted 7 lines
Quoted 1 line
I'm thus returning the question as: why would we not want to do this?
Mostly because what we have today works, and the idea of "the target ABI is known at compile-time" is quite deeply embedded in the way the linux-user code is written (both in terms of ifdefs and also C types being defined appropriately for one specific ABI).
The last part is what we had for system mode, and precisely what we have been able to eliminate while working on the single-binary. We could keep minimal wrappers to previous binaries in case we want to wait a few releases to completely remove them.
In this case, the benefit is that the same existing binary (without endianness variant) will be able to run "more things". Since we talk about user-mode, it's strictly dependent on the program passed in parameter, and we don't need to manually specify endianness anywhere.
For the "how to make sure it works like before?", as usual, testing, and a small leap of faith are required.
Overall, I think it would be a nice move for user-mode.
Quoted 5 lines
The idea of not having to have 18 different MIPS linux-user binaries is pretty tempting, though.
thanks
-- PMM
Regards,
Pierrick
Quoted 38 lines · Pierrick Bouvier
Quoted 36 lines · Peter Maydell
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Peter Maydell
As a more general question, is this something we would want for architectures where both endiannesses are relevant (e.g. mips, ppc64)? At the moment we consistently for all targets handle big vs little endian as "it's a separate target with its own executable". That's convenient because you can at compile time hardwire in things like variations in struct layout between the two. We could switch to doing that kind of thing at runtime, but what is the benefit we're aiming for by doing that?
I did the other conversions (Microblaze, Xtensa, PPC, MIPS, SH4) and wanted to test the water first where this would get more attention, with the series involving less changes.
My motivation is MIPS where we currently have 6 binaries and I'd like to add binaries to cover more ABIs without having a combinatory explosion and have 18 linux-user MIPS binaries. With this approach I reduced the current MIPS set to 3 binaries and add 2 more, ending with 5 covering more ABIs instead of currently 6.
In order to get there I need the few core changes introduced in this series, which affect all user binaries. I have the idea ARM users are the first ones interested by no performance change thus is where I started the benchmark to prove this approach have no impact in emulation.
The TargetInfo structure change (one initializer LTO-protected and all accessors via read-only exposed structure) is also what Richard was very keen to have (page size support planned) instead of the current approach.
I'm thus returning the question as: why would we not want to do this?
Quoted 8 lines
Quoted 5 lines
Mostly because what we have today works, and the idea of "the target ABI is known at compile-time" is quite deeply embedded in the way the linux-user code is written (both in terms of ifdefs and also C types being defined appropriately for one specific ABI).
The last part is what we had for system mode, and precisely what we have been able to eliminate while working on the single-binary.
Yes, but it's taken a lot of work to get to that point. For system mode we had some clear reasons why that work was necessary and worthwhile. For user-mode it's less clear to me. Keeping the zoo of MIPS ABIs under control seems the most promising reason.
For aarch64 in particular I would prefer to deprecate-and-drop big-endian support (probably starting with the deprecation for 12.0, rather than pushing it into 11.2), since the kernel just did that in 7.4.
thanks
-- PMM
Quoted 38 lines · Peter Maydell
Quoted 36 lines · Pierrick Bouvier
Quoted 34 lines · Peter Maydell
Quoted 32 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Peter Maydell
As a more general question, is this something we would want for architectures where both endiannesses are relevant (e.g. mips, ppc64)? At the moment we consistently for all targets handle big vs little endian as "it's a separate target with its own executable". That's convenient because you can at compile time hardwire in things like variations in struct layout between the two. We could switch to doing that kind of thing at runtime, but what is the benefit we're aiming for by doing that?
I did the other conversions (Microblaze, Xtensa, PPC, MIPS, SH4) and wanted to test the water first where this would get more attention, with the series involving less changes.
My motivation is MIPS where we currently have 6 binaries and I'd like to add binaries to cover more ABIs without having a combinatory explosion and have 18 linux-user MIPS binaries. With this approach I reduced the current MIPS set to 3 binaries and add 2 more, ending with 5 covering more ABIs instead of currently 6.
In order to get there I need the few core changes introduced in this series, which affect all user binaries. I have the idea ARM users are the first ones interested by no performance change thus is where I started the benchmark to prove this approach have no impact in emulation.
The TargetInfo structure change (one initializer LTO-protected and all accessors via read-only exposed structure) is also what Richard was very keen to have (page size support planned) instead of the current approach.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
I'm thus returning the question as: why would we not want to do this?
Mostly because what we have today works, and the idea of "the target ABI is known at compile-time" is quite deeply embedded in the way the linux-user code is written (both in terms of ifdefs and also C types being defined appropriately for one specific ABI).
While we could go one step further and manage distincts ABIs at runtime, I don't see the point so far, and that might have some performance impact (although I'm not that sure). While endianness is part of the kernel ABI, the changes are less invasive because we already did them on system path.
Quoted 6 lines
Quoted 2 lines
The last part is what we had for system mode, and precisely what we have been able to eliminate while working on the single-binary.
Yes, but it's taken a lot of work to get to that point. For system mode we had some clear reasons why that work was necessary and worthwhile. For user-mode it's less clear to me.
On that point, I already did the work -- and test / benchmark -- so it isn't an issue ;) The expected review part isn't huge neither.
Quoted 7 lines
Keeping the zoo of MIPS ABIs under control seems the most promising reason.
For aarch64 in particular I would prefer to deprecate-and-drop big-endian support (probably starting with the deprecation for 12.0, rather than pushing it into 11.2), since the kernel just did that in 7.4.
Tangent to this, it makes sense to deprecate quickly enough on QEMU side when a host-related project we use deprecates / removes it; when this is guest related I don't see the urge, in particular when the maintenance is almost zero cost. For the particular aarch64_be I agree what we lacks is coverage testing; but for other features I'd prefer we keep them as long as there is interest within QEMU users, independent of external projects change like the Linux kernel.
Quoted 8 lines · Philippe Mathieu-Daudé
Tangent to this, it makes sense to deprecate quickly enough on QEMU side when a host-related project we use deprecates / removes it; when this is guest related I don't see the urge, in particular when the maintenance is almost zero cost. For the particular
aarch64_beI agree what we lacks is coverage testing; but for other features I'd prefer we keep them as long as there is interest within QEMU users, independent of external projects change like the Linux kernel.
There have been a couple of attempts at aarch64_be, but *never* any upstream traction. qemu-linux-user is about emulating Linux -- you can't divorce these two.
In my opinion, those that want to work on aarch64_be can work in system mode, where the endian switching bits work as required by the architecture.
r~
Quoted 10 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé
Tangent to this, it makes sense to deprecate quickly enough on QEMU side when a host-related project we use deprecates / removes it; when this is guest related I don't see the urge, in particular when the maintenance is almost zero cost. For the particular
aarch64_beI agree what we lacks is coverage testing; but for other features I'd prefer we keep them as long as there is interest within QEMU users, independent of external projects change like the Linux kernel.
Quoted 3 lines
There have been a couple of attempts at
aarch64_be, but *never* any upstream traction. qemu-linux-user is about emulating Linux -- you can't divorce these two.In my opinion, those that want to work on
aarch64_becan work in system mode, where the endian switching bits work as required by the architecture.
OK I'm happy dropping Aarch64_be. Patches 7-10 are still common to all targets and worth review comments :)
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 14 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé
Tangent to this, it makes sense to deprecate quickly enough on QEMU side when a host-related project we use deprecates / removes it; when this is guest related I don't see the urge, in particular when the maintenance is almost zero cost. For the particular
aarch64_beI agree what we lacks is coverage testing; but for other features I'd prefer we keep them as long as there is interest within QEMU users, independent of external projects change like the Linux kernel.There have been a couple of attempts at
aarch64_be, but *never* any upstream traction. qemu-linux-user is about emulating Linux -- you can't divorce these two.
Quoted 6 lines
Quoted 3 lines
In my opinion, those that want to work on
aarch64_becan work in system mode, where the endian switching bits work as required by the architecture.OK I'm happy dropping
Aarch64_be. Patches 7-10 are still common to all targets and worth review comments :)
Beyond aarch64, what about qemu-arm and qemu-armeb?
If we all agree to try to unify that, I would be happy to help review the series.
Regards,
Pierrick
Quoted 6 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Peter Maydell
For aarch64 in particular I would prefer to deprecate-and-drop big-endian support (probably starting with the deprecation for 12.0, rather than pushing it into 11.2), since the kernel just did that in 7.4.
Quoted 8 lines
Tangent to this, it makes sense to deprecate quickly enough on QEMU side when a host-related project we use deprecates / removes it; when this is guest related I don't see the urge, in particular when the maintenance is almost zero cost. For the particular
aarch64_beI agree what we lacks is coverage testing; but for other features I'd prefer we keep them as long as there is interest within QEMU users, independent of external projects change like the Linux kernel.
I'm not in a huge hurry about deprecating aarch64_be (as you say it's not a huge cost to us to carry it, though it is
a small extra amount of compilation time in CI). It's more that I would favour dropping it over doing any future work or refactoring on it. In terms of QEMU user interest, I really don't think we actually have much of it (though of course it's difficult to tell since users don't tell us about stuff that works for them). About the only thing I can remember is
https://gitlab.com/qemu-project/qemu/-/work_items/3958
which is a report from one user that it doesn't work for them at all! (My suspicion is that this is because their userspace is built with some custom local kernel / libc changes which aren't upstream.)
As Richard says, BE AArch64 on Linux has pretty much never been something with much serious interest, and the config has been marked BROKEN in Linux for some time prior to removal. I don't think there is a big stock of BE userspace binaries out there that people want to try to run.
thanks
-- PMM