linux-user/aarch64: Support both endianness at runtime
cover linux-user/aarch64: Support both endianness at runtime
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é (8):
tests/tcg/aarch64_be: Check data byte order in hello linux-user/aarch64: Move ELF/vDSO endian checks to runtime linux-user/aarch64: Move CPU/signal 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 byte orders under qemu-aarch64
docs/about/deprecated.rst | 13 ++++++++ docs/user/main.rst | 7 ++++ configs/targets/aarch64-linux-user.mak | 2 ++ configs/targets/aarch64_be-linux-user.mak | 10 ------ 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 | 2 +- linux-user/qemu.h | 17 +++++++++- linux-user/syscall_defs.h | 7 ---- 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/elfload.c | 6 +--- linux-user/main.c | 26 +++++++++++++++ linux-user/syscall.c | 6 ++-- target-info-def.c | 19 +++++++++++ target/arm/gdbstub64.c | 4 +-- target/arm/tcg/translate-sve.c | 2 +- tests/tcg/aarch64_be/hello.c | 11 ++++--- .gitlab-ci.d/buildtest.yml | 2 +- .gitlab-ci.d/crossbuild-template.yml | 4 +-- linux-user/aarch64/meson.build | 10 +++--- tests/tcg/aarch64_be/meson.build | 4 +-- 28 files changed, 208 insertions(+), 84 deletions(-) delete mode 100644 configs/targets/aarch64_be-linux-user.mak
Signature · 1 line
2.55.0
PATCH 1/8 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 twelve bytes. This detects incorrect CPU data byte order rather than merely accepting the ELF header.
--- tests/tcg/aarch64_be/hello.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
tests/tcg/aarch64_be/hello.c +7 -4
@@ -14,9 +14,10 @@ int write(int fd, char *buf, int len) 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,8 @@ 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 volatile int len =12 ; + +exit (write (1 ,"Hello World\n" , len) !=12 ); }
Signature · 1 line
2.55.0
PATCH 2/8 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 3/8 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 4/8 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 5/8 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 6/8 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 7/8 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 8/8 linux-user/aarch64: Unify both byte orders 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 | 7 +++++++ 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 ++-- 7 files changed, 27 insertions(+), 15 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 byte order from +the ELF header, regardless of the executable name used to invoke it. + linux-user mode CPUs --------------------
docs/user/main.rst +7 -0
@@ -65,6 +65,13 @@ 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. + Command line options ~~~~~~~~~~~~~~~~~~~~
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
Re: [PATCH-for-12.0 8/8] linux-user/aarch64: Unify both byte orders under qemu-aarch64
Quoted 53 lines · 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.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- docs/about/deprecated.rst | 13 +++++++++++++ docs/user/main.rst | 7 +++++++ 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 ++-- 7 files changed, 27 insertions(+), 15 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 byte order from +the ELF header, regardless of the executable name used to invoke it. + linux-user mode CPUs --------------------docs/user/main.rst +0
-0
docs/user/main.rst emulator. · line 74
Quoted 10 lines
docs/user/main.rst +7
-0@@ -65,6 +65,13 @@ 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. +
Squashing:
-- >8 --
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
---