From 553bf7dbd466794955f93c07b5c6fc0a7f65abb4 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Sat, 2 Aug 2025 19:38:28 +1000 Subject: linux-user: Declare elf_core_copy_regs in loader.h Drop the static from all implementations. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/loader.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'linux-user/loader.h') diff --git a/linux-user/loader.h b/linux-user/loader.h index 6482c7c90c..8f4a7f69ac 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -106,4 +106,7 @@ const char *elf_hwcap2_str(uint32_t bit); const char *get_elf_platform(CPUState *cs); const char *get_elf_base_platform(CPUState *cs); +struct target_elf_gregset_t; +void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *); + #endif /* LINUX_USER_LOADER_H */ -- cgit 1.4.1 From 8d4a6f8e4c95e11a3da2e38682da2819d4e2160c Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 29 Jul 2025 09:06:15 -1000 Subject: linux-user: Move init_guest_commpage to x86_64/elfload.c Rename INIT_GUEST_COMMPAGE to HAVE_GUEST_COMMPAGE to match the other HAVE_* defines. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/elfload.c | 23 +---------------------- linux-user/loader.h | 3 +++ linux-user/x86_64/elfload.c | 20 ++++++++++++++++++++ linux-user/x86_64/target_elf.h | 1 + 4 files changed, 25 insertions(+), 22 deletions(-) (limited to 'linux-user/loader.h') diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 07d83c674d..0ba75a83b3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -145,27 +145,6 @@ typedef abi_int target_pid_t; #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_X86_64 -#if ULONG_MAX > UINT32_MAX -#define INIT_GUEST_COMMPAGE -static bool init_guest_commpage(void) -{ - /* - * The vsyscall page is at a high negative address aka kernel space, - * which means that we cannot actually allocate it with target_mmap. - * We still should be able to use page_set_flags, unless the user - * has specified -R reserved_va, which would trigger an assert(). - */ - if (reserved_va != 0 && - TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) { - error_report("Cannot allocate vsyscall page"); - exit(EXIT_FAILURE); - } - page_set_flags(TARGET_VSYSCALL_PAGE, - TARGET_VSYSCALL_PAGE | ~TARGET_PAGE_MASK, - PAGE_EXEC | PAGE_VALID); - return true; -} -#endif #else /* @@ -1215,7 +1194,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, #else #define HI_COMMPAGE 0 #define LO_COMMPAGE -1 -#ifndef INIT_GUEST_COMMPAGE +#ifndef HAVE_GUEST_COMMPAGE #define init_guest_commpage() true #endif #endif diff --git a/linux-user/loader.h b/linux-user/loader.h index 8f4a7f69ac..98015fba7d 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -105,6 +105,9 @@ const char *elf_hwcap_str(uint32_t bit); const char *elf_hwcap2_str(uint32_t bit); const char *get_elf_platform(CPUState *cs); const char *get_elf_base_platform(CPUState *cs); +#if defined(TARGET_X86_64) +bool init_guest_commpage(void); +#endif struct target_elf_gregset_t; void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *); diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c index 12de1c54c7..1e7000c6bc 100644 --- a/linux-user/x86_64/elfload.c +++ b/linux-user/x86_64/elfload.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "qemu.h" #include "loader.h" #include "target_elf.h" @@ -21,6 +22,25 @@ const char *get_elf_platform(CPUState *cs) return "x86_64"; } +bool init_guest_commpage(void) +{ + /* + * The vsyscall page is at a high negative address aka kernel space, + * which means that we cannot actually allocate it with target_mmap. + * We still should be able to use page_set_flags, unless the user + * has specified -R reserved_va, which would trigger an assert(). + */ + if (reserved_va != 0 && + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) { + error_report("Cannot allocate vsyscall page"); + exit(EXIT_FAILURE); + } + page_set_flags(TARGET_VSYSCALL_PAGE, + TARGET_VSYSCALL_PAGE | ~TARGET_PAGE_MASK, + PAGE_EXEC | PAGE_VALID); + return true; +} + void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env) { r->pt.r15 = tswapal(env->regs[15]); diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h index 32a9eec431..f05b1d4dba 100644 --- a/linux-user/x86_64/target_elf.h +++ b/linux-user/x86_64/target_elf.h @@ -13,6 +13,7 @@ #define HAVE_ELF_HWCAP 1 #define HAVE_ELF_PLATFORM 1 #define HAVE_ELF_CORE_DUMP 1 +#define HAVE_GUEST_COMMPAGE 1 /* * See linux kernel: arch/x86/include/asm/elf.h, where -- cgit 1.4.1 From a56ef5e8454e42c0d263a97a1297ae67f4ce19cd Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 29 Jul 2025 09:11:12 -1000 Subject: linux-user: Move init_guest_commpage to arm/elfload.c Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/arm/elfload.c | 46 +++++++++++++++++++++++++++++++++++++++++++ linux-user/arm/target_elf.h | 2 ++ linux-user/elfload.c | 48 --------------------------------------------- linux-user/loader.h | 2 +- 4 files changed, 49 insertions(+), 49 deletions(-) (limited to 'linux-user/loader.h') diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c index f811c2f07a..1205687976 100644 --- a/linux-user/arm/elfload.c +++ b/linux-user/arm/elfload.c @@ -3,6 +3,8 @@ #include "qemu/osdep.h" #include "qemu.h" #include "loader.h" +#include "user-internals.h" +#include "target_elf.h" #include "target/arm/cpu-features.h" #include "target_elf.h" @@ -201,6 +203,50 @@ const char *get_elf_platform(CPUState *cs) #undef END } +bool init_guest_commpage(void) +{ + ARMCPU *cpu = ARM_CPU(thread_cpu); + int host_page_size = qemu_real_host_page_size(); + abi_ptr commpage; + void *want; + void *addr; + + /* + * M-profile allocates maximum of 2GB address space, so can never + * allocate the commpage. Skip it. + */ + if (arm_feature(&cpu->env, ARM_FEATURE_M)) { + return true; + } + + commpage = HI_COMMPAGE & -host_page_size; + want = g2h_untagged(commpage); + addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | + (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE), + -1, 0); + + if (addr == MAP_FAILED) { + perror("Allocating guest commpage"); + exit(EXIT_FAILURE); + } + if (addr != want) { + return false; + } + + /* Set kernel helper versions; rest of page is 0. */ + __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); + + if (mprotect(addr, host_page_size, PROT_READ)) { + perror("Protecting guest commpage"); + exit(EXIT_FAILURE); + } + + page_set_flags(commpage, commpage | (host_page_size - 1), + PAGE_READ | PAGE_EXEC | PAGE_VALID); + return true; +} + void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env) { for (int i = 0; i < 16; ++i) { diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h index fa8f8af2f3..5f81a43efb 100644 --- a/linux-user/arm/target_elf.h +++ b/linux-user/arm/target_elf.h @@ -15,6 +15,8 @@ #define HAVE_ELF_PLATFORM 1 #define HAVE_ELF_CORE_DUMP 1 +#define HI_COMMPAGE ((intptr_t)0xffff0f00u) + /* * See linux kernel: arch/arm/include/asm/elf.h, where * elf_gregset_t is mapped to struct pt_regs via sizeof. diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0ba75a83b3..2281853c57 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -191,54 +191,6 @@ typedef abi_int target_pid_t; #define ELF_EXEC_PAGESIZE 4096 -/* The commpage only exists for 32 bit kernels */ - -#define HI_COMMPAGE (intptr_t)0xffff0f00u - -static bool init_guest_commpage(void) -{ - ARMCPU *cpu = ARM_CPU(thread_cpu); - int host_page_size = qemu_real_host_page_size(); - abi_ptr commpage; - void *want; - void *addr; - - /* - * M-profile allocates maximum of 2GB address space, so can never - * allocate the commpage. Skip it. - */ - if (arm_feature(&cpu->env, ARM_FEATURE_M)) { - return true; - } - - commpage = HI_COMMPAGE & -host_page_size; - want = g2h_untagged(commpage); - addr = mmap(want, host_page_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | - (commpage < reserved_va ? MAP_FIXED : MAP_FIXED_NOREPLACE), - -1, 0); - - if (addr == MAP_FAILED) { - perror("Allocating guest commpage"); - exit(EXIT_FAILURE); - } - if (addr != want) { - return false; - } - - /* Set kernel helper versions; rest of page is 0. */ - __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); - - if (mprotect(addr, host_page_size, PROT_READ)) { - perror("Protecting guest commpage"); - exit(EXIT_FAILURE); - } - - page_set_flags(commpage, commpage | (host_page_size - 1), - PAGE_READ | PAGE_EXEC | PAGE_VALID); - return true; -} - #if TARGET_BIG_ENDIAN #include "elf.h" #include "vdso-be8.c.inc" diff --git a/linux-user/loader.h b/linux-user/loader.h index 98015fba7d..0c2cc556c3 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -105,7 +105,7 @@ const char *elf_hwcap_str(uint32_t bit); const char *elf_hwcap2_str(uint32_t bit); const char *get_elf_platform(CPUState *cs); const char *get_elf_base_platform(CPUState *cs); -#if defined(TARGET_X86_64) +#if defined(TARGET_X86_64) || defined(TARGET_ARM) bool init_guest_commpage(void); #endif -- cgit 1.4.1 From 6a91f64ee12fe54d1a9573e9ecbbae037b113097 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 29 Jul 2025 09:13:54 -1000 Subject: linux-user: Move init_guest_commpage to hppa/elfload.c Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/elfload.c | 32 -------------------------------- linux-user/hppa/elfload.c | 31 +++++++++++++++++++++++++++++++ linux-user/hppa/target_elf.h | 2 ++ linux-user/loader.h | 2 -- 4 files changed, 33 insertions(+), 34 deletions(-) (limited to 'linux-user/loader.h') diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2281853c57..25f29e60de 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -415,38 +415,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags) #define VDSO_HEADER "vdso.c.inc" -#define LO_COMMPAGE 0 - -static bool init_guest_commpage(void) -{ - /* If reserved_va, then we have already mapped 0 page on the host. */ - if (!reserved_va) { - void *want, *addr; - - want = g2h_untagged(LO_COMMPAGE); - addr = mmap(want, TARGET_PAGE_SIZE, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0); - if (addr == MAP_FAILED) { - perror("Allocating guest commpage"); - exit(EXIT_FAILURE); - } - if (addr != want) { - return false; - } - } - - /* - * On Linux, page zero is normally marked execute only + gateway. - * Normal read or write is supposed to fail (thus PROT_NONE above), - * but specific offsets have kernel code mapped to raise permissions - * and implement syscalls. Here, simply mark the page executable. - * Special case the entry points during translation (see do_page_zero). - */ - page_set_flags(LO_COMMPAGE, LO_COMMPAGE | ~TARGET_PAGE_MASK, - PAGE_EXEC | PAGE_VALID); - return true; -} - #endif /* TARGET_HPPA */ #ifdef TARGET_XTENSA diff --git a/linux-user/hppa/elfload.c b/linux-user/hppa/elfload.c index 9dd3fe092a..018034f244 100644 --- a/linux-user/hppa/elfload.c +++ b/linux-user/hppa/elfload.c @@ -3,6 +3,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "loader.h" +#include "target_elf.h" const char *get_elf_cpu_model(uint32_t eflags) @@ -14,3 +15,33 @@ const char *get_elf_platform(CPUState *cs) { return "PARISC"; } + +bool init_guest_commpage(void) +{ + /* If reserved_va, then we have already mapped 0 page on the host. */ + if (!reserved_va) { + void *want, *addr; + + want = g2h_untagged(LO_COMMPAGE); + addr = mmap(want, TARGET_PAGE_SIZE, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0); + if (addr == MAP_FAILED) { + perror("Allocating guest commpage"); + exit(EXIT_FAILURE); + } + if (addr != want) { + return false; + } + } + + /* + * On Linux, page zero is normally marked execute only + gateway. + * Normal read or write is supposed to fail (thus PROT_NONE above), + * but specific offsets have kernel code mapped to raise permissions + * and implement syscalls. Here, simply mark the page executable. + * Special case the entry points during translation (see do_page_zero). + */ + page_set_flags(LO_COMMPAGE, LO_COMMPAGE | ~TARGET_PAGE_MASK, + PAGE_EXEC | PAGE_VALID); + return true; +} diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h index 85be00584d..b654758afa 100644 --- a/linux-user/hppa/target_elf.h +++ b/linux-user/hppa/target_elf.h @@ -10,4 +10,6 @@ #define HAVE_ELF_PLATFORM 1 +#define LO_COMMPAGE 0 + #endif diff --git a/linux-user/loader.h b/linux-user/loader.h index 0c2cc556c3..c3b8f92e23 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -105,9 +105,7 @@ const char *elf_hwcap_str(uint32_t bit); const char *elf_hwcap2_str(uint32_t bit); const char *get_elf_platform(CPUState *cs); const char *get_elf_base_platform(CPUState *cs); -#if defined(TARGET_X86_64) || defined(TARGET_ARM) bool init_guest_commpage(void); -#endif struct target_elf_gregset_t; void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *); -- cgit 1.4.1 From 71cc79a4a172d28638ad27a4e6327a4ce1bcdf2b Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 29 Jul 2025 09:33:51 -1000 Subject: linux-user: Move get_vdso_image_info to arm/elfload.c Rename from vdso_image_info to avoid a symbol clash. Define HAVE_VDSO_IMAGE_INFO to signal the external definition exists. Provide fallback versions for other targets. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/arm/elfload.c | 20 ++++++++++++++++++++ linux-user/arm/target_elf.h | 1 + linux-user/elfload.c | 41 +++++++++-------------------------------- linux-user/loader.h | 12 ++++++++++++ 4 files changed, 42 insertions(+), 32 deletions(-) (limited to 'linux-user/loader.h') diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c index 1205687976..308ed23fcb 100644 --- a/linux-user/arm/elfload.c +++ b/linux-user/arm/elfload.c @@ -7,6 +7,7 @@ #include "target_elf.h" #include "target/arm/cpu-features.h" #include "target_elf.h" +#include "elf.h" const char *get_elf_cpu_model(uint32_t eflags) @@ -255,3 +256,22 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env) r->pt.cpsr = tswapal(cpsr_read((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 + return &vdso_image_info; +#endif +} diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h index 5f81a43efb..19fdfa2f2c 100644 --- a/linux-user/arm/target_elf.h +++ b/linux-user/arm/target_elf.h @@ -14,6 +14,7 @@ #define HAVE_ELF_HWCAP2 1 #define HAVE_ELF_PLATFORM 1 #define HAVE_ELF_CORE_DUMP 1 +#define HAVE_VDSO_IMAGE_INFO 1 #define HI_COMMPAGE ((intptr_t)0xffff0f00u) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 81bf05f581..aed390ebb3 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -40,15 +40,6 @@ #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0 #endif -typedef struct { - const uint8_t *image; - const uint32_t *relocs; - unsigned image_size; - unsigned reloc_count; - unsigned sigreturn_ofs; - unsigned rt_sigreturn_ofs; -} VdsoImageInfo; - #define ELF_OSABI ELFOSABI_SYSV /* from personality.h */ @@ -191,23 +182,6 @@ typedef abi_int target_pid_t; #define ELF_EXEC_PAGESIZE 4096 -#if TARGET_BIG_ENDIAN -#include "elf.h" -#include "vdso-be8.c.inc" -#include "vdso-be32.c.inc" - -static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags) -{ - return (EF_ARM_EABI_VERSION(elf_flags) >= EF_ARM_EABI_VER4 - && (elf_flags & EF_ARM_BE8) - ? &vdso_be8_image_info - : &vdso_be32_image_info); -} -#define vdso_image_info vdso_image_info -#else -# define VDSO_HEADER "vdso-le.c.inc" -#endif - #else /* 64 bit ARM definitions */ @@ -1973,14 +1947,17 @@ static void load_elf_interp(const char *filename, struct image_info *info, load_elf_image(filename, &src, info, &ehdr, NULL); } -#ifndef vdso_image_info +#ifndef HAVE_VDSO_IMAGE_INFO +const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags) +{ #ifdef VDSO_HEADER #include VDSO_HEADER -#define vdso_image_info(flags) &vdso_image_info + return &vdso_image_info; #else -#define vdso_image_info(flags) NULL -#endif /* VDSO_HEADER */ -#endif /* vdso_image_info */ + return NULL; +#endif +} +#endif /* HAVE_VDSO_IMAGE_INFO */ static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso) { @@ -2311,7 +2288,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * Load a vdso if available, which will amongst other things contain the * signal trampolines. Otherwise, allocate a separate page for them. */ - const VdsoImageInfo *vdso = vdso_image_info(info->elf_flags); + const VdsoImageInfo *vdso = get_vdso_image_info(info->elf_flags); if (vdso) { load_elf_vdso(&vdso_info, vdso); info->vdso = vdso_info.load_bias; diff --git a/linux-user/loader.h b/linux-user/loader.h index c3b8f92e23..2175dd4e0a 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -110,4 +110,16 @@ bool init_guest_commpage(void); struct target_elf_gregset_t; void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *); +typedef struct { + const uint8_t *image; + const uint32_t *relocs; + unsigned image_size; + unsigned reloc_count; + unsigned sigreturn_ofs; + unsigned rt_sigreturn_ofs; +} VdsoImageInfo; + +/* Note that both Elf32_Word and Elf64_Word are uint32_t. */ +const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags); + #endif /* LINUX_USER_LOADER_H */ -- cgit 1.4.1 From 8218eb6f52abd08c9e89baafdddec6f0d9234768 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Tue, 29 Jul 2025 11:43:27 -1000 Subject: linux-user: Move arch_parse_elf_property to aarch64/elfload.c Rename the controlling macro to HAVE_ELF_GNU_PROPERTY to match the other HAVE_* macros. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/aarch64/elfload.c | 18 ++++++++++++++++++ linux-user/aarch64/target_elf.h | 1 + linux-user/elfload.c | 39 ++++++++------------------------------- linux-user/loader.h | 5 +++++ 4 files changed, 32 insertions(+), 31 deletions(-) (limited to 'linux-user/loader.h') diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c index 07a0c3f844..8076968251 100644 --- a/linux-user/aarch64/elfload.c +++ b/linux-user/aarch64/elfload.c @@ -1,10 +1,12 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #include "qemu/osdep.h" +#include "qapi/error.h" #include "qemu.h" #include "loader.h" #include "target/arm/cpu-features.h" #include "target_elf.h" +#include "elf.h" const char *get_elf_cpu_model(uint32_t eflags) @@ -349,6 +351,22 @@ const char *get_elf_platform(CPUState *cs) return TARGET_BIG_ENDIAN ? "aarch64_be" : "aarch64"; } +bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, + const uint32_t *data, + struct image_info *info, + Error **errp) +{ + if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { + if (pr_datasz != sizeof(uint32_t)) { + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); + return false; + } + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ + info->note_flags = *data; + } + return true; +} + void elf_core_copy_regs(target_elf_gregset_t *r, const CPUARMState *env) { for (int i = 0; i < 31; i++) { diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h index 9ec51f6237..4cdeb64b0d 100644 --- a/linux-user/aarch64/target_elf.h +++ b/linux-user/aarch64/target_elf.h @@ -17,6 +17,7 @@ #define HAVE_ELF_HWCAP2 1 #define HAVE_ELF_PLATFORM 1 #define HAVE_ELF_CORE_DUMP 1 +#define HAVE_ELF_GNU_PROPERTY 1 /* * See linux kernel: arch/arm64/include/asm/elf.h, where diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 8b92fba0f0..12d4873212 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -166,41 +166,18 @@ const char *get_elf_platform(CPUState *cs) { return NULL; } const char *get_elf_base_platform(CPUState *cs) { return NULL; } #endif -#include "elf.h" - -/* We must delay the following stanzas until after "elf.h". */ -#if defined(TARGET_AARCH64) - -static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, - const uint32_t *data, - struct image_info *info, - Error **errp) -{ - if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { - if (pr_datasz != sizeof(uint32_t)) { - error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); - return false; - } - /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ - info->note_flags = *data; - } - return true; -} -#define ARCH_USE_GNU_PROPERTY 1 - -#else - -static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, - const uint32_t *data, - struct image_info *info, - Error **errp) +#ifndef HAVE_ELF_GNU_PROPERTY +bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, + const uint32_t *data, struct image_info *info, + Error **errp) { g_assert_not_reached(); } -#define ARCH_USE_GNU_PROPERTY 0 - +#define HAVE_ELF_GNU_PROPERTY 0 #endif +#include "elf.h" + struct exec { unsigned int a_info; /* Use macros N_MAGIC, etc for access */ @@ -1233,7 +1210,7 @@ static bool parse_elf_properties(const ImageSource *src, uint32_t prev_type; /* Unless the arch requires properties, ignore them. */ - if (!ARCH_USE_GNU_PROPERTY) { + if (!HAVE_ELF_GNU_PROPERTY) { return true; } diff --git a/linux-user/loader.h b/linux-user/loader.h index 2175dd4e0a..e42b8fa1e3 100644 --- a/linux-user/loader.h +++ b/linux-user/loader.h @@ -122,4 +122,9 @@ typedef struct { /* Note that both Elf32_Word and Elf64_Word are uint32_t. */ const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags); +bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, + const uint32_t *data, + struct image_info *info, + Error **errp); + #endif /* LINUX_USER_LOADER_H */ -- cgit 1.4.1