qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-10.2 00/89] linux-user: Split up elfload.c
@ 2025-07-29 23:58 Richard Henderson
  2025-07-29 23:58 ` [PATCH 01/89] linux-user: Create target/elfload.c files Richard Henderson
                   ` (89 more replies)
  0 siblings, 90 replies; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

The goal is to kill the massive target ifdef ladder in elfload.c.

The functions get moved to linux-user/target/elfload.c.
Define weak functions to provide a default value, or a
weak reference to determine if the function is provided.

The core dump types and functions are moved to
linux-user/target/target_coredump.h.

The macros get moved to linux-user/target/target_elf.h.
These are mostly use to parameterize include/elf.h, but
there are some other outliers.

The init_thread functions, storing into target_pt_regs, have been
merged with target_cpu_copy_regs, copying out of target_pt_regs
into CPUArchState.  Merging these found a few bits of silliness
where pt_regs fields were initialized but not used.  To encourage
this never to return, remove most target_pt_regs and hide the rest
within the relevant signal.c.


r~


Richard Henderson (89):
  linux-user: Create target/elfload.c files
  linux-user: Move get_elf_hwcap to {i386,x86_64}/elfload.c
  linux-user: Move hwcap functions to {arm,aarch64}/elfload.c
  linux-user: Move get_elf_hwcap to sparc/elfload.c
  linux-user: Move hwcap functions to ppc/elfload.c
  linux-user: Move get_elf_hwcap to loongarch64/elfload.c
  linux-user: Move get_elf_hwcap to mips/elfload.c
  linux-user: Move get_elf_hwcap to sh4/elfload.c
  linux-user: Move hwcap functions to s390x/elfload.c
  linux-user: Move get_elf_hwcap to riscv/elfload.c
  linux-user: Remove ELF_HWCAP
  linux-user: Remove ELF_HWCAP2
  linux-user: Move get_elf_platform to {i386,x86_64}/elfload.c
  linux-user/i386: Return const data from get_elf_platform
  linux-user: Move get_elf_platform to arm/elfload.c
  linux-user/loongarch64: Create get_elf_platform
  linux-user/hppa: Create get_elf_platform
  linux-user: Remove ELF_PLATFORM
  linux-user: Move get_elf_base_platform to mips/elfload.c
  linux-user: Move target_cpu_copy_regs decl to qemu.h
  linux-user: Unify init of semihosting fields in TaskState
  linux-user: Create do_init_main_thread
  linux-user/i386: Create init_main_thread
  linux-user/arm: Create init_main_thread
  linux-user/aarch64: Create init_main_thread
  linux-user/sparc: Create init_main_thread
  linux-user/ppc: Create init_main_thread
  linux-user/loongarch64: Create init_main_thread
  linux-user/mips: Create init_main_thread
  linux-user/microblaze: Create init_main_thread
  linux-user/openrisc: Create init_main_thread
  linux-user/sh4: Create init_main_thread
  linux-user/m68k: Create init_main_thread
  linux-user/alpha: Create init_main_thread
  linux-user/s390x: Create init_main_thread
  linux-user/riscv: Create init_main_thread
  linux-user/hppa: Create init_main_thread
  linux-user/xtensa: Create init_main_thread
  linux-user/hexagon: Create init_main_thread
  linux-user: Remove do_init_main_thread
  linux-user/x86_64: Split out target_coredump.c.inc
  linux-user/i386: Split out target_coredump.c.inc
  linux-user/arm: Split out target_coredump.c.inc
  linux-user/aarch64: Split out target_coredump.c.inc
  linux-user/ppc: Split out target_coredump.c.inc
  linux-user/loongarch64: Split out target_coredump.c.inc
  linux-user/mips: Split out target_coredump.c.inc
  linux-user/microblaze: Split out target_coredump.c.inc
  target/openrisc: Split out target_coredump.c.inc
  target/sh4: Split out target_coredump.c.inc
  linux-user/m68k: Split out target_coredump.c.inc
  linux-user/s390x: Split out target_coredump.c.inc
  linux-user/xtensa: Split out target_coredump.c.inc
  linux-user: Unify the include of target_coredump.c.inc
  linux-user: Move init_guest_commpage to x86_64/elfload.c
  linux-user: Move init_guest_commpage to arm/elfload.c
  linux-user: Move init_guest_commpage to hppa/elfload.c
  linux-user: Remove INIT_GUEST_COMMPAGE
  linux-user: Move get_vdso_image_info to arm/elfload.c
  linux-user: Remove ELF_EXEC_PAGESIZE
  linux-user: Move get_elf_cpu_model to target/elfload.c
  linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h
  linux-user: Move elf parameters to {i386,x86_64}/target_elf.h
  linux-user: Move elf parameters to {arm,aarch64}/target_elf.h
  linux-user: Move elf parameters to sparc/target_elf.h
  linux-user: Move elf parameters to ppc/target_elf.h
  linux-user: Move elf parameters to loongarch64/target_elf.h
  linux-user: Move elf parameters to {mips,mips64}/target_elf.h
  linux-user: Move elf parameters to microblaze/target_elf.h
  linux-user: Move elf parameters to openrisc/target_elf.h
  linux-user: Move elf parameters to sh4/target_elf.h
  linux-user: Move elf parameters to m68k/target_elf.h
  linux-user: Move elf parameters to alpha/target_elf.h
  linux-user: Move elf parameters to s390x/target_elf.h
  linux-user: Move elf parameters to riscv/target_elf.h
  linux-user: Move elf parameters to hppa/target_elf.h
  linux-user: Move elf parameters to xtensa/target_elf.h
  linux-user: Move elf parameters to hexagon/target_elf.h
  linux-user: Standardize on ELF_MACHINE not ELF_ARCH
  linux-user: Rename elf_check_arch
  linux-user: Remove ELIBBAD from elfload.c
  linux-user: Remove MAP_DENYWRITE from elfload.c
  linux-user: Move arch_parse_elf_property to aarch64/elfload.c
  linux-user: Remove a.out declarations from elfload.c
  linux-user/sparc: Move target_pt_regs to signal.c
  linux-user/microblaze: Move target_pt_regs to signal.c
  linux-user/openrisc: Move target_pt_regs to signal.c
  linux-user/s390x: Move target_psw_t to signal.c
  linux-user: Remove struct target_pt_regs from target_syscall.h

 include/qemu/osdep.h                         |    8 +
 include/user/cpu_loop.h                      |    4 -
 linux-user/aarch64/target_elf.h              |   16 +-
 linux-user/aarch64/target_syscall.h          |    7 -
 linux-user/alpha/target_elf.h                |    8 +-
 linux-user/alpha/target_syscall.h            |   40 -
 linux-user/arm/target_elf.h                  |   12 +-
 linux-user/arm/target_proc.h                 |    4 +-
 linux-user/arm/target_syscall.h              |    8 -
 linux-user/hexagon/target_elf.h              |   30 +-
 linux-user/hexagon/target_syscall.h          |    5 -
 linux-user/hppa/target_elf.h                 |   13 +-
 linux-user/hppa/target_syscall.h             |   18 -
 linux-user/i386/target_elf.h                 |   28 +-
 linux-user/i386/target_syscall.h             |   18 -
 linux-user/loader.h                          |   33 +-
 linux-user/loongarch64/target_elf.h          |   11 +-
 linux-user/loongarch64/target_syscall.h      |   23 -
 linux-user/m68k/target_elf.h                 |   13 +-
 linux-user/m68k/target_syscall.h             |   16 -
 linux-user/microblaze/target_elf.h           |   10 +-
 linux-user/microblaze/target_syscall.h       |   44 -
 linux-user/mips/target_elf.h                 |   16 +-
 linux-user/mips/target_syscall.h             |   19 -
 linux-user/mips64/target_elf.h               |   39 +-
 linux-user/mips64/target_syscall.h           |   16 -
 linux-user/openrisc/target_elf.h             |    9 +-
 linux-user/openrisc/target_syscall.h         |   11 -
 linux-user/ppc/target_elf.h                  |   45 +-
 linux-user/ppc/target_syscall.h              |   28 -
 linux-user/qemu.h                            |    6 +-
 linux-user/riscv/target_elf.h                |   15 +-
 linux-user/riscv/target_syscall.h            |   35 -
 linux-user/s390x/target_elf.h                |   11 +-
 linux-user/s390x/target_proc.h               |    2 +-
 linux-user/s390x/target_syscall.h            |   22 -
 linux-user/sh4/target_elf.h                  |    9 +-
 linux-user/sh4/target_syscall.h              |   11 -
 linux-user/sparc/target_elf.h                |   16 +-
 linux-user/sparc/target_syscall.h            |   19 -
 linux-user/x86_64/target_elf.h               |   10 +-
 linux-user/x86_64/target_syscall.h           |   28 -
 linux-user/xtensa/target_elf.h               |    7 +-
 linux-user/xtensa/target_syscall.h           |   35 -
 linux-user/aarch64/cpu_loop.c                |   22 +-
 linux-user/aarch64/elfload.c                 |  367 +++
 linux-user/alpha/cpu_loop.c                  |   11 +-
 linux-user/alpha/elfload.c                   |   11 +
 linux-user/arm/cpu_loop.c                    |   80 +-
 linux-user/arm/elfload.c                     |  267 +++
 linux-user/elfload.c                         | 2116 +-----------------
 linux-user/hexagon/cpu_loop.c                |    8 +-
 linux-user/hexagon/elfload.c                 |   35 +
 linux-user/hppa/cpu_loop.c                   |   18 +-
 linux-user/hppa/elfload.c                    |   47 +
 linux-user/i386/cpu_loop.c                   |   31 +-
 linux-user/i386/elfload.c                    |   25 +
 linux-user/linuxload.c                       |    6 +-
 linux-user/loongarch64/cpu_loop.c            |   11 +-
 linux-user/loongarch64/elfload.c             |   63 +
 linux-user/m68k/cpu_loop.c                   |   32 +-
 linux-user/m68k/elfload.c                    |   18 +
 linux-user/main.c                            |   18 +-
 linux-user/microblaze/cpu_loop.c             |   39 +-
 linux-user/microblaze/elfload.c              |   11 +
 linux-user/microblaze/signal.c               |   44 +
 linux-user/mips/cpu_loop.c                   |   16 +-
 linux-user/mips/elfload.c                    |  124 +
 linux-user/mips64/elfload.c                  |    1 +
 linux-user/openrisc/cpu_loop.c               |   11 +-
 linux-user/openrisc/elfload.c                |   11 +
 linux-user/openrisc/signal.c                 |   12 +
 linux-user/ppc/cpu_loop.c                    |   26 +-
 linux-user/ppc/elfload.c                     |  131 ++
 linux-user/riscv/cpu_loop.c                  |   15 +-
 linux-user/riscv/elfload.c                   |   23 +
 linux-user/s390x/cpu_loop.c                  |   15 +-
 linux-user/s390x/elfload.c                   |   68 +
 linux-user/s390x/signal.c                    |    5 +
 linux-user/sh4/cpu_loop.c                    |   10 +-
 linux-user/sh4/elfload.c                     |   38 +
 linux-user/sparc/cpu_loop.c                  |   16 +-
 linux-user/sparc/elfload.c                   |   42 +
 linux-user/sparc/signal.c                    |   20 +
 linux-user/x86_64/elfload.c                  |   41 +
 linux-user/xtensa/cpu_loop.c                 |   22 +-
 linux-user/xtensa/elfload.c                  |   11 +
 linux-user/aarch64/target_coredump.c.inc     |   14 +
 linux-user/arm/target_coredump.c.inc         |   28 +
 linux-user/i386/target_coredump.c.inc        |   32 +
 linux-user/loongarch64/target_coredump.c.inc |   24 +
 linux-user/m68k/target_coredump.c.inc        |   30 +
 linux-user/microblaze/target_coredump.c.inc  |   21 +
 linux-user/mips/target_coredump.c.inc        |   46 +
 linux-user/mips64/target_coredump.c.inc      |    1 +
 linux-user/openrisc/target_coredump.c.inc    |   15 +
 linux-user/ppc/target_coredump.c.inc         |   24 +
 linux-user/s390x/target_coredump.c.inc       |   31 +
 linux-user/sh4/target_coredump.c.inc         |   32 +
 linux-user/x86_64/target_coredump.c.inc      |   42 +
 linux-user/xtensa/target_coredump.c.inc      |   38 +
 meson.build                                  |    6 +-
 102 files changed, 2259 insertions(+), 2841 deletions(-)
 create mode 100644 linux-user/aarch64/elfload.c
 create mode 100644 linux-user/alpha/elfload.c
 create mode 100644 linux-user/arm/elfload.c
 create mode 100644 linux-user/hexagon/elfload.c
 create mode 100644 linux-user/hppa/elfload.c
 create mode 100644 linux-user/i386/elfload.c
 create mode 100644 linux-user/loongarch64/elfload.c
 create mode 100644 linux-user/m68k/elfload.c
 create mode 100644 linux-user/microblaze/elfload.c
 create mode 100644 linux-user/mips/elfload.c
 create mode 100644 linux-user/mips64/elfload.c
 create mode 100644 linux-user/openrisc/elfload.c
 create mode 100644 linux-user/ppc/elfload.c
 create mode 100644 linux-user/riscv/elfload.c
 create mode 100644 linux-user/s390x/elfload.c
 create mode 100644 linux-user/sh4/elfload.c
 create mode 100644 linux-user/sparc/elfload.c
 create mode 100644 linux-user/x86_64/elfload.c
 create mode 100644 linux-user/xtensa/elfload.c
 create mode 100644 linux-user/aarch64/target_coredump.c.inc
 create mode 100644 linux-user/arm/target_coredump.c.inc
 create mode 100644 linux-user/i386/target_coredump.c.inc
 create mode 100644 linux-user/loongarch64/target_coredump.c.inc
 create mode 100644 linux-user/m68k/target_coredump.c.inc
 create mode 100644 linux-user/microblaze/target_coredump.c.inc
 create mode 100644 linux-user/mips/target_coredump.c.inc
 create mode 100644 linux-user/mips64/target_coredump.c.inc
 create mode 100644 linux-user/openrisc/target_coredump.c.inc
 create mode 100644 linux-user/ppc/target_coredump.c.inc
 create mode 100644 linux-user/s390x/target_coredump.c.inc
 create mode 100644 linux-user/sh4/target_coredump.c.inc
 create mode 100644 linux-user/x86_64/target_coredump.c.inc
 create mode 100644 linux-user/xtensa/target_coredump.c.inc

-- 
2.43.0



^ permalink raw reply	[flat|nested] 187+ messages in thread

* [PATCH 01/89] linux-user: Create target/elfload.c files
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:47   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 02/89] linux-user: Move get_elf_hwcap to {i386, x86_64}/elfload.c Richard Henderson
                   ` (88 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Prepare to split the main linux-user/elfload.c.
Create empty files for each target, and add the
common build rule.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/elfload.c     | 1 +
 linux-user/alpha/elfload.c       | 1 +
 linux-user/arm/elfload.c         | 1 +
 linux-user/hexagon/elfload.c     | 1 +
 linux-user/hppa/elfload.c        | 1 +
 linux-user/i386/elfload.c        | 1 +
 linux-user/loongarch64/elfload.c | 1 +
 linux-user/m68k/elfload.c        | 1 +
 linux-user/microblaze/elfload.c  | 1 +
 linux-user/mips/elfload.c        | 1 +
 linux-user/mips64/elfload.c      | 1 +
 linux-user/openrisc/elfload.c    | 1 +
 linux-user/ppc/elfload.c         | 1 +
 linux-user/riscv/elfload.c       | 1 +
 linux-user/s390x/elfload.c       | 1 +
 linux-user/sh4/elfload.c         | 1 +
 linux-user/sparc/elfload.c       | 1 +
 linux-user/x86_64/elfload.c      | 1 +
 linux-user/xtensa/elfload.c      | 1 +
 meson.build                      | 6 +++++-
 20 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 linux-user/aarch64/elfload.c
 create mode 100644 linux-user/alpha/elfload.c
 create mode 100644 linux-user/arm/elfload.c
 create mode 100644 linux-user/hexagon/elfload.c
 create mode 100644 linux-user/hppa/elfload.c
 create mode 100644 linux-user/i386/elfload.c
 create mode 100644 linux-user/loongarch64/elfload.c
 create mode 100644 linux-user/m68k/elfload.c
 create mode 100644 linux-user/microblaze/elfload.c
 create mode 100644 linux-user/mips/elfload.c
 create mode 100644 linux-user/mips64/elfload.c
 create mode 100644 linux-user/openrisc/elfload.c
 create mode 100644 linux-user/ppc/elfload.c
 create mode 100644 linux-user/riscv/elfload.c
 create mode 100644 linux-user/s390x/elfload.c
 create mode 100644 linux-user/sh4/elfload.c
 create mode 100644 linux-user/sparc/elfload.c
 create mode 100644 linux-user/x86_64/elfload.c
 create mode 100644 linux-user/xtensa/elfload.c

diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/aarch64/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/alpha/elfload.c b/linux-user/alpha/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/alpha/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/arm/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/hexagon/elfload.c b/linux-user/hexagon/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/hexagon/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/hppa/elfload.c b/linux-user/hppa/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/hppa/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/i386/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/loongarch64/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/m68k/elfload.c b/linux-user/m68k/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/m68k/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/microblaze/elfload.c b/linux-user/microblaze/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/microblaze/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/mips/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/mips64/elfload.c b/linux-user/mips64/elfload.c
new file mode 100644
index 0000000000..b719555e65
--- /dev/null
+++ b/linux-user/mips64/elfload.c
@@ -0,0 +1 @@
+#include "../mips/elfload.c"
diff --git a/linux-user/openrisc/elfload.c b/linux-user/openrisc/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/openrisc/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/ppc/elfload.c b/linux-user/ppc/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/ppc/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/riscv/elfload.c b/linux-user/riscv/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/riscv/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/s390x/elfload.c b/linux-user/s390x/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/s390x/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/sh4/elfload.c b/linux-user/sh4/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/sh4/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/sparc/elfload.c b/linux-user/sparc/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/sparc/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/x86_64/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/linux-user/xtensa/elfload.c b/linux-user/xtensa/elfload.c
new file mode 100644
index 0000000000..73fa78ef14
--- /dev/null
+++ b/linux-user/xtensa/elfload.c
@@ -0,0 +1 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
diff --git a/meson.build b/meson.build
index e53cd5b413..516b1a43c3 100644
--- a/meson.build
+++ b/meson.build
@@ -4325,7 +4325,11 @@ foreach target : target_dirs
     )
     if 'CONFIG_LINUX_USER' in config_target
       dir = base_dir / abi
-      arch_srcs += files(dir / 'signal.c', dir / 'cpu_loop.c')
+      arch_srcs += files(
+        dir / 'cpu_loop.c',
+        dir / 'elfload.c',
+        dir / 'signal.c',
+      )
       if config_target.has_key('TARGET_SYSTBL_ABI')
         arch_srcs += \
           syscall_nr_generators[abi].process(base_dir / abi / config_target['TARGET_SYSTBL'],
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 02/89] linux-user: Move get_elf_hwcap to {i386, x86_64}/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
  2025-07-29 23:58 ` [PATCH 01/89] linux-user: Create target/elfload.c files Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:51   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 03/89] linux-user: Move hwcap functions to {arm, aarch64}/elfload.c Richard Henderson
                   ` (87 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.
Duplicate the one line function between i386 and x86_64,
as most other additions to elfload.c won't be common.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h         |  3 +++
 linux-user/elfload.c        |  9 +--------
 linux-user/i386/elfload.c   | 10 ++++++++++
 linux-user/x86_64/elfload.c | 10 ++++++++++
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index e102e6f410..a2869ec5de 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -98,6 +98,9 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
+#if defined(TARGET_I386) || defined(TARGET_X86_64)
+abi_ulong get_elf_hwcap(CPUState *cs);
+#endif
 #if defined(TARGET_S390X) || defined(TARGET_AARCH64) || defined(TARGET_ARM)
 uint32_t get_elf_hwcap(void);
 const char *elf_hwcap_str(uint32_t bit);
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index ea214105ff..f05888055f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -158,14 +158,7 @@ typedef abi_int         target_pid_t;
 
 #ifdef TARGET_I386
 
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-    X86CPU *cpu = X86_CPU(thread_cpu);
-
-    return cpu->env.features[FEAT_1_EDX];
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index 73fa78ef14..df171d896a 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    return cpu_env(cs)->features[FEAT_1_EDX];
+}
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index 73fa78ef14..df171d896a 100644
--- a/linux-user/x86_64/elfload.c
+++ b/linux-user/x86_64/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    return cpu_env(cs)->features[FEAT_1_EDX];
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 03/89] linux-user: Move hwcap functions to {arm, aarch64}/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
  2025-07-29 23:58 ` [PATCH 01/89] linux-user: Create target/elfload.c files Richard Henderson
  2025-07-29 23:58 ` [PATCH 02/89] linux-user: Move get_elf_hwcap to {i386, x86_64}/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:53   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 04/89] linux-user: Move get_elf_hwcap to sparc/elfload.c Richard Henderson
                   ` (86 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

For get_elf_hwcap and get_elf_hwcap2, change the return type to
abi_ulong, and pass in the cpu.  We must do these targets at the
same time because of the ifdef dependency between TARGET_AARCH64
and TARGET_ARM.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/arm/target_proc.h |   4 +-
 linux-user/loader.h          |  10 +-
 linux-user/aarch64/elfload.c | 338 +++++++++++++++++++++++
 linux-user/arm/elfload.c     | 166 ++++++++++++
 linux-user/elfload.c         | 505 +----------------------------------
 5 files changed, 514 insertions(+), 509 deletions(-)

diff --git a/linux-user/arm/target_proc.h b/linux-user/arm/target_proc.h
index ac75af9ca6..a4cd6948c6 100644
--- a/linux-user/arm/target_proc.h
+++ b/linux-user/arm/target_proc.h
@@ -10,8 +10,8 @@ static int open_cpuinfo(CPUArchState *cpu_env, int fd)
 {
     ARMCPU *cpu = env_archcpu(cpu_env);
     int arch, midr_rev, midr_part, midr_var, midr_impl;
-    target_ulong elf_hwcap = get_elf_hwcap();
-    target_ulong elf_hwcap2 = get_elf_hwcap2();
+    target_ulong elf_hwcap = get_elf_hwcap(env_cpu(cpu_env));
+    target_ulong elf_hwcap2 = get_elf_hwcap2(env_cpu(cpu_env));
     const char *elf_name;
     int num_cpus, len_part, len_var;
 
diff --git a/linux-user/loader.h b/linux-user/loader.h
index a2869ec5de..be92207c2b 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -98,16 +98,14 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
-#if defined(TARGET_I386) || defined(TARGET_X86_64)
+#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM)
 abi_ulong get_elf_hwcap(CPUState *cs);
+abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
-#if defined(TARGET_S390X) || defined(TARGET_AARCH64) || defined(TARGET_ARM)
+#if defined(TARGET_S390X)
 uint32_t get_elf_hwcap(void);
+#endif
 const char *elf_hwcap_str(uint32_t bit);
-#endif
-#if defined(TARGET_AARCH64) || defined(TARGET_ARM)
-uint64_t get_elf_hwcap2(void);
 const char *elf_hwcap2_str(uint32_t bit);
-#endif
 
 #endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 73fa78ef14..8a8bd22784 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -1 +1,339 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "target/arm/cpu-features.h"
+
+
+enum {
+    ARM_HWCAP_A64_FP            = 1 << 0,
+    ARM_HWCAP_A64_ASIMD         = 1 << 1,
+    ARM_HWCAP_A64_EVTSTRM       = 1 << 2,
+    ARM_HWCAP_A64_AES           = 1 << 3,
+    ARM_HWCAP_A64_PMULL         = 1 << 4,
+    ARM_HWCAP_A64_SHA1          = 1 << 5,
+    ARM_HWCAP_A64_SHA2          = 1 << 6,
+    ARM_HWCAP_A64_CRC32         = 1 << 7,
+    ARM_HWCAP_A64_ATOMICS       = 1 << 8,
+    ARM_HWCAP_A64_FPHP          = 1 << 9,
+    ARM_HWCAP_A64_ASIMDHP       = 1 << 10,
+    ARM_HWCAP_A64_CPUID         = 1 << 11,
+    ARM_HWCAP_A64_ASIMDRDM      = 1 << 12,
+    ARM_HWCAP_A64_JSCVT         = 1 << 13,
+    ARM_HWCAP_A64_FCMA          = 1 << 14,
+    ARM_HWCAP_A64_LRCPC         = 1 << 15,
+    ARM_HWCAP_A64_DCPOP         = 1 << 16,
+    ARM_HWCAP_A64_SHA3          = 1 << 17,
+    ARM_HWCAP_A64_SM3           = 1 << 18,
+    ARM_HWCAP_A64_SM4           = 1 << 19,
+    ARM_HWCAP_A64_ASIMDDP       = 1 << 20,
+    ARM_HWCAP_A64_SHA512        = 1 << 21,
+    ARM_HWCAP_A64_SVE           = 1 << 22,
+    ARM_HWCAP_A64_ASIMDFHM      = 1 << 23,
+    ARM_HWCAP_A64_DIT           = 1 << 24,
+    ARM_HWCAP_A64_USCAT         = 1 << 25,
+    ARM_HWCAP_A64_ILRCPC        = 1 << 26,
+    ARM_HWCAP_A64_FLAGM         = 1 << 27,
+    ARM_HWCAP_A64_SSBS          = 1 << 28,
+    ARM_HWCAP_A64_SB            = 1 << 29,
+    ARM_HWCAP_A64_PACA          = 1 << 30,
+    ARM_HWCAP_A64_PACG          = 1ULL << 31,
+    ARM_HWCAP_A64_GCS           = 1ULL << 32,
+    ARM_HWCAP_A64_CMPBR         = 1ULL << 33,
+    ARM_HWCAP_A64_FPRCVT        = 1ULL << 34,
+    ARM_HWCAP_A64_F8MM8         = 1ULL << 35,
+    ARM_HWCAP_A64_F8MM4         = 1ULL << 36,
+    ARM_HWCAP_A64_SVE_F16MM     = 1ULL << 37,
+    ARM_HWCAP_A64_SVE_ELTPERM   = 1ULL << 38,
+    ARM_HWCAP_A64_SVE_AES2      = 1ULL << 39,
+    ARM_HWCAP_A64_SVE_BFSCALE   = 1ULL << 40,
+    ARM_HWCAP_A64_SVE2P2        = 1ULL << 41,
+    ARM_HWCAP_A64_SME2P2        = 1ULL << 42,
+    ARM_HWCAP_A64_SME_SBITPERM  = 1ULL << 43,
+    ARM_HWCAP_A64_SME_AES       = 1ULL << 44,
+    ARM_HWCAP_A64_SME_SFEXPA    = 1ULL << 45,
+    ARM_HWCAP_A64_SME_STMOP     = 1ULL << 46,
+    ARM_HWCAP_A64_SME_SMOP4     = 1ULL << 47,
+
+    ARM_HWCAP2_A64_DCPODP       = 1 << 0,
+    ARM_HWCAP2_A64_SVE2         = 1 << 1,
+    ARM_HWCAP2_A64_SVEAES       = 1 << 2,
+    ARM_HWCAP2_A64_SVEPMULL     = 1 << 3,
+    ARM_HWCAP2_A64_SVEBITPERM   = 1 << 4,
+    ARM_HWCAP2_A64_SVESHA3      = 1 << 5,
+    ARM_HWCAP2_A64_SVESM4       = 1 << 6,
+    ARM_HWCAP2_A64_FLAGM2       = 1 << 7,
+    ARM_HWCAP2_A64_FRINT        = 1 << 8,
+    ARM_HWCAP2_A64_SVEI8MM      = 1 << 9,
+    ARM_HWCAP2_A64_SVEF32MM     = 1 << 10,
+    ARM_HWCAP2_A64_SVEF64MM     = 1 << 11,
+    ARM_HWCAP2_A64_SVEBF16      = 1 << 12,
+    ARM_HWCAP2_A64_I8MM         = 1 << 13,
+    ARM_HWCAP2_A64_BF16         = 1 << 14,
+    ARM_HWCAP2_A64_DGH          = 1 << 15,
+    ARM_HWCAP2_A64_RNG          = 1 << 16,
+    ARM_HWCAP2_A64_BTI          = 1 << 17,
+    ARM_HWCAP2_A64_MTE          = 1 << 18,
+    ARM_HWCAP2_A64_ECV          = 1 << 19,
+    ARM_HWCAP2_A64_AFP          = 1 << 20,
+    ARM_HWCAP2_A64_RPRES        = 1 << 21,
+    ARM_HWCAP2_A64_MTE3         = 1 << 22,
+    ARM_HWCAP2_A64_SME          = 1 << 23,
+    ARM_HWCAP2_A64_SME_I16I64   = 1 << 24,
+    ARM_HWCAP2_A64_SME_F64F64   = 1 << 25,
+    ARM_HWCAP2_A64_SME_I8I32    = 1 << 26,
+    ARM_HWCAP2_A64_SME_F16F32   = 1 << 27,
+    ARM_HWCAP2_A64_SME_B16F32   = 1 << 28,
+    ARM_HWCAP2_A64_SME_F32F32   = 1 << 29,
+    ARM_HWCAP2_A64_SME_FA64     = 1 << 30,
+    ARM_HWCAP2_A64_WFXT         = 1ULL << 31,
+    ARM_HWCAP2_A64_EBF16        = 1ULL << 32,
+    ARM_HWCAP2_A64_SVE_EBF16    = 1ULL << 33,
+    ARM_HWCAP2_A64_CSSC         = 1ULL << 34,
+    ARM_HWCAP2_A64_RPRFM        = 1ULL << 35,
+    ARM_HWCAP2_A64_SVE2P1       = 1ULL << 36,
+    ARM_HWCAP2_A64_SME2         = 1ULL << 37,
+    ARM_HWCAP2_A64_SME2P1       = 1ULL << 38,
+    ARM_HWCAP2_A64_SME_I16I32   = 1ULL << 39,
+    ARM_HWCAP2_A64_SME_BI32I32  = 1ULL << 40,
+    ARM_HWCAP2_A64_SME_B16B16   = 1ULL << 41,
+    ARM_HWCAP2_A64_SME_F16F16   = 1ULL << 42,
+    ARM_HWCAP2_A64_MOPS         = 1ULL << 43,
+    ARM_HWCAP2_A64_HBC          = 1ULL << 44,
+    ARM_HWCAP2_A64_SVE_B16B16   = 1ULL << 45,
+    ARM_HWCAP2_A64_LRCPC3       = 1ULL << 46,
+    ARM_HWCAP2_A64_LSE128       = 1ULL << 47,
+    ARM_HWCAP2_A64_FPMR         = 1ULL << 48,
+    ARM_HWCAP2_A64_LUT          = 1ULL << 49,
+    ARM_HWCAP2_A64_FAMINMAX     = 1ULL << 50,
+    ARM_HWCAP2_A64_F8CVT        = 1ULL << 51,
+    ARM_HWCAP2_A64_F8FMA        = 1ULL << 52,
+    ARM_HWCAP2_A64_F8DP4        = 1ULL << 53,
+    ARM_HWCAP2_A64_F8DP2        = 1ULL << 54,
+    ARM_HWCAP2_A64_F8E4M3       = 1ULL << 55,
+    ARM_HWCAP2_A64_F8E5M2       = 1ULL << 56,
+    ARM_HWCAP2_A64_SME_LUTV2    = 1ULL << 57,
+    ARM_HWCAP2_A64_SME_F8F16    = 1ULL << 58,
+    ARM_HWCAP2_A64_SME_F8F32    = 1ULL << 59,
+    ARM_HWCAP2_A64_SME_SF8FMA   = 1ULL << 60,
+    ARM_HWCAP2_A64_SME_SF8DP4   = 1ULL << 61,
+    ARM_HWCAP2_A64_SME_SF8DP2   = 1ULL << 62,
+    ARM_HWCAP2_A64_POE          = 1ULL << 63,
+};
+
+#define GET_FEATURE_ID(feat, hwcap) \
+    do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0)
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    abi_ulong hwcaps = 0;
+
+    hwcaps |= ARM_HWCAP_A64_FP;
+    hwcaps |= ARM_HWCAP_A64_ASIMD;
+    hwcaps |= ARM_HWCAP_A64_CPUID;
+
+    /* probe for the extra features */
+
+    GET_FEATURE_ID(aa64_aes, ARM_HWCAP_A64_AES);
+    GET_FEATURE_ID(aa64_pmull, ARM_HWCAP_A64_PMULL);
+    GET_FEATURE_ID(aa64_sha1, ARM_HWCAP_A64_SHA1);
+    GET_FEATURE_ID(aa64_sha256, ARM_HWCAP_A64_SHA2);
+    GET_FEATURE_ID(aa64_sha512, ARM_HWCAP_A64_SHA512);
+    GET_FEATURE_ID(aa64_crc32, ARM_HWCAP_A64_CRC32);
+    GET_FEATURE_ID(aa64_sha3, ARM_HWCAP_A64_SHA3);
+    GET_FEATURE_ID(aa64_sm3, ARM_HWCAP_A64_SM3);
+    GET_FEATURE_ID(aa64_sm4, ARM_HWCAP_A64_SM4);
+    GET_FEATURE_ID(aa64_fp16, ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
+    GET_FEATURE_ID(aa64_atomics, ARM_HWCAP_A64_ATOMICS);
+    GET_FEATURE_ID(aa64_lse2, ARM_HWCAP_A64_USCAT);
+    GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM);
+    GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP);
+    GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA);
+    GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE);
+    GET_FEATURE_ID(aa64_pauth, ARM_HWCAP_A64_PACA | ARM_HWCAP_A64_PACG);
+    GET_FEATURE_ID(aa64_fhm, ARM_HWCAP_A64_ASIMDFHM);
+    GET_FEATURE_ID(aa64_dit, ARM_HWCAP_A64_DIT);
+    GET_FEATURE_ID(aa64_jscvt, ARM_HWCAP_A64_JSCVT);
+    GET_FEATURE_ID(aa64_sb, ARM_HWCAP_A64_SB);
+    GET_FEATURE_ID(aa64_condm_4, ARM_HWCAP_A64_FLAGM);
+    GET_FEATURE_ID(aa64_dcpop, ARM_HWCAP_A64_DCPOP);
+    GET_FEATURE_ID(aa64_rcpc_8_3, ARM_HWCAP_A64_LRCPC);
+    GET_FEATURE_ID(aa64_rcpc_8_4, ARM_HWCAP_A64_ILRCPC);
+
+    return hwcaps;
+}
+
+abi_ulong get_elf_hwcap2(CPUState *cs)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    abi_ulong hwcaps = 0;
+
+    GET_FEATURE_ID(aa64_dcpodp, ARM_HWCAP2_A64_DCPODP);
+    GET_FEATURE_ID(aa64_sve2, ARM_HWCAP2_A64_SVE2);
+    GET_FEATURE_ID(aa64_sve2_aes, ARM_HWCAP2_A64_SVEAES);
+    GET_FEATURE_ID(aa64_sve2_pmull128, ARM_HWCAP2_A64_SVEPMULL);
+    GET_FEATURE_ID(aa64_sve2_bitperm, ARM_HWCAP2_A64_SVEBITPERM);
+    GET_FEATURE_ID(aa64_sve2_sha3, ARM_HWCAP2_A64_SVESHA3);
+    GET_FEATURE_ID(aa64_sve2_sm4, ARM_HWCAP2_A64_SVESM4);
+    GET_FEATURE_ID(aa64_condm_5, ARM_HWCAP2_A64_FLAGM2);
+    GET_FEATURE_ID(aa64_frint, ARM_HWCAP2_A64_FRINT);
+    GET_FEATURE_ID(aa64_sve_i8mm, ARM_HWCAP2_A64_SVEI8MM);
+    GET_FEATURE_ID(aa64_sve_f32mm, ARM_HWCAP2_A64_SVEF32MM);
+    GET_FEATURE_ID(aa64_sve_f64mm, ARM_HWCAP2_A64_SVEF64MM);
+    GET_FEATURE_ID(aa64_sve_bf16, ARM_HWCAP2_A64_SVEBF16);
+    GET_FEATURE_ID(aa64_i8mm, ARM_HWCAP2_A64_I8MM);
+    GET_FEATURE_ID(aa64_bf16, ARM_HWCAP2_A64_BF16);
+    GET_FEATURE_ID(aa64_rndr, ARM_HWCAP2_A64_RNG);
+    GET_FEATURE_ID(aa64_bti, ARM_HWCAP2_A64_BTI);
+    GET_FEATURE_ID(aa64_mte, ARM_HWCAP2_A64_MTE);
+    GET_FEATURE_ID(aa64_mte3, ARM_HWCAP2_A64_MTE3);
+    GET_FEATURE_ID(aa64_sme, (ARM_HWCAP2_A64_SME |
+                              ARM_HWCAP2_A64_SME_F32F32 |
+                              ARM_HWCAP2_A64_SME_B16F32 |
+                              ARM_HWCAP2_A64_SME_F16F32 |
+                              ARM_HWCAP2_A64_SME_I8I32));
+    GET_FEATURE_ID(aa64_sme_f64f64, ARM_HWCAP2_A64_SME_F64F64);
+    GET_FEATURE_ID(aa64_sme_i16i64, ARM_HWCAP2_A64_SME_I16I64);
+    GET_FEATURE_ID(aa64_sme_fa64, ARM_HWCAP2_A64_SME_FA64);
+    GET_FEATURE_ID(aa64_hbc, ARM_HWCAP2_A64_HBC);
+    GET_FEATURE_ID(aa64_mops, ARM_HWCAP2_A64_MOPS);
+    GET_FEATURE_ID(aa64_sve2p1, ARM_HWCAP2_A64_SVE2P1);
+    GET_FEATURE_ID(aa64_sme2, (ARM_HWCAP2_A64_SME2 |
+                               ARM_HWCAP2_A64_SME_I16I32 |
+                               ARM_HWCAP2_A64_SME_BI32I32));
+    GET_FEATURE_ID(aa64_sme2p1, ARM_HWCAP2_A64_SME2P1);
+    GET_FEATURE_ID(aa64_sme_b16b16, ARM_HWCAP2_A64_SME_B16B16);
+    GET_FEATURE_ID(aa64_sme_f16f16, ARM_HWCAP2_A64_SME_F16F16);
+    GET_FEATURE_ID(aa64_sve_b16b16, ARM_HWCAP2_A64_SVE_B16B16);
+
+    return hwcaps;
+}
+
+const char *elf_hwcap_str(uint32_t bit)
+{
+    static const char * const hwcap_str[] = {
+    [__builtin_ctz(ARM_HWCAP_A64_FP      )] = "fp",
+    [__builtin_ctz(ARM_HWCAP_A64_ASIMD   )] = "asimd",
+    [__builtin_ctz(ARM_HWCAP_A64_EVTSTRM )] = "evtstrm",
+    [__builtin_ctz(ARM_HWCAP_A64_AES     )] = "aes",
+    [__builtin_ctz(ARM_HWCAP_A64_PMULL   )] = "pmull",
+    [__builtin_ctz(ARM_HWCAP_A64_SHA1    )] = "sha1",
+    [__builtin_ctz(ARM_HWCAP_A64_SHA2    )] = "sha2",
+    [__builtin_ctz(ARM_HWCAP_A64_CRC32   )] = "crc32",
+    [__builtin_ctz(ARM_HWCAP_A64_ATOMICS )] = "atomics",
+    [__builtin_ctz(ARM_HWCAP_A64_FPHP    )] = "fphp",
+    [__builtin_ctz(ARM_HWCAP_A64_ASIMDHP )] = "asimdhp",
+    [__builtin_ctz(ARM_HWCAP_A64_CPUID   )] = "cpuid",
+    [__builtin_ctz(ARM_HWCAP_A64_ASIMDRDM)] = "asimdrdm",
+    [__builtin_ctz(ARM_HWCAP_A64_JSCVT   )] = "jscvt",
+    [__builtin_ctz(ARM_HWCAP_A64_FCMA    )] = "fcma",
+    [__builtin_ctz(ARM_HWCAP_A64_LRCPC   )] = "lrcpc",
+    [__builtin_ctz(ARM_HWCAP_A64_DCPOP   )] = "dcpop",
+    [__builtin_ctz(ARM_HWCAP_A64_SHA3    )] = "sha3",
+    [__builtin_ctz(ARM_HWCAP_A64_SM3     )] = "sm3",
+    [__builtin_ctz(ARM_HWCAP_A64_SM4     )] = "sm4",
+    [__builtin_ctz(ARM_HWCAP_A64_ASIMDDP )] = "asimddp",
+    [__builtin_ctz(ARM_HWCAP_A64_SHA512  )] = "sha512",
+    [__builtin_ctz(ARM_HWCAP_A64_SVE     )] = "sve",
+    [__builtin_ctz(ARM_HWCAP_A64_ASIMDFHM)] = "asimdfhm",
+    [__builtin_ctz(ARM_HWCAP_A64_DIT     )] = "dit",
+    [__builtin_ctz(ARM_HWCAP_A64_USCAT   )] = "uscat",
+    [__builtin_ctz(ARM_HWCAP_A64_ILRCPC  )] = "ilrcpc",
+    [__builtin_ctz(ARM_HWCAP_A64_FLAGM   )] = "flagm",
+    [__builtin_ctz(ARM_HWCAP_A64_SSBS    )] = "ssbs",
+    [__builtin_ctz(ARM_HWCAP_A64_SB      )] = "sb",
+    [__builtin_ctz(ARM_HWCAP_A64_PACA    )] = "paca",
+    [__builtin_ctz(ARM_HWCAP_A64_PACG    )] = "pacg",
+    [__builtin_ctzll(ARM_HWCAP_A64_GCS   )] = "gcs",
+    [__builtin_ctzll(ARM_HWCAP_A64_CMPBR )] = "cmpbr",
+    [__builtin_ctzll(ARM_HWCAP_A64_FPRCVT)] = "fprcvt",
+    [__builtin_ctzll(ARM_HWCAP_A64_F8MM8 )] = "f8mm8",
+    [__builtin_ctzll(ARM_HWCAP_A64_F8MM4 )] = "f8mm4",
+    [__builtin_ctzll(ARM_HWCAP_A64_SVE_F16MM)] = "svef16mm",
+    [__builtin_ctzll(ARM_HWCAP_A64_SVE_ELTPERM)] = "sveeltperm",
+    [__builtin_ctzll(ARM_HWCAP_A64_SVE_AES2)] = "sveaes2",
+    [__builtin_ctzll(ARM_HWCAP_A64_SVE_BFSCALE)] = "svebfscale",
+    [__builtin_ctzll(ARM_HWCAP_A64_SVE2P2)] = "sve2p2",
+    [__builtin_ctzll(ARM_HWCAP_A64_SME2P2)] = "sme2p2",
+    [__builtin_ctzll(ARM_HWCAP_A64_SME_SBITPERM)] = "smesbitperm",
+    [__builtin_ctzll(ARM_HWCAP_A64_SME_AES)] = "smeaes",
+    [__builtin_ctzll(ARM_HWCAP_A64_SME_SFEXPA)] = "smesfexpa",
+    [__builtin_ctzll(ARM_HWCAP_A64_SME_STMOP)] = "smestmop",
+    [__builtin_ctzll(ARM_HWCAP_A64_SME_SMOP4)] = "smesmop4",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
+
+const char *elf_hwcap2_str(uint32_t bit)
+{
+    static const char * const hwcap_str[] = {
+    [__builtin_ctz(ARM_HWCAP2_A64_DCPODP       )] = "dcpodp",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVE2         )] = "sve2",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEAES       )] = "sveaes",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEPMULL     )] = "svepmull",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEBITPERM   )] = "svebitperm",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVESHA3      )] = "svesha3",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVESM4       )] = "svesm4",
+    [__builtin_ctz(ARM_HWCAP2_A64_FLAGM2       )] = "flagm2",
+    [__builtin_ctz(ARM_HWCAP2_A64_FRINT        )] = "frint",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEI8MM      )] = "svei8mm",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEF32MM     )] = "svef32mm",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEF64MM     )] = "svef64mm",
+    [__builtin_ctz(ARM_HWCAP2_A64_SVEBF16      )] = "svebf16",
+    [__builtin_ctz(ARM_HWCAP2_A64_I8MM         )] = "i8mm",
+    [__builtin_ctz(ARM_HWCAP2_A64_BF16         )] = "bf16",
+    [__builtin_ctz(ARM_HWCAP2_A64_DGH          )] = "dgh",
+    [__builtin_ctz(ARM_HWCAP2_A64_RNG          )] = "rng",
+    [__builtin_ctz(ARM_HWCAP2_A64_BTI          )] = "bti",
+    [__builtin_ctz(ARM_HWCAP2_A64_MTE          )] = "mte",
+    [__builtin_ctz(ARM_HWCAP2_A64_ECV          )] = "ecv",
+    [__builtin_ctz(ARM_HWCAP2_A64_AFP          )] = "afp",
+    [__builtin_ctz(ARM_HWCAP2_A64_RPRES        )] = "rpres",
+    [__builtin_ctz(ARM_HWCAP2_A64_MTE3         )] = "mte3",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME          )] = "sme",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_I16I64   )] = "smei16i64",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_F64F64   )] = "smef64f64",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_I8I32    )] = "smei8i32",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_F16F32   )] = "smef16f32",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32   )] = "smeb16f32",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32   )] = "smef32f32",
+    [__builtin_ctz(ARM_HWCAP2_A64_SME_FA64     )] = "smefa64",
+    [__builtin_ctz(ARM_HWCAP2_A64_WFXT         )] = "wfxt",
+    [__builtin_ctzll(ARM_HWCAP2_A64_EBF16      )] = "ebf16",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SVE_EBF16  )] = "sveebf16",
+    [__builtin_ctzll(ARM_HWCAP2_A64_CSSC       )] = "cssc",
+    [__builtin_ctzll(ARM_HWCAP2_A64_RPRFM      )] = "rprfm",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SVE2P1     )] = "sve2p1",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME2       )] = "sme2",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME2P1     )] = "sme2p1",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_I16I32 )] = "smei16i32",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_BI32I32)] = "smebi32i32",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_B16B16 )] = "smeb16b16",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_F16F16 )] = "smef16f16",
+    [__builtin_ctzll(ARM_HWCAP2_A64_MOPS       )] = "mops",
+    [__builtin_ctzll(ARM_HWCAP2_A64_HBC        )] = "hbc",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SVE_B16B16 )] = "sveb16b16",
+    [__builtin_ctzll(ARM_HWCAP2_A64_LRCPC3     )] = "lrcpc3",
+    [__builtin_ctzll(ARM_HWCAP2_A64_LSE128     )] = "lse128",
+    [__builtin_ctzll(ARM_HWCAP2_A64_FPMR       )] = "fpmr",
+    [__builtin_ctzll(ARM_HWCAP2_A64_LUT        )] = "lut",
+    [__builtin_ctzll(ARM_HWCAP2_A64_FAMINMAX   )] = "faminmax",
+    [__builtin_ctzll(ARM_HWCAP2_A64_F8CVT      )] = "f8cvt",
+    [__builtin_ctzll(ARM_HWCAP2_A64_F8FMA      )] = "f8fma",
+    [__builtin_ctzll(ARM_HWCAP2_A64_F8DP4      )] = "f8dp4",
+    [__builtin_ctzll(ARM_HWCAP2_A64_F8DP2      )] = "f8dp2",
+    [__builtin_ctzll(ARM_HWCAP2_A64_F8E4M3     )] = "f8e4m3",
+    [__builtin_ctzll(ARM_HWCAP2_A64_F8E5M2     )] = "f8e5m2",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_LUTV2  )] = "smelutv2",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_F8F16  )] = "smef8f16",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_F8F32  )] = "smef8f32",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_SF8DP4 )] = "smesf8dp4",
+    [__builtin_ctzll(ARM_HWCAP2_A64_SME_SF8DP2 )] = "smesf8dp2",
+    [__builtin_ctzll(ARM_HWCAP2_A64_POE        )] = "poe",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 73fa78ef14..be80e04f9c 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -1 +1,167 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "target/arm/cpu-features.h"
+
+
+enum
+{
+    ARM_HWCAP_ARM_SWP       = 1 << 0,
+    ARM_HWCAP_ARM_HALF      = 1 << 1,
+    ARM_HWCAP_ARM_THUMB     = 1 << 2,
+    ARM_HWCAP_ARM_26BIT     = 1 << 3,
+    ARM_HWCAP_ARM_FAST_MULT = 1 << 4,
+    ARM_HWCAP_ARM_FPA       = 1 << 5,
+    ARM_HWCAP_ARM_VFP       = 1 << 6,
+    ARM_HWCAP_ARM_EDSP      = 1 << 7,
+    ARM_HWCAP_ARM_JAVA      = 1 << 8,
+    ARM_HWCAP_ARM_IWMMXT    = 1 << 9,
+    ARM_HWCAP_ARM_CRUNCH    = 1 << 10,
+    ARM_HWCAP_ARM_THUMBEE   = 1 << 11,
+    ARM_HWCAP_ARM_NEON      = 1 << 12,
+    ARM_HWCAP_ARM_VFPv3     = 1 << 13,
+    ARM_HWCAP_ARM_VFPv3D16  = 1 << 14,
+    ARM_HWCAP_ARM_TLS       = 1 << 15,
+    ARM_HWCAP_ARM_VFPv4     = 1 << 16,
+    ARM_HWCAP_ARM_IDIVA     = 1 << 17,
+    ARM_HWCAP_ARM_IDIVT     = 1 << 18,
+    ARM_HWCAP_ARM_VFPD32    = 1 << 19,
+    ARM_HWCAP_ARM_LPAE      = 1 << 20,
+    ARM_HWCAP_ARM_EVTSTRM   = 1 << 21,
+    ARM_HWCAP_ARM_FPHP      = 1 << 22,
+    ARM_HWCAP_ARM_ASIMDHP   = 1 << 23,
+    ARM_HWCAP_ARM_ASIMDDP   = 1 << 24,
+    ARM_HWCAP_ARM_ASIMDFHM  = 1 << 25,
+    ARM_HWCAP_ARM_ASIMDBF16 = 1 << 26,
+    ARM_HWCAP_ARM_I8MM      = 1 << 27,
+};
+
+enum {
+    ARM_HWCAP2_ARM_AES      = 1 << 0,
+    ARM_HWCAP2_ARM_PMULL    = 1 << 1,
+    ARM_HWCAP2_ARM_SHA1     = 1 << 2,
+    ARM_HWCAP2_ARM_SHA2     = 1 << 3,
+    ARM_HWCAP2_ARM_CRC32    = 1 << 4,
+    ARM_HWCAP2_ARM_SB       = 1 << 5,
+    ARM_HWCAP2_ARM_SSBS     = 1 << 6,
+};
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    abi_ulong hwcaps = 0;
+
+    hwcaps |= ARM_HWCAP_ARM_SWP;
+    hwcaps |= ARM_HWCAP_ARM_HALF;
+    hwcaps |= ARM_HWCAP_ARM_THUMB;
+    hwcaps |= ARM_HWCAP_ARM_FAST_MULT;
+
+    /* probe for the extra features */
+#define GET_FEATURE(feat, hwcap) \
+    do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0)
+
+#define GET_FEATURE_ID(feat, hwcap) \
+    do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0)
+
+    /* EDSP is in v5TE and above, but all our v5 CPUs are v5TE */
+    GET_FEATURE(ARM_FEATURE_V5, ARM_HWCAP_ARM_EDSP);
+    GET_FEATURE(ARM_FEATURE_IWMMXT, ARM_HWCAP_ARM_IWMMXT);
+    GET_FEATURE(ARM_FEATURE_THUMB2EE, ARM_HWCAP_ARM_THUMBEE);
+    GET_FEATURE(ARM_FEATURE_NEON, ARM_HWCAP_ARM_NEON);
+    GET_FEATURE(ARM_FEATURE_V6K, ARM_HWCAP_ARM_TLS);
+    GET_FEATURE(ARM_FEATURE_LPAE, ARM_HWCAP_ARM_LPAE);
+    GET_FEATURE_ID(aa32_arm_div, ARM_HWCAP_ARM_IDIVA);
+    GET_FEATURE_ID(aa32_thumb_div, ARM_HWCAP_ARM_IDIVT);
+    GET_FEATURE_ID(aa32_vfp, ARM_HWCAP_ARM_VFP);
+
+    if (cpu_isar_feature(aa32_fpsp_v3, cpu) ||
+        cpu_isar_feature(aa32_fpdp_v3, cpu)) {
+        hwcaps |= ARM_HWCAP_ARM_VFPv3;
+        if (cpu_isar_feature(aa32_simd_r32, cpu)) {
+            hwcaps |= ARM_HWCAP_ARM_VFPD32;
+        } else {
+            hwcaps |= ARM_HWCAP_ARM_VFPv3D16;
+        }
+    }
+    GET_FEATURE_ID(aa32_simdfmac, ARM_HWCAP_ARM_VFPv4);
+    /*
+     * MVFR1.FPHP and .SIMDHP must be in sync, and QEMU uses the same
+     * isar_feature function for both. The kernel reports them as two hwcaps.
+     */
+    GET_FEATURE_ID(aa32_fp16_arith, ARM_HWCAP_ARM_FPHP);
+    GET_FEATURE_ID(aa32_fp16_arith, ARM_HWCAP_ARM_ASIMDHP);
+    GET_FEATURE_ID(aa32_dp, ARM_HWCAP_ARM_ASIMDDP);
+    GET_FEATURE_ID(aa32_fhm, ARM_HWCAP_ARM_ASIMDFHM);
+    GET_FEATURE_ID(aa32_bf16, ARM_HWCAP_ARM_ASIMDBF16);
+    GET_FEATURE_ID(aa32_i8mm, ARM_HWCAP_ARM_I8MM);
+
+    return hwcaps;
+}
+
+abi_ulong get_elf_hwcap2(CPUState *cs)
+{
+    ARMCPU *cpu = ARM_CPU(cs);
+    abi_ulong hwcaps = 0;
+
+    GET_FEATURE_ID(aa32_aes, ARM_HWCAP2_ARM_AES);
+    GET_FEATURE_ID(aa32_pmull, ARM_HWCAP2_ARM_PMULL);
+    GET_FEATURE_ID(aa32_sha1, ARM_HWCAP2_ARM_SHA1);
+    GET_FEATURE_ID(aa32_sha2, ARM_HWCAP2_ARM_SHA2);
+    GET_FEATURE_ID(aa32_crc32, ARM_HWCAP2_ARM_CRC32);
+    GET_FEATURE_ID(aa32_sb, ARM_HWCAP2_ARM_SB);
+    GET_FEATURE_ID(aa32_ssbs, ARM_HWCAP2_ARM_SSBS);
+    return hwcaps;
+}
+
+const char *elf_hwcap_str(uint32_t bit)
+{
+    static const char *hwcap_str[] = {
+    [__builtin_ctz(ARM_HWCAP_ARM_SWP      )] = "swp",
+    [__builtin_ctz(ARM_HWCAP_ARM_HALF     )] = "half",
+    [__builtin_ctz(ARM_HWCAP_ARM_THUMB    )] = "thumb",
+    [__builtin_ctz(ARM_HWCAP_ARM_26BIT    )] = "26bit",
+    [__builtin_ctz(ARM_HWCAP_ARM_FAST_MULT)] = "fast_mult",
+    [__builtin_ctz(ARM_HWCAP_ARM_FPA      )] = "fpa",
+    [__builtin_ctz(ARM_HWCAP_ARM_VFP      )] = "vfp",
+    [__builtin_ctz(ARM_HWCAP_ARM_EDSP     )] = "edsp",
+    [__builtin_ctz(ARM_HWCAP_ARM_JAVA     )] = "java",
+    [__builtin_ctz(ARM_HWCAP_ARM_IWMMXT   )] = "iwmmxt",
+    [__builtin_ctz(ARM_HWCAP_ARM_CRUNCH   )] = "crunch",
+    [__builtin_ctz(ARM_HWCAP_ARM_THUMBEE  )] = "thumbee",
+    [__builtin_ctz(ARM_HWCAP_ARM_NEON     )] = "neon",
+    [__builtin_ctz(ARM_HWCAP_ARM_VFPv3    )] = "vfpv3",
+    [__builtin_ctz(ARM_HWCAP_ARM_VFPv3D16 )] = "vfpv3d16",
+    [__builtin_ctz(ARM_HWCAP_ARM_TLS      )] = "tls",
+    [__builtin_ctz(ARM_HWCAP_ARM_VFPv4    )] = "vfpv4",
+    [__builtin_ctz(ARM_HWCAP_ARM_IDIVA    )] = "idiva",
+    [__builtin_ctz(ARM_HWCAP_ARM_IDIVT    )] = "idivt",
+    [__builtin_ctz(ARM_HWCAP_ARM_VFPD32   )] = "vfpd32",
+    [__builtin_ctz(ARM_HWCAP_ARM_LPAE     )] = "lpae",
+    [__builtin_ctz(ARM_HWCAP_ARM_EVTSTRM  )] = "evtstrm",
+    [__builtin_ctz(ARM_HWCAP_ARM_FPHP     )] = "fphp",
+    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDHP  )] = "asimdhp",
+    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDDP  )] = "asimddp",
+    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDFHM )] = "asimdfhm",
+    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDBF16)] = "asimdbf16",
+    [__builtin_ctz(ARM_HWCAP_ARM_I8MM     )] = "i8mm",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
+
+const char *elf_hwcap2_str(uint32_t bit)
+{
+    static const char *hwcap_str[] = {
+    [__builtin_ctz(ARM_HWCAP2_ARM_AES  )] = "aes",
+    [__builtin_ctz(ARM_HWCAP2_ARM_PMULL)] = "pmull",
+    [__builtin_ctz(ARM_HWCAP2_ARM_SHA1 )] = "sha1",
+    [__builtin_ctz(ARM_HWCAP2_ARM_SHA2 )] = "sha2",
+    [__builtin_ctz(ARM_HWCAP2_ARM_CRC32)] = "crc32",
+    [__builtin_ctz(ARM_HWCAP2_ARM_SB   )] = "sb",
+    [__builtin_ctz(ARM_HWCAP2_ARM_SSBS )] = "ssbs",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f05888055f..3a4f68f503 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -411,48 +411,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUARMState *en
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
-enum
-{
-    ARM_HWCAP_ARM_SWP       = 1 << 0,
-    ARM_HWCAP_ARM_HALF      = 1 << 1,
-    ARM_HWCAP_ARM_THUMB     = 1 << 2,
-    ARM_HWCAP_ARM_26BIT     = 1 << 3,
-    ARM_HWCAP_ARM_FAST_MULT = 1 << 4,
-    ARM_HWCAP_ARM_FPA       = 1 << 5,
-    ARM_HWCAP_ARM_VFP       = 1 << 6,
-    ARM_HWCAP_ARM_EDSP      = 1 << 7,
-    ARM_HWCAP_ARM_JAVA      = 1 << 8,
-    ARM_HWCAP_ARM_IWMMXT    = 1 << 9,
-    ARM_HWCAP_ARM_CRUNCH    = 1 << 10,
-    ARM_HWCAP_ARM_THUMBEE   = 1 << 11,
-    ARM_HWCAP_ARM_NEON      = 1 << 12,
-    ARM_HWCAP_ARM_VFPv3     = 1 << 13,
-    ARM_HWCAP_ARM_VFPv3D16  = 1 << 14,
-    ARM_HWCAP_ARM_TLS       = 1 << 15,
-    ARM_HWCAP_ARM_VFPv4     = 1 << 16,
-    ARM_HWCAP_ARM_IDIVA     = 1 << 17,
-    ARM_HWCAP_ARM_IDIVT     = 1 << 18,
-    ARM_HWCAP_ARM_VFPD32    = 1 << 19,
-    ARM_HWCAP_ARM_LPAE      = 1 << 20,
-    ARM_HWCAP_ARM_EVTSTRM   = 1 << 21,
-    ARM_HWCAP_ARM_FPHP      = 1 << 22,
-    ARM_HWCAP_ARM_ASIMDHP   = 1 << 23,
-    ARM_HWCAP_ARM_ASIMDDP   = 1 << 24,
-    ARM_HWCAP_ARM_ASIMDFHM  = 1 << 25,
-    ARM_HWCAP_ARM_ASIMDBF16 = 1 << 26,
-    ARM_HWCAP_ARM_I8MM      = 1 << 27,
-};
-
-enum {
-    ARM_HWCAP2_ARM_AES      = 1 << 0,
-    ARM_HWCAP2_ARM_PMULL    = 1 << 1,
-    ARM_HWCAP2_ARM_SHA1     = 1 << 2,
-    ARM_HWCAP2_ARM_SHA2     = 1 << 3,
-    ARM_HWCAP2_ARM_CRC32    = 1 << 4,
-    ARM_HWCAP2_ARM_SB       = 1 << 5,
-    ARM_HWCAP2_ARM_SSBS     = 1 << 6,
-};
-
 /* The commpage only exists for 32 bit kernels */
 
 #define HI_COMMPAGE (intptr_t)0xffff0f00u
@@ -501,129 +459,8 @@ static bool init_guest_commpage(void)
     return true;
 }
 
-#define ELF_HWCAP get_elf_hwcap()
-#define ELF_HWCAP2 get_elf_hwcap2()
-
-uint32_t get_elf_hwcap(void)
-{
-    ARMCPU *cpu = ARM_CPU(thread_cpu);
-    uint32_t hwcaps = 0;
-
-    hwcaps |= ARM_HWCAP_ARM_SWP;
-    hwcaps |= ARM_HWCAP_ARM_HALF;
-    hwcaps |= ARM_HWCAP_ARM_THUMB;
-    hwcaps |= ARM_HWCAP_ARM_FAST_MULT;
-
-    /* probe for the extra features */
-#define GET_FEATURE(feat, hwcap) \
-    do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0)
-
-#define GET_FEATURE_ID(feat, hwcap) \
-    do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0)
-
-    /* EDSP is in v5TE and above, but all our v5 CPUs are v5TE */
-    GET_FEATURE(ARM_FEATURE_V5, ARM_HWCAP_ARM_EDSP);
-    GET_FEATURE(ARM_FEATURE_IWMMXT, ARM_HWCAP_ARM_IWMMXT);
-    GET_FEATURE(ARM_FEATURE_THUMB2EE, ARM_HWCAP_ARM_THUMBEE);
-    GET_FEATURE(ARM_FEATURE_NEON, ARM_HWCAP_ARM_NEON);
-    GET_FEATURE(ARM_FEATURE_V6K, ARM_HWCAP_ARM_TLS);
-    GET_FEATURE(ARM_FEATURE_LPAE, ARM_HWCAP_ARM_LPAE);
-    GET_FEATURE_ID(aa32_arm_div, ARM_HWCAP_ARM_IDIVA);
-    GET_FEATURE_ID(aa32_thumb_div, ARM_HWCAP_ARM_IDIVT);
-    GET_FEATURE_ID(aa32_vfp, ARM_HWCAP_ARM_VFP);
-
-    if (cpu_isar_feature(aa32_fpsp_v3, cpu) ||
-        cpu_isar_feature(aa32_fpdp_v3, cpu)) {
-        hwcaps |= ARM_HWCAP_ARM_VFPv3;
-        if (cpu_isar_feature(aa32_simd_r32, cpu)) {
-            hwcaps |= ARM_HWCAP_ARM_VFPD32;
-        } else {
-            hwcaps |= ARM_HWCAP_ARM_VFPv3D16;
-        }
-    }
-    GET_FEATURE_ID(aa32_simdfmac, ARM_HWCAP_ARM_VFPv4);
-    /*
-     * MVFR1.FPHP and .SIMDHP must be in sync, and QEMU uses the same
-     * isar_feature function for both. The kernel reports them as two hwcaps.
-     */
-    GET_FEATURE_ID(aa32_fp16_arith, ARM_HWCAP_ARM_FPHP);
-    GET_FEATURE_ID(aa32_fp16_arith, ARM_HWCAP_ARM_ASIMDHP);
-    GET_FEATURE_ID(aa32_dp, ARM_HWCAP_ARM_ASIMDDP);
-    GET_FEATURE_ID(aa32_fhm, ARM_HWCAP_ARM_ASIMDFHM);
-    GET_FEATURE_ID(aa32_bf16, ARM_HWCAP_ARM_ASIMDBF16);
-    GET_FEATURE_ID(aa32_i8mm, ARM_HWCAP_ARM_I8MM);
-
-    return hwcaps;
-}
-
-uint64_t get_elf_hwcap2(void)
-{
-    ARMCPU *cpu = ARM_CPU(thread_cpu);
-    uint64_t hwcaps = 0;
-
-    GET_FEATURE_ID(aa32_aes, ARM_HWCAP2_ARM_AES);
-    GET_FEATURE_ID(aa32_pmull, ARM_HWCAP2_ARM_PMULL);
-    GET_FEATURE_ID(aa32_sha1, ARM_HWCAP2_ARM_SHA1);
-    GET_FEATURE_ID(aa32_sha2, ARM_HWCAP2_ARM_SHA2);
-    GET_FEATURE_ID(aa32_crc32, ARM_HWCAP2_ARM_CRC32);
-    GET_FEATURE_ID(aa32_sb, ARM_HWCAP2_ARM_SB);
-    GET_FEATURE_ID(aa32_ssbs, ARM_HWCAP2_ARM_SSBS);
-    return hwcaps;
-}
-
-const char *elf_hwcap_str(uint32_t bit)
-{
-    static const char *hwcap_str[] = {
-    [__builtin_ctz(ARM_HWCAP_ARM_SWP      )] = "swp",
-    [__builtin_ctz(ARM_HWCAP_ARM_HALF     )] = "half",
-    [__builtin_ctz(ARM_HWCAP_ARM_THUMB    )] = "thumb",
-    [__builtin_ctz(ARM_HWCAP_ARM_26BIT    )] = "26bit",
-    [__builtin_ctz(ARM_HWCAP_ARM_FAST_MULT)] = "fast_mult",
-    [__builtin_ctz(ARM_HWCAP_ARM_FPA      )] = "fpa",
-    [__builtin_ctz(ARM_HWCAP_ARM_VFP      )] = "vfp",
-    [__builtin_ctz(ARM_HWCAP_ARM_EDSP     )] = "edsp",
-    [__builtin_ctz(ARM_HWCAP_ARM_JAVA     )] = "java",
-    [__builtin_ctz(ARM_HWCAP_ARM_IWMMXT   )] = "iwmmxt",
-    [__builtin_ctz(ARM_HWCAP_ARM_CRUNCH   )] = "crunch",
-    [__builtin_ctz(ARM_HWCAP_ARM_THUMBEE  )] = "thumbee",
-    [__builtin_ctz(ARM_HWCAP_ARM_NEON     )] = "neon",
-    [__builtin_ctz(ARM_HWCAP_ARM_VFPv3    )] = "vfpv3",
-    [__builtin_ctz(ARM_HWCAP_ARM_VFPv3D16 )] = "vfpv3d16",
-    [__builtin_ctz(ARM_HWCAP_ARM_TLS      )] = "tls",
-    [__builtin_ctz(ARM_HWCAP_ARM_VFPv4    )] = "vfpv4",
-    [__builtin_ctz(ARM_HWCAP_ARM_IDIVA    )] = "idiva",
-    [__builtin_ctz(ARM_HWCAP_ARM_IDIVT    )] = "idivt",
-    [__builtin_ctz(ARM_HWCAP_ARM_VFPD32   )] = "vfpd32",
-    [__builtin_ctz(ARM_HWCAP_ARM_LPAE     )] = "lpae",
-    [__builtin_ctz(ARM_HWCAP_ARM_EVTSTRM  )] = "evtstrm",
-    [__builtin_ctz(ARM_HWCAP_ARM_FPHP     )] = "fphp",
-    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDHP  )] = "asimdhp",
-    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDDP  )] = "asimddp",
-    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDFHM )] = "asimdfhm",
-    [__builtin_ctz(ARM_HWCAP_ARM_ASIMDBF16)] = "asimdbf16",
-    [__builtin_ctz(ARM_HWCAP_ARM_I8MM     )] = "i8mm",
-    };
-
-    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
-}
-
-const char *elf_hwcap2_str(uint32_t bit)
-{
-    static const char *hwcap_str[] = {
-    [__builtin_ctz(ARM_HWCAP2_ARM_AES  )] = "aes",
-    [__builtin_ctz(ARM_HWCAP2_ARM_PMULL)] = "pmull",
-    [__builtin_ctz(ARM_HWCAP2_ARM_SHA1 )] = "sha1",
-    [__builtin_ctz(ARM_HWCAP2_ARM_SHA2 )] = "sha2",
-    [__builtin_ctz(ARM_HWCAP2_ARM_CRC32)] = "crc32",
-    [__builtin_ctz(ARM_HWCAP2_ARM_SB   )] = "sb",
-    [__builtin_ctz(ARM_HWCAP2_ARM_SSBS )] = "ssbs",
-    };
-
-    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
-}
-
-#undef GET_FEATURE
-#undef GET_FEATURE_ID
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
+#define ELF_HWCAP2 get_elf_hwcap2(thread_cpu)
 
 #define ELF_PLATFORM get_elf_platform()
 
@@ -712,342 +549,8 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
-enum {
-    ARM_HWCAP_A64_FP            = 1 << 0,
-    ARM_HWCAP_A64_ASIMD         = 1 << 1,
-    ARM_HWCAP_A64_EVTSTRM       = 1 << 2,
-    ARM_HWCAP_A64_AES           = 1 << 3,
-    ARM_HWCAP_A64_PMULL         = 1 << 4,
-    ARM_HWCAP_A64_SHA1          = 1 << 5,
-    ARM_HWCAP_A64_SHA2          = 1 << 6,
-    ARM_HWCAP_A64_CRC32         = 1 << 7,
-    ARM_HWCAP_A64_ATOMICS       = 1 << 8,
-    ARM_HWCAP_A64_FPHP          = 1 << 9,
-    ARM_HWCAP_A64_ASIMDHP       = 1 << 10,
-    ARM_HWCAP_A64_CPUID         = 1 << 11,
-    ARM_HWCAP_A64_ASIMDRDM      = 1 << 12,
-    ARM_HWCAP_A64_JSCVT         = 1 << 13,
-    ARM_HWCAP_A64_FCMA          = 1 << 14,
-    ARM_HWCAP_A64_LRCPC         = 1 << 15,
-    ARM_HWCAP_A64_DCPOP         = 1 << 16,
-    ARM_HWCAP_A64_SHA3          = 1 << 17,
-    ARM_HWCAP_A64_SM3           = 1 << 18,
-    ARM_HWCAP_A64_SM4           = 1 << 19,
-    ARM_HWCAP_A64_ASIMDDP       = 1 << 20,
-    ARM_HWCAP_A64_SHA512        = 1 << 21,
-    ARM_HWCAP_A64_SVE           = 1 << 22,
-    ARM_HWCAP_A64_ASIMDFHM      = 1 << 23,
-    ARM_HWCAP_A64_DIT           = 1 << 24,
-    ARM_HWCAP_A64_USCAT         = 1 << 25,
-    ARM_HWCAP_A64_ILRCPC        = 1 << 26,
-    ARM_HWCAP_A64_FLAGM         = 1 << 27,
-    ARM_HWCAP_A64_SSBS          = 1 << 28,
-    ARM_HWCAP_A64_SB            = 1 << 29,
-    ARM_HWCAP_A64_PACA          = 1 << 30,
-    ARM_HWCAP_A64_PACG          = 1ULL << 31,
-    ARM_HWCAP_A64_GCS           = 1ULL << 32,
-    ARM_HWCAP_A64_CMPBR         = 1ULL << 33,
-    ARM_HWCAP_A64_FPRCVT        = 1ULL << 34,
-    ARM_HWCAP_A64_F8MM8         = 1ULL << 35,
-    ARM_HWCAP_A64_F8MM4         = 1ULL << 36,
-    ARM_HWCAP_A64_SVE_F16MM     = 1ULL << 37,
-    ARM_HWCAP_A64_SVE_ELTPERM   = 1ULL << 38,
-    ARM_HWCAP_A64_SVE_AES2      = 1ULL << 39,
-    ARM_HWCAP_A64_SVE_BFSCALE   = 1ULL << 40,
-    ARM_HWCAP_A64_SVE2P2        = 1ULL << 41,
-    ARM_HWCAP_A64_SME2P2        = 1ULL << 42,
-    ARM_HWCAP_A64_SME_SBITPERM  = 1ULL << 43,
-    ARM_HWCAP_A64_SME_AES       = 1ULL << 44,
-    ARM_HWCAP_A64_SME_SFEXPA    = 1ULL << 45,
-    ARM_HWCAP_A64_SME_STMOP     = 1ULL << 46,
-    ARM_HWCAP_A64_SME_SMOP4     = 1ULL << 47,
-
-    ARM_HWCAP2_A64_DCPODP       = 1 << 0,
-    ARM_HWCAP2_A64_SVE2         = 1 << 1,
-    ARM_HWCAP2_A64_SVEAES       = 1 << 2,
-    ARM_HWCAP2_A64_SVEPMULL     = 1 << 3,
-    ARM_HWCAP2_A64_SVEBITPERM   = 1 << 4,
-    ARM_HWCAP2_A64_SVESHA3      = 1 << 5,
-    ARM_HWCAP2_A64_SVESM4       = 1 << 6,
-    ARM_HWCAP2_A64_FLAGM2       = 1 << 7,
-    ARM_HWCAP2_A64_FRINT        = 1 << 8,
-    ARM_HWCAP2_A64_SVEI8MM      = 1 << 9,
-    ARM_HWCAP2_A64_SVEF32MM     = 1 << 10,
-    ARM_HWCAP2_A64_SVEF64MM     = 1 << 11,
-    ARM_HWCAP2_A64_SVEBF16      = 1 << 12,
-    ARM_HWCAP2_A64_I8MM         = 1 << 13,
-    ARM_HWCAP2_A64_BF16         = 1 << 14,
-    ARM_HWCAP2_A64_DGH          = 1 << 15,
-    ARM_HWCAP2_A64_RNG          = 1 << 16,
-    ARM_HWCAP2_A64_BTI          = 1 << 17,
-    ARM_HWCAP2_A64_MTE          = 1 << 18,
-    ARM_HWCAP2_A64_ECV          = 1 << 19,
-    ARM_HWCAP2_A64_AFP          = 1 << 20,
-    ARM_HWCAP2_A64_RPRES        = 1 << 21,
-    ARM_HWCAP2_A64_MTE3         = 1 << 22,
-    ARM_HWCAP2_A64_SME          = 1 << 23,
-    ARM_HWCAP2_A64_SME_I16I64   = 1 << 24,
-    ARM_HWCAP2_A64_SME_F64F64   = 1 << 25,
-    ARM_HWCAP2_A64_SME_I8I32    = 1 << 26,
-    ARM_HWCAP2_A64_SME_F16F32   = 1 << 27,
-    ARM_HWCAP2_A64_SME_B16F32   = 1 << 28,
-    ARM_HWCAP2_A64_SME_F32F32   = 1 << 29,
-    ARM_HWCAP2_A64_SME_FA64     = 1 << 30,
-    ARM_HWCAP2_A64_WFXT         = 1ULL << 31,
-    ARM_HWCAP2_A64_EBF16        = 1ULL << 32,
-    ARM_HWCAP2_A64_SVE_EBF16    = 1ULL << 33,
-    ARM_HWCAP2_A64_CSSC         = 1ULL << 34,
-    ARM_HWCAP2_A64_RPRFM        = 1ULL << 35,
-    ARM_HWCAP2_A64_SVE2P1       = 1ULL << 36,
-    ARM_HWCAP2_A64_SME2         = 1ULL << 37,
-    ARM_HWCAP2_A64_SME2P1       = 1ULL << 38,
-    ARM_HWCAP2_A64_SME_I16I32   = 1ULL << 39,
-    ARM_HWCAP2_A64_SME_BI32I32  = 1ULL << 40,
-    ARM_HWCAP2_A64_SME_B16B16   = 1ULL << 41,
-    ARM_HWCAP2_A64_SME_F16F16   = 1ULL << 42,
-    ARM_HWCAP2_A64_MOPS         = 1ULL << 43,
-    ARM_HWCAP2_A64_HBC          = 1ULL << 44,
-    ARM_HWCAP2_A64_SVE_B16B16   = 1ULL << 45,
-    ARM_HWCAP2_A64_LRCPC3       = 1ULL << 46,
-    ARM_HWCAP2_A64_LSE128       = 1ULL << 47,
-    ARM_HWCAP2_A64_FPMR         = 1ULL << 48,
-    ARM_HWCAP2_A64_LUT          = 1ULL << 49,
-    ARM_HWCAP2_A64_FAMINMAX     = 1ULL << 50,
-    ARM_HWCAP2_A64_F8CVT        = 1ULL << 51,
-    ARM_HWCAP2_A64_F8FMA        = 1ULL << 52,
-    ARM_HWCAP2_A64_F8DP4        = 1ULL << 53,
-    ARM_HWCAP2_A64_F8DP2        = 1ULL << 54,
-    ARM_HWCAP2_A64_F8E4M3       = 1ULL << 55,
-    ARM_HWCAP2_A64_F8E5M2       = 1ULL << 56,
-    ARM_HWCAP2_A64_SME_LUTV2    = 1ULL << 57,
-    ARM_HWCAP2_A64_SME_F8F16    = 1ULL << 58,
-    ARM_HWCAP2_A64_SME_F8F32    = 1ULL << 59,
-    ARM_HWCAP2_A64_SME_SF8FMA   = 1ULL << 60,
-    ARM_HWCAP2_A64_SME_SF8DP4   = 1ULL << 61,
-    ARM_HWCAP2_A64_SME_SF8DP2   = 1ULL << 62,
-    ARM_HWCAP2_A64_POE          = 1ULL << 63,
-};
-
-#define ELF_HWCAP   get_elf_hwcap()
-#define ELF_HWCAP2  get_elf_hwcap2()
-
-#define GET_FEATURE_ID(feat, hwcap) \
-    do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0)
-
-uint32_t get_elf_hwcap(void)
-{
-    ARMCPU *cpu = ARM_CPU(thread_cpu);
-    uint32_t hwcaps = 0;
-
-    hwcaps |= ARM_HWCAP_A64_FP;
-    hwcaps |= ARM_HWCAP_A64_ASIMD;
-    hwcaps |= ARM_HWCAP_A64_CPUID;
-
-    /* probe for the extra features */
-
-    GET_FEATURE_ID(aa64_aes, ARM_HWCAP_A64_AES);
-    GET_FEATURE_ID(aa64_pmull, ARM_HWCAP_A64_PMULL);
-    GET_FEATURE_ID(aa64_sha1, ARM_HWCAP_A64_SHA1);
-    GET_FEATURE_ID(aa64_sha256, ARM_HWCAP_A64_SHA2);
-    GET_FEATURE_ID(aa64_sha512, ARM_HWCAP_A64_SHA512);
-    GET_FEATURE_ID(aa64_crc32, ARM_HWCAP_A64_CRC32);
-    GET_FEATURE_ID(aa64_sha3, ARM_HWCAP_A64_SHA3);
-    GET_FEATURE_ID(aa64_sm3, ARM_HWCAP_A64_SM3);
-    GET_FEATURE_ID(aa64_sm4, ARM_HWCAP_A64_SM4);
-    GET_FEATURE_ID(aa64_fp16, ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP);
-    GET_FEATURE_ID(aa64_atomics, ARM_HWCAP_A64_ATOMICS);
-    GET_FEATURE_ID(aa64_lse2, ARM_HWCAP_A64_USCAT);
-    GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM);
-    GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP);
-    GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA);
-    GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE);
-    GET_FEATURE_ID(aa64_pauth, ARM_HWCAP_A64_PACA | ARM_HWCAP_A64_PACG);
-    GET_FEATURE_ID(aa64_fhm, ARM_HWCAP_A64_ASIMDFHM);
-    GET_FEATURE_ID(aa64_dit, ARM_HWCAP_A64_DIT);
-    GET_FEATURE_ID(aa64_jscvt, ARM_HWCAP_A64_JSCVT);
-    GET_FEATURE_ID(aa64_sb, ARM_HWCAP_A64_SB);
-    GET_FEATURE_ID(aa64_condm_4, ARM_HWCAP_A64_FLAGM);
-    GET_FEATURE_ID(aa64_dcpop, ARM_HWCAP_A64_DCPOP);
-    GET_FEATURE_ID(aa64_rcpc_8_3, ARM_HWCAP_A64_LRCPC);
-    GET_FEATURE_ID(aa64_rcpc_8_4, ARM_HWCAP_A64_ILRCPC);
-
-    return hwcaps;
-}
-
-uint64_t get_elf_hwcap2(void)
-{
-    ARMCPU *cpu = ARM_CPU(thread_cpu);
-    uint64_t hwcaps = 0;
-
-    GET_FEATURE_ID(aa64_dcpodp, ARM_HWCAP2_A64_DCPODP);
-    GET_FEATURE_ID(aa64_sve2, ARM_HWCAP2_A64_SVE2);
-    GET_FEATURE_ID(aa64_sve2_aes, ARM_HWCAP2_A64_SVEAES);
-    GET_FEATURE_ID(aa64_sve2_pmull128, ARM_HWCAP2_A64_SVEPMULL);
-    GET_FEATURE_ID(aa64_sve2_bitperm, ARM_HWCAP2_A64_SVEBITPERM);
-    GET_FEATURE_ID(aa64_sve2_sha3, ARM_HWCAP2_A64_SVESHA3);
-    GET_FEATURE_ID(aa64_sve2_sm4, ARM_HWCAP2_A64_SVESM4);
-    GET_FEATURE_ID(aa64_condm_5, ARM_HWCAP2_A64_FLAGM2);
-    GET_FEATURE_ID(aa64_frint, ARM_HWCAP2_A64_FRINT);
-    GET_FEATURE_ID(aa64_sve_i8mm, ARM_HWCAP2_A64_SVEI8MM);
-    GET_FEATURE_ID(aa64_sve_f32mm, ARM_HWCAP2_A64_SVEF32MM);
-    GET_FEATURE_ID(aa64_sve_f64mm, ARM_HWCAP2_A64_SVEF64MM);
-    GET_FEATURE_ID(aa64_sve_bf16, ARM_HWCAP2_A64_SVEBF16);
-    GET_FEATURE_ID(aa64_i8mm, ARM_HWCAP2_A64_I8MM);
-    GET_FEATURE_ID(aa64_bf16, ARM_HWCAP2_A64_BF16);
-    GET_FEATURE_ID(aa64_rndr, ARM_HWCAP2_A64_RNG);
-    GET_FEATURE_ID(aa64_bti, ARM_HWCAP2_A64_BTI);
-    GET_FEATURE_ID(aa64_mte, ARM_HWCAP2_A64_MTE);
-    GET_FEATURE_ID(aa64_mte3, ARM_HWCAP2_A64_MTE3);
-    GET_FEATURE_ID(aa64_sme, (ARM_HWCAP2_A64_SME |
-                              ARM_HWCAP2_A64_SME_F32F32 |
-                              ARM_HWCAP2_A64_SME_B16F32 |
-                              ARM_HWCAP2_A64_SME_F16F32 |
-                              ARM_HWCAP2_A64_SME_I8I32));
-    GET_FEATURE_ID(aa64_sme_f64f64, ARM_HWCAP2_A64_SME_F64F64);
-    GET_FEATURE_ID(aa64_sme_i16i64, ARM_HWCAP2_A64_SME_I16I64);
-    GET_FEATURE_ID(aa64_sme_fa64, ARM_HWCAP2_A64_SME_FA64);
-    GET_FEATURE_ID(aa64_hbc, ARM_HWCAP2_A64_HBC);
-    GET_FEATURE_ID(aa64_mops, ARM_HWCAP2_A64_MOPS);
-    GET_FEATURE_ID(aa64_sve2p1, ARM_HWCAP2_A64_SVE2P1);
-    GET_FEATURE_ID(aa64_sme2, (ARM_HWCAP2_A64_SME2 |
-                               ARM_HWCAP2_A64_SME_I16I32 |
-                               ARM_HWCAP2_A64_SME_BI32I32));
-    GET_FEATURE_ID(aa64_sme2p1, ARM_HWCAP2_A64_SME2P1);
-    GET_FEATURE_ID(aa64_sme_b16b16, ARM_HWCAP2_A64_SME_B16B16);
-    GET_FEATURE_ID(aa64_sme_f16f16, ARM_HWCAP2_A64_SME_F16F16);
-    GET_FEATURE_ID(aa64_sve_b16b16, ARM_HWCAP2_A64_SVE_B16B16);
-
-    return hwcaps;
-}
-
-const char *elf_hwcap_str(uint32_t bit)
-{
-    static const char * const hwcap_str[] = {
-    [__builtin_ctz(ARM_HWCAP_A64_FP      )] = "fp",
-    [__builtin_ctz(ARM_HWCAP_A64_ASIMD   )] = "asimd",
-    [__builtin_ctz(ARM_HWCAP_A64_EVTSTRM )] = "evtstrm",
-    [__builtin_ctz(ARM_HWCAP_A64_AES     )] = "aes",
-    [__builtin_ctz(ARM_HWCAP_A64_PMULL   )] = "pmull",
-    [__builtin_ctz(ARM_HWCAP_A64_SHA1    )] = "sha1",
-    [__builtin_ctz(ARM_HWCAP_A64_SHA2    )] = "sha2",
-    [__builtin_ctz(ARM_HWCAP_A64_CRC32   )] = "crc32",
-    [__builtin_ctz(ARM_HWCAP_A64_ATOMICS )] = "atomics",
-    [__builtin_ctz(ARM_HWCAP_A64_FPHP    )] = "fphp",
-    [__builtin_ctz(ARM_HWCAP_A64_ASIMDHP )] = "asimdhp",
-    [__builtin_ctz(ARM_HWCAP_A64_CPUID   )] = "cpuid",
-    [__builtin_ctz(ARM_HWCAP_A64_ASIMDRDM)] = "asimdrdm",
-    [__builtin_ctz(ARM_HWCAP_A64_JSCVT   )] = "jscvt",
-    [__builtin_ctz(ARM_HWCAP_A64_FCMA    )] = "fcma",
-    [__builtin_ctz(ARM_HWCAP_A64_LRCPC   )] = "lrcpc",
-    [__builtin_ctz(ARM_HWCAP_A64_DCPOP   )] = "dcpop",
-    [__builtin_ctz(ARM_HWCAP_A64_SHA3    )] = "sha3",
-    [__builtin_ctz(ARM_HWCAP_A64_SM3     )] = "sm3",
-    [__builtin_ctz(ARM_HWCAP_A64_SM4     )] = "sm4",
-    [__builtin_ctz(ARM_HWCAP_A64_ASIMDDP )] = "asimddp",
-    [__builtin_ctz(ARM_HWCAP_A64_SHA512  )] = "sha512",
-    [__builtin_ctz(ARM_HWCAP_A64_SVE     )] = "sve",
-    [__builtin_ctz(ARM_HWCAP_A64_ASIMDFHM)] = "asimdfhm",
-    [__builtin_ctz(ARM_HWCAP_A64_DIT     )] = "dit",
-    [__builtin_ctz(ARM_HWCAP_A64_USCAT   )] = "uscat",
-    [__builtin_ctz(ARM_HWCAP_A64_ILRCPC  )] = "ilrcpc",
-    [__builtin_ctz(ARM_HWCAP_A64_FLAGM   )] = "flagm",
-    [__builtin_ctz(ARM_HWCAP_A64_SSBS    )] = "ssbs",
-    [__builtin_ctz(ARM_HWCAP_A64_SB      )] = "sb",
-    [__builtin_ctz(ARM_HWCAP_A64_PACA    )] = "paca",
-    [__builtin_ctz(ARM_HWCAP_A64_PACG    )] = "pacg",
-    [__builtin_ctzll(ARM_HWCAP_A64_GCS   )] = "gcs",
-    [__builtin_ctzll(ARM_HWCAP_A64_CMPBR )] = "cmpbr",
-    [__builtin_ctzll(ARM_HWCAP_A64_FPRCVT)] = "fprcvt",
-    [__builtin_ctzll(ARM_HWCAP_A64_F8MM8 )] = "f8mm8",
-    [__builtin_ctzll(ARM_HWCAP_A64_F8MM4 )] = "f8mm4",
-    [__builtin_ctzll(ARM_HWCAP_A64_SVE_F16MM)] = "svef16mm",
-    [__builtin_ctzll(ARM_HWCAP_A64_SVE_ELTPERM)] = "sveeltperm",
-    [__builtin_ctzll(ARM_HWCAP_A64_SVE_AES2)] = "sveaes2",
-    [__builtin_ctzll(ARM_HWCAP_A64_SVE_BFSCALE)] = "svebfscale",
-    [__builtin_ctzll(ARM_HWCAP_A64_SVE2P2)] = "sve2p2",
-    [__builtin_ctzll(ARM_HWCAP_A64_SME2P2)] = "sme2p2",
-    [__builtin_ctzll(ARM_HWCAP_A64_SME_SBITPERM)] = "smesbitperm",
-    [__builtin_ctzll(ARM_HWCAP_A64_SME_AES)] = "smeaes",
-    [__builtin_ctzll(ARM_HWCAP_A64_SME_SFEXPA)] = "smesfexpa",
-    [__builtin_ctzll(ARM_HWCAP_A64_SME_STMOP)] = "smestmop",
-    [__builtin_ctzll(ARM_HWCAP_A64_SME_SMOP4)] = "smesmop4",
-    };
-
-    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
-}
-
-const char *elf_hwcap2_str(uint32_t bit)
-{
-    static const char * const hwcap_str[] = {
-    [__builtin_ctz(ARM_HWCAP2_A64_DCPODP       )] = "dcpodp",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVE2         )] = "sve2",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEAES       )] = "sveaes",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEPMULL     )] = "svepmull",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEBITPERM   )] = "svebitperm",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVESHA3      )] = "svesha3",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVESM4       )] = "svesm4",
-    [__builtin_ctz(ARM_HWCAP2_A64_FLAGM2       )] = "flagm2",
-    [__builtin_ctz(ARM_HWCAP2_A64_FRINT        )] = "frint",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEI8MM      )] = "svei8mm",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEF32MM     )] = "svef32mm",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEF64MM     )] = "svef64mm",
-    [__builtin_ctz(ARM_HWCAP2_A64_SVEBF16      )] = "svebf16",
-    [__builtin_ctz(ARM_HWCAP2_A64_I8MM         )] = "i8mm",
-    [__builtin_ctz(ARM_HWCAP2_A64_BF16         )] = "bf16",
-    [__builtin_ctz(ARM_HWCAP2_A64_DGH          )] = "dgh",
-    [__builtin_ctz(ARM_HWCAP2_A64_RNG          )] = "rng",
-    [__builtin_ctz(ARM_HWCAP2_A64_BTI          )] = "bti",
-    [__builtin_ctz(ARM_HWCAP2_A64_MTE          )] = "mte",
-    [__builtin_ctz(ARM_HWCAP2_A64_ECV          )] = "ecv",
-    [__builtin_ctz(ARM_HWCAP2_A64_AFP          )] = "afp",
-    [__builtin_ctz(ARM_HWCAP2_A64_RPRES        )] = "rpres",
-    [__builtin_ctz(ARM_HWCAP2_A64_MTE3         )] = "mte3",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME          )] = "sme",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_I16I64   )] = "smei16i64",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_F64F64   )] = "smef64f64",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_I8I32    )] = "smei8i32",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_F16F32   )] = "smef16f32",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_B16F32   )] = "smeb16f32",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_F32F32   )] = "smef32f32",
-    [__builtin_ctz(ARM_HWCAP2_A64_SME_FA64     )] = "smefa64",
-    [__builtin_ctz(ARM_HWCAP2_A64_WFXT         )] = "wfxt",
-    [__builtin_ctzll(ARM_HWCAP2_A64_EBF16      )] = "ebf16",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SVE_EBF16  )] = "sveebf16",
-    [__builtin_ctzll(ARM_HWCAP2_A64_CSSC       )] = "cssc",
-    [__builtin_ctzll(ARM_HWCAP2_A64_RPRFM      )] = "rprfm",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SVE2P1     )] = "sve2p1",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME2       )] = "sme2",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME2P1     )] = "sme2p1",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_I16I32 )] = "smei16i32",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_BI32I32)] = "smebi32i32",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_B16B16 )] = "smeb16b16",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_F16F16 )] = "smef16f16",
-    [__builtin_ctzll(ARM_HWCAP2_A64_MOPS       )] = "mops",
-    [__builtin_ctzll(ARM_HWCAP2_A64_HBC        )] = "hbc",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SVE_B16B16 )] = "sveb16b16",
-    [__builtin_ctzll(ARM_HWCAP2_A64_LRCPC3     )] = "lrcpc3",
-    [__builtin_ctzll(ARM_HWCAP2_A64_LSE128     )] = "lse128",
-    [__builtin_ctzll(ARM_HWCAP2_A64_FPMR       )] = "fpmr",
-    [__builtin_ctzll(ARM_HWCAP2_A64_LUT        )] = "lut",
-    [__builtin_ctzll(ARM_HWCAP2_A64_FAMINMAX   )] = "faminmax",
-    [__builtin_ctzll(ARM_HWCAP2_A64_F8CVT      )] = "f8cvt",
-    [__builtin_ctzll(ARM_HWCAP2_A64_F8FMA      )] = "f8fma",
-    [__builtin_ctzll(ARM_HWCAP2_A64_F8DP4      )] = "f8dp4",
-    [__builtin_ctzll(ARM_HWCAP2_A64_F8DP2      )] = "f8dp2",
-    [__builtin_ctzll(ARM_HWCAP2_A64_F8E4M3     )] = "f8e4m3",
-    [__builtin_ctzll(ARM_HWCAP2_A64_F8E5M2     )] = "f8e5m2",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_LUTV2  )] = "smelutv2",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_F8F16  )] = "smef8f16",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_F8F32  )] = "smef8f32",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_SF8DP4 )] = "smesf8dp4",
-    [__builtin_ctzll(ARM_HWCAP2_A64_SME_SF8DP2 )] = "smesf8dp2",
-    [__builtin_ctzll(ARM_HWCAP2_A64_POE        )] = "poe",
-    };
-
-    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
-}
-
-#undef GET_FEATURE_ID
+#define ELF_HWCAP   get_elf_hwcap(thread_cpu)
+#define ELF_HWCAP2  get_elf_hwcap2(thread_cpu)
 
 #if TARGET_BIG_ENDIAN
 # define VDSO_HEADER  "vdso-be.c.inc"
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 04/89] linux-user: Move get_elf_hwcap to sparc/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (2 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 03/89] linux-user: Move hwcap functions to {arm, aarch64}/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:53   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 05/89] linux-user: Move hwcap functions to ppc/elfload.c Richard Henderson
                   ` (85 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h        |  3 ++-
 linux-user/elfload.c       | 30 +-----------------------------
 linux-user/sparc/elfload.c | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index be92207c2b..d2f0bea2b2 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -98,7 +98,8 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
-#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM)
+#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
+    || defined(TARGET_SPARC)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 3a4f68f503..220af18cb8 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -575,35 +575,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 # define ELF_ARCH   EM_SPARCV9
 #endif
 
-#include "elf.h"
-
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-    /* There are not many sparc32 hwcap bits -- we have all of them. */
-    uint32_t r = HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
-                 HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV;
-
-#ifdef TARGET_SPARC64
-    CPUSPARCState *env = cpu_env(thread_cpu);
-    uint32_t features = env->def.features;
-
-    r |= HWCAP_SPARC_V9 | HWCAP_SPARC_V8PLUS;
-    /* 32x32 multiply and divide are efficient. */
-    r |= HWCAP_SPARC_MUL32 | HWCAP_SPARC_DIV32;
-    /* We don't have an internal feature bit for this. */
-    r |= HWCAP_SPARC_POPC;
-    r |= features & CPU_FEATURE_FSMULD ? HWCAP_SPARC_FSMULD : 0;
-    r |= features & CPU_FEATURE_VIS1 ? HWCAP_SPARC_VIS : 0;
-    r |= features & CPU_FEATURE_VIS2 ? HWCAP_SPARC_VIS2 : 0;
-    r |= features & CPU_FEATURE_FMAF ? HWCAP_SPARC_FMAF : 0;
-    r |= features & CPU_FEATURE_VIS3 ? HWCAP_SPARC_VIS3 : 0;
-    r |= features & CPU_FEATURE_IMA ? HWCAP_SPARC_IMA : 0;
-#endif
-
-    return r;
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
diff --git a/linux-user/sparc/elfload.c b/linux-user/sparc/elfload.c
index 73fa78ef14..b4b8e4916e 100644
--- a/linux-user/sparc/elfload.c
+++ b/linux-user/sparc/elfload.c
@@ -1 +1,33 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "elf.h"
+
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    /* There are not many sparc32 hwcap bits -- we have all of them. */
+    abi_ulong r = HWCAP_SPARC_FLUSH | HWCAP_SPARC_STBAR |
+                  HWCAP_SPARC_SWAP | HWCAP_SPARC_MULDIV;
+
+#ifdef TARGET_SPARC64
+    CPUSPARCState *env = cpu_env(cs);
+    uint32_t features = env->def.features;
+
+    r |= HWCAP_SPARC_V9 | HWCAP_SPARC_V8PLUS;
+    /* 32x32 multiply and divide are efficient. */
+    r |= HWCAP_SPARC_MUL32 | HWCAP_SPARC_DIV32;
+    /* We don't have an internal feature bit for this. */
+    r |= HWCAP_SPARC_POPC;
+    r |= features & CPU_FEATURE_FSMULD ? HWCAP_SPARC_FSMULD : 0;
+    r |= features & CPU_FEATURE_VIS1 ? HWCAP_SPARC_VIS : 0;
+    r |= features & CPU_FEATURE_VIS2 ? HWCAP_SPARC_VIS2 : 0;
+    r |= features & CPU_FEATURE_FMAF ? HWCAP_SPARC_FMAF : 0;
+    r |= features & CPU_FEATURE_VIS3 ? HWCAP_SPARC_VIS3 : 0;
+    r |= features & CPU_FEATURE_IMA ? HWCAP_SPARC_IMA : 0;
+#endif
+
+    return r;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 05/89] linux-user: Move hwcap functions to ppc/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (3 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 04/89] linux-user: Move get_elf_hwcap to sparc/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:54   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 06/89] linux-user: Move get_elf_hwcap to loongarch64/elfload.c Richard Henderson
                   ` (84 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h      |   2 +-
 linux-user/elfload.c     | 116 +------------------------------------
 linux-user/ppc/elfload.c | 121 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 115 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index d2f0bea2b2..781bf89e88 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -99,7 +99,7 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 extern unsigned long guest_stack_size;
 
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
-    || defined(TARGET_SPARC)
+    || defined(TARGET_SPARC) || defined(TARGET_PPC)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 220af18cb8..32cf2db718 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -608,120 +608,8 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #define ELF_ARCH        EM_PPC
 
-/* Feature masks for the Aux Vector Hardware Capabilities (AT_HWCAP).
-   See arch/powerpc/include/asm/cputable.h.  */
-enum {
-    QEMU_PPC_FEATURE_32 = 0x80000000,
-    QEMU_PPC_FEATURE_64 = 0x40000000,
-    QEMU_PPC_FEATURE_601_INSTR = 0x20000000,
-    QEMU_PPC_FEATURE_HAS_ALTIVEC = 0x10000000,
-    QEMU_PPC_FEATURE_HAS_FPU = 0x08000000,
-    QEMU_PPC_FEATURE_HAS_MMU = 0x04000000,
-    QEMU_PPC_FEATURE_HAS_4xxMAC = 0x02000000,
-    QEMU_PPC_FEATURE_UNIFIED_CACHE = 0x01000000,
-    QEMU_PPC_FEATURE_HAS_SPE = 0x00800000,
-    QEMU_PPC_FEATURE_HAS_EFP_SINGLE = 0x00400000,
-    QEMU_PPC_FEATURE_HAS_EFP_DOUBLE = 0x00200000,
-    QEMU_PPC_FEATURE_NO_TB = 0x00100000,
-    QEMU_PPC_FEATURE_POWER4 = 0x00080000,
-    QEMU_PPC_FEATURE_POWER5 = 0x00040000,
-    QEMU_PPC_FEATURE_POWER5_PLUS = 0x00020000,
-    QEMU_PPC_FEATURE_CELL = 0x00010000,
-    QEMU_PPC_FEATURE_BOOKE = 0x00008000,
-    QEMU_PPC_FEATURE_SMT = 0x00004000,
-    QEMU_PPC_FEATURE_ICACHE_SNOOP = 0x00002000,
-    QEMU_PPC_FEATURE_ARCH_2_05 = 0x00001000,
-    QEMU_PPC_FEATURE_PA6T = 0x00000800,
-    QEMU_PPC_FEATURE_HAS_DFP = 0x00000400,
-    QEMU_PPC_FEATURE_POWER6_EXT = 0x00000200,
-    QEMU_PPC_FEATURE_ARCH_2_06 = 0x00000100,
-    QEMU_PPC_FEATURE_HAS_VSX = 0x00000080,
-    QEMU_PPC_FEATURE_PSERIES_PERFMON_COMPAT = 0x00000040,
-
-    QEMU_PPC_FEATURE_TRUE_LE = 0x00000002,
-    QEMU_PPC_FEATURE_PPC_LE = 0x00000001,
-
-    /* Feature definitions in AT_HWCAP2.  */
-    QEMU_PPC_FEATURE2_ARCH_2_07 = 0x80000000, /* ISA 2.07 */
-    QEMU_PPC_FEATURE2_HAS_HTM = 0x40000000, /* Hardware Transactional Memory */
-    QEMU_PPC_FEATURE2_HAS_DSCR = 0x20000000, /* Data Stream Control Register */
-    QEMU_PPC_FEATURE2_HAS_EBB = 0x10000000, /* Event Base Branching */
-    QEMU_PPC_FEATURE2_HAS_ISEL = 0x08000000, /* Integer Select */
-    QEMU_PPC_FEATURE2_HAS_TAR = 0x04000000, /* Target Address Register */
-    QEMU_PPC_FEATURE2_VEC_CRYPTO = 0x02000000,
-    QEMU_PPC_FEATURE2_HTM_NOSC = 0x01000000,
-    QEMU_PPC_FEATURE2_ARCH_3_00 = 0x00800000, /* ISA 3.00 */
-    QEMU_PPC_FEATURE2_HAS_IEEE128 = 0x00400000, /* VSX IEEE Bin Float 128-bit */
-    QEMU_PPC_FEATURE2_DARN = 0x00200000, /* darn random number insn */
-    QEMU_PPC_FEATURE2_SCV = 0x00100000, /* scv syscall */
-    QEMU_PPC_FEATURE2_HTM_NO_SUSPEND = 0x00080000, /* TM w/o suspended state */
-    QEMU_PPC_FEATURE2_ARCH_3_1 = 0x00040000, /* ISA 3.1 */
-    QEMU_PPC_FEATURE2_MMA = 0x00020000, /* Matrix-Multiply Assist */
-};
-
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-    PowerPCCPU *cpu = POWERPC_CPU(thread_cpu);
-    uint32_t features = 0;
-
-    /* We don't have to be terribly complete here; the high points are
-       Altivec/FP/SPE support.  Anything else is just a bonus.  */
-#define GET_FEATURE(flag, feature)                                      \
-    do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0)
-#define GET_FEATURE2(flags, feature) \
-    do { \
-        if ((cpu->env.insns_flags2 & flags) == flags) { \
-            features |= feature; \
-        } \
-    } while (0)
-    GET_FEATURE(PPC_64B, QEMU_PPC_FEATURE_64);
-    GET_FEATURE(PPC_FLOAT, QEMU_PPC_FEATURE_HAS_FPU);
-    GET_FEATURE(PPC_ALTIVEC, QEMU_PPC_FEATURE_HAS_ALTIVEC);
-    GET_FEATURE(PPC_SPE, QEMU_PPC_FEATURE_HAS_SPE);
-    GET_FEATURE(PPC_SPE_SINGLE, QEMU_PPC_FEATURE_HAS_EFP_SINGLE);
-    GET_FEATURE(PPC_SPE_DOUBLE, QEMU_PPC_FEATURE_HAS_EFP_DOUBLE);
-    GET_FEATURE(PPC_BOOKE, QEMU_PPC_FEATURE_BOOKE);
-    GET_FEATURE(PPC_405_MAC, QEMU_PPC_FEATURE_HAS_4xxMAC);
-    GET_FEATURE2(PPC2_DFP, QEMU_PPC_FEATURE_HAS_DFP);
-    GET_FEATURE2(PPC2_VSX, QEMU_PPC_FEATURE_HAS_VSX);
-    GET_FEATURE2((PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 |
-                  PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206),
-                  QEMU_PPC_FEATURE_ARCH_2_06);
-#undef GET_FEATURE
-#undef GET_FEATURE2
-
-    return features;
-}
-
-#define ELF_HWCAP2 get_elf_hwcap2()
-
-static uint32_t get_elf_hwcap2(void)
-{
-    PowerPCCPU *cpu = POWERPC_CPU(thread_cpu);
-    uint32_t features = 0;
-
-#define GET_FEATURE(flag, feature)                                      \
-    do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0)
-#define GET_FEATURE2(flag, feature)                                      \
-    do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0)
-
-    GET_FEATURE(PPC_ISEL, QEMU_PPC_FEATURE2_HAS_ISEL);
-    GET_FEATURE2(PPC2_BCTAR_ISA207, QEMU_PPC_FEATURE2_HAS_TAR);
-    GET_FEATURE2((PPC2_BCTAR_ISA207 | PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
-                  PPC2_ISA207S), QEMU_PPC_FEATURE2_ARCH_2_07 |
-                  QEMU_PPC_FEATURE2_VEC_CRYPTO);
-    GET_FEATURE2(PPC2_ISA300, QEMU_PPC_FEATURE2_ARCH_3_00 |
-                 QEMU_PPC_FEATURE2_DARN | QEMU_PPC_FEATURE2_HAS_IEEE128);
-    GET_FEATURE2(PPC2_ISA310, QEMU_PPC_FEATURE2_ARCH_3_1 |
-                 QEMU_PPC_FEATURE2_MMA);
-
-#undef GET_FEATURE
-#undef GET_FEATURE2
-
-    return features;
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
+#define ELF_HWCAP2 get_elf_hwcap2(thread_cpu)
 
 /*
  * The requirements here are:
diff --git a/linux-user/ppc/elfload.c b/linux-user/ppc/elfload.c
index 73fa78ef14..3b2dcdfc47 100644
--- a/linux-user/ppc/elfload.c
+++ b/linux-user/ppc/elfload.c
@@ -1 +1,122 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+/*
+ * Feature masks for the Aux Vector Hardware Capabilities (AT_HWCAP).
+ * See arch/powerpc/include/asm/cputable.h.
+ */
+enum {
+    QEMU_PPC_FEATURE_32 = 0x80000000,
+    QEMU_PPC_FEATURE_64 = 0x40000000,
+    QEMU_PPC_FEATURE_601_INSTR = 0x20000000,
+    QEMU_PPC_FEATURE_HAS_ALTIVEC = 0x10000000,
+    QEMU_PPC_FEATURE_HAS_FPU = 0x08000000,
+    QEMU_PPC_FEATURE_HAS_MMU = 0x04000000,
+    QEMU_PPC_FEATURE_HAS_4xxMAC = 0x02000000,
+    QEMU_PPC_FEATURE_UNIFIED_CACHE = 0x01000000,
+    QEMU_PPC_FEATURE_HAS_SPE = 0x00800000,
+    QEMU_PPC_FEATURE_HAS_EFP_SINGLE = 0x00400000,
+    QEMU_PPC_FEATURE_HAS_EFP_DOUBLE = 0x00200000,
+    QEMU_PPC_FEATURE_NO_TB = 0x00100000,
+    QEMU_PPC_FEATURE_POWER4 = 0x00080000,
+    QEMU_PPC_FEATURE_POWER5 = 0x00040000,
+    QEMU_PPC_FEATURE_POWER5_PLUS = 0x00020000,
+    QEMU_PPC_FEATURE_CELL = 0x00010000,
+    QEMU_PPC_FEATURE_BOOKE = 0x00008000,
+    QEMU_PPC_FEATURE_SMT = 0x00004000,
+    QEMU_PPC_FEATURE_ICACHE_SNOOP = 0x00002000,
+    QEMU_PPC_FEATURE_ARCH_2_05 = 0x00001000,
+    QEMU_PPC_FEATURE_PA6T = 0x00000800,
+    QEMU_PPC_FEATURE_HAS_DFP = 0x00000400,
+    QEMU_PPC_FEATURE_POWER6_EXT = 0x00000200,
+    QEMU_PPC_FEATURE_ARCH_2_06 = 0x00000100,
+    QEMU_PPC_FEATURE_HAS_VSX = 0x00000080,
+    QEMU_PPC_FEATURE_PSERIES_PERFMON_COMPAT = 0x00000040,
+
+    QEMU_PPC_FEATURE_TRUE_LE = 0x00000002,
+    QEMU_PPC_FEATURE_PPC_LE = 0x00000001,
+
+    /* Feature definitions in AT_HWCAP2.  */
+    QEMU_PPC_FEATURE2_ARCH_2_07 = 0x80000000, /* ISA 2.07 */
+    QEMU_PPC_FEATURE2_HAS_HTM = 0x40000000, /* Hardware Transactional Memory */
+    QEMU_PPC_FEATURE2_HAS_DSCR = 0x20000000, /* Data Stream Control Register */
+    QEMU_PPC_FEATURE2_HAS_EBB = 0x10000000, /* Event Base Branching */
+    QEMU_PPC_FEATURE2_HAS_ISEL = 0x08000000, /* Integer Select */
+    QEMU_PPC_FEATURE2_HAS_TAR = 0x04000000, /* Target Address Register */
+    QEMU_PPC_FEATURE2_VEC_CRYPTO = 0x02000000,
+    QEMU_PPC_FEATURE2_HTM_NOSC = 0x01000000,
+    QEMU_PPC_FEATURE2_ARCH_3_00 = 0x00800000, /* ISA 3.00 */
+    QEMU_PPC_FEATURE2_HAS_IEEE128 = 0x00400000, /* VSX IEEE Bin Float 128-bit */
+    QEMU_PPC_FEATURE2_DARN = 0x00200000, /* darn random number insn */
+    QEMU_PPC_FEATURE2_SCV = 0x00100000, /* scv syscall */
+    QEMU_PPC_FEATURE2_HTM_NO_SUSPEND = 0x00080000, /* TM w/o suspended state */
+    QEMU_PPC_FEATURE2_ARCH_3_1 = 0x00040000, /* ISA 3.1 */
+    QEMU_PPC_FEATURE2_MMA = 0x00020000, /* Matrix-Multiply Assist */
+};
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    uint32_t features = 0;
+
+    /*
+     * We don't have to be terribly complete here; the high points are
+     * Altivec/FP/SPE support.  Anything else is just a bonus.
+     */
+#define GET_FEATURE(flag, feature)                                      \
+    do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0)
+#define GET_FEATURE2(flags, feature) \
+    do { \
+        if ((cpu->env.insns_flags2 & flags) == flags) { \
+            features |= feature; \
+        } \
+    } while (0)
+    GET_FEATURE(PPC_64B, QEMU_PPC_FEATURE_64);
+    GET_FEATURE(PPC_FLOAT, QEMU_PPC_FEATURE_HAS_FPU);
+    GET_FEATURE(PPC_ALTIVEC, QEMU_PPC_FEATURE_HAS_ALTIVEC);
+    GET_FEATURE(PPC_SPE, QEMU_PPC_FEATURE_HAS_SPE);
+    GET_FEATURE(PPC_SPE_SINGLE, QEMU_PPC_FEATURE_HAS_EFP_SINGLE);
+    GET_FEATURE(PPC_SPE_DOUBLE, QEMU_PPC_FEATURE_HAS_EFP_DOUBLE);
+    GET_FEATURE(PPC_BOOKE, QEMU_PPC_FEATURE_BOOKE);
+    GET_FEATURE(PPC_405_MAC, QEMU_PPC_FEATURE_HAS_4xxMAC);
+    GET_FEATURE2(PPC2_DFP, QEMU_PPC_FEATURE_HAS_DFP);
+    GET_FEATURE2(PPC2_VSX, QEMU_PPC_FEATURE_HAS_VSX);
+    GET_FEATURE2((PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 |
+                  PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206),
+                  QEMU_PPC_FEATURE_ARCH_2_06);
+
+#undef GET_FEATURE
+#undef GET_FEATURE2
+
+    return features;
+}
+
+abi_ulong get_elf_hwcap2(CPUState *cs)
+{
+    PowerPCCPU *cpu = POWERPC_CPU(cs);
+    uint32_t features = 0;
+
+#define GET_FEATURE(flag, feature)                                      \
+    do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0)
+#define GET_FEATURE2(flag, feature)                                      \
+    do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0)
+
+    GET_FEATURE(PPC_ISEL, QEMU_PPC_FEATURE2_HAS_ISEL);
+    GET_FEATURE2(PPC2_BCTAR_ISA207, QEMU_PPC_FEATURE2_HAS_TAR);
+    GET_FEATURE2((PPC2_BCTAR_ISA207 | PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
+                  PPC2_ISA207S), QEMU_PPC_FEATURE2_ARCH_2_07 |
+                  QEMU_PPC_FEATURE2_VEC_CRYPTO);
+    GET_FEATURE2(PPC2_ISA300, QEMU_PPC_FEATURE2_ARCH_3_00 |
+                 QEMU_PPC_FEATURE2_DARN | QEMU_PPC_FEATURE2_HAS_IEEE128);
+    GET_FEATURE2(PPC2_ISA310, QEMU_PPC_FEATURE2_ARCH_3_1 |
+                 QEMU_PPC_FEATURE2_MMA);
+
+#undef GET_FEATURE
+#undef GET_FEATURE2
+
+    return features;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 06/89] linux-user: Move get_elf_hwcap to loongarch64/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (4 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 05/89] linux-user: Move hwcap functions to ppc/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:54   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 07/89] linux-user: Move get_elf_hwcap to mips/elfload.c Richard Henderson
                   ` (83 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h              |  3 +-
 linux-user/elfload.c             | 49 +-----------------------------
 linux-user/loongarch64/elfload.c | 52 ++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 781bf89e88..786482e68a 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -99,7 +99,8 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 extern unsigned long guest_stack_size;
 
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
-    || defined(TARGET_SPARC) || defined(TARGET_PPC)
+    || defined(TARGET_SPARC) || defined(TARGET_PPC) \
+    || defined(TARGET_LOONGARCH64)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 32cf2db718..f173a4f5b8 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -735,54 +735,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-#define ELF_HWCAP get_elf_hwcap()
-
-/* See arch/loongarch/include/uapi/asm/hwcap.h */
-enum {
-    HWCAP_LOONGARCH_CPUCFG   = (1 << 0),
-    HWCAP_LOONGARCH_LAM      = (1 << 1),
-    HWCAP_LOONGARCH_UAL      = (1 << 2),
-    HWCAP_LOONGARCH_FPU      = (1 << 3),
-    HWCAP_LOONGARCH_LSX      = (1 << 4),
-    HWCAP_LOONGARCH_LASX     = (1 << 5),
-    HWCAP_LOONGARCH_CRC32    = (1 << 6),
-    HWCAP_LOONGARCH_COMPLEX  = (1 << 7),
-    HWCAP_LOONGARCH_CRYPTO   = (1 << 8),
-    HWCAP_LOONGARCH_LVZ      = (1 << 9),
-    HWCAP_LOONGARCH_LBT_X86  = (1 << 10),
-    HWCAP_LOONGARCH_LBT_ARM  = (1 << 11),
-    HWCAP_LOONGARCH_LBT_MIPS = (1 << 12),
-};
-
-static uint32_t get_elf_hwcap(void)
-{
-    LoongArchCPU *cpu = LOONGARCH_CPU(thread_cpu);
-    uint32_t hwcaps = 0;
-
-    hwcaps |= HWCAP_LOONGARCH_CRC32;
-
-    if (FIELD_EX32(cpu->env.cpucfg[1], CPUCFG1, UAL)) {
-        hwcaps |= HWCAP_LOONGARCH_UAL;
-    }
-
-    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, FP)) {
-        hwcaps |= HWCAP_LOONGARCH_FPU;
-    }
-
-    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LAM)) {
-        hwcaps |= HWCAP_LOONGARCH_LAM;
-    }
-
-    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
-        hwcaps |= HWCAP_LOONGARCH_LSX;
-    }
-
-    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
-        hwcaps |= HWCAP_LOONGARCH_LASX;
-    }
-
-    return hwcaps;
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 #define ELF_PLATFORM "loongarch"
 
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
index 73fa78ef14..f27992459b 100644
--- a/linux-user/loongarch64/elfload.c
+++ b/linux-user/loongarch64/elfload.c
@@ -1 +1,53 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+/* See arch/loongarch/include/uapi/asm/hwcap.h */
+enum {
+    HWCAP_LOONGARCH_CPUCFG   = (1 << 0),
+    HWCAP_LOONGARCH_LAM      = (1 << 1),
+    HWCAP_LOONGARCH_UAL      = (1 << 2),
+    HWCAP_LOONGARCH_FPU      = (1 << 3),
+    HWCAP_LOONGARCH_LSX      = (1 << 4),
+    HWCAP_LOONGARCH_LASX     = (1 << 5),
+    HWCAP_LOONGARCH_CRC32    = (1 << 6),
+    HWCAP_LOONGARCH_COMPLEX  = (1 << 7),
+    HWCAP_LOONGARCH_CRYPTO   = (1 << 8),
+    HWCAP_LOONGARCH_LVZ      = (1 << 9),
+    HWCAP_LOONGARCH_LBT_X86  = (1 << 10),
+    HWCAP_LOONGARCH_LBT_ARM  = (1 << 11),
+    HWCAP_LOONGARCH_LBT_MIPS = (1 << 12),
+};
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    LoongArchCPU *cpu = LOONGARCH_CPU(cs);
+    abi_ulong hwcaps = 0;
+
+    hwcaps |= HWCAP_LOONGARCH_CRC32;
+
+    if (FIELD_EX32(cpu->env.cpucfg[1], CPUCFG1, UAL)) {
+        hwcaps |= HWCAP_LOONGARCH_UAL;
+    }
+
+    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, FP)) {
+        hwcaps |= HWCAP_LOONGARCH_FPU;
+    }
+
+    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LAM)) {
+        hwcaps |= HWCAP_LOONGARCH_LAM;
+    }
+
+    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) {
+        hwcaps |= HWCAP_LOONGARCH_LSX;
+    }
+
+    if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) {
+        hwcaps |= HWCAP_LOONGARCH_LASX;
+    }
+
+    return hwcaps;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 07/89] linux-user: Move get_elf_hwcap to mips/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (5 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 06/89] linux-user: Move get_elf_hwcap to loongarch64/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:55   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 08/89] linux-user: Move get_elf_hwcap to sh4/elfload.c Richard Henderson
                   ` (82 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h       |  2 +-
 linux-user/elfload.c      | 52 +-----------------------------------
 linux-user/mips/elfload.c | 55 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 52 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 786482e68a..0544ab3398 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -100,7 +100,7 @@ extern unsigned long guest_stack_size;
 
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
     || defined(TARGET_SPARC) || defined(TARGET_PPC) \
-    || defined(TARGET_LOONGARCH64)
+    || defined(TARGET_LOONGARCH64) || defined(TARGET_MIPS)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index f173a4f5b8..c6d42afde7 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -844,57 +844,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *e
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-/* See arch/mips/include/uapi/asm/hwcap.h.  */
-enum {
-    HWCAP_MIPS_R6           = (1 << 0),
-    HWCAP_MIPS_MSA          = (1 << 1),
-    HWCAP_MIPS_CRC32        = (1 << 2),
-    HWCAP_MIPS_MIPS16       = (1 << 3),
-    HWCAP_MIPS_MDMX         = (1 << 4),
-    HWCAP_MIPS_MIPS3D       = (1 << 5),
-    HWCAP_MIPS_SMARTMIPS    = (1 << 6),
-    HWCAP_MIPS_DSP          = (1 << 7),
-    HWCAP_MIPS_DSP2         = (1 << 8),
-    HWCAP_MIPS_DSP3         = (1 << 9),
-    HWCAP_MIPS_MIPS16E2     = (1 << 10),
-    HWCAP_LOONGSON_MMI      = (1 << 11),
-    HWCAP_LOONGSON_EXT      = (1 << 12),
-    HWCAP_LOONGSON_EXT2     = (1 << 13),
-    HWCAP_LOONGSON_CPUCFG   = (1 << 14),
-};
-
-#define ELF_HWCAP get_elf_hwcap()
-
-#define GET_FEATURE_INSN(_flag, _hwcap) \
-    do { if (cpu->env.insn_flags & (_flag)) { hwcaps |= _hwcap; } } while (0)
-
-#define GET_FEATURE_REG_SET(_reg, _mask, _hwcap) \
-    do { if (cpu->env._reg & (_mask)) { hwcaps |= _hwcap; } } while (0)
-
-#define GET_FEATURE_REG_EQU(_reg, _start, _length, _val, _hwcap) \
-    do { \
-        if (extract32(cpu->env._reg, (_start), (_length)) == (_val)) { \
-            hwcaps |= _hwcap; \
-        } \
-    } while (0)
-
-static uint32_t get_elf_hwcap(void)
-{
-    MIPSCPU *cpu = MIPS_CPU(thread_cpu);
-    uint32_t hwcaps = 0;
-
-    GET_FEATURE_REG_EQU(CP0_Config0, CP0C0_AR, CP0C0_AR_LENGTH,
-                        2, HWCAP_MIPS_R6);
-    GET_FEATURE_REG_SET(CP0_Config3, 1 << CP0C3_MSAP, HWCAP_MIPS_MSA);
-    GET_FEATURE_INSN(ASE_LMMI, HWCAP_LOONGSON_MMI);
-    GET_FEATURE_INSN(ASE_LEXT, HWCAP_LOONGSON_EXT);
-
-    return hwcaps;
-}
-
-#undef GET_FEATURE_REG_EQU
-#undef GET_FEATURE_REG_SET
-#undef GET_FEATURE_INSN
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 #endif /* TARGET_MIPS */
 
diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c
index 73fa78ef14..07c30b5f4c 100644
--- a/linux-user/mips/elfload.c
+++ b/linux-user/mips/elfload.c
@@ -1 +1,56 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+/* See arch/mips/include/uapi/asm/hwcap.h.  */
+enum {
+    HWCAP_MIPS_R6           = (1 << 0),
+    HWCAP_MIPS_MSA          = (1 << 1),
+    HWCAP_MIPS_CRC32        = (1 << 2),
+    HWCAP_MIPS_MIPS16       = (1 << 3),
+    HWCAP_MIPS_MDMX         = (1 << 4),
+    HWCAP_MIPS_MIPS3D       = (1 << 5),
+    HWCAP_MIPS_SMARTMIPS    = (1 << 6),
+    HWCAP_MIPS_DSP          = (1 << 7),
+    HWCAP_MIPS_DSP2         = (1 << 8),
+    HWCAP_MIPS_DSP3         = (1 << 9),
+    HWCAP_MIPS_MIPS16E2     = (1 << 10),
+    HWCAP_LOONGSON_MMI      = (1 << 11),
+    HWCAP_LOONGSON_EXT      = (1 << 12),
+    HWCAP_LOONGSON_EXT2     = (1 << 13),
+    HWCAP_LOONGSON_CPUCFG   = (1 << 14),
+};
+
+#define GET_FEATURE_INSN(_flag, _hwcap) \
+    do { if (cpu->env.insn_flags & (_flag)) { hwcaps |= _hwcap; } } while (0)
+
+#define GET_FEATURE_REG_SET(_reg, _mask, _hwcap) \
+    do { if (cpu->env._reg & (_mask)) { hwcaps |= _hwcap; } } while (0)
+
+#define GET_FEATURE_REG_EQU(_reg, _start, _length, _val, _hwcap) \
+    do { \
+        if (extract32(cpu->env._reg, (_start), (_length)) == (_val)) { \
+            hwcaps |= _hwcap; \
+        } \
+    } while (0)
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    MIPSCPU *cpu = MIPS_CPU(cs);
+    abi_ulong hwcaps = 0;
+
+    GET_FEATURE_REG_EQU(CP0_Config0, CP0C0_AR, CP0C0_AR_LENGTH,
+                        2, HWCAP_MIPS_R6);
+    GET_FEATURE_REG_SET(CP0_Config3, 1 << CP0C3_MSAP, HWCAP_MIPS_MSA);
+    GET_FEATURE_INSN(ASE_LMMI, HWCAP_LOONGSON_MMI);
+    GET_FEATURE_INSN(ASE_LEXT, HWCAP_LOONGSON_EXT);
+
+    return hwcaps;
+}
+
+#undef GET_FEATURE_REG_EQU
+#undef GET_FEATURE_REG_SET
+#undef GET_FEATURE_INSN
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 08/89] linux-user: Move get_elf_hwcap to sh4/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (6 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 07/89] linux-user: Move get_elf_hwcap to mips/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:56   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 09/89] linux-user: Move hwcap functions to s390x/elfload.c Richard Henderson
                   ` (81 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h      |  3 ++-
 linux-user/elfload.c     | 29 +----------------------------
 linux-user/sh4/elfload.c | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 0544ab3398..cfb474e257 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -100,7 +100,8 @@ extern unsigned long guest_stack_size;
 
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
     || defined(TARGET_SPARC) || defined(TARGET_PPC) \
-    || defined(TARGET_LOONGARCH64) || defined(TARGET_MIPS)
+    || defined(TARGET_LOONGARCH64) || defined(TARGET_MIPS) \
+    || defined(TARGET_SH4)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c6d42afde7..1e855713b6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -973,34 +973,7 @@ static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-enum {
-    SH_CPU_HAS_FPU            = 0x0001, /* Hardware FPU support */
-    SH_CPU_HAS_P2_FLUSH_BUG   = 0x0002, /* Need to flush the cache in P2 area */
-    SH_CPU_HAS_MMU_PAGE_ASSOC = 0x0004, /* SH3: TLB way selection bit support */
-    SH_CPU_HAS_DSP            = 0x0008, /* SH-DSP: DSP support */
-    SH_CPU_HAS_PERF_COUNTER   = 0x0010, /* Hardware performance counters */
-    SH_CPU_HAS_PTEA           = 0x0020, /* PTEA register */
-    SH_CPU_HAS_LLSC           = 0x0040, /* movli.l/movco.l */
-    SH_CPU_HAS_L2_CACHE       = 0x0080, /* Secondary cache / URAM */
-    SH_CPU_HAS_OP32           = 0x0100, /* 32-bit instruction support */
-    SH_CPU_HAS_PTEAEX         = 0x0200, /* PTE ASID Extension support */
-};
-
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-    SuperHCPU *cpu = SUPERH_CPU(thread_cpu);
-    uint32_t hwcap = 0;
-
-    hwcap |= SH_CPU_HAS_FPU;
-
-    if (cpu->env.features & SH_FEATURE_SH4A) {
-        hwcap |= SH_CPU_HAS_LLSC;
-    }
-
-    return hwcap;
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 #endif
 
diff --git a/linux-user/sh4/elfload.c b/linux-user/sh4/elfload.c
index 73fa78ef14..098ca44f80 100644
--- a/linux-user/sh4/elfload.c
+++ b/linux-user/sh4/elfload.c
@@ -1 +1,33 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+enum {
+    SH_CPU_HAS_FPU            = 0x0001, /* Hardware FPU support */
+    SH_CPU_HAS_P2_FLUSH_BUG   = 0x0002, /* Need to flush the cache in P2 area */
+    SH_CPU_HAS_MMU_PAGE_ASSOC = 0x0004, /* SH3: TLB way selection bit support */
+    SH_CPU_HAS_DSP            = 0x0008, /* SH-DSP: DSP support */
+    SH_CPU_HAS_PERF_COUNTER   = 0x0010, /* Hardware performance counters */
+    SH_CPU_HAS_PTEA           = 0x0020, /* PTEA register */
+    SH_CPU_HAS_LLSC           = 0x0040, /* movli.l/movco.l */
+    SH_CPU_HAS_L2_CACHE       = 0x0080, /* Secondary cache / URAM */
+    SH_CPU_HAS_OP32           = 0x0100, /* 32-bit instruction support */
+    SH_CPU_HAS_PTEAEX         = 0x0200, /* PTE ASID Extension support */
+};
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    SuperHCPU *cpu = SUPERH_CPU(cs);
+    abi_ulong hwcap = 0;
+
+    hwcap |= SH_CPU_HAS_FPU;
+
+    if (cpu->env.features & SH_FEATURE_SH4A) {
+        hwcap |= SH_CPU_HAS_LLSC;
+    }
+
+    return hwcap;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 09/89] linux-user: Move hwcap functions to s390x/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (7 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 08/89] linux-user: Move get_elf_hwcap to sh4/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:56   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 10/89] linux-user: Move get_elf_hwcap to riscv/elfload.c Richard Henderson
                   ` (80 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

For get_elf_hwcap, change the return type to abi_ulong
and pass in the cpu.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h            |  5 +--
 linux-user/s390x/target_proc.h |  2 +-
 linux-user/elfload.c           | 60 +-------------------------------
 linux-user/s390x/elfload.c     | 62 ++++++++++++++++++++++++++++++++++
 4 files changed, 65 insertions(+), 64 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index cfb474e257..72eb3e68cb 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -101,13 +101,10 @@ extern unsigned long guest_stack_size;
 #if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
     || defined(TARGET_SPARC) || defined(TARGET_PPC) \
     || defined(TARGET_LOONGARCH64) || defined(TARGET_MIPS) \
-    || defined(TARGET_SH4)
+    || defined(TARGET_SH4) || defined(TARGET_S390X)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 #endif
-#if defined(TARGET_S390X)
-uint32_t get_elf_hwcap(void);
-#endif
 const char *elf_hwcap_str(uint32_t bit);
 const char *elf_hwcap2_str(uint32_t bit);
 
diff --git a/linux-user/s390x/target_proc.h b/linux-user/s390x/target_proc.h
index a4a4821ea5..60cc22d3b4 100644
--- a/linux-user/s390x/target_proc.h
+++ b/linux-user/s390x/target_proc.h
@@ -48,7 +48,7 @@ static void show_cpu_summary(CPUArchState *cpu_env, int fd)
 {
     S390CPUModel *model = env_archcpu(cpu_env)->model;
     int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
-    uint32_t elf_hwcap = get_elf_hwcap();
+    uint32_t elf_hwcap = get_elf_hwcap(env_cpu(cpu_env));
     const char *hwcap_str;
     int i;
 
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1e855713b6..8d4429242f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1049,65 +1049,7 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
-#include "elf.h"
-
-#define ELF_HWCAP get_elf_hwcap()
-
-#define GET_FEATURE(_feat, _hwcap) \
-    do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
-
-uint32_t get_elf_hwcap(void)
-{
-    /*
-     * Let's assume we always have esan3 and zarch.
-     * 31-bit processes can use 64-bit registers (high gprs).
-     */
-    uint32_t hwcap = HWCAP_S390_ESAN3 | HWCAP_S390_ZARCH | HWCAP_S390_HIGH_GPRS;
-
-    GET_FEATURE(S390_FEAT_STFLE, HWCAP_S390_STFLE);
-    GET_FEATURE(S390_FEAT_MSA, HWCAP_S390_MSA);
-    GET_FEATURE(S390_FEAT_LONG_DISPLACEMENT, HWCAP_S390_LDISP);
-    GET_FEATURE(S390_FEAT_EXTENDED_IMMEDIATE, HWCAP_S390_EIMM);
-    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
-        s390_has_feat(S390_FEAT_ETF3_ENH)) {
-        hwcap |= HWCAP_S390_ETF3EH;
-    }
-    GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
-    GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
-    GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
-
-    return hwcap;
-}
-
-const char *elf_hwcap_str(uint32_t bit)
-{
-    static const char *hwcap_str[] = {
-        [HWCAP_S390_NR_ESAN3]     = "esan3",
-        [HWCAP_S390_NR_ZARCH]     = "zarch",
-        [HWCAP_S390_NR_STFLE]     = "stfle",
-        [HWCAP_S390_NR_MSA]       = "msa",
-        [HWCAP_S390_NR_LDISP]     = "ldisp",
-        [HWCAP_S390_NR_EIMM]      = "eimm",
-        [HWCAP_S390_NR_DFP]       = "dfp",
-        [HWCAP_S390_NR_HPAGE]     = "edat",
-        [HWCAP_S390_NR_ETF3EH]    = "etf3eh",
-        [HWCAP_S390_NR_HIGH_GPRS] = "highgprs",
-        [HWCAP_S390_NR_TE]        = "te",
-        [HWCAP_S390_NR_VXRS]      = "vx",
-        [HWCAP_S390_NR_VXRS_BCD]  = "vxd",
-        [HWCAP_S390_NR_VXRS_EXT]  = "vxe",
-        [HWCAP_S390_NR_GS]        = "gs",
-        [HWCAP_S390_NR_VXRS_EXT2] = "vxe2",
-        [HWCAP_S390_NR_VXRS_PDE]  = "vxp",
-        [HWCAP_S390_NR_SORT]      = "sort",
-        [HWCAP_S390_NR_DFLT]      = "dflt",
-        [HWCAP_S390_NR_NNPA]      = "nnpa",
-        [HWCAP_S390_NR_PCI_MIO]   = "pcimio",
-        [HWCAP_S390_NR_SIE]       = "sie",
-    };
-
-    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
diff --git a/linux-user/s390x/elfload.c b/linux-user/s390x/elfload.c
index 73fa78ef14..29dab42933 100644
--- a/linux-user/s390x/elfload.c
+++ b/linux-user/s390x/elfload.c
@@ -1 +1,63 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "elf.h"
+
+
+#define GET_FEATURE(_feat, _hwcap) \
+    do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+    /*
+     * Let's assume we always have esan3 and zarch.
+     * 31-bit processes can use 64-bit registers (high gprs).
+     */
+    uint32_t hwcap = HWCAP_S390_ESAN3 | HWCAP_S390_ZARCH | HWCAP_S390_HIGH_GPRS;
+
+    GET_FEATURE(S390_FEAT_STFLE, HWCAP_S390_STFLE);
+    GET_FEATURE(S390_FEAT_MSA, HWCAP_S390_MSA);
+    GET_FEATURE(S390_FEAT_LONG_DISPLACEMENT, HWCAP_S390_LDISP);
+    GET_FEATURE(S390_FEAT_EXTENDED_IMMEDIATE, HWCAP_S390_EIMM);
+    if (s390_has_feat(S390_FEAT_EXTENDED_TRANSLATION_3) &&
+        s390_has_feat(S390_FEAT_ETF3_ENH)) {
+        hwcap |= HWCAP_S390_ETF3EH;
+    }
+    GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
+    GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
+    GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
+
+    return hwcap;
+}
+
+const char *elf_hwcap_str(uint32_t bit)
+{
+    static const char *hwcap_str[] = {
+        [HWCAP_S390_NR_ESAN3]     = "esan3",
+        [HWCAP_S390_NR_ZARCH]     = "zarch",
+        [HWCAP_S390_NR_STFLE]     = "stfle",
+        [HWCAP_S390_NR_MSA]       = "msa",
+        [HWCAP_S390_NR_LDISP]     = "ldisp",
+        [HWCAP_S390_NR_EIMM]      = "eimm",
+        [HWCAP_S390_NR_DFP]       = "dfp",
+        [HWCAP_S390_NR_HPAGE]     = "edat",
+        [HWCAP_S390_NR_ETF3EH]    = "etf3eh",
+        [HWCAP_S390_NR_HIGH_GPRS] = "highgprs",
+        [HWCAP_S390_NR_TE]        = "te",
+        [HWCAP_S390_NR_VXRS]      = "vx",
+        [HWCAP_S390_NR_VXRS_BCD]  = "vxd",
+        [HWCAP_S390_NR_VXRS_EXT]  = "vxe",
+        [HWCAP_S390_NR_GS]        = "gs",
+        [HWCAP_S390_NR_VXRS_EXT2] = "vxe2",
+        [HWCAP_S390_NR_VXRS_PDE]  = "vxp",
+        [HWCAP_S390_NR_SORT]      = "sort",
+        [HWCAP_S390_NR_DFLT]      = "dflt",
+        [HWCAP_S390_NR_NNPA]      = "nnpa",
+        [HWCAP_S390_NR_PCI_MIO]   = "pcimio",
+        [HWCAP_S390_NR_SIE]       = "sie",
+    };
+
+    return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 10/89] linux-user: Move get_elf_hwcap to riscv/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (8 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 09/89] linux-user: Move hwcap functions to s390x/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 14:57   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 11/89] linux-user: Remove ELF_HWCAP Richard Henderson
                   ` (79 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Change the return type to abi_ulong, and pass in the cpu.
As this is the last instance of get_elf_hwcap to be converted,
remove the ifdef around the declaration in loader.h.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h        |  5 -----
 linux-user/elfload.c       | 14 +-------------
 linux-user/riscv/elfload.c | 17 +++++++++++++++++
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 72eb3e68cb..484d20aecd 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -98,13 +98,8 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
-#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_ARM) \
-    || defined(TARGET_SPARC) || defined(TARGET_PPC) \
-    || defined(TARGET_LOONGARCH64) || defined(TARGET_MIPS) \
-    || defined(TARGET_SH4) || defined(TARGET_S390X)
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
-#endif
 const char *elf_hwcap_str(uint32_t bit);
 const char *elf_hwcap2_str(uint32_t bit);
 
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8d4429242f..cd83307750 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1109,19 +1109,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define VDSO_HEADER "vdso-64.c.inc"
 #endif
 
-#define ELF_HWCAP get_elf_hwcap()
-
-static uint32_t get_elf_hwcap(void)
-{
-#define MISA_BIT(EXT) (1 << (EXT - 'A'))
-    RISCVCPU *cpu = RISCV_CPU(thread_cpu);
-    uint32_t mask = MISA_BIT('I') | MISA_BIT('M') | MISA_BIT('A')
-                    | MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C')
-                    | MISA_BIT('V');
-
-    return cpu->env.misa_ext & mask;
-#undef MISA_BIT
-}
+#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
diff --git a/linux-user/riscv/elfload.c b/linux-user/riscv/elfload.c
index 73fa78ef14..4e2ec3df5b 100644
--- a/linux-user/riscv/elfload.c
+++ b/linux-user/riscv/elfload.c
@@ -1 +1,18 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+abi_ulong get_elf_hwcap(CPUState *cs)
+{
+#define MISA_BIT(EXT) (1 << (EXT - 'A'))
+    RISCVCPU *cpu = RISCV_CPU(cs);
+    uint32_t mask = MISA_BIT('I') | MISA_BIT('M') | MISA_BIT('A')
+                    | MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C')
+                    | MISA_BIT('V');
+
+    return cpu->env.misa_ext & mask;
+#undef MISA_BIT
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 11/89] linux-user: Remove ELF_HWCAP
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (9 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 10/89] linux-user: Move get_elf_hwcap to riscv/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:06   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 12/89] linux-user: Remove ELF_HWCAP2 Richard Henderson
                   ` (78 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

All real definitions of ELF_HWCAP are now identical, and the stub
definitions are 0.  Provide a weak stub as a fallback definition.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index cd83307750..8036f902cc 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -38,7 +38,6 @@
 #ifdef _ARCH_PPC64
 #undef ARCH_DLINFO
 #undef ELF_PLATFORM
-#undef ELF_HWCAP
 #undef ELF_HWCAP2
 #undef ELF_CLASS
 #undef ELF_DATA
@@ -158,8 +157,6 @@ typedef abi_int         target_pid_t;
 
 #ifdef TARGET_I386
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
@@ -459,7 +456,6 @@ static bool init_guest_commpage(void)
     return true;
 }
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 #define ELF_HWCAP2 get_elf_hwcap2(thread_cpu)
 
 #define ELF_PLATFORM get_elf_platform()
@@ -549,7 +545,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
-#define ELF_HWCAP   get_elf_hwcap(thread_cpu)
 #define ELF_HWCAP2  get_elf_hwcap2(thread_cpu)
 
 #if TARGET_BIG_ENDIAN
@@ -575,8 +570,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 # define ELF_ARCH   EM_SPARCV9
 #endif
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
@@ -608,7 +601,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #define ELF_ARCH        EM_PPC
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
 #define ELF_HWCAP2 get_elf_hwcap2(thread_cpu)
 
 /*
@@ -735,8 +727,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 #define ELF_PLATFORM "loongarch"
 
 #endif /* TARGET_LOONGARCH64 */
@@ -844,8 +834,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *e
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 #endif /* TARGET_MIPS */
 
 #ifdef TARGET_MICROBLAZE
@@ -919,7 +907,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
     (*regs)[32] = tswapreg(env->pc);
     (*regs)[33] = tswapreg(cpu_get_sr(env));
 }
-#define ELF_HWCAP 0
+
 #define ELF_PLATFORM NULL
 
 #endif /* TARGET_OPENRISC */
@@ -973,8 +961,6 @@ static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 #endif
 
 #ifdef TARGET_M68K
@@ -1049,8 +1035,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     regs->psw.addr = infop->entry;
@@ -1109,8 +1093,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define VDSO_HEADER "vdso-64.c.inc"
 #endif
 
-#define ELF_HWCAP get_elf_hwcap(thread_cpu)
-
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
@@ -1278,10 +1260,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define elf_check_abi(x) (1)
 #endif
 
-#ifndef ELF_HWCAP
-#define ELF_HWCAP 0
-#endif
-
 #ifndef STACK_GROWS_DOWN
 #define STACK_GROWS_DOWN 1
 #endif
@@ -1301,6 +1279,14 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define EXSTACK_DEFAULT false
 #endif
 
+/*
+ * Provide fallback definitions that the target may omit.
+ */
+abi_ulong __attribute__((weak)) get_elf_hwcap(CPUState *cs)
+{
+    return 0;
+}
+
 #include "elf.h"
 
 /* We must delay the following stanzas until after "elf.h". */
@@ -1878,7 +1864,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     NEW_AUX_ENT(AT_EUID, (abi_ulong) geteuid());
     NEW_AUX_ENT(AT_GID, (abi_ulong) getgid());
     NEW_AUX_ENT(AT_EGID, (abi_ulong) getegid());
-    NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP);
+    NEW_AUX_ENT(AT_HWCAP, get_elf_hwcap(thread_cpu));
     NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK));
     NEW_AUX_ENT(AT_RANDOM, (abi_ulong) u_rand_bytes);
     NEW_AUX_ENT(AT_SECURE, (abi_ulong) qemu_getauxval(AT_SECURE));
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 12/89] linux-user: Remove ELF_HWCAP2
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (10 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 11/89] linux-user: Remove ELF_HWCAP Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:09   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 13/89] linux-user: Move get_elf_platform to {i386, x86_64}/elfload.c Richard Henderson
                   ` (77 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

All definitions of ELF_HWCAP2 are now identical.  The only
catch is whether or not a target defines it.  Unlike the
primary AT_HWCAP, we'd like to omit AT_HWCAP2 entirely if
there is no definition for it.

Mark get_elf_hwcap2 as weak, so that the function may be omitted.
Check that the function exists before calling it.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8036f902cc..54413bf651 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -38,7 +38,6 @@
 #ifdef _ARCH_PPC64
 #undef ARCH_DLINFO
 #undef ELF_PLATFORM
-#undef ELF_HWCAP2
 #undef ELF_CLASS
 #undef ELF_DATA
 #undef ELF_ARCH
@@ -456,8 +455,6 @@ static bool init_guest_commpage(void)
     return true;
 }
 
-#define ELF_HWCAP2 get_elf_hwcap2(thread_cpu)
-
 #define ELF_PLATFORM get_elf_platform()
 
 static const char *get_elf_platform(void)
@@ -545,8 +542,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
-#define ELF_HWCAP2  get_elf_hwcap2(thread_cpu)
-
 #if TARGET_BIG_ENDIAN
 # define VDSO_HEADER  "vdso-be.c.inc"
 #else
@@ -601,8 +596,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #define ELF_ARCH        EM_PPC
 
-#define ELF_HWCAP2 get_elf_hwcap2(thread_cpu)
-
 /*
  * The requirements here are:
  * - keep the final alignment of sp (sp & 0xf)
@@ -1279,6 +1272,17 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define EXSTACK_DEFAULT false
 #endif
 
+/*
+ * Locally declare get_elf_hwcap2 weak, so a target may omit it, and
+ * so that here in elfload.c we can tell that the target omitted it.
+ * The declaration in loader.h, used by the definitions in arch/hwcap.c,
+ * remains strong.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wredundant-decls"
+abi_ulong get_elf_hwcap2(CPUState *cs) __attribute__((weak));
+#pragma GCC diagnostic pop
+
 /*
  * Provide fallback definitions that the target may omit.
  */
@@ -1808,9 +1812,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
 #ifdef DLINFO_ARCH_ITEMS
     size += DLINFO_ARCH_ITEMS * 2;
 #endif
-#ifdef ELF_HWCAP2
-    size += 2;
-#endif
+    if (get_elf_hwcap2) {
+        size += 2;
+    }
     info->auxv_len = size * n;
 
     size += envc + argc + 2;
@@ -1870,10 +1874,9 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     NEW_AUX_ENT(AT_SECURE, (abi_ulong) qemu_getauxval(AT_SECURE));
     NEW_AUX_ENT(AT_EXECFN, info->file_string);
 
-#ifdef ELF_HWCAP2
-    NEW_AUX_ENT(AT_HWCAP2, (abi_ulong) ELF_HWCAP2);
-#endif
-
+    if (get_elf_hwcap2) {
+        NEW_AUX_ENT(AT_HWCAP2, get_elf_hwcap(thread_cpu));
+    }
     if (u_base_platform) {
         NEW_AUX_ENT(AT_BASE_PLATFORM, u_base_platform);
     }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 13/89] linux-user: Move get_elf_platform to {i386, x86_64}/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (11 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 12/89] linux-user: Remove ELF_HWCAP2 Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:26   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform Richard Henderson
                   ` (76 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Move get_elf_platform to i386/elfload.c; pass in CPUState.
Create a simple get_elf_platform for x86_64.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h         |  3 +++
 linux-user/elfload.c        | 18 ++----------------
 linux-user/i386/elfload.c   | 13 +++++++++++++
 linux-user/x86_64/elfload.c |  5 +++++
 4 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 484d20aecd..3bfe47ef22 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -102,5 +102,8 @@ abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 const char *elf_hwcap_str(uint32_t bit);
 const char *elf_hwcap2_str(uint32_t bit);
+#if defined(TARGET_I386)
+const char *get_elf_platform(CPUState *cs);
+#endif
 
 #endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 54413bf651..6cbbee6608 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -156,12 +156,12 @@ typedef abi_int         target_pid_t;
 
 #ifdef TARGET_I386
 
+#define ELF_PLATFORM get_elf_platform(thread_cpu)
+
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
 
-#define ELF_PLATFORM   "x86_64"
-
 static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
 {
     regs->rax = 0;
@@ -244,22 +244,8 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_386
 
-#define ELF_PLATFORM get_elf_platform()
 #define EXSTACK_DEFAULT true
 
-static const char *get_elf_platform(void)
-{
-    static char elf_platform[] = "i386";
-    int family = object_property_get_int(OBJECT(thread_cpu), "family", NULL);
-    if (family > 6) {
-        family = 6;
-    }
-    if (family >= 3) {
-        elf_platform[1] = '0' + family;
-    }
-    return elf_platform;
-}
-
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index df171d896a..cc75b4f2d9 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -9,3 +9,16 @@ abi_ulong get_elf_hwcap(CPUState *cs)
 {
     return cpu_env(cs)->features[FEAT_1_EDX];
 }
+
+const char *get_elf_platform(CPUState *cs)
+{
+    static char elf_platform[] = "i386";
+    int family = object_property_get_int(OBJECT(cs), "family", NULL);
+    if (family > 6) {
+        family = 6;
+    }
+    if (family >= 3) {
+        elf_platform[1] = '0' + family;
+    }
+    return elf_platform;
+}
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index df171d896a..bc40ed8c5b 100644
--- a/linux-user/x86_64/elfload.c
+++ b/linux-user/x86_64/elfload.c
@@ -9,3 +9,8 @@ abi_ulong get_elf_hwcap(CPUState *cs)
 {
     return cpu_env(cs)->features[FEAT_1_EDX];
 }
+
+const char *get_elf_platform(CPUState *cs)
+{
+    return "x86_64";
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (12 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 13/89] linux-user: Move get_elf_platform to {i386, x86_64}/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:28   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 15/89] linux-user: Move get_elf_platform to arm/elfload.c Richard Henderson
                   ` (75 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Rather than modify a static buffer, index into an array
of const data.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/i386/elfload.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index cc75b4f2d9..6a79738786 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -12,13 +12,9 @@ abi_ulong get_elf_hwcap(CPUState *cs)
 
 const char *get_elf_platform(CPUState *cs)
 {
-    static char elf_platform[] = "i386";
+    static const char elf_platform[4][5] = { "i386", "i486", "i586", "i686" };
     int family = object_property_get_int(OBJECT(cs), "family", NULL);
-    if (family > 6) {
-        family = 6;
-    }
-    if (family >= 3) {
-        elf_platform[1] = '0' + family;
-    }
-    return elf_platform;
+
+    family = MAX(MIN(family, 6), 3);
+    return elf_platform[family - 3];
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 15/89] linux-user: Move get_elf_platform to arm/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (13 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:30   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 16/89] linux-user/loongarch64: Create get_elf_platform Richard Henderson
                   ` (74 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Move the aarch32 get_elf_platform to arm/elfload.c; pass in CPUState.
Create a simple version in aarch64/elfload.c, which we must do at the
same time because of the ifdef dependency between TARGET_AARCH64
and TARGET_ARM.

Since all versions of get_elf_platform now have the same
signature, remove the ifdef from the declaration in loader.h

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h          |  2 --
 linux-user/aarch64/elfload.c |  5 +++++
 linux-user/arm/elfload.c     | 29 +++++++++++++++++++++++++++
 linux-user/elfload.c         | 38 ++----------------------------------
 4 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 3bfe47ef22..1cc505832b 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -102,8 +102,6 @@ abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 const char *elf_hwcap_str(uint32_t bit);
 const char *elf_hwcap2_str(uint32_t bit);
-#if defined(TARGET_I386)
 const char *get_elf_platform(CPUState *cs);
-#endif
 
 #endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 8a8bd22784..825be0a25a 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -337,3 +337,8 @@ const char *elf_hwcap2_str(uint32_t bit)
 
     return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
 }
+
+const char *get_elf_platform(CPUState *cs)
+{
+    return TARGET_BIG_ENDIAN ? "aarch64_be" : "aarch64";
+}
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index be80e04f9c..8573e46f2c 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -165,3 +165,32 @@ const char *elf_hwcap2_str(uint32_t bit)
 
     return bit < ARRAY_SIZE(hwcap_str) ? hwcap_str[bit] : NULL;
 }
+
+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;
+    } else if (arm_feature(env, ARM_FEATURE_V7)) {
+        if (arm_feature(env, ARM_FEATURE_M)) {
+            return "v7m" END;
+        } else {
+            return "v7" END;
+        }
+    } else if (arm_feature(env, ARM_FEATURE_V6)) {
+        return "v6" END;
+    } else if (arm_feature(env, ARM_FEATURE_V5)) {
+        return "v5" END;
+    } else {
+        return "v4" END;
+    }
+
+#undef END
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6cbbee6608..2e1c12f247 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -316,6 +316,8 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
 
 #ifdef TARGET_ARM
 
+#define ELF_PLATFORM get_elf_platform(thread_cpu)
+
 #ifndef TARGET_AARCH64
 /* 32 bit ARM definitions */
 
@@ -441,37 +443,6 @@ static bool init_guest_commpage(void)
     return true;
 }
 
-#define ELF_PLATFORM get_elf_platform()
-
-static const char *get_elf_platform(void)
-{
-    CPUARMState *env = cpu_env(thread_cpu);
-
-#if TARGET_BIG_ENDIAN
-# define END  "b"
-#else
-# define END  "l"
-#endif
-
-    if (arm_feature(env, ARM_FEATURE_V8)) {
-        return "v8" END;
-    } else if (arm_feature(env, ARM_FEATURE_V7)) {
-        if (arm_feature(env, ARM_FEATURE_M)) {
-            return "v7m" END;
-        } else {
-            return "v7" END;
-        }
-    } else if (arm_feature(env, ARM_FEATURE_V6)) {
-        return "v6" END;
-    } else if (arm_feature(env, ARM_FEATURE_V5)) {
-        return "v5" END;
-    } else {
-        return "v4" END;
-    }
-
-#undef END
-}
-
 #if TARGET_BIG_ENDIAN
 #include "elf.h"
 #include "vdso-be8.c.inc"
@@ -494,11 +465,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 
 #define ELF_ARCH        EM_AARCH64
 #define ELF_CLASS       ELFCLASS64
-#if TARGET_BIG_ENDIAN
-# define ELF_PLATFORM    "aarch64_be"
-#else
-# define ELF_PLATFORM    "aarch64"
-#endif
 
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 16/89] linux-user/loongarch64: Create get_elf_platform
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (14 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 15/89] linux-user: Move get_elf_platform to arm/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:30   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 17/89] linux-user/hppa: " Richard Henderson
                   ` (73 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Move the string literal to a new function.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c             | 2 +-
 linux-user/loongarch64/elfload.c | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 2e1c12f247..7591ec3fb6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -672,7 +672,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-#define ELF_PLATFORM "loongarch"
+#define ELF_PLATFORM get_elf_platform(thread_cpu)
 
 #endif /* TARGET_LOONGARCH64 */
 
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
index f27992459b..450e567c72 100644
--- a/linux-user/loongarch64/elfload.c
+++ b/linux-user/loongarch64/elfload.c
@@ -51,3 +51,8 @@ abi_ulong get_elf_hwcap(CPUState *cs)
 
     return hwcaps;
 }
+
+const char *get_elf_platform(CPUState *cs)
+{
+    return "loongarch";
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 17/89] linux-user/hppa: Create get_elf_platform
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (15 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 16/89] linux-user/loongarch64: Create get_elf_platform Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:32   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 18/89] linux-user: Remove ELF_PLATFORM Richard Henderson
                   ` (72 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Move the string literal to a new function.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c      |  2 +-
 linux-user/hppa/elfload.c | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7591ec3fb6..58f4b642a5 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1053,7 +1053,7 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_PARISC
-#define ELF_PLATFORM    "PARISC"
+#define ELF_PLATFORM    get_elf_platform(thread_cpu)
 #define STACK_GROWS_DOWN 0
 #define STACK_ALIGNMENT  64
 
diff --git a/linux-user/hppa/elfload.c b/linux-user/hppa/elfload.c
index 73fa78ef14..ff0c2b862a 100644
--- a/linux-user/hppa/elfload.c
+++ b/linux-user/hppa/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_platform(CPUState *cs)
+{
+    return "PARISC";
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 18/89] linux-user: Remove ELF_PLATFORM
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (16 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 17/89] linux-user/hppa: " Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:33   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 19/89] linux-user: Move get_elf_base_platform to mips/elfload.c Richard Henderson
                   ` (71 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

All real definitions of ELF_PLATFORM are now identical, and the stub
definitions are NULL.  Provide a weak stub as a fallback definition.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 58f4b642a5..7e218e8cec 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -37,7 +37,6 @@
 
 #ifdef _ARCH_PPC64
 #undef ARCH_DLINFO
-#undef ELF_PLATFORM
 #undef ELF_CLASS
 #undef ELF_DATA
 #undef ELF_ARCH
@@ -156,8 +155,6 @@ typedef abi_int         target_pid_t;
 
 #ifdef TARGET_I386
 
-#define ELF_PLATFORM get_elf_platform(thread_cpu)
-
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
@@ -316,8 +313,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
 
 #ifdef TARGET_ARM
 
-#define ELF_PLATFORM get_elf_platform(thread_cpu)
-
 #ifndef TARGET_AARCH64
 /* 32 bit ARM definitions */
 
@@ -672,8 +667,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
-#define ELF_PLATFORM get_elf_platform(thread_cpu)
-
 #endif /* TARGET_LOONGARCH64 */
 
 #ifdef TARGET_MIPS
@@ -853,8 +846,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
     (*regs)[33] = tswapreg(cpu_get_sr(env));
 }
 
-#define ELF_PLATFORM NULL
-
 #endif /* TARGET_OPENRISC */
 
 #ifdef TARGET_SH4
@@ -1053,7 +1044,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_PARISC
-#define ELF_PLATFORM    get_elf_platform(thread_cpu)
 #define STACK_GROWS_DOWN 0
 #define STACK_ALIGNMENT  64
 
@@ -1189,10 +1179,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 #define ELF_BASE_PLATFORM (NULL)
 #endif
 
-#ifndef ELF_PLATFORM
-#define ELF_PLATFORM (NULL)
-#endif
-
 #ifndef ELF_MACHINE
 #define ELF_MACHINE ELF_ARCH
 #endif
@@ -1243,6 +1229,11 @@ abi_ulong __attribute__((weak)) get_elf_hwcap(CPUState *cs)
     return 0;
 }
 
+const char * __attribute__((weak)) get_elf_platform(CPUState *cs)
+{
+    return NULL;
+}
+
 #include "elf.h"
 
 /* We must delay the following stanzas until after "elf.h". */
@@ -1712,7 +1703,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     }
 
     u_platform = 0;
-    k_platform = ELF_PLATFORM;
+    k_platform = get_elf_platform(thread_cpu);
     if (k_platform) {
         size_t len = strlen(k_platform) + 1;
         if (STACK_GROWS_DOWN) {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 19/89] linux-user: Move get_elf_base_platform to mips/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (17 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 18/89] linux-user: Remove ELF_PLATFORM Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:35   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 20/89] linux-user: Move target_cpu_copy_regs decl to qemu.h Richard Henderson
                   ` (70 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Pass in CPUState.  Since this was the only instance of ELF_BASE_PLATFORM,
go ahead provide a weak fallback for all other targets.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h       |  1 +
 linux-user/elfload.c      | 42 ++++++---------------------------------
 linux-user/mips/elfload.c | 30 ++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 1cc505832b..a5eef18eff 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -103,5 +103,6 @@ abi_ulong get_elf_hwcap2(CPUState *cs);
 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);
 
 #endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7e218e8cec..b26daf925d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -685,37 +685,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
 #endif
 
-#define ELF_BASE_PLATFORM get_elf_base_platform()
-
-#define MATCH_PLATFORM_INSN(_flags, _base_platform)      \
-    do { if ((cpu->env.insn_flags & (_flags)) == _flags) \
-    { return _base_platform; } } while (0)
-
-static const char *get_elf_base_platform(void)
-{
-    MIPSCPU *cpu = MIPS_CPU(thread_cpu);
-
-    /* 64 bit ISAs goes first */
-    MATCH_PLATFORM_INSN(CPU_MIPS64R6, "mips64r6");
-    MATCH_PLATFORM_INSN(CPU_MIPS64R5, "mips64r5");
-    MATCH_PLATFORM_INSN(CPU_MIPS64R2, "mips64r2");
-    MATCH_PLATFORM_INSN(CPU_MIPS64R1, "mips64");
-    MATCH_PLATFORM_INSN(CPU_MIPS5, "mips5");
-    MATCH_PLATFORM_INSN(CPU_MIPS4, "mips4");
-    MATCH_PLATFORM_INSN(CPU_MIPS3, "mips3");
-
-    /* 32 bit ISAs */
-    MATCH_PLATFORM_INSN(CPU_MIPS32R6, "mips32r6");
-    MATCH_PLATFORM_INSN(CPU_MIPS32R5, "mips32r5");
-    MATCH_PLATFORM_INSN(CPU_MIPS32R2, "mips32r2");
-    MATCH_PLATFORM_INSN(CPU_MIPS32R1, "mips32");
-    MATCH_PLATFORM_INSN(CPU_MIPS2, "mips2");
-
-    /* Fallback */
-    return "mips";
-}
-#undef MATCH_PLATFORM_INSN
-
 static inline void init_thread(struct target_pt_regs *regs,
                                struct image_info *infop)
 {
@@ -1175,10 +1144,6 @@ static inline void init_thread(struct target_pt_regs *regs,
 
 #endif /* TARGET_HEXAGON */
 
-#ifndef ELF_BASE_PLATFORM
-#define ELF_BASE_PLATFORM (NULL)
-#endif
-
 #ifndef ELF_MACHINE
 #define ELF_MACHINE ELF_ARCH
 #endif
@@ -1234,6 +1199,11 @@ const char * __attribute__((weak)) get_elf_platform(CPUState *cs)
     return NULL;
 }
 
+const char * __attribute__((weak)) get_elf_base_platform(CPUState *cs)
+{
+    return NULL;
+}
+
 #include "elf.h"
 
 /* We must delay the following stanzas until after "elf.h". */
@@ -1687,7 +1657,7 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
     }
 
     u_base_platform = 0;
-    k_base_platform = ELF_BASE_PLATFORM;
+    k_base_platform = get_elf_base_platform(thread_cpu);
     if (k_base_platform) {
         size_t len = strlen(k_base_platform) + 1;
         if (STACK_GROWS_DOWN) {
diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c
index 07c30b5f4c..f2b132697e 100644
--- a/linux-user/mips/elfload.c
+++ b/linux-user/mips/elfload.c
@@ -54,3 +54,33 @@ abi_ulong get_elf_hwcap(CPUState *cs)
 #undef GET_FEATURE_REG_EQU
 #undef GET_FEATURE_REG_SET
 #undef GET_FEATURE_INSN
+
+#define MATCH_PLATFORM_INSN(_flags, _base_platform)      \
+    do { if ((cpu->env.insn_flags & (_flags)) == _flags) \
+    { return _base_platform; } } while (0)
+
+const char *get_elf_base_platform(CPUState *cs)
+{
+    MIPSCPU *cpu = MIPS_CPU(cs);
+
+    /* 64 bit ISAs goes first */
+    MATCH_PLATFORM_INSN(CPU_MIPS64R6, "mips64r6");
+    MATCH_PLATFORM_INSN(CPU_MIPS64R5, "mips64r5");
+    MATCH_PLATFORM_INSN(CPU_MIPS64R2, "mips64r2");
+    MATCH_PLATFORM_INSN(CPU_MIPS64R1, "mips64");
+    MATCH_PLATFORM_INSN(CPU_MIPS5, "mips5");
+    MATCH_PLATFORM_INSN(CPU_MIPS4, "mips4");
+    MATCH_PLATFORM_INSN(CPU_MIPS3, "mips3");
+
+    /* 32 bit ISAs */
+    MATCH_PLATFORM_INSN(CPU_MIPS32R6, "mips32r6");
+    MATCH_PLATFORM_INSN(CPU_MIPS32R5, "mips32r5");
+    MATCH_PLATFORM_INSN(CPU_MIPS32R2, "mips32r2");
+    MATCH_PLATFORM_INSN(CPU_MIPS32R1, "mips32");
+    MATCH_PLATFORM_INSN(CPU_MIPS2, "mips2");
+
+    /* Fallback */
+    return "mips";
+}
+
+#undef MATCH_PLATFORM_INSN
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 20/89] linux-user: Move target_cpu_copy_regs decl to qemu.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (18 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 19/89] linux-user: Move get_elf_base_platform to mips/elfload.c Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 15:36   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState Richard Henderson
                   ` (69 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

The function is not used by bsd-user, so placement
within include/user/cpu_loop.h is not ideal.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/user/cpu_loop.h | 4 ----
 linux-user/qemu.h       | 3 +++
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/user/cpu_loop.h b/include/user/cpu_loop.h
index ad8a1d711f..346e37ede8 100644
--- a/include/user/cpu_loop.h
+++ b/include/user/cpu_loop.h
@@ -81,8 +81,4 @@ void target_exception_dump(CPUArchState *env, const char *fmt, int code);
 #define EXCP_DUMP(env, fmt, code) \
     target_exception_dump(env, fmt, code)
 
-typedef struct target_pt_regs target_pt_regs;
-
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs);
-
 #endif
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 0b19fa43e6..6c97ab221f 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -365,4 +365,7 @@ void *lock_user_string(abi_ulong guest_addr);
 /* Clone cpu state */
 CPUArchState *cpu_copy(CPUArchState *env);
 
+typedef struct target_pt_regs target_pt_regs;
+void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs);
+
 #endif /* QEMU_H */
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (19 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 20/89] linux-user: Move target_cpu_copy_regs decl to qemu.h Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 16:05   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 22/89] linux-user: Create do_init_main_thread Richard Henderson
                   ` (68 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Initialize all 3 fields in main(), rather than in 4 different
target-specific functions.  Adjust the ifdef to be function
rather than target specific.  Include stack_base in the ifdef.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/qemu.h             |  4 ++--
 linux-user/aarch64/cpu_loop.c |  8 --------
 linux-user/arm/cpu_loop.c     | 37 +++++++++++++++--------------------
 linux-user/m68k/cpu_loop.c    |  9 ---------
 linux-user/main.c             |  5 +++++
 linux-user/riscv/cpu_loop.c   |  5 -----
 6 files changed, 23 insertions(+), 45 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 6c97ab221f..dff7767bc8 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -122,12 +122,12 @@ struct TaskState {
 #ifdef TARGET_M68K
     abi_ulong tp_value;
 #endif
-#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_RISCV)
+#ifdef CONFIG_SEMIHOSTING
     /* Extra fields for semihosted binaries.  */
     abi_ulong heap_base;
     abi_ulong heap_limit;
-#endif
     abi_ulong stack_base;
+#endif
     int used; /* non zero if used */
     struct image_info *info;
     struct linux_binprm *bprm;
diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
index fea43cefa6..030a630c93 100644
--- a/linux-user/aarch64/cpu_loop.c
+++ b/linux-user/aarch64/cpu_loop.c
@@ -140,9 +140,6 @@ void cpu_loop(CPUARMState *env)
 void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
 {
     ARMCPU *cpu = env_archcpu(env);
-    CPUState *cs = env_cpu(env);
-    TaskState *ts = get_task_state(cs);
-    struct image_info *info = ts->info;
     int i;
 
     if (!(arm_feature(env, ARM_FEATURE_AARCH64))) {
@@ -167,9 +164,4 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
     if (cpu_isar_feature(aa64_pauth, cpu)) {
         qemu_guest_getrandom_nofail(&env->keys, sizeof(env->keys));
     }
-
-    ts->stack_base = info->start_stack;
-    ts->heap_base = info->brk;
-    /* This will be filled in on the first SYS_HEAPINFO call.  */
-    ts->heap_limit = 0;
 }
diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index 33f63951a9..1f3bb96484 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -482,30 +482,25 @@ void cpu_loop(CPUARMState *env)
 
 void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
 {
-    CPUState *cpu = env_cpu(env);
-    TaskState *ts = get_task_state(cpu);
-    struct image_info *info = ts->info;
-    int i;
-
     cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC,
                CPSRWriteByInstr);
-    for(i = 0; i < 16; i++) {
+    for (int i = 0; i < 16; i++) {
         env->regs[i] = regs->uregs[i];
     }
-#if TARGET_BIG_ENDIAN
-    /* Enable BE8.  */
-    if (EF_ARM_EABI_VERSION(info->elf_flags) >= EF_ARM_EABI_VER4
-        && (info->elf_flags & EF_ARM_BE8)) {
-        env->uncached_cpsr |= CPSR_E;
-        env->cp15.sctlr_el[1] |= SCTLR_E0E;
-    } else {
-        env->cp15.sctlr_el[1] |= SCTLR_B;
-    }
-    arm_rebuild_hflags(env);
-#endif
 
-    ts->stack_base = info->start_stack;
-    ts->heap_base = info->brk;
-    /* This will be filled in on the first SYS_HEAPINFO call.  */
-    ts->heap_limit = 0;
+    if (TARGET_BIG_ENDIAN) {
+        CPUState *cpu = env_cpu(env);
+        TaskState *ts = get_task_state(cpu);
+        struct image_info *info = ts->info;
+
+        /* Enable BE8.  */
+        if (EF_ARM_EABI_VERSION(info->elf_flags) >= EF_ARM_EABI_VER4
+            && (info->elf_flags & EF_ARM_BE8)) {
+            env->uncached_cpsr |= CPSR_E;
+            env->cp15.sctlr_el[1] |= SCTLR_E0E;
+        } else {
+            env->cp15.sctlr_el[1] |= SCTLR_B;
+        }
+        arm_rebuild_hflags(env);
+    }
 }
diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c
index 5da91b997a..23693f3358 100644
--- a/linux-user/m68k/cpu_loop.c
+++ b/linux-user/m68k/cpu_loop.c
@@ -94,10 +94,6 @@ void cpu_loop(CPUM68KState *env)
 
 void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
 {
-    CPUState *cpu = env_cpu(env);
-    TaskState *ts = get_task_state(cpu);
-    struct image_info *info = ts->info;
-
     env->pc = regs->pc;
     env->dregs[0] = regs->d0;
     env->dregs[1] = regs->d1;
@@ -116,9 +112,4 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
     env->aregs[6] = regs->a6;
     env->aregs[7] = regs->usp;
     env->sr = regs->sr;
-
-    ts->stack_base = info->start_stack;
-    ts->heap_base = info->brk;
-    /* This will be filled in on the first SYS_HEAPINFO call.  */
-    ts->heap_limit = 0;
 }
diff --git a/linux-user/main.c b/linux-user/main.c
index 68972f00a1..4def4be1c1 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1050,6 +1050,11 @@ int main(int argc, char **argv, char **envp)
 
 #ifdef CONFIG_SEMIHOSTING
     qemu_semihosting_guestfd_init();
+
+    ts->stack_base = info->start_stack;
+    ts->heap_base = info->brk;
+    /* This will be filled in on the first SYS_HEAPINFO call.  */
+    ts->heap_limit = 0;
 #endif
 
     cpu_loop(env);
diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c
index 3ac8bbfec1..2dd30c7b28 100644
--- a/linux-user/riscv/cpu_loop.c
+++ b/linux-user/riscv/cpu_loop.c
@@ -108,9 +108,4 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
         error_report("Incompatible ELF: RVE cpu requires RVE ABI binary");
         exit(EXIT_FAILURE);
     }
-
-    ts->stack_base = info->start_stack;
-    ts->heap_base = info->brk;
-    /* This will be filled in on the first SYS_HEAPINFO call.  */
-    ts->heap_limit = 0;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 22/89] linux-user: Create do_init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (20 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 16:13   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 23/89] linux-user/i386: Create init_main_thread Richard Henderson
                   ` (67 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Provide a unified function to initialize the main thread.
Keep target_pt_regs isolated to this function.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h    |  5 ++---
 linux-user/elfload.c   |  7 +++++--
 linux-user/linuxload.c |  6 ++----
 linux-user/main.c      | 10 +++-------
 4 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index a5eef18eff..b7dceb4abe 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -82,12 +82,11 @@ struct linux_binprm {
     int (*core_dump)(int, const CPUArchState *); /* coredump routine */
 };
 
-void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);
+void do_init_main_thread(CPUState *cs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr);
 int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
-             struct target_pt_regs *regs, struct image_info *infop,
-             struct linux_binprm *);
+                struct image_info *infop, struct linux_binprm *);
 
 uint32_t get_elf_eflags(int fd);
 int load_elf_binary(struct linux_binprm *bprm, struct image_info *info);
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b26daf925d..1d8cc7f6b5 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -3635,7 +3635,10 @@ static int elf_core_dump(int signr, const CPUArchState *env)
 }
 #endif /* USE_ELF_CORE_DUMP */
 
-void do_init_thread(struct target_pt_regs *regs, struct image_info *infop)
+void do_init_main_thread(CPUState *cs, struct image_info *infop)
 {
-    init_thread(regs, infop);
+    target_pt_regs regs = { };
+
+    init_thread(&regs, infop);
+    target_cpu_copy_regs(cpu_env(cs), &regs);
 }
diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 37f132be4a..85d700953e 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -139,8 +139,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
 }
 
 int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
-                struct target_pt_regs *regs, struct image_info *infop,
-                struct linux_binprm *bprm)
+                struct image_info *infop, struct linux_binprm *bprm)
 {
     int retval;
 
@@ -175,8 +174,7 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
         return retval;
     }
 
-    /* Success.  Initialize important registers. */
-    do_init_thread(regs, infop);
+    /* Success. */
     return 0;
 }
 
diff --git a/linux-user/main.c b/linux-user/main.c
index 4def4be1c1..121dc4a0e6 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -697,7 +697,6 @@ static int parse_args(int argc, char **argv)
 
 int main(int argc, char **argv, char **envp)
 {
-    struct target_pt_regs regs1, *regs = &regs1;
     struct image_info info1, *info = &info1;
     struct linux_binprm bprm;
     TaskState *ts;
@@ -763,9 +762,6 @@ int main(int argc, char **argv, char **envp)
     trace_init_file();
     qemu_plugin_load_list(&plugins, &error_fatal);
 
-    /* Zero out regs */
-    memset(regs, 0, sizeof(struct target_pt_regs));
-
     /* Zero out image_info */
     memset(info, 0, sizeof(struct image_info));
 
@@ -989,8 +985,8 @@ int main(int argc, char **argv, char **envp)
 
     fd_trans_init();
 
-    ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs,
-        info, &bprm);
+    ret = loader_exec(execfd, exec_path, target_argv, target_environ,
+                      info, &bprm);
     if (ret != 0) {
         printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
         _exit(EXIT_FAILURE);
@@ -1042,7 +1038,7 @@ int main(int argc, char **argv, char **envp)
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init();
 
-    target_cpu_copy_regs(env, regs);
+    do_init_main_thread(cpu, info);
 
     if (gdbstub) {
         gdbserver_start(gdbstub, &error_fatal);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 23/89] linux-user/i386: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (21 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 22/89] linux-user: Create do_init_main_thread Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 16:17   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 24/89] linux-user/arm: " Richard Henderson
                   ` (66 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.
Temporarily introduce HAVE_INIT_MAIN_THREAD during conversion.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/qemu.h          |  1 +
 linux-user/elfload.c       | 29 ++++++-----------------------
 linux-user/i386/cpu_loop.c | 31 ++++++-------------------------
 3 files changed, 13 insertions(+), 48 deletions(-)

diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index dff7767bc8..475b11e4c4 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -367,5 +367,6 @@ CPUArchState *cpu_copy(CPUArchState *env);
 
 typedef struct target_pt_regs target_pt_regs;
 void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs);
+void init_main_thread(CPUState *cs, struct image_info *info);
 
 #endif /* QEMU_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1d8cc7f6b5..553d632d46 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -155,17 +155,12 @@ typedef abi_int         target_pid_t;
 
 #ifdef TARGET_I386
 
+#define HAVE_INIT_MAIN_THREAD
+
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->rax = 0;
-    regs->rsp = infop->start_stack;
-    regs->rip = infop->entry;
-}
-
 #define ELF_NREG    27
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -243,22 +238,6 @@ static bool init_guest_commpage(void)
 
 #define EXSTACK_DEFAULT true
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->esp = infop->start_stack;
-    regs->eip = infop->entry;
-
-    /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
-       starts %edx contains a pointer to a function which might be
-       registered using `atexit'.  This provides a mean for the
-       dynamic linker to call DT_FINI functions for shared libraries
-       that have been loaded before the code runs.
-
-       A value of 0 tells we have no such handler.  */
-    regs->edx = 0;
-}
-
 #define ELF_NREG    17
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -3637,8 +3616,12 @@ static int elf_core_dump(int signr, const CPUArchState *env)
 
 void do_init_main_thread(CPUState *cs, struct image_info *infop)
 {
+#ifdef HAVE_INIT_MAIN_THREAD
+    init_main_thread(cs, infop);
+#else
     target_pt_regs regs = { };
 
     init_thread(&regs, infop);
     target_cpu_copy_regs(cpu_env(cs), &regs);
+#endif
 }
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index d96d5553fa..d60462172e 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -331,11 +331,10 @@ static void target_cpu_free(void *obj)
     g_free(obj);
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cpu, struct image_info *info)
 {
-    CPUState *cpu = env_cpu(env);
+    CPUArchState *env = cpu_env(cpu);
     bool is64 = (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) != 0;
-    int i;
 
     OBJECT(cpu)->free = target_cpu_free;
     env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK;
@@ -362,27 +361,9 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
     env->eflags |= IF_MASK;
 
     /* linux register setup */
-#ifndef TARGET_ABI32
-    env->regs[R_EAX] = regs->rax;
-    env->regs[R_EBX] = regs->rbx;
-    env->regs[R_ECX] = regs->rcx;
-    env->regs[R_EDX] = regs->rdx;
-    env->regs[R_ESI] = regs->rsi;
-    env->regs[R_EDI] = regs->rdi;
-    env->regs[R_EBP] = regs->rbp;
-    env->regs[R_ESP] = regs->rsp;
-    env->eip = regs->rip;
-#else
-    env->regs[R_EAX] = regs->eax;
-    env->regs[R_EBX] = regs->ebx;
-    env->regs[R_ECX] = regs->ecx;
-    env->regs[R_EDX] = regs->edx;
-    env->regs[R_ESI] = regs->esi;
-    env->regs[R_EDI] = regs->edi;
-    env->regs[R_EBP] = regs->ebp;
-    env->regs[R_ESP] = regs->esp;
-    env->eip = regs->eip;
-#endif
+    memset(env->regs, 0, sizeof(env->regs));
+    env->regs[R_ESP] = info->start_stack;
+    env->eip = info->entry;
 
     /* linux interrupt setup */
 #ifndef TARGET_ABI32
@@ -394,7 +375,7 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
                                 PROT_READ|PROT_WRITE,
                                 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
     idt_table = g2h_untagged(env->idt.base);
-    for (i = 0; i < 20; i++) {
+    for (int i = 0; i < 20; i++) {
         set_idt(i, 0, is64);
     }
     set_idt(3, 3, is64);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 24/89] linux-user/arm: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (22 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 23/89] linux-user/i386: Create init_main_thread Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 16:33   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 25/89] linux-user/aarch64: " Richard Henderson
                   ` (65 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/arm/cpu_loop.c | 53 ++++++++++++++++++++++++++++++++-------
 linux-user/elfload.c      | 41 +-----------------------------
 2 files changed, 45 insertions(+), 49 deletions(-)

diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
index 1f3bb96484..8974b35e8d 100644
--- a/linux-user/arm/cpu_loop.c
+++ b/linux-user/arm/cpu_loop.c
@@ -480,19 +480,54 @@ void cpu_loop(CPUARMState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC,
-               CPSRWriteByInstr);
-    for (int i = 0; i < 16; i++) {
-        env->regs[i] = regs->uregs[i];
+    CPUARMState *env = cpu_env(cs);
+    abi_ptr stack = info->start_stack;
+    abi_ptr entry = info->entry;
+
+    cpsr_write(env, ARM_CPU_MODE_USR | (entry & 1 ? CPSR_T : 0),
+               CPSR_USER | CPSR_EXEC, CPSRWriteByInstr);
+
+    env->regs[15] = entry & 0xfffffffe;
+    env->regs[13] = stack;
+
+    /* FIXME - what to for failure of get_user()? */
+    /* FIXME - a modern kernel does not do this? */
+    get_user_ual(env->regs[2], stack + 8); /* envp */
+    get_user_ual(env->regs[1], stack + 4); /* envp */
+
+    /*
+     * Per the SVR4 ABI, r0 contains a pointer to a function to be
+     * registered with atexit.  A value of 0 means we have no such handler.
+     */
+    env->regs[0] = 0;
+
+    /* For uClinux PIC binaries.  */
+    /* XXX: Linux does this only on ARM with no MMU (do we care ?) */
+    env->regs[10] = info->start_data;
+
+    /* Support ARM FDPIC.  */
+    if (info_is_fdpic(info)) {
+        /*
+         * As described in the ABI document, r7 points to the loadmap info
+         * prepared by the kernel. If an interpreter is needed, r8 points
+         * to the interpreter loadmap and r9 points to the interpreter
+         * PT_DYNAMIC info. If no interpreter is needed, r8 is zero, and
+         * r9 points to the main program PT_DYNAMIC info.
+         */
+        env->regs[7] = info->loadmap_addr;
+        if (info->interpreter_loadmap_addr) {
+            /* Executable is dynamically loaded.  */
+            env->regs[8] = info->interpreter_loadmap_addr;
+            env->regs[9] = info->interpreter_pt_dynamic_addr;
+        } else {
+            env->regs[8] = 0;
+            env->regs[9] = info->pt_dynamic_addr;
+        }
     }
 
     if (TARGET_BIG_ENDIAN) {
-        CPUState *cpu = env_cpu(env);
-        TaskState *ts = get_task_state(cpu);
-        struct image_info *info = ts->info;
-
         /* Enable BE8.  */
         if (EF_ARM_EABI_VERSION(info->elf_flags) >= EF_ARM_EABI_VER4
             && (info->elf_flags & EF_ARM_BE8)) {
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 553d632d46..a9a1d7222a 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -299,46 +299,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
 #define ELF_CLASS       ELFCLASS32
 #define EXSTACK_DEFAULT true
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    abi_long stack = infop->start_stack;
-    memset(regs, 0, sizeof(*regs));
-
-    regs->uregs[16] = ARM_CPU_MODE_USR;
-    if (infop->entry & 1) {
-        regs->uregs[16] |= CPSR_T;
-    }
-    regs->uregs[15] = infop->entry & 0xfffffffe;
-    regs->uregs[13] = infop->start_stack;
-    /* FIXME - what to for failure of get_user()? */
-    get_user_ual(regs->uregs[2], stack + 8); /* envp */
-    get_user_ual(regs->uregs[1], stack + 4); /* envp */
-    /* XXX: it seems that r0 is zeroed after ! */
-    regs->uregs[0] = 0;
-    /* For uClinux PIC binaries.  */
-    /* XXX: Linux does this only on ARM with no MMU (do we care ?) */
-    regs->uregs[10] = infop->start_data;
-
-    /* Support ARM FDPIC.  */
-    if (info_is_fdpic(infop)) {
-        /* As described in the ABI document, r7 points to the loadmap info
-         * prepared by the kernel. If an interpreter is needed, r8 points
-         * to the interpreter loadmap and r9 points to the interpreter
-         * PT_DYNAMIC info. If no interpreter is needed, r8 is zero, and
-         * r9 points to the main program PT_DYNAMIC info.
-         */
-        regs->uregs[7] = infop->loadmap_addr;
-        if (infop->interpreter_loadmap_addr) {
-            /* Executable is dynamically loaded.  */
-            regs->uregs[8] = infop->interpreter_loadmap_addr;
-            regs->uregs[9] = infop->interpreter_pt_dynamic_addr;
-        } else {
-            regs->uregs[8] = 0;
-            regs->uregs[9] = infop->pt_dynamic_addr;
-        }
-    }
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define ELF_NREG    18
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 25/89] linux-user/aarch64: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (23 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 24/89] linux-user/arm: " Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 16:33   ` Peter Maydell
  2025-07-29 23:58 ` [PATCH 26/89] linux-user/sparc: " Richard Henderson
                   ` (64 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/cpu_loop.c | 14 ++++++--------
 linux-user/elfload.c          | 10 +---------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c
index 030a630c93..4c4921152e 100644
--- a/linux-user/aarch64/cpu_loop.c
+++ b/linux-user/aarch64/cpu_loop.c
@@ -137,10 +137,10 @@ void cpu_loop(CPUARMState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
+    CPUARMState *env = cpu_env(cs);
     ARMCPU *cpu = env_archcpu(env);
-    int i;
 
     if (!(arm_feature(env, ARM_FEATURE_AARCH64))) {
         fprintf(stderr,
@@ -148,14 +148,12 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
         exit(EXIT_FAILURE);
     }
 
-    for (i = 0; i < 31; i++) {
-        env->xregs[i] = regs->regs[i];
-    }
-    env->pc = regs->pc;
-    env->xregs[31] = regs->sp;
+    env->pc = info->entry & ~0x3ULL;
+    env->xregs[31] = info->start_stack;
+
 #if TARGET_BIG_ENDIAN
     env->cp15.sctlr_el[1] |= SCTLR_E0E;
-    for (i = 1; i < 4; ++i) {
+    for (int i = 1; i < 4; ++i) {
         env->cp15.sctlr_el[i] |= SCTLR_EE;
     }
     arm_rebuild_hflags(env);
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a9a1d7222a..0fe15eab72 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -401,15 +401,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_ARCH        EM_AARCH64
 #define ELF_CLASS       ELFCLASS64
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    abi_long stack = infop->start_stack;
-    memset(regs, 0, sizeof(*regs));
-
-    regs->pc = infop->entry & ~0x3ULL;
-    regs->sp = stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define ELF_NREG    34
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 26/89] linux-user/sparc: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (24 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 25/89] linux-user/aarch64: " Richard Henderson
@ 2025-07-29 23:58 ` Richard Henderson
  2025-08-01 17:24   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 27/89] linux-user/ppc: " Richard Henderson
                   ` (63 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:58 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c        | 12 ++----------
 linux-user/sparc/cpu_loop.c | 16 +++++++---------
 2 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0fe15eab72..07f02378ad 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -444,16 +444,8 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 # define ELF_ARCH   EM_SPARCV9
 #endif
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    /* Note that target_cpu_copy_regs does not read psr/tstate. */
-    regs->pc = infop->entry;
-    regs->npc = regs->pc + 4;
-    regs->y = 0;
-    regs->u_regs[14] = (infop->start_stack - 16 * sizeof(abi_ulong)
-                        - TARGET_STACK_BIAS);
-}
+#define HAVE_INIT_MAIN_THREAD
+
 #endif /* TARGET_SPARC */
 
 #ifdef TARGET_PPC
diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c
index 68f1e8ecd4..7d30cd1ff2 100644
--- a/linux-user/sparc/cpu_loop.c
+++ b/linux-user/sparc/cpu_loop.c
@@ -357,14 +357,12 @@ void cpu_loop (CPUSPARCState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
-    env->pc = regs->pc;
-    env->npc = regs->npc;
-    env->y = regs->y;
-    for(i = 0; i < 8; i++)
-        env->gregs[i] = regs->u_regs[i];
-    for(i = 0; i < 8; i++)
-        env->regwptr[i] = regs->u_regs[i + 8];
+    CPUArchState *env = cpu_env(cs);
+
+    env->pc = info->entry;
+    env->npc = env->pc + 4;
+    env->regwptr[WREG_SP] = (info->start_stack - 16 * sizeof(abi_ulong)
+                             - TARGET_STACK_BIAS);
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 27/89] linux-user/ppc: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (25 preceding siblings ...)
  2025-07-29 23:58 ` [PATCH 26/89] linux-user/sparc: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:26   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 28/89] linux-user/loongarch64: " Richard Henderson
                   ` (62 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c      | 17 +----------------
 linux-user/ppc/cpu_loop.c | 26 ++++++++++++++++++--------
 2 files changed, 19 insertions(+), 24 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 07f02378ad..00a3f6d33d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -491,22 +491,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
         NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
     } while (0)
 
-static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
-{
-    _regs->gpr[1] = infop->start_stack;
-#if defined(TARGET_PPC64)
-    if (get_ppc64_abi(infop) < 2) {
-        uint64_t val;
-        get_user_u64(val, infop->entry + 8);
-        _regs->gpr[2] = val + infop->load_bias;
-        get_user_u64(val, infop->entry);
-        infop->entry = val + infop->load_bias;
-    } else {
-        _regs->gpr[12] = infop->entry;  /* r12 set to global entry address */
-    }
-#endif
-    _regs->nip = infop->entry;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/powerpc/include/asm/elf.h.  */
 #define ELF_NREG 48
diff --git a/linux-user/ppc/cpu_loop.c b/linux-user/ppc/cpu_loop.c
index 2a0efaffcd..22885ffd90 100644
--- a/linux-user/ppc/cpu_loop.c
+++ b/linux-user/ppc/cpu_loop.c
@@ -378,21 +378,31 @@ void cpu_loop(CPUPPCState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
+    CPUArchState *env = cpu_env(cs);
+    abi_ptr entry = info->entry;
+
+    env->gpr[1] = info->start_stack;
+
+#ifdef TARGET_PPC64
+    if (get_ppc64_abi(info) < 2) {
+        uint64_t val;
+        get_user_u64(val, entry + 8);
+        env->gpr[2] = val + info->load_bias;
+        get_user_u64(val, entry);
+        entry = val + info->load_bias;
+    } else {
+        env->gpr[12] = entry;  /* r12 set to global entry address */
+    }
 
-#if defined(TARGET_PPC64)
     int flag = (env->insns_flags2 & PPC2_BOOKE206) ? MSR_CM : MSR_SF;
 #if defined(TARGET_ABI32)
     ppc_store_msr(env, env->msr & ~((target_ulong)1 << flag));
 #else
     ppc_store_msr(env, env->msr | (target_ulong)1 << flag);
 #endif
-#endif
+#endif /* TARGET_PPC64 */
 
-    env->nip = regs->nip;
-    for(i = 0; i < 32; i++) {
-        env->gpr[i] = regs->gpr[i];
-    }
+    env->nip = entry;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 28/89] linux-user/loongarch64: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (26 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 27/89] linux-user/ppc: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:27   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 29/89] linux-user/mips: " Richard Henderson
                   ` (61 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Note that init_thread had set crmd in target_pt_regs, but
target_cpu_copy_regs did not copy to env.  This turns out to be
ok because loongarch_cpu_reset_hold initializes CRMD properly.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c              |  9 +--------
 linux-user/loongarch64/cpu_loop.c | 11 ++++-------
 2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 00a3f6d33d..4095f7615d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -539,14 +539,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en
 
 #define VDSO_HEADER "vdso.c.inc"
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    /*Set crmd PG,DA = 1,0 */
-    regs->csr.crmd = 2 << 3;
-    regs->csr.era = infop->entry;
-    regs->regs[3] = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/loongarch/include/asm/elf.h */
 #define ELF_NREG 45
diff --git a/linux-user/loongarch64/cpu_loop.c b/linux-user/loongarch64/cpu_loop.c
index ec8a06c88c..a0a4cbb7cc 100644
--- a/linux-user/loongarch64/cpu_loop.c
+++ b/linux-user/loongarch64/cpu_loop.c
@@ -120,13 +120,10 @@ void cpu_loop(CPULoongArchState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
-
-    for (i = 0; i < 32; i++) {
-        env->gpr[i] = regs->regs[i];
-    }
-    env->pc = regs->csr.era;
+    CPUArchState *env = cpu_env(cs);
 
+    env->pc = info->entry;
+    env->gpr[3] = info->start_stack;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 29/89] linux-user/mips: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (27 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 28/89] linux-user/loongarch64: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:27   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 30/89] linux-user/microblaze: " Richard Henderson
                   ` (60 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Note that init_thread had set cp0_status in target_pt_regs, but
target_cpu_copy_regs did not copy to env.  This turns out to be
ok because mips_cpu_reset_hold initializes CP0_Status properly.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c       |  8 +-------
 linux-user/mips/cpu_loop.c | 16 ++++++----------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 4095f7615d..e295dda0bd 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -587,13 +587,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
 #endif
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->cp0_status = 2 << CP0St_KSU;
-    regs->cp0_epc = infop->entry;
-    regs->regs[29] = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/mips/include/asm/elf.h.  */
 #define ELF_NREG 45
diff --git a/linux-user/mips/cpu_loop.c b/linux-user/mips/cpu_loop.c
index 6405806eb0..e67b8a2e46 100644
--- a/linux-user/mips/cpu_loop.c
+++ b/linux-user/mips/cpu_loop.c
@@ -211,12 +211,9 @@ done_syscall:
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    CPUState *cpu = env_cpu(env);
-    TaskState *ts = get_task_state(cpu);
-    struct image_info *info = ts->info;
-    int i;
+    CPUArchState *env = cpu_env(cs);
 
     struct mode_req {
         bool single;
@@ -245,12 +242,11 @@ void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
 
     struct mode_req prog_req;
     struct mode_req interp_req;
+    target_ulong entry = info->entry;
 
-    for(i = 0; i < 32; i++) {
-        env->active_tc.gpr[i] = regs->regs[i];
-    }
-    env->active_tc.PC = regs->cp0_epc & ~(target_ulong)1;
-    if (regs->cp0_epc & 1) {
+    env->active_tc.gpr[29] = info->start_stack;
+    env->active_tc.PC = entry & ~(target_ulong)1;
+    if (entry & 1) {
         env->hflags |= MIPS_HFLAG_M16;
     }
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 30/89] linux-user/microblaze: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (28 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 29/89] linux-user/mips: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:28   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 31/89] linux-user/openrisc: " Richard Henderson
                   ` (59 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c             |  8 +------
 linux-user/microblaze/cpu_loop.c | 39 ++++----------------------------
 2 files changed, 6 insertions(+), 41 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index e295dda0bd..9e6ec4f20a 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -646,13 +646,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *e
 #define ELF_CLASS   ELFCLASS32
 #define ELF_ARCH    EM_MICROBLAZE
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->pc = infop->entry;
-    regs->r1 = infop->start_stack;
-
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define ELF_EXEC_PAGESIZE        4096
 
diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_loop.c
index 87236c166f..d8277961c7 100644
--- a/linux-user/microblaze/cpu_loop.c
+++ b/linux-user/microblaze/cpu_loop.c
@@ -127,39 +127,10 @@ void cpu_loop(CPUMBState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    env->regs[0] = regs->r0;
-    env->regs[1] = regs->r1;
-    env->regs[2] = regs->r2;
-    env->regs[3] = regs->r3;
-    env->regs[4] = regs->r4;
-    env->regs[5] = regs->r5;
-    env->regs[6] = regs->r6;
-    env->regs[7] = regs->r7;
-    env->regs[8] = regs->r8;
-    env->regs[9] = regs->r9;
-    env->regs[10] = regs->r10;
-    env->regs[11] = regs->r11;
-    env->regs[12] = regs->r12;
-    env->regs[13] = regs->r13;
-    env->regs[14] = regs->r14;
-    env->regs[15] = regs->r15;
-    env->regs[16] = regs->r16;
-    env->regs[17] = regs->r17;
-    env->regs[18] = regs->r18;
-    env->regs[19] = regs->r19;
-    env->regs[20] = regs->r20;
-    env->regs[21] = regs->r21;
-    env->regs[22] = regs->r22;
-    env->regs[23] = regs->r23;
-    env->regs[24] = regs->r24;
-    env->regs[25] = regs->r25;
-    env->regs[26] = regs->r26;
-    env->regs[27] = regs->r27;
-    env->regs[28] = regs->r28;
-    env->regs[29] = regs->r29;
-    env->regs[30] = regs->r30;
-    env->regs[31] = regs->r31;
-    env->pc = regs->pc;
+    CPUArchState *env = cpu_env(cs);
+
+    env->pc = info->entry;
+    env->regs[1] = info->start_stack;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 31/89] linux-user/openrisc: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (29 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 30/89] linux-user/microblaze: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:29   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 32/89] linux-user/sh4: " Richard Henderson
                   ` (58 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c           |  7 +------
 linux-user/openrisc/cpu_loop.c | 11 ++++-------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 9e6ec4f20a..808f9f9ad0 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -679,12 +679,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env
 #define ELF_CLASS ELFCLASS32
 #define ELF_DATA  ELFDATA2MSB
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->pc = infop->entry;
-    regs->gpr[1] = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 8192
diff --git a/linux-user/openrisc/cpu_loop.c b/linux-user/openrisc/cpu_loop.c
index 306b4f8eb4..8c72347a99 100644
--- a/linux-user/openrisc/cpu_loop.c
+++ b/linux-user/openrisc/cpu_loop.c
@@ -83,13 +83,10 @@ void cpu_loop(CPUOpenRISCState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
+    CPUArchState *env = cpu_env(cs);
 
-    for (i = 0; i < 32; i++) {
-        cpu_set_gpr(env, i, regs->gpr[i]);
-    }
-    env->pc = regs->pc;
-    cpu_set_sr(env, regs->sr);
+    env->pc = info->entry;
+    cpu_set_gpr(env, 1, info->start_stack);
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 32/89] linux-user/sh4: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (30 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 31/89] linux-user/openrisc: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:30   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 33/89] linux-user/m68k: " Richard Henderson
                   ` (57 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c      |  8 +-------
 linux-user/sh4/cpu_loop.c | 10 ++++------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 808f9f9ad0..a0bddce3cf 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -707,13 +707,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define ELF_CLASS ELFCLASS32
 #define ELF_ARCH  EM_SH
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    /* Check other registers XXXXX */
-    regs->pc = infop->entry;
-    regs->regs[15] = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/sh/include/asm/elf.h.  */
 #define ELF_NREG 23
diff --git a/linux-user/sh4/cpu_loop.c b/linux-user/sh4/cpu_loop.c
index ee9eff3428..259ea1cc8b 100644
--- a/linux-user/sh4/cpu_loop.c
+++ b/linux-user/sh4/cpu_loop.c
@@ -81,12 +81,10 @@ void cpu_loop(CPUSH4State *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
+    CPUArchState *env = cpu_env(cs);
 
-    for(i = 0; i < 16; i++) {
-        env->gregs[i] = regs->regs[i];
-    }
-    env->pc = regs->pc;
+    env->pc = info->entry;
+    env->gregs[15] = info->start_stack;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 33/89] linux-user/m68k: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (31 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 32/89] linux-user/sh4: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:30   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 34/89] linux-user/alpha: " Richard Henderson
                   ` (56 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c       | 11 +----------
 linux-user/m68k/cpu_loop.c | 25 ++++++-------------------
 2 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a0bddce3cf..5029d9af9e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -752,16 +752,7 @@ static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_68K
 
-/* ??? Does this need to do anything?
-   #define ELF_PLAT_INIT(_r) */
-
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->usp = infop->start_stack;
-    regs->sr = 0;
-    regs->pc = infop->entry;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/m68k/include/asm/elf.h.  */
 #define ELF_NREG 20
diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c
index 23693f3358..aca0bf23dc 100644
--- a/linux-user/m68k/cpu_loop.c
+++ b/linux-user/m68k/cpu_loop.c
@@ -92,24 +92,11 @@ void cpu_loop(CPUM68KState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    env->pc = regs->pc;
-    env->dregs[0] = regs->d0;
-    env->dregs[1] = regs->d1;
-    env->dregs[2] = regs->d2;
-    env->dregs[3] = regs->d3;
-    env->dregs[4] = regs->d4;
-    env->dregs[5] = regs->d5;
-    env->dregs[6] = regs->d6;
-    env->dregs[7] = regs->d7;
-    env->aregs[0] = regs->a0;
-    env->aregs[1] = regs->a1;
-    env->aregs[2] = regs->a2;
-    env->aregs[3] = regs->a3;
-    env->aregs[4] = regs->a4;
-    env->aregs[5] = regs->a5;
-    env->aregs[6] = regs->a6;
-    env->aregs[7] = regs->usp;
-    env->sr = regs->sr;
+    CPUArchState *env = cpu_env(cs);
+
+    env->pc = info->entry;
+    env->aregs[7] = info->start_stack;
+    env->sr = 0;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 34/89] linux-user/alpha: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (32 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 33/89] linux-user/m68k: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:31   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 35/89] linux-user/s390x: " Richard Henderson
                   ` (55 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Note that init_thread had set ps in target_pt_regs, but
target_cpu_copy_regs did not copy to env.  This turns out to be
ok because alpha_cpu_initfn initializes flags properly.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/alpha/cpu_loop.c | 11 ++++-------
 linux-user/elfload.c        |  8 +-------
 2 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/linux-user/alpha/cpu_loop.c b/linux-user/alpha/cpu_loop.c
index 80ad536c5f..728b64906d 100644
--- a/linux-user/alpha/cpu_loop.c
+++ b/linux-user/alpha/cpu_loop.c
@@ -173,13 +173,10 @@ void cpu_loop(CPUAlphaState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
+    CPUArchState *env = cpu_env(cs);
 
-    for(i = 0; i < 28; i++) {
-        env->ir[i] = ((abi_ulong *)regs)[i];
-    }
-    env->ir[IR_SP] = regs->usp;
-    env->pc = regs->pc;
+    env->pc = info->entry;
+    env->ir[IR_SP] = info->start_stack;
 }
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5029d9af9e..67c00f75fd 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -792,13 +792,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *e
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_ALPHA
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->pc = infop->entry;
-    regs->ps = 8;
-    regs->usp = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define ELF_EXEC_PAGESIZE        8192
 
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 35/89] linux-user/s390x: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (33 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 34/89] linux-user/alpha: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:32   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 36/89] linux-user/riscv: " Richard Henderson
                   ` (54 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c        |  9 +--------
 linux-user/s390x/cpu_loop.c | 15 ++++++++-------
 2 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 67c00f75fd..62452d7c45 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -804,14 +804,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *e
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
-static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
-{
-    regs->psw.addr = infop->entry;
-    regs->psw.mask = PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | \
-                     PSW_MASK_MCHECK | PSW_MASK_PSTATE | PSW_MASK_64 | \
-                     PSW_MASK_32;
-    regs->gprs[15] = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs).  */
 #define ELF_NREG 27
diff --git a/linux-user/s390x/cpu_loop.c b/linux-user/s390x/cpu_loop.c
index c9124444ed..49e44548f8 100644
--- a/linux-user/s390x/cpu_loop.c
+++ b/linux-user/s390x/cpu_loop.c
@@ -180,12 +180,13 @@ void cpu_loop(CPUS390XState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
-    for (i = 0; i < 16; i++) {
-        env->regs[i] = regs->gprs[i];
-    }
-    env->psw.mask = regs->psw.mask;
-    env->psw.addr = regs->psw.addr;
+    CPUArchState *env = cpu_env(cs);
+
+    env->psw.addr = info->entry;
+    env->psw.mask = PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT |
+                    PSW_MASK_MCHECK | PSW_MASK_PSTATE | PSW_MASK_64 |
+                    PSW_MASK_32;
+    env->regs[15] = info->start_stack;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 36/89] linux-user/riscv: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (34 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 35/89] linux-user/s390x: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:32   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 37/89] linux-user/hppa: " Richard Henderson
                   ` (53 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c        |  7 +------
 linux-user/riscv/cpu_loop.c | 10 ++++------
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 62452d7c45..b1f889193e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -855,12 +855,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define VDSO_HEADER "vdso-64.c.inc"
 #endif
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->sepc = infop->entry;
-    regs->sp = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define ELF_EXEC_PAGESIZE 4096
 
diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c
index 2dd30c7b28..b316281532 100644
--- a/linux-user/riscv/cpu_loop.c
+++ b/linux-user/riscv/cpu_loop.c
@@ -94,14 +94,12 @@ void cpu_loop(CPURISCVState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    CPUState *cpu = env_cpu(env);
-    TaskState *ts = get_task_state(cpu);
-    struct image_info *info = ts->info;
+    CPUArchState *env = cpu_env(cs);
 
-    env->pc = regs->sepc;
-    env->gpr[xSP] = regs->sp;
+    env->pc = info->entry;
+    env->gpr[xSP] = info->start_stack;
     env->elf_flags = info->elf_flags;
 
     if ((env->misa_ext & RVE) && !(env->elf_flags & EF_RISCV_RVE)) {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 37/89] linux-user/hppa: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (35 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 36/89] linux-user/riscv: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:33   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 38/89] linux-user/xtensa: " Richard Henderson
                   ` (52 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c       | 13 +------------
 linux-user/hppa/cpu_loop.c | 18 +++++++++++-------
 2 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b1f889193e..48c04f9f33 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -870,18 +870,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 
 #define VDSO_HEADER "vdso.c.inc"
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->iaoq[0] = infop->entry | PRIV_USER;
-    regs->iaoq[1] = regs->iaoq[0] + 4;
-    regs->gr[23] = 0;
-    regs->gr[24] = infop->argv;
-    regs->gr[25] = infop->argc;
-    /* The top-of-stack contains a linkage buffer.  */
-    regs->gr[30] = infop->start_stack + 64;
-    regs->gr[31] = infop->entry;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #define LO_COMMPAGE  0
 
diff --git a/linux-user/hppa/cpu_loop.c b/linux-user/hppa/cpu_loop.c
index 9abaad5ef8..3af50653bb 100644
--- a/linux-user/hppa/cpu_loop.c
+++ b/linux-user/hppa/cpu_loop.c
@@ -196,12 +196,16 @@ void cpu_loop(CPUHPPAState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
-    for (i = 1; i < 32; i++) {
-        env->gr[i] = regs->gr[i];
-    }
-    env->iaoq_f = regs->iaoq[0];
-    env->iaoq_b = regs->iaoq[1];
+    CPUArchState *env = cpu_env(cs);
+
+    env->iaoq_f = info->entry | PRIV_USER;
+    env->iaoq_b = env->iaoq_f + 4;
+    env->gr[23] = 0;
+    env->gr[24] = info->argv;
+    env->gr[25] = info->argc;
+    /* The top-of-stack contains a linkage buffer.  */
+    env->gr[30] = info->start_stack + 64;
+    env->gr[31] = info->entry;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 38/89] linux-user/xtensa: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (36 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 37/89] linux-user/hppa: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:34   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 39/89] linux-user/hexagon: " Richard Henderson
                   ` (51 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c         | 18 +-----------------
 linux-user/xtensa/cpu_loop.c | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 23 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 48c04f9f33..4a58811f4f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -911,23 +911,7 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_XTENSA
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->windowbase = 0;
-    regs->windowstart = 1;
-    regs->areg[1] = infop->start_stack;
-    regs->pc = infop->entry;
-    if (info_is_fdpic(infop)) {
-        regs->areg[4] = infop->loadmap_addr;
-        regs->areg[5] = infop->interpreter_loadmap_addr;
-        if (infop->interpreter_loadmap_addr) {
-            regs->areg[6] = infop->interpreter_pt_dynamic_addr;
-        } else {
-            regs->areg[6] = infop->pt_dynamic_addr;
-        }
-    }
-}
+#define HAVE_INIT_MAIN_THREAD
 
 /* See linux kernel: arch/xtensa/include/asm/elf.h.  */
 #define ELF_NREG 128
diff --git a/linux-user/xtensa/cpu_loop.c b/linux-user/xtensa/cpu_loop.c
index c0fcf743e7..43a194fc4a 100644
--- a/linux-user/xtensa/cpu_loop.c
+++ b/linux-user/xtensa/cpu_loop.c
@@ -238,12 +238,22 @@ void cpu_loop(CPUXtensaState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    int i;
-    for (i = 0; i < 16; ++i) {
-        env->regs[i] = regs->areg[i];
+    CPUArchState *env = cpu_env(cs);
+
+    env->sregs[WINDOW_BASE] = 0;
+    env->sregs[WINDOW_START] = 1;
+    env->regs[1] = info->start_stack;
+    env->pc = info->entry;
+
+    if (info_is_fdpic(info)) {
+        env->regs[4] = info->loadmap_addr;
+        env->regs[5] = info->interpreter_loadmap_addr;
+        if (info->interpreter_loadmap_addr) {
+            env->regs[6] = info->interpreter_pt_dynamic_addr;
+        } else {
+            env->regs[6] = info->pt_dynamic_addr;
+        }
     }
-    env->sregs[WINDOW_START] = regs->windowstart;
-    env->pc = regs->pc;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 39/89] linux-user/hexagon: Create init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (37 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 38/89] linux-user/xtensa: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:35   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 40/89] linux-user: Remove do_init_main_thread Richard Henderson
                   ` (50 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Merge init_thread and target_cpu_copy_regs.
There's no point going through a target_pt_regs intermediate.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c          | 7 +------
 linux-user/hexagon/cpu_loop.c | 8 +++++---
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 4a58811f4f..1276b57f0d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -960,12 +960,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_HEXAGON
 
-static inline void init_thread(struct target_pt_regs *regs,
-                               struct image_info *infop)
-{
-    regs->sepc = infop->entry;
-    regs->sp = infop->start_stack;
-}
+#define HAVE_INIT_MAIN_THREAD
 
 #endif /* TARGET_HEXAGON */
 
diff --git a/linux-user/hexagon/cpu_loop.c b/linux-user/hexagon/cpu_loop.c
index e18a0183b5..25c97edcae 100644
--- a/linux-user/hexagon/cpu_loop.c
+++ b/linux-user/hexagon/cpu_loop.c
@@ -79,9 +79,11 @@ void cpu_loop(CPUHexagonState *env)
     }
 }
 
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
+void init_main_thread(CPUState *cs, struct image_info *info)
 {
-    env->gpr[HEX_REG_PC] = regs->sepc;
-    env->gpr[HEX_REG_SP] = regs->sp;
+    CPUArchState *env = cpu_env(cs);
+
+    env->gpr[HEX_REG_PC] = info->entry;
+    env->gpr[HEX_REG_SP] = info->start_stack;
     env->gpr[HEX_REG_USR] = 0x56000;
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 40/89] linux-user: Remove do_init_main_thread
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (38 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 39/89] linux-user/hexagon: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:37   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc Richard Henderson
                   ` (49 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

All targets have been converted, so we can call init_main_thread
directly.  Remove do_init_main_thread and HAVE_INIT_MAIN_THREAD.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h  |  1 -
 linux-user/qemu.h    |  2 --
 linux-user/elfload.c | 46 --------------------------------------------
 linux-user/main.c    |  2 +-
 4 files changed, 1 insertion(+), 50 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index b7dceb4abe..700bbdb02e 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -82,7 +82,6 @@ struct linux_binprm {
     int (*core_dump)(int, const CPUArchState *); /* coredump routine */
 };
 
-void do_init_main_thread(CPUState *cs, struct image_info *infop);
 abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
                               abi_ulong stringp, int push_ptr);
 int loader_exec(int fdexec, const char *filename, char **argv, char **envp,
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index 475b11e4c4..4c626f270c 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -365,8 +365,6 @@ void *lock_user_string(abi_ulong guest_addr);
 /* Clone cpu state */
 CPUArchState *cpu_copy(CPUArchState *env);
 
-typedef struct target_pt_regs target_pt_regs;
-void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs);
 void init_main_thread(CPUState *cs, struct image_info *info);
 
 #endif /* QEMU_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1276b57f0d..27682f0c81 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -155,8 +155,6 @@ typedef abi_int         target_pid_t;
 
 #ifdef TARGET_I386
 
-#define HAVE_INIT_MAIN_THREAD
-
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
@@ -299,8 +297,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en
 #define ELF_CLASS       ELFCLASS32
 #define EXSTACK_DEFAULT true
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define ELF_NREG    18
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -401,8 +397,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_ARCH        EM_AARCH64
 #define ELF_CLASS       ELFCLASS64
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define ELF_NREG    34
 typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
 
@@ -444,8 +438,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 # define ELF_ARCH   EM_SPARCV9
 #endif
 
-#define HAVE_INIT_MAIN_THREAD
-
 #endif /* TARGET_SPARC */
 
 #ifdef TARGET_PPC
@@ -491,8 +483,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
         NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
     } while (0)
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/powerpc/include/asm/elf.h.  */
 #define ELF_NREG 48
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -539,8 +529,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en
 
 #define VDSO_HEADER "vdso.c.inc"
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/loongarch/include/asm/elf.h */
 #define ELF_NREG 45
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -587,8 +575,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
 #endif
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/mips/include/asm/elf.h.  */
 #define ELF_NREG 45
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -646,8 +632,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *e
 #define ELF_CLASS   ELFCLASS32
 #define ELF_ARCH    EM_MICROBLAZE
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define ELF_EXEC_PAGESIZE        4096
 
 #define USE_ELF_CORE_DUMP
@@ -679,8 +663,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env
 #define ELF_CLASS ELFCLASS32
 #define ELF_DATA  ELFDATA2MSB
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 8192
 
@@ -707,8 +689,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define ELF_CLASS ELFCLASS32
 #define ELF_ARCH  EM_SH
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/sh/include/asm/elf.h.  */
 #define ELF_NREG 23
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -752,8 +732,6 @@ static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_68K
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/m68k/include/asm/elf.h.  */
 #define ELF_NREG 20
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -792,8 +770,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *e
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_ALPHA
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define ELF_EXEC_PAGESIZE        8192
 
 #endif /* TARGET_ALPHA */
@@ -804,8 +780,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *e
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs).  */
 #define ELF_NREG 27
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -855,8 +829,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define VDSO_HEADER "vdso-64.c.inc"
 #endif
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define ELF_EXEC_PAGESIZE 4096
 
 #endif /* TARGET_RISCV */
@@ -870,8 +842,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 
 #define VDSO_HEADER "vdso.c.inc"
 
-#define HAVE_INIT_MAIN_THREAD
-
 #define LO_COMMPAGE  0
 
 static bool init_guest_commpage(void)
@@ -911,8 +881,6 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_XTENSA
 
-#define HAVE_INIT_MAIN_THREAD
-
 /* See linux kernel: arch/xtensa/include/asm/elf.h.  */
 #define ELF_NREG 128
 typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
@@ -960,8 +928,6 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs,
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_HEXAGON
 
-#define HAVE_INIT_MAIN_THREAD
-
 #endif /* TARGET_HEXAGON */
 
 #ifndef ELF_MACHINE
@@ -3454,15 +3420,3 @@ static int elf_core_dump(int signr, const CPUArchState *env)
     return ret;
 }
 #endif /* USE_ELF_CORE_DUMP */
-
-void do_init_main_thread(CPUState *cs, struct image_info *infop)
-{
-#ifdef HAVE_INIT_MAIN_THREAD
-    init_main_thread(cs, infop);
-#else
-    target_pt_regs regs = { };
-
-    init_thread(&regs, infop);
-    target_cpu_copy_regs(cpu_env(cs), &regs);
-#endif
-}
diff --git a/linux-user/main.c b/linux-user/main.c
index 121dc4a0e6..d962f344b8 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -1038,7 +1038,7 @@ int main(int argc, char **argv, char **envp)
        the real value of GUEST_BASE into account.  */
     tcg_prologue_init();
 
-    do_init_main_thread(cpu, info);
+    init_main_thread(cpu, info);
 
     if (gdbstub) {
         gdbserver_start(gdbstub, &error_fatal);
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (39 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 40/89] linux-user: Remove do_init_main_thread Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:45   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 42/89] linux-user/i386: " Richard Henderson
                   ` (48 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                    | 41 +-----------------------
 linux-user/x86_64/target_coredump.c.inc | 42 +++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 40 deletions(-)
 create mode 100644 linux-user/x86_64/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 27682f0c81..fc2ee4e0e3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -159,46 +159,7 @@ typedef abi_int         target_pid_t;
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
 
-#define ELF_NREG    27
-typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
-
-/*
- * Note that ELF_NREG should be 29 as there should be place for
- * TRAPNO and ERR "registers" as well but linux doesn't dump
- * those.
- *
- * See linux kernel: arch/x86/include/asm/elf.h
- */
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env)
-{
-    (*regs)[0] = tswapreg(env->regs[15]);
-    (*regs)[1] = tswapreg(env->regs[14]);
-    (*regs)[2] = tswapreg(env->regs[13]);
-    (*regs)[3] = tswapreg(env->regs[12]);
-    (*regs)[4] = tswapreg(env->regs[R_EBP]);
-    (*regs)[5] = tswapreg(env->regs[R_EBX]);
-    (*regs)[6] = tswapreg(env->regs[11]);
-    (*regs)[7] = tswapreg(env->regs[10]);
-    (*regs)[8] = tswapreg(env->regs[9]);
-    (*regs)[9] = tswapreg(env->regs[8]);
-    (*regs)[10] = tswapreg(env->regs[R_EAX]);
-    (*regs)[11] = tswapreg(env->regs[R_ECX]);
-    (*regs)[12] = tswapreg(env->regs[R_EDX]);
-    (*regs)[13] = tswapreg(env->regs[R_ESI]);
-    (*regs)[14] = tswapreg(env->regs[R_EDI]);
-    (*regs)[15] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
-    (*regs)[16] = tswapreg(env->eip);
-    (*regs)[17] = tswapreg(env->segs[R_CS].selector & 0xffff);
-    (*regs)[18] = tswapreg(env->eflags);
-    (*regs)[19] = tswapreg(env->regs[R_ESP]);
-    (*regs)[20] = tswapreg(env->segs[R_SS].selector & 0xffff);
-    (*regs)[21] = tswapreg(env->segs[R_FS].selector & 0xffff);
-    (*regs)[22] = tswapreg(env->segs[R_GS].selector & 0xffff);
-    (*regs)[23] = tswapreg(env->segs[R_DS].selector & 0xffff);
-    (*regs)[24] = tswapreg(env->segs[R_ES].selector & 0xffff);
-    (*regs)[25] = tswapreg(env->segs[R_FS].selector & 0xffff);
-    (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff);
-}
+#include "target_coredump.c.inc"
 
 #if ULONG_MAX > UINT32_MAX
 #define INIT_GUEST_COMMPAGE
diff --git a/linux-user/x86_64/target_coredump.c.inc b/linux-user/x86_64/target_coredump.c.inc
new file mode 100644
index 0000000000..b85ee22669
--- /dev/null
+++ b/linux-user/x86_64/target_coredump.c.inc
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#define ELF_NREG    27
+typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
+
+/*
+ * Note that ELF_NREG should be 29 as there should be place for
+ * TRAPNO and ERR "registers" as well but linux doesn't dump those.
+ *
+ * See linux kernel: arch/x86/include/asm/elf.h
+ */
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUX86State *env)
+{
+    (*regs)[0] = tswapreg(env->regs[15]);
+    (*regs)[1] = tswapreg(env->regs[14]);
+    (*regs)[2] = tswapreg(env->regs[13]);
+    (*regs)[3] = tswapreg(env->regs[12]);
+    (*regs)[4] = tswapreg(env->regs[R_EBP]);
+    (*regs)[5] = tswapreg(env->regs[R_EBX]);
+    (*regs)[6] = tswapreg(env->regs[11]);
+    (*regs)[7] = tswapreg(env->regs[10]);
+    (*regs)[8] = tswapreg(env->regs[9]);
+    (*regs)[9] = tswapreg(env->regs[8]);
+    (*regs)[10] = tswapreg(env->regs[R_EAX]);
+    (*regs)[11] = tswapreg(env->regs[R_ECX]);
+    (*regs)[12] = tswapreg(env->regs[R_EDX]);
+    (*regs)[13] = tswapreg(env->regs[R_ESI]);
+    (*regs)[14] = tswapreg(env->regs[R_EDI]);
+    (*regs)[15] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
+    (*regs)[16] = tswapreg(env->eip);
+    (*regs)[17] = tswapreg(env->segs[R_CS].selector & 0xffff);
+    (*regs)[18] = tswapreg(env->eflags);
+    (*regs)[19] = tswapreg(env->regs[R_ESP]);
+    (*regs)[20] = tswapreg(env->segs[R_SS].selector & 0xffff);
+    (*regs)[21] = tswapreg(env->segs[R_FS].selector & 0xffff);
+    (*regs)[22] = tswapreg(env->segs[R_GS].selector & 0xffff);
+    (*regs)[23] = tswapreg(env->segs[R_DS].selector & 0xffff);
+    (*regs)[24] = tswapreg(env->segs[R_ES].selector & 0xffff);
+    (*regs)[25] = tswapreg(env->segs[R_FS].selector & 0xffff);
+    (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff);
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 42/89] linux-user/i386: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (40 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:46   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 43/89] linux-user/arm: " Richard Henderson
                   ` (47 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                  | 31 +-------------------------
 linux-user/i386/target_coredump.c.inc | 32 +++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 30 deletions(-)
 create mode 100644 linux-user/i386/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index fc2ee4e0e3..b315a5a243 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -197,36 +197,7 @@ static bool init_guest_commpage(void)
 
 #define EXSTACK_DEFAULT true
 
-#define ELF_NREG    17
-typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
-
-/*
- * Note that ELF_NREG should be 19 as there should be place for
- * TRAPNO and ERR "registers" as well but linux doesn't dump
- * those.
- *
- * See linux kernel: arch/x86/include/asm/elf.h
- */
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env)
-{
-    (*regs)[0] = tswapreg(env->regs[R_EBX]);
-    (*regs)[1] = tswapreg(env->regs[R_ECX]);
-    (*regs)[2] = tswapreg(env->regs[R_EDX]);
-    (*regs)[3] = tswapreg(env->regs[R_ESI]);
-    (*regs)[4] = tswapreg(env->regs[R_EDI]);
-    (*regs)[5] = tswapreg(env->regs[R_EBP]);
-    (*regs)[6] = tswapreg(env->regs[R_EAX]);
-    (*regs)[7] = tswapreg(env->segs[R_DS].selector & 0xffff);
-    (*regs)[8] = tswapreg(env->segs[R_ES].selector & 0xffff);
-    (*regs)[9] = tswapreg(env->segs[R_FS].selector & 0xffff);
-    (*regs)[10] = tswapreg(env->segs[R_GS].selector & 0xffff);
-    (*regs)[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
-    (*regs)[12] = tswapreg(env->eip);
-    (*regs)[13] = tswapreg(env->segs[R_CS].selector & 0xffff);
-    (*regs)[14] = tswapreg(env->eflags);
-    (*regs)[15] = tswapreg(env->regs[R_ESP]);
-    (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff);
-}
+#include "target_coredump.c.inc"
 
 /*
  * i386 is the only target which supplies AT_SYSINFO for the vdso.
diff --git a/linux-user/i386/target_coredump.c.inc b/linux-user/i386/target_coredump.c.inc
new file mode 100644
index 0000000000..df7a3e73b3
--- /dev/null
+++ b/linux-user/i386/target_coredump.c.inc
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#define ELF_NREG    17
+typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
+
+/*
+ * Note that ELF_NREG should be 19 as there should be place for
+ * TRAPNO and ERR "registers" as well but linux doesn't dump those.
+ *
+ * See linux kernel: arch/x86/include/asm/elf.h
+ */
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUX86State *env)
+{
+    (*regs)[0] = tswapreg(env->regs[R_EBX]);
+    (*regs)[1] = tswapreg(env->regs[R_ECX]);
+    (*regs)[2] = tswapreg(env->regs[R_EDX]);
+    (*regs)[3] = tswapreg(env->regs[R_ESI]);
+    (*regs)[4] = tswapreg(env->regs[R_EDI]);
+    (*regs)[5] = tswapreg(env->regs[R_EBP]);
+    (*regs)[6] = tswapreg(env->regs[R_EAX]);
+    (*regs)[7] = tswapreg(env->segs[R_DS].selector & 0xffff);
+    (*regs)[8] = tswapreg(env->segs[R_ES].selector & 0xffff);
+    (*regs)[9] = tswapreg(env->segs[R_FS].selector & 0xffff);
+    (*regs)[10] = tswapreg(env->segs[R_GS].selector & 0xffff);
+    (*regs)[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax);
+    (*regs)[12] = tswapreg(env->eip);
+    (*regs)[13] = tswapreg(env->segs[R_CS].selector & 0xffff);
+    (*regs)[14] = tswapreg(env->eflags);
+    (*regs)[15] = tswapreg(env->regs[R_ESP]);
+    (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff);
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 43/89] linux-user/arm: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (41 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 42/89] linux-user/i386: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:46   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 44/89] linux-user/aarch64: " Richard Henderson
                   ` (46 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                 | 27 +--------------------------
 linux-user/arm/target_coredump.c.inc | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 26 deletions(-)
 create mode 100644 linux-user/arm/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b315a5a243..b35f35b2a6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -229,32 +229,7 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define EXSTACK_DEFAULT true
 
-#define ELF_NREG    18
-typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUARMState *env)
-{
-    (*regs)[0] = tswapreg(env->regs[0]);
-    (*regs)[1] = tswapreg(env->regs[1]);
-    (*regs)[2] = tswapreg(env->regs[2]);
-    (*regs)[3] = tswapreg(env->regs[3]);
-    (*regs)[4] = tswapreg(env->regs[4]);
-    (*regs)[5] = tswapreg(env->regs[5]);
-    (*regs)[6] = tswapreg(env->regs[6]);
-    (*regs)[7] = tswapreg(env->regs[7]);
-    (*regs)[8] = tswapreg(env->regs[8]);
-    (*regs)[9] = tswapreg(env->regs[9]);
-    (*regs)[10] = tswapreg(env->regs[10]);
-    (*regs)[11] = tswapreg(env->regs[11]);
-    (*regs)[12] = tswapreg(env->regs[12]);
-    (*regs)[13] = tswapreg(env->regs[13]);
-    (*regs)[14] = tswapreg(env->regs[14]);
-    (*regs)[15] = tswapreg(env->regs[15]);
-
-    (*regs)[16] = tswapreg(cpsr_read((CPUARMState *)env));
-    (*regs)[17] = tswapreg(env->regs[0]); /* XXX */
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
diff --git a/linux-user/arm/target_coredump.c.inc b/linux-user/arm/target_coredump.c.inc
new file mode 100644
index 0000000000..e3cb51b145
--- /dev/null
+++ b/linux-user/arm/target_coredump.c.inc
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#define ELF_NREG    18
+typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUARMState *env)
+{
+    (*regs)[0] = tswapreg(env->regs[0]);
+    (*regs)[1] = tswapreg(env->regs[1]);
+    (*regs)[2] = tswapreg(env->regs[2]);
+    (*regs)[3] = tswapreg(env->regs[3]);
+    (*regs)[4] = tswapreg(env->regs[4]);
+    (*regs)[5] = tswapreg(env->regs[5]);
+    (*regs)[6] = tswapreg(env->regs[6]);
+    (*regs)[7] = tswapreg(env->regs[7]);
+    (*regs)[8] = tswapreg(env->regs[8]);
+    (*regs)[9] = tswapreg(env->regs[9]);
+    (*regs)[10] = tswapreg(env->regs[10]);
+    (*regs)[11] = tswapreg(env->regs[11]);
+    (*regs)[12] = tswapreg(env->regs[12]);
+    (*regs)[13] = tswapreg(env->regs[13]);
+    (*regs)[14] = tswapreg(env->regs[14]);
+    (*regs)[15] = tswapreg(env->regs[15]);
+
+    (*regs)[16] = tswapreg(cpsr_read((CPUARMState *)env));
+    (*regs)[17] = tswapreg(env->regs[0]); /* XXX */
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 44/89] linux-user/aarch64: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (42 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 43/89] linux-user/arm: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:46   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 45/89] linux-user/ppc: " Richard Henderson
                   ` (45 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                     | 16 +---------------
 linux-user/aarch64/target_coredump.c.inc | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 15 deletions(-)
 create mode 100644 linux-user/aarch64/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b35f35b2a6..57bb011e63 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -304,21 +304,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_ARCH        EM_AARCH64
 #define ELF_CLASS       ELFCLASS64
 
-#define ELF_NREG    34
-typedef target_elf_greg_t  target_elf_gregset_t[ELF_NREG];
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
-                               const CPUARMState *env)
-{
-    int i;
-
-    for (i = 0; i < 32; i++) {
-        (*regs)[i] = tswapreg(env->xregs[i]);
-    }
-    (*regs)[32] = tswapreg(env->pc);
-    (*regs)[33] = tswapreg(pstate_read((CPUARMState *)env));
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
diff --git a/linux-user/aarch64/target_coredump.c.inc b/linux-user/aarch64/target_coredump.c.inc
new file mode 100644
index 0000000000..9b653aa12f
--- /dev/null
+++ b/linux-user/aarch64/target_coredump.c.inc
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#define ELF_NREG    34
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUARMState *env)
+{
+    for (int i = 0; i < 32; i++) {
+        (*regs)[i] = tswapreg(env->xregs[i]);
+    }
+    (*regs)[32] = tswapreg(env->pc);
+    (*regs)[33] = tswapreg(pstate_read((CPUARMState *)env));
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 45/89] linux-user/ppc: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (43 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 44/89] linux-user/aarch64: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:46   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 46/89] linux-user/loongarch64: " Richard Henderson
                   ` (44 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                 | 24 +-----------------------
 linux-user/ppc/target_coredump.c.inc | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 23 deletions(-)
 create mode 100644 linux-user/ppc/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 57bb011e63..a6e4ac86bf 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -376,29 +376,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
         NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
     } while (0)
 
-/* See linux kernel: arch/powerpc/include/asm/elf.h.  */
-#define ELF_NREG 48
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *env)
-{
-    int i;
-    target_ulong ccr = 0;
-
-    for (i = 0; i < ARRAY_SIZE(env->gpr); i++) {
-        (*regs)[i] = tswapreg(env->gpr[i]);
-    }
-
-    (*regs)[32] = tswapreg(env->nip);
-    (*regs)[33] = tswapreg(env->msr);
-    (*regs)[35] = tswapreg(env->ctr);
-    (*regs)[36] = tswapreg(env->lr);
-    (*regs)[37] = tswapreg(cpu_read_xer(env));
-
-    ccr = ppc_get_cr(env);
-    (*regs)[38] = tswapreg(ccr);
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
diff --git a/linux-user/ppc/target_coredump.c.inc b/linux-user/ppc/target_coredump.c.inc
new file mode 100644
index 0000000000..7671bf86e8
--- /dev/null
+++ b/linux-user/ppc/target_coredump.c.inc
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/powerpc/include/asm/elf.h.  */
+#define ELF_NREG 48
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUPPCState *env)
+{
+    target_ulong ccr = 0;
+
+    for (int i = 0; i < ARRAY_SIZE(env->gpr); i++) {
+        (*regs)[i] = tswapreg(env->gpr[i]);
+    }
+
+    (*regs)[32] = tswapreg(env->nip);
+    (*regs)[33] = tswapreg(env->msr);
+    (*regs)[35] = tswapreg(env->ctr);
+    (*regs)[36] = tswapreg(env->lr);
+    (*regs)[37] = tswapreg(cpu_read_xer(env));
+
+    ccr = ppc_get_cr(env);
+    (*regs)[38] = tswapreg(ccr);
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 46/89] linux-user/loongarch64: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (44 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 45/89] linux-user/ppc: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:47   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 47/89] linux-user/mips: " Richard Henderson
                   ` (43 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                         | 26 +-------------------
 linux-user/loongarch64/target_coredump.c.inc | 24 ++++++++++++++++++
 2 files changed, 25 insertions(+), 25 deletions(-)
 create mode 100644 linux-user/loongarch64/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a6e4ac86bf..77730fdbaf 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -400,31 +400,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 
 #define VDSO_HEADER "vdso.c.inc"
 
-/* See linux kernel: arch/loongarch/include/asm/elf.h */
-#define ELF_NREG 45
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-enum {
-    TARGET_EF_R0 = 0,
-    TARGET_EF_CSR_ERA = TARGET_EF_R0 + 33,
-    TARGET_EF_CSR_BADV = TARGET_EF_R0 + 34,
-};
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
-                               const CPULoongArchState *env)
-{
-    int i;
-
-    (*regs)[TARGET_EF_R0] = 0;
-
-    for (i = 1; i < ARRAY_SIZE(env->gpr); i++) {
-        (*regs)[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
-    }
-
-    (*regs)[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
-    (*regs)[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
diff --git a/linux-user/loongarch64/target_coredump.c.inc b/linux-user/loongarch64/target_coredump.c.inc
new file mode 100644
index 0000000000..34207f9fb0
--- /dev/null
+++ b/linux-user/loongarch64/target_coredump.c.inc
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/loongarch/include/asm/elf.h */
+#define ELF_NREG 45
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+enum {
+    TARGET_EF_R0 = 0,
+    TARGET_EF_CSR_ERA = TARGET_EF_R0 + 33,
+    TARGET_EF_CSR_BADV = TARGET_EF_R0 + 34,
+};
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPULoongArchState *env)
+{
+    (*regs)[TARGET_EF_R0] = 0;
+
+    for (int i = 1; i < ARRAY_SIZE(env->gpr); i++) {
+        (*regs)[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]);
+    }
+
+    (*regs)[TARGET_EF_CSR_ERA] = tswapreg(env->pc);
+    (*regs)[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV);
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 47/89] linux-user/mips: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (45 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 46/89] linux-user/loongarch64: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:47   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 48/89] linux-user/microblaze: " Richard Henderson
                   ` (42 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                    | 46 +------------------------
 linux-user/mips/target_coredump.c.inc   | 46 +++++++++++++++++++++++++
 linux-user/mips64/target_coredump.c.inc |  1 +
 3 files changed, 48 insertions(+), 45 deletions(-)
 create mode 100644 linux-user/mips/target_coredump.c.inc
 create mode 100644 linux-user/mips64/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 77730fdbaf..d37e580ada 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -422,51 +422,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
 #endif
 
-/* See linux kernel: arch/mips/include/asm/elf.h.  */
-#define ELF_NREG 45
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-/* See linux kernel: arch/mips/include/asm/reg.h.  */
-enum {
-#ifdef TARGET_MIPS64
-    TARGET_EF_R0 = 0,
-#else
-    TARGET_EF_R0 = 6,
-#endif
-    TARGET_EF_R26 = TARGET_EF_R0 + 26,
-    TARGET_EF_R27 = TARGET_EF_R0 + 27,
-    TARGET_EF_LO = TARGET_EF_R0 + 32,
-    TARGET_EF_HI = TARGET_EF_R0 + 33,
-    TARGET_EF_CP0_EPC = TARGET_EF_R0 + 34,
-    TARGET_EF_CP0_BADVADDR = TARGET_EF_R0 + 35,
-    TARGET_EF_CP0_STATUS = TARGET_EF_R0 + 36,
-    TARGET_EF_CP0_CAUSE = TARGET_EF_R0 + 37
-};
-
-/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs.  */
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMIPSState *env)
-{
-    int i;
-
-    for (i = 0; i < TARGET_EF_R0; i++) {
-        (*regs)[i] = 0;
-    }
-    (*regs)[TARGET_EF_R0] = 0;
-
-    for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
-        (*regs)[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
-    }
-
-    (*regs)[TARGET_EF_R26] = 0;
-    (*regs)[TARGET_EF_R27] = 0;
-    (*regs)[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
-    (*regs)[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
-    (*regs)[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
-    (*regs)[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
-    (*regs)[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
-    (*regs)[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
diff --git a/linux-user/mips/target_coredump.c.inc b/linux-user/mips/target_coredump.c.inc
new file mode 100644
index 0000000000..bbdf5faba3
--- /dev/null
+++ b/linux-user/mips/target_coredump.c.inc
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/mips/include/asm/elf.h.  */
+#define ELF_NREG 45
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/mips/include/asm/reg.h.  */
+enum {
+#ifdef TARGET_MIPS64
+    TARGET_EF_R0 = 0,
+#else
+    TARGET_EF_R0 = 6,
+#endif
+    TARGET_EF_R26 = TARGET_EF_R0 + 26,
+    TARGET_EF_R27 = TARGET_EF_R0 + 27,
+    TARGET_EF_LO = TARGET_EF_R0 + 32,
+    TARGET_EF_HI = TARGET_EF_R0 + 33,
+    TARGET_EF_CP0_EPC = TARGET_EF_R0 + 34,
+    TARGET_EF_CP0_BADVADDR = TARGET_EF_R0 + 35,
+    TARGET_EF_CP0_STATUS = TARGET_EF_R0 + 36,
+    TARGET_EF_CP0_CAUSE = TARGET_EF_R0 + 37
+};
+
+/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs.  */
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUMIPSState *env)
+{
+    for (int i = 0; i < TARGET_EF_R0; i++) {
+        (*regs)[i] = 0;
+    }
+    (*regs)[TARGET_EF_R0] = 0;
+
+
+    for (int i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) {
+        (*regs)[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]);
+    }
+
+    (*regs)[TARGET_EF_R26] = 0;
+    (*regs)[TARGET_EF_R27] = 0;
+    (*regs)[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]);
+    (*regs)[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]);
+    (*regs)[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC);
+    (*regs)[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr);
+    (*regs)[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status);
+    (*regs)[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause);
+}
diff --git a/linux-user/mips64/target_coredump.c.inc b/linux-user/mips64/target_coredump.c.inc
new file mode 100644
index 0000000000..950d873550
--- /dev/null
+++ b/linux-user/mips64/target_coredump.c.inc
@@ -0,0 +1 @@
+#include "../mips/target_coredump.c.inc"
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 48/89] linux-user/microblaze: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (46 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 47/89] linux-user/mips: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:47   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 49/89] target/openrisc: " Richard Henderson
                   ` (41 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                        | 21 +--------------------
 linux-user/microblaze/target_coredump.c.inc | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 20 deletions(-)
 create mode 100644 linux-user/microblaze/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d37e580ada..59d179092b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -437,27 +437,8 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 
 #define ELF_EXEC_PAGESIZE        4096
 
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
-#define ELF_NREG 38
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs.  */
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env)
-{
-    int i, pos = 0;
-
-    for (i = 0; i < 32; i++) {
-        (*regs)[pos++] = tswapreg(env->regs[i]);
-    }
-
-    (*regs)[pos++] = tswapreg(env->pc);
-    (*regs)[pos++] = tswapreg(mb_cpu_read_msr(env));
-    (*regs)[pos++] = 0;
-    (*regs)[pos++] = tswapreg(env->ear);
-    (*regs)[pos++] = 0;
-    (*regs)[pos++] = tswapreg(env->esr);
-}
-
 #endif /* TARGET_MICROBLAZE */
 
 #ifdef TARGET_OPENRISC
diff --git a/linux-user/microblaze/target_coredump.c.inc b/linux-user/microblaze/target_coredump.c.inc
new file mode 100644
index 0000000000..11ef0e3e92
--- /dev/null
+++ b/linux-user/microblaze/target_coredump.c.inc
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#define ELF_NREG 38
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs.  */
+static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUMBState *env)
+{
+    int i, pos = 0;
+
+    for (i = 0; i < 32; i++) {
+        (*regs)[pos++] = tswapreg(env->regs[i]);
+    }
+
+    (*regs)[pos++] = tswapreg(env->pc);
+    (*regs)[pos++] = tswapreg(mb_cpu_read_msr(env));
+    (*regs)[pos++] = 0;
+    (*regs)[pos++] = tswapreg(env->ear);
+    (*regs)[pos++] = 0;
+    (*regs)[pos++] = tswapreg(env->esr);
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 49/89] target/openrisc: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (47 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 48/89] linux-user/microblaze: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:48   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 50/89] target/sh4: " Richard Henderson
                   ` (40 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                      | 17 +----------------
 linux-user/openrisc/target_coredump.c.inc | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)
 create mode 100644 linux-user/openrisc/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 59d179092b..051e9b72cf 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -447,25 +447,10 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_CLASS ELFCLASS32
 #define ELF_DATA  ELFDATA2MSB
 
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 8192
 
-/* See linux kernel arch/openrisc/include/asm/elf.h.  */
-#define ELF_NREG 34 /* gprs and pc, sr */
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
-                               const CPUOpenRISCState *env)
-{
-    int i;
-
-    for (i = 0; i < 32; i++) {
-        (*regs)[i] = tswapreg(cpu_get_gpr(env, i));
-    }
-    (*regs)[32] = tswapreg(env->pc);
-    (*regs)[33] = tswapreg(cpu_get_sr(env));
-}
-
 #endif /* TARGET_OPENRISC */
 
 #ifdef TARGET_SH4
diff --git a/linux-user/openrisc/target_coredump.c.inc b/linux-user/openrisc/target_coredump.c.inc
new file mode 100644
index 0000000000..fe6c17f199
--- /dev/null
+++ b/linux-user/openrisc/target_coredump.c.inc
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel arch/openrisc/include/asm/elf.h.  */
+#define ELF_NREG 34 /* gprs and pc, sr */
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUOpenRISCState *env)
+{
+    for (int i = 0; i < 32; i++) {
+        (*regs)[i] = tswapreg(cpu_get_gpr(env, i));
+    }
+    (*regs)[32] = tswapreg(env->pc);
+    (*regs)[33] = tswapreg(cpu_get_sr(env));
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 50/89] target/sh4: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (48 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 49/89] target/openrisc: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:49   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 51/89] linux-user/m68k: " Richard Henderson
                   ` (39 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                 | 34 +---------------------------
 linux-user/sh4/target_coredump.c.inc | 32 ++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 33 deletions(-)
 create mode 100644 linux-user/sh4/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 051e9b72cf..836f01e579 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -458,39 +458,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_CLASS ELFCLASS32
 #define ELF_ARCH  EM_SH
 
-/* See linux kernel: arch/sh/include/asm/elf.h.  */
-#define ELF_NREG 23
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-/* See linux kernel: arch/sh/include/asm/ptrace.h.  */
-enum {
-    TARGET_REG_PC = 16,
-    TARGET_REG_PR = 17,
-    TARGET_REG_SR = 18,
-    TARGET_REG_GBR = 19,
-    TARGET_REG_MACH = 20,
-    TARGET_REG_MACL = 21,
-    TARGET_REG_SYSCALL = 22
-};
-
-static inline void elf_core_copy_regs(target_elf_gregset_t *regs,
-                                      const CPUSH4State *env)
-{
-    int i;
-
-    for (i = 0; i < 16; i++) {
-        (*regs)[i] = tswapreg(env->gregs[i]);
-    }
-
-    (*regs)[TARGET_REG_PC] = tswapreg(env->pc);
-    (*regs)[TARGET_REG_PR] = tswapreg(env->pr);
-    (*regs)[TARGET_REG_SR] = tswapreg(env->sr);
-    (*regs)[TARGET_REG_GBR] = tswapreg(env->gbr);
-    (*regs)[TARGET_REG_MACH] = tswapreg(env->mach);
-    (*regs)[TARGET_REG_MACL] = tswapreg(env->macl);
-    (*regs)[TARGET_REG_SYSCALL] = 0; /* FIXME */
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
diff --git a/linux-user/sh4/target_coredump.c.inc b/linux-user/sh4/target_coredump.c.inc
new file mode 100644
index 0000000000..559cd21b1d
--- /dev/null
+++ b/linux-user/sh4/target_coredump.c.inc
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/sh/include/asm/elf.h.  */
+#define ELF_NREG 23
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+/* See linux kernel: arch/sh/include/asm/ptrace.h.  */
+enum {
+    TARGET_REG_PC = 16,
+    TARGET_REG_PR = 17,
+    TARGET_REG_SR = 18,
+    TARGET_REG_GBR = 19,
+    TARGET_REG_MACH = 20,
+    TARGET_REG_MACL = 21,
+    TARGET_REG_SYSCALL = 22
+};
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUSH4State *env)
+{
+    for (int i = 0; i < 16; i++) {
+        (*regs)[i] = tswapreg(env->gregs[i]);
+    }
+
+    (*regs)[TARGET_REG_PC] = tswapreg(env->pc);
+    (*regs)[TARGET_REG_PR] = tswapreg(env->pr);
+    (*regs)[TARGET_REG_SR] = tswapreg(env->sr);
+    (*regs)[TARGET_REG_GBR] = tswapreg(env->gbr);
+    (*regs)[TARGET_REG_MACH] = tswapreg(env->mach);
+    (*regs)[TARGET_REG_MACL] = tswapreg(env->macl);
+    (*regs)[TARGET_REG_SYSCALL] = 0; /* FIXME */
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 51/89] linux-user/m68k: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (49 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 50/89] target/sh4: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:49   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 52/89] linux-user/s390x: " Richard Henderson
                   ` (38 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                  | 29 +-------------------------
 linux-user/m68k/target_coredump.c.inc | 30 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 28 deletions(-)
 create mode 100644 linux-user/m68k/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 836f01e579..d9def102e3 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -469,34 +469,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_68K
 
-/* See linux kernel: arch/m68k/include/asm/elf.h.  */
-#define ELF_NREG 20
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUM68KState *env)
-{
-    (*regs)[0] = tswapreg(env->dregs[1]);
-    (*regs)[1] = tswapreg(env->dregs[2]);
-    (*regs)[2] = tswapreg(env->dregs[3]);
-    (*regs)[3] = tswapreg(env->dregs[4]);
-    (*regs)[4] = tswapreg(env->dregs[5]);
-    (*regs)[5] = tswapreg(env->dregs[6]);
-    (*regs)[6] = tswapreg(env->dregs[7]);
-    (*regs)[7] = tswapreg(env->aregs[0]);
-    (*regs)[8] = tswapreg(env->aregs[1]);
-    (*regs)[9] = tswapreg(env->aregs[2]);
-    (*regs)[10] = tswapreg(env->aregs[3]);
-    (*regs)[11] = tswapreg(env->aregs[4]);
-    (*regs)[12] = tswapreg(env->aregs[5]);
-    (*regs)[13] = tswapreg(env->aregs[6]);
-    (*regs)[14] = tswapreg(env->dregs[0]);
-    (*regs)[15] = tswapreg(env->aregs[7]);
-    (*regs)[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
-    (*regs)[17] = tswapreg(env->sr);
-    (*regs)[18] = tswapreg(env->pc);
-    (*regs)[19] = 0;  /* FIXME: regs->format | regs->vector */
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       8192
 
diff --git a/linux-user/m68k/target_coredump.c.inc b/linux-user/m68k/target_coredump.c.inc
new file mode 100644
index 0000000000..99821759a3
--- /dev/null
+++ b/linux-user/m68k/target_coredump.c.inc
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/m68k/include/asm/elf.h.  */
+#define ELF_NREG 20
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUM68KState *env)
+{
+    (*regs)[0] = tswapreg(env->dregs[1]);
+    (*regs)[1] = tswapreg(env->dregs[2]);
+    (*regs)[2] = tswapreg(env->dregs[3]);
+    (*regs)[3] = tswapreg(env->dregs[4]);
+    (*regs)[4] = tswapreg(env->dregs[5]);
+    (*regs)[5] = tswapreg(env->dregs[6]);
+    (*regs)[6] = tswapreg(env->dregs[7]);
+    (*regs)[7] = tswapreg(env->aregs[0]);
+    (*regs)[8] = tswapreg(env->aregs[1]);
+    (*regs)[9] = tswapreg(env->aregs[2]);
+    (*regs)[10] = tswapreg(env->aregs[3]);
+    (*regs)[11] = tswapreg(env->aregs[4]);
+    (*regs)[12] = tswapreg(env->aregs[5]);
+    (*regs)[13] = tswapreg(env->aregs[6]);
+    (*regs)[14] = tswapreg(env->dregs[0]);
+    (*regs)[15] = tswapreg(env->aregs[7]);
+    (*regs)[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */
+    (*regs)[17] = tswapreg(env->sr);
+    (*regs)[18] = tswapreg(env->pc);
+    (*regs)[19] = 0;  /* FIXME: regs->format | regs->vector */
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 52/89] linux-user/s390x: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (50 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 51/89] linux-user/m68k: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:49   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 53/89] linux-user/xtensa: " Richard Henderson
                   ` (37 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                   | 31 +-------------------------
 linux-user/s390x/target_coredump.c.inc | 31 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 30 deletions(-)
 create mode 100644 linux-user/s390x/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d9def102e3..7cd0d5e7db 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -490,36 +490,7 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
-/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs).  */
-#define ELF_NREG 27
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-enum {
-    TARGET_REG_PSWM = 0,
-    TARGET_REG_PSWA = 1,
-    TARGET_REG_GPRS = 2,
-    TARGET_REG_ARS = 18,
-    TARGET_REG_ORIG_R2 = 26,
-};
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
-                               const CPUS390XState *env)
-{
-    int i;
-    uint32_t *aregs;
-
-    (*regs)[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
-    (*regs)[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
-    for (i = 0; i < 16; i++) {
-        (*regs)[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
-    }
-    aregs = (uint32_t *)&((*regs)[TARGET_REG_ARS]);
-    for (i = 0; i < 16; i++) {
-        aregs[i] = tswap32(env->aregs[i]);
-    }
-    (*regs)[TARGET_REG_ORIG_R2] = 0;
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 4096
 
diff --git a/linux-user/s390x/target_coredump.c.inc b/linux-user/s390x/target_coredump.c.inc
new file mode 100644
index 0000000000..bc8cd9d6c6
--- /dev/null
+++ b/linux-user/s390x/target_coredump.c.inc
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/s390/include/uapi/asm/ptrace.h (s390_regs).  */
+#define ELF_NREG 27
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+enum {
+    TARGET_REG_PSWM = 0,
+    TARGET_REG_PSWA = 1,
+    TARGET_REG_GPRS = 2,
+    TARGET_REG_ARS = 18,
+    TARGET_REG_ORIG_R2 = 26,
+};
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUS390XState *env)
+{
+    int i;
+    uint32_t *aregs;
+
+    (*regs)[TARGET_REG_PSWM] = tswapreg(env->psw.mask);
+    (*regs)[TARGET_REG_PSWA] = tswapreg(env->psw.addr);
+    for (i = 0; i < 16; i++) {
+        (*regs)[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]);
+    }
+    aregs = (uint32_t *)&((*regs)[TARGET_REG_ARS]);
+    for (i = 0; i < 16; i++) {
+        aregs[i] = tswap32(env->aregs[i]);
+    }
+    (*regs)[TARGET_REG_ORIG_R2] = 0;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 53/89] linux-user/xtensa: Split out target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (51 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 52/89] linux-user/s390x: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:50   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 54/89] linux-user: Unify the include of target_coredump.c.inc Richard Henderson
                   ` (36 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c                    | 38 +------------------------
 linux-user/xtensa/target_coredump.c.inc | 38 +++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 37 deletions(-)
 create mode 100644 linux-user/xtensa/target_coredump.c.inc

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 7cd0d5e7db..347af3202c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -562,43 +562,7 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_XTENSA
 
-/* See linux kernel: arch/xtensa/include/asm/elf.h.  */
-#define ELF_NREG 128
-typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
-
-enum {
-    TARGET_REG_PC,
-    TARGET_REG_PS,
-    TARGET_REG_LBEG,
-    TARGET_REG_LEND,
-    TARGET_REG_LCOUNT,
-    TARGET_REG_SAR,
-    TARGET_REG_WINDOWSTART,
-    TARGET_REG_WINDOWBASE,
-    TARGET_REG_THREADPTR,
-    TARGET_REG_AR0 = 64,
-};
-
-static void elf_core_copy_regs(target_elf_gregset_t *regs,
-                               const CPUXtensaState *env)
-{
-    unsigned i;
-
-    (*regs)[TARGET_REG_PC] = tswapreg(env->pc);
-    (*regs)[TARGET_REG_PS] = tswapreg(env->sregs[PS] & ~PS_EXCM);
-    (*regs)[TARGET_REG_LBEG] = tswapreg(env->sregs[LBEG]);
-    (*regs)[TARGET_REG_LEND] = tswapreg(env->sregs[LEND]);
-    (*regs)[TARGET_REG_LCOUNT] = tswapreg(env->sregs[LCOUNT]);
-    (*regs)[TARGET_REG_SAR] = tswapreg(env->sregs[SAR]);
-    (*regs)[TARGET_REG_WINDOWSTART] = tswapreg(env->sregs[WINDOW_START]);
-    (*regs)[TARGET_REG_WINDOWBASE] = tswapreg(env->sregs[WINDOW_BASE]);
-    (*regs)[TARGET_REG_THREADPTR] = tswapreg(env->uregs[THREADPTR]);
-    xtensa_sync_phys_from_window((CPUXtensaState *)env);
-    for (i = 0; i < env->config->nareg; ++i) {
-        (*regs)[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]);
-    }
-}
-
+#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
diff --git a/linux-user/xtensa/target_coredump.c.inc b/linux-user/xtensa/target_coredump.c.inc
new file mode 100644
index 0000000000..192589d1e3
--- /dev/null
+++ b/linux-user/xtensa/target_coredump.c.inc
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/* See linux kernel: arch/xtensa/include/asm/elf.h.  */
+#define ELF_NREG 128
+typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG];
+
+enum {
+    TARGET_REG_PC,
+    TARGET_REG_PS,
+    TARGET_REG_LBEG,
+    TARGET_REG_LEND,
+    TARGET_REG_LCOUNT,
+    TARGET_REG_SAR,
+    TARGET_REG_WINDOWSTART,
+    TARGET_REG_WINDOWBASE,
+    TARGET_REG_THREADPTR,
+    TARGET_REG_AR0 = 64,
+};
+
+static void elf_core_copy_regs(target_elf_gregset_t *regs,
+                               const CPUXtensaState *env)
+{
+    unsigned i;
+
+    (*regs)[TARGET_REG_PC] = tswapreg(env->pc);
+    (*regs)[TARGET_REG_PS] = tswapreg(env->sregs[PS] & ~PS_EXCM);
+    (*regs)[TARGET_REG_LBEG] = tswapreg(env->sregs[LBEG]);
+    (*regs)[TARGET_REG_LEND] = tswapreg(env->sregs[LEND]);
+    (*regs)[TARGET_REG_LCOUNT] = tswapreg(env->sregs[LCOUNT]);
+    (*regs)[TARGET_REG_SAR] = tswapreg(env->sregs[SAR]);
+    (*regs)[TARGET_REG_WINDOWSTART] = tswapreg(env->sregs[WINDOW_START]);
+    (*regs)[TARGET_REG_WINDOWBASE] = tswapreg(env->sregs[WINDOW_BASE]);
+    (*regs)[TARGET_REG_THREADPTR] = tswapreg(env->uregs[THREADPTR]);
+    xtensa_sync_phys_from_window((CPUXtensaState *)env);
+    for (i = 0; i < env->config->nareg; ++i) {
+        (*regs)[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]);
+    }
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 54/89] linux-user: Unify the include of target_coredump.c.inc
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (52 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 53/89] linux-user/xtensa: " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 17:50   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 55/89] linux-user: Move init_guest_commpage to x86_64/elfload.c Richard Henderson
                   ` (35 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Now that all target_coredump.c.inc files have been created,
USE_ELF_CORE_DUMP signals that it is available.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 347af3202c..6feab68a52 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -159,8 +159,6 @@ typedef abi_int         target_pid_t;
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
 
-#include "target_coredump.c.inc"
-
 #if ULONG_MAX > UINT32_MAX
 #define INIT_GUEST_COMMPAGE
 static bool init_guest_commpage(void)
@@ -197,8 +195,6 @@ static bool init_guest_commpage(void)
 
 #define EXSTACK_DEFAULT true
 
-#include "target_coredump.c.inc"
-
 /*
  * i386 is the only target which supplies AT_SYSINFO for the vdso.
  * All others only supply AT_SYSINFO_EHDR.
@@ -229,7 +225,6 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define EXSTACK_DEFAULT true
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
@@ -304,7 +299,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_ARCH        EM_AARCH64
 #define ELF_CLASS       ELFCLASS64
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
@@ -376,7 +370,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
         NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
     } while (0)
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
@@ -400,7 +393,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 
 #define VDSO_HEADER "vdso.c.inc"
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
@@ -422,7 +414,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
 #endif
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
@@ -437,7 +428,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 
 #define ELF_EXEC_PAGESIZE        4096
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #endif /* TARGET_MICROBLAZE */
 
@@ -447,7 +437,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_CLASS ELFCLASS32
 #define ELF_DATA  ELFDATA2MSB
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 8192
 
@@ -458,7 +447,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_CLASS ELFCLASS32
 #define ELF_ARCH  EM_SH
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE        4096
 
@@ -469,7 +457,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_68K
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       8192
 
@@ -490,7 +477,6 @@ static const VdsoImageInfo *vdso_image_info(uint32_t elf_flags)
 #define ELF_DATA	ELFDATA2MSB
 #define ELF_ARCH	EM_S390
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE 4096
 
@@ -562,7 +548,6 @@ static bool init_guest_commpage(void)
 #define ELF_CLASS       ELFCLASS32
 #define ELF_ARCH        EM_XTENSA
 
-#include "target_coredump.c.inc"
 #define USE_ELF_CORE_DUMP
 #define ELF_EXEC_PAGESIZE       4096
 
@@ -2502,6 +2487,7 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
 }
 
 #ifdef USE_ELF_CORE_DUMP
+#include "target_coredump.c.inc"
 
 /*
  * Definitions to generate Intel SVR4-like core files.
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 55/89] linux-user: Move init_guest_commpage to x86_64/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (53 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 54/89] linux-user: Unify the include of target_coredump.c.inc Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 18:07   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 56/89] linux-user: Move init_guest_commpage to arm/elfload.c Richard Henderson
                   ` (34 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h         |  3 +++
 linux-user/elfload.c        | 20 --------------------
 linux-user/x86_64/elfload.c | 20 ++++++++++++++++++++
 3 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index 700bbdb02e..e5e317ab76 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -102,5 +102,8 @@ 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
 
 #endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6feab68a52..297151e4fa 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -159,27 +159,7 @@ 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
 
 /*
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index bc40ed8c5b..98acca94ef 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"
 
@@ -14,3 +15,22 @@ 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;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 56/89] linux-user: Move init_guest_commpage to arm/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (54 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 55/89] linux-user: Move init_guest_commpage to x86_64/elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 18:08   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 57/89] linux-user: Move init_guest_commpage to hppa/elfload.c Richard Henderson
                   ` (33 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/arm/target_elf.h |  4 ++++
 linux-user/loader.h         |  2 +-
 linux-user/arm/elfload.c    | 46 +++++++++++++++++++++++++++++++++++
 linux-user/elfload.c        | 48 -------------------------------------
 4 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 58ff6a0986..bb9875fa2d 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -7,8 +7,12 @@
 
 #ifndef ARM_TARGET_ELF_H
 #define ARM_TARGET_ELF_H
+
+#define HI_COMMPAGE (intptr_t)0xffff0f00u
+
 static inline const char *cpu_get_model(uint32_t eflags)
 {
     return "any";
 }
+
 #endif
diff --git a/linux-user/loader.h b/linux-user/loader.h
index e5e317ab76..28eebf2f0b 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -102,7 +102,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
 
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 8573e46f2c..ad0d88a7e0 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"
 
 
@@ -194,3 +196,47 @@ 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;
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 297151e4fa..714b70757c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -208,54 +208,6 @@ typedef abi_int         target_pid_t;
 #define USE_ELF_CORE_DUMP
 #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"
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 57/89] linux-user: Move init_guest_commpage to hppa/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (55 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 56/89] linux-user: Move init_guest_commpage to arm/elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 18:08   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 58/89] linux-user: Remove INIT_GUEST_COMMPAGE Richard Henderson
                   ` (32 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/hppa/target_elf.h |  4 ++++
 linux-user/loader.h          |  2 --
 linux-user/elfload.c         | 32 --------------------------------
 linux-user/hppa/elfload.c    | 31 +++++++++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index 19cae8bd65..00dc2d6684 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -7,8 +7,12 @@
 
 #ifndef HPPA_TARGET_ELF_H
 #define HPPA_TARGET_ELF_H
+
+#define LO_COMMPAGE  0
+
 static inline const char *cpu_get_model(uint32_t eflags)
 {
     return "hppa";
 }
+
 #endif
diff --git a/linux-user/loader.h b/linux-user/loader.h
index 28eebf2f0b..e6d02d186e 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -102,8 +102,6 @@ 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
 
 #endif /* LINUX_USER_LOADER_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 714b70757c..8ebde57fa5 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -441,38 +441,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 ff0c2b862a..c7e1e3952a 100644
--- a/linux-user/hppa/elfload.c
+++ b/linux-user/hppa/elfload.c
@@ -3,9 +3,40 @@
 #include "qemu/osdep.h"
 #include "qemu.h"
 #include "loader.h"
+#include "target_elf.h"
 
 
 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;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 58/89] linux-user: Remove INIT_GUEST_COMMPAGE
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (56 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 57/89] linux-user: Move init_guest_commpage to hppa/elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 18:09   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 59/89] linux-user: Move get_vdso_image_info to arm/elfload.c Richard Henderson
                   ` (31 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Provide a weak stub version of init_guest_commpage
instead of using the preprocessor.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 8ebde57fa5..01c39bf456 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -158,8 +158,6 @@ typedef abi_int         target_pid_t;
 #ifdef TARGET_X86_64
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_X86_64
-
-#define INIT_GUEST_COMMPAGE
 #else
 
 /*
@@ -1151,11 +1149,14 @@ 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
-#define init_guest_commpage() true
-#endif
 #endif
 
+bool __attribute__((weak)) init_guest_commpage(void)
+{
+    return true;
+}
+
+
 /**
  * pgb_try_mmap:
  * @addr: host start address
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 59/89] linux-user: Move get_vdso_image_info to arm/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (57 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 58/89] linux-user: Remove INIT_GUEST_COMMPAGE Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 18:11   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 60/89] linux-user: Remove ELF_EXEC_PAGESIZE Richard Henderson
                   ` (30 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Rename from vdso_image_info to avoid a symbol clash.
Provide fallback versions for other targets.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loader.h      | 12 ++++++++++++
 linux-user/arm/elfload.c | 20 ++++++++++++++++++++
 linux-user/elfload.c     | 41 ++++++++++------------------------------
 3 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/linux-user/loader.h b/linux-user/loader.h
index e6d02d186e..db6547ea7a 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -104,4 +104,16 @@ const char *get_elf_platform(CPUState *cs);
 const char *get_elf_base_platform(CPUState *cs);
 bool init_guest_commpage(void);
 
+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 */
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index ad0d88a7e0..901141ad2a 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -6,6 +6,7 @@
 #include "user-internals.h"
 #include "target_elf.h"
 #include "target/arm/cpu-features.h"
+#include "elf.h"
 
 
 enum
@@ -240,3 +241,22 @@ bool init_guest_commpage(void)
                    PAGE_READ | PAGE_EXEC | PAGE_VALID);
     return true;
 }
+
+#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/elfload.c b/linux-user/elfload.c
index 01c39bf456..10fbe71e35 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -46,15 +46,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 */
@@ -206,23 +197,6 @@ typedef abi_int         target_pid_t;
 #define USE_ELF_CORE_DUMP
 #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 */
 
@@ -2011,14 +1985,19 @@ static void load_elf_interp(const char *filename, struct image_info *info,
     load_elf_image(filename, &src, info, &ehdr, NULL);
 }
 
-#ifndef vdso_image_info
 #ifdef VDSO_HEADER
 #include VDSO_HEADER
-#define  vdso_image_info(flags)  &vdso_image_info
+const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags)
+{
+    return &vdso_image_info;
+}
 #else
-#define  vdso_image_info(flags)  NULL
+const VdsoImageInfo * __attribute__((weak))
+get_vdso_image_info(uint32_t elf_flags)
+{
+    return NULL;
+}
 #endif /* VDSO_HEADER */
-#endif /* vdso_image_info */
 
 static void load_elf_vdso(struct image_info *info, const VdsoImageInfo *vdso)
 {
@@ -2349,7 +2328,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;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 60/89] linux-user: Remove ELF_EXEC_PAGESIZE
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (58 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 59/89] linux-user: Move get_vdso_image_info to arm/elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-01 18:12   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 61/89] linux-user: Move get_elf_cpu_model to target/elfload.c Richard Henderson
                   ` (29 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Use TARGET_PAGE_SIZE instead.  If the target page size may vary,
using a different fixed size is wrong.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 10fbe71e35..1ac3a20813 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -181,7 +181,6 @@ typedef abi_int         target_pid_t;
 #define VDSO_HEADER "vdso.c.inc"
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
 
 #endif /* TARGET_I386 */
 
@@ -195,7 +194,6 @@ typedef abi_int         target_pid_t;
 #define EXSTACK_DEFAULT true
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
 
 #else
 /* 64 bit ARM definitions */
@@ -204,7 +202,6 @@ typedef abi_int         target_pid_t;
 #define ELF_CLASS       ELFCLASS64
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
 
 #if TARGET_BIG_ENDIAN
 # define VDSO_HEADER  "vdso-be.c.inc"
@@ -275,7 +272,6 @@ typedef abi_int         target_pid_t;
     } while (0)
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
 
 #ifndef TARGET_PPC64
 # define VDSO_HEADER  "vdso-32.c.inc"
@@ -298,7 +294,6 @@ typedef abi_int         target_pid_t;
 #define VDSO_HEADER "vdso.c.inc"
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        4096
 
 #endif /* TARGET_LOONGARCH64 */
 
@@ -319,7 +314,6 @@ typedef abi_int         target_pid_t;
 #endif
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        4096
 
 #endif /* TARGET_MIPS */
 
@@ -330,8 +324,6 @@ typedef abi_int         target_pid_t;
 #define ELF_CLASS   ELFCLASS32
 #define ELF_ARCH    EM_MICROBLAZE
 
-#define ELF_EXEC_PAGESIZE        4096
-
 #define USE_ELF_CORE_DUMP
 #endif /* TARGET_MICROBLAZE */
 
@@ -342,7 +334,6 @@ typedef abi_int         target_pid_t;
 #define ELF_DATA  ELFDATA2MSB
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE 8192
 
 #endif /* TARGET_OPENRISC */
 
@@ -352,7 +343,6 @@ typedef abi_int         target_pid_t;
 #define ELF_ARCH  EM_SH
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE        4096
 
 #endif
 
@@ -362,7 +352,6 @@ typedef abi_int         target_pid_t;
 #define ELF_ARCH        EM_68K
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       8192
 
 #endif
 
@@ -371,8 +360,6 @@ typedef abi_int         target_pid_t;
 #define ELF_CLASS      ELFCLASS64
 #define ELF_ARCH       EM_ALPHA
 
-#define ELF_EXEC_PAGESIZE        8192
-
 #endif /* TARGET_ALPHA */
 
 #ifdef TARGET_S390X
@@ -382,7 +369,6 @@ typedef abi_int         target_pid_t;
 #define ELF_ARCH	EM_S390
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE 4096
 
 #define VDSO_HEADER "vdso.c.inc"
 
@@ -400,8 +386,6 @@ typedef abi_int         target_pid_t;
 #define VDSO_HEADER "vdso-64.c.inc"
 #endif
 
-#define ELF_EXEC_PAGESIZE 4096
-
 #endif /* TARGET_RISCV */
 
 #ifdef TARGET_HPPA
@@ -421,7 +405,6 @@ typedef abi_int         target_pid_t;
 #define ELF_ARCH        EM_XTENSA
 
 #define USE_ELF_CORE_DUMP
-#define ELF_EXEC_PAGESIZE       4096
 
 #endif /* TARGET_XTENSA */
 
@@ -2743,7 +2726,7 @@ static int wmr_fill_region_phdr(void *opaque, vaddr start,
     phdr->p_flags = (flags & PAGE_READ ? PF_R : 0)
                   | (flags & PAGE_WRITE_ORG ? PF_W : 0)
                   | (flags & PAGE_EXEC ? PF_X : 0);
-    phdr->p_align = ELF_EXEC_PAGESIZE;
+    phdr->p_align = TARGET_PAGE_SIZE;
 
     bswap_phdr(phdr, 1);
     d->phdr = phdr + 1;
@@ -2851,7 +2834,7 @@ static int elf_core_dump(int signr, const CPUArchState *env)
     offset += size_note("CORE", sizeof(struct target_elf_prpsinfo));
     offset += size_note("CORE", sizeof(struct target_elf_prstatus)) * cpus;
     note_size = offset - note_offset;
-    data_offset = ROUND_UP(offset, ELF_EXEC_PAGESIZE);
+    data_offset = TARGET_PAGE_ALIGN(offset);
 
     /* Do not dump if the corefile size exceeds the limit. */
     if (dumpsize.rlim_cur != RLIM_INFINITY
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 61/89] linux-user: Move get_elf_cpu_model to target/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (59 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 60/89] linux-user: Remove ELF_EXEC_PAGESIZE Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:14   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h Richard Henderson
                   ` (28 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Rename from cpu_get_model to emphasize that this is
an elf-specific function.  Declare the function once
in loader.h.

This frees up target_elf.h for other uses.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/target_elf.h     |  5 +---
 linux-user/alpha/target_elf.h       |  5 +---
 linux-user/arm/target_elf.h         |  5 ----
 linux-user/hexagon/target_elf.h     | 29 ----------------------
 linux-user/hppa/target_elf.h        |  5 ----
 linux-user/i386/target_elf.h        |  5 +---
 linux-user/loader.h                 |  1 +
 linux-user/loongarch64/target_elf.h |  5 +---
 linux-user/m68k/target_elf.h        |  9 -------
 linux-user/microblaze/target_elf.h  |  5 +---
 linux-user/mips/target_elf.h        | 11 +--------
 linux-user/mips64/target_elf.h      | 27 +-------------------
 linux-user/openrisc/target_elf.h    |  5 +---
 linux-user/ppc/target_elf.h         |  9 +------
 linux-user/riscv/target_elf.h       |  5 +---
 linux-user/s390x/target_elf.h       |  5 +---
 linux-user/sh4/target_elf.h         |  5 +---
 linux-user/sparc/target_elf.h       |  9 +------
 linux-user/x86_64/target_elf.h      |  5 +---
 linux-user/xtensa/target_elf.h      |  5 ----
 linux-user/aarch64/elfload.c        |  5 ++++
 linux-user/alpha/elfload.c          | 10 ++++++++
 linux-user/arm/elfload.c            |  5 ++++
 linux-user/hexagon/elfload.c        | 34 ++++++++++++++++++++++++++
 linux-user/hppa/elfload.c           |  5 ++++
 linux-user/i386/elfload.c           |  5 ++++
 linux-user/loongarch64/elfload.c    |  5 ++++
 linux-user/m68k/elfload.c           | 17 +++++++++++++
 linux-user/main.c                   |  3 +--
 linux-user/microblaze/elfload.c     | 10 ++++++++
 linux-user/mips/elfload.c           | 38 +++++++++++++++++++++++++++++
 linux-user/openrisc/elfload.c       | 10 ++++++++
 linux-user/ppc/elfload.c            |  9 +++++++
 linux-user/riscv/elfload.c          |  5 ++++
 linux-user/s390x/elfload.c          |  5 ++++
 linux-user/sh4/elfload.c            |  5 ++++
 linux-user/sparc/elfload.c          |  9 +++++++
 linux-user/x86_64/elfload.c         |  5 ++++
 linux-user/xtensa/elfload.c         | 10 ++++++++
 39 files changed, 208 insertions(+), 147 deletions(-)

diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index a7eb962fba..d955b3d07f 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef AARCH64_TARGET_ELF_H
 #define AARCH64_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h
index b77d638f6d..52b68680ad 100644
--- a/linux-user/alpha/target_elf.h
+++ b/linux-user/alpha/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef ALPHA_TARGET_ELF_H
 #define ALPHA_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "ev67";
-}
+
 #endif
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index bb9875fa2d..209076284b 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -10,9 +10,4 @@
 
 #define HI_COMMPAGE (intptr_t)0xffff0f00u
 
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
-
 #endif
diff --git a/linux-user/hexagon/target_elf.h b/linux-user/hexagon/target_elf.h
index 36056fc9f0..eccf207f6b 100644
--- a/linux-user/hexagon/target_elf.h
+++ b/linux-user/hexagon/target_elf.h
@@ -18,33 +18,4 @@
 #ifndef HEXAGON_TARGET_ELF_H
 #define HEXAGON_TARGET_ELF_H
 
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    static char buf[32];
-    int err;
-
-    /* For now, treat anything newer than v5 as a v73 */
-    /* FIXME - Disable instructions that are newer than the specified arch */
-    if (eflags == 0x04 ||    /* v5  */
-        eflags == 0x05 ||    /* v55 */
-        eflags == 0x60 ||    /* v60 */
-        eflags == 0x61 ||    /* v61 */
-        eflags == 0x62 ||    /* v62 */
-        eflags == 0x65 ||    /* v65 */
-        eflags == 0x66 ||    /* v66 */
-        eflags == 0x67 ||    /* v67 */
-        eflags == 0x8067 ||  /* v67t */
-        eflags == 0x68 ||    /* v68 */
-        eflags == 0x69 ||    /* v69 */
-        eflags == 0x71 ||    /* v71 */
-        eflags == 0x8071 ||  /* v71t */
-        eflags == 0x73       /* v73 */
-       ) {
-        return "v73";
-    }
-
-    err = snprintf(buf, sizeof(buf), "unknown (0x%x)", eflags);
-    return err >= 0 && err < sizeof(buf) ? buf : "unknown";
-}
-
 #endif
diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index 00dc2d6684..a736bb9bb3 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -10,9 +10,4 @@
 
 #define LO_COMMPAGE  0
 
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "hppa";
-}
-
 #endif
diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index 238a9aba73..e6f0d8fa4e 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef I386_TARGET_ELF_H
 #define I386_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "max";
-}
+
 #endif
diff --git a/linux-user/loader.h b/linux-user/loader.h
index db6547ea7a..a4178ce2c1 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -96,6 +96,7 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src,
 
 extern unsigned long guest_stack_size;
 
+const char *get_elf_cpu_model(uint32_t eflags);
 abi_ulong get_elf_hwcap(CPUState *cs);
 abi_ulong get_elf_hwcap2(CPUState *cs);
 const char *elf_hwcap_str(uint32_t bit);
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index 95c3f05a46..39a08d35d9 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -5,8 +5,5 @@
 
 #ifndef LOONGARCH_TARGET_ELF_H
 #define LOONGARCH_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "la464";
-}
+
 #endif
diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index 998fe0fe2f..62ff9d38d4 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -7,14 +7,5 @@
 
 #ifndef M68K_TARGET_ELF_H
 #define M68K_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    if (eflags == 0 || (eflags & EF_M68K_M68000)) {
-        /* 680x0 */
-        return "m68040";
-    }
 
-    /* Coldfire */
-    return "any";
-}
 #endif
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index 8a8f1debff..bfe2997fd2 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef MICROBLAZE_TARGET_ELF_H
 #define MICROBLAZE_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index 71a32315a8..febf710c7a 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -7,14 +7,5 @@
 
 #ifndef MIPS_TARGET_ELF_H
 #define MIPS_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    if ((eflags & EF_MIPS_ARCH) == EF_MIPS_ARCH_32R6) {
-        return "mips32r6-generic";
-    }
-    if (eflags & EF_MIPS_NAN2008) {
-        return "P5600";
-    }
-    return "24Kf";
-}
+
 #endif
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index 502af9d278..02e6d14840 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -7,30 +7,5 @@
 
 #ifndef MIPS64_TARGET_ELF_H
 #define MIPS64_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    switch (eflags & EF_MIPS_MACH) {
-    case EF_MIPS_MACH_OCTEON:
-    case EF_MIPS_MACH_OCTEON2:
-    case EF_MIPS_MACH_OCTEON3:
-        return "Octeon68XX";
-    case EF_MIPS_MACH_LS2E:
-        return "Loongson-2E";
-    case EF_MIPS_MACH_LS2F:
-        return "Loongson-2F";
-    case EF_MIPS_MACH_LS3A:
-        return "Loongson-3A1000";
-    default:
-        break;
-    }
-    switch (eflags & EF_MIPS_ARCH) {
-    case EF_MIPS_ARCH_64R6:
-        return "I6400";
-    case EF_MIPS_ARCH_64R2:
-        return "MIPS64R2-generic";
-    default:
-        break;
-    }
-    return "5KEf";
-}
+
 #endif
diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index 265ecd3079..b34f2ff672 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef OPENRISC_TARGET_ELF_H
 #define OPENRISC_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "any";
-}
+
 #endif
diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index 0616618854..8c0a8ea431 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -7,12 +7,5 @@
 
 #ifndef PPC_TARGET_ELF_H
 #define PPC_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-#ifdef TARGET_PPC64
-    return "POWER9";
-#else
-    return "750";
-#endif
-}
+
 #endif
diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h
index dedd5956f3..bfe86105d0 100644
--- a/linux-user/riscv/target_elf.h
+++ b/linux-user/riscv/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef RISCV_TARGET_ELF_H
 #define RISCV_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "max";
-}
+
 #endif
diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index 8114b59c1d..e51b053339 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef S390X_TARGET_ELF_H
 #define S390X_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "qemu";
-}
+
 #endif
diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index f485e0cef2..d17011bd75 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef SH4_TARGET_ELF_H
 #define SH4_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "sh7785";
-}
+
 #endif
diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index a510ceb612..7e46748d26 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -7,12 +7,5 @@
 
 #ifndef SPARC_TARGET_ELF_H
 #define SPARC_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-#ifdef TARGET_SPARC64
-    return "TI UltraSparc II";
-#else
-    return "Fujitsu MB86904";
-#endif
-}
+
 #endif
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index 3f628f8d66..5849f96350 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -7,8 +7,5 @@
 
 #ifndef X86_64_TARGET_ELF_H
 #define X86_64_TARGET_ELF_H
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return "max";
-}
+
 #endif
diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index a9a3fabd89..2c55c22e14 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -8,9 +8,4 @@
 #ifndef XTENSA_TARGET_ELF_H
 #define XTENSA_TARGET_ELF_H
 
-static inline const char *cpu_get_model(uint32_t eflags)
-{
-    return XTENSA_DEFAULT_CPU_MODEL;
-}
-
 #endif
diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 825be0a25a..1030cb8094 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -6,6 +6,11 @@
 #include "target/arm/cpu-features.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
+
 enum {
     ARM_HWCAP_A64_FP            = 1 << 0,
     ARM_HWCAP_A64_ASIMD         = 1 << 1,
diff --git a/linux-user/alpha/elfload.c b/linux-user/alpha/elfload.c
index 73fa78ef14..1e44475c47 100644
--- a/linux-user/alpha/elfload.c
+++ b/linux-user/alpha/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "ev67";
+}
diff --git a/linux-user/arm/elfload.c b/linux-user/arm/elfload.c
index 901141ad2a..82768c437a 100644
--- a/linux-user/arm/elfload.c
+++ b/linux-user/arm/elfload.c
@@ -9,6 +9,11 @@
 #include "elf.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
+
 enum
 {
     ARM_HWCAP_ARM_SWP       = 1 << 0,
diff --git a/linux-user/hexagon/elfload.c b/linux-user/hexagon/elfload.c
index 73fa78ef14..d8b545032a 100644
--- a/linux-user/hexagon/elfload.c
+++ b/linux-user/hexagon/elfload.c
@@ -1 +1,35 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    static char buf[32];
+    int err;
+
+    /* For now, treat anything newer than v5 as a v73 */
+    /* FIXME - Disable instructions that are newer than the specified arch */
+    if (eflags == 0x04 ||    /* v5  */
+        eflags == 0x05 ||    /* v55 */
+        eflags == 0x60 ||    /* v60 */
+        eflags == 0x61 ||    /* v61 */
+        eflags == 0x62 ||    /* v62 */
+        eflags == 0x65 ||    /* v65 */
+        eflags == 0x66 ||    /* v66 */
+        eflags == 0x67 ||    /* v67 */
+        eflags == 0x8067 ||  /* v67t */
+        eflags == 0x68 ||    /* v68 */
+        eflags == 0x69 ||    /* v69 */
+        eflags == 0x71 ||    /* v71 */
+        eflags == 0x8071 ||  /* v71t */
+        eflags == 0x73       /* v73 */
+       ) {
+        return "v73";
+    }
+
+    err = snprintf(buf, sizeof(buf), "unknown (0x%x)", eflags);
+    return err >= 0 && err < sizeof(buf) ? buf : "unknown";
+}
diff --git a/linux-user/hppa/elfload.c b/linux-user/hppa/elfload.c
index c7e1e3952a..018034f244 100644
--- a/linux-user/hppa/elfload.c
+++ b/linux-user/hppa/elfload.c
@@ -6,6 +6,11 @@
 #include "target_elf.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "hppa";
+}
+
 const char *get_elf_platform(CPUState *cs)
 {
     return "PARISC";
diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index 6a79738786..ef3a6c35d2 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -5,6 +5,11 @@
 #include "loader.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "max";
+}
+
 abi_ulong get_elf_hwcap(CPUState *cs)
 {
     return cpu_env(cs)->features[FEAT_1_EDX];
diff --git a/linux-user/loongarch64/elfload.c b/linux-user/loongarch64/elfload.c
index 450e567c72..911352840f 100644
--- a/linux-user/loongarch64/elfload.c
+++ b/linux-user/loongarch64/elfload.c
@@ -5,6 +5,11 @@
 #include "loader.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "la464";
+}
+
 /* See arch/loongarch/include/uapi/asm/hwcap.h */
 enum {
     HWCAP_LOONGARCH_CPUCFG   = (1 << 0),
diff --git a/linux-user/m68k/elfload.c b/linux-user/m68k/elfload.c
index 73fa78ef14..561ac5b3b3 100644
--- a/linux-user/m68k/elfload.c
+++ b/linux-user/m68k/elfload.c
@@ -1 +1,18 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+#include "elf.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    if (eflags == 0 || (eflags & EF_M68K_M68000)) {
+        /* 680x0 */
+        return "m68040";
+    }
+
+    /* Coldfire */
+    return "any";
+}
diff --git a/linux-user/main.c b/linux-user/main.c
index d962f344b8..189b77b578 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -49,7 +49,6 @@
 #include "qemu/guest-random.h"
 #include "elf.h"
 #include "trace/control.h"
-#include "target_elf.h"
 #include "user/cpu_loop.h"
 #include "crypto/init.h"
 #include "fd-trans.h"
@@ -805,7 +804,7 @@ int main(int argc, char **argv, char **envp)
     }
 
     if (cpu_model == NULL) {
-        cpu_model = cpu_get_model(get_elf_eflags(execfd));
+        cpu_model = get_elf_cpu_model(get_elf_eflags(execfd));
     }
     cpu_type = parse_cpu_option(cpu_model);
 
diff --git a/linux-user/microblaze/elfload.c b/linux-user/microblaze/elfload.c
index 73fa78ef14..b92442dfeb 100644
--- a/linux-user/microblaze/elfload.c
+++ b/linux-user/microblaze/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c
index f2b132697e..c353ccc1ad 100644
--- a/linux-user/mips/elfload.c
+++ b/linux-user/mips/elfload.c
@@ -3,8 +3,46 @@
 #include "qemu/osdep.h"
 #include "qemu.h"
 #include "loader.h"
+#include "elf.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+#ifdef TARGET_MIPS64
+    switch (eflags & EF_MIPS_MACH) {
+    case EF_MIPS_MACH_OCTEON:
+    case EF_MIPS_MACH_OCTEON2:
+    case EF_MIPS_MACH_OCTEON3:
+        return "Octeon68XX";
+    case EF_MIPS_MACH_LS2E:
+        return "Loongson-2E";
+    case EF_MIPS_MACH_LS2F:
+        return "Loongson-2F";
+    case EF_MIPS_MACH_LS3A:
+        return "Loongson-3A1000";
+    default:
+        break;
+    }
+    switch (eflags & EF_MIPS_ARCH) {
+    case EF_MIPS_ARCH_64R6:
+        return "I6400";
+    case EF_MIPS_ARCH_64R2:
+        return "MIPS64R2-generic";
+    default:
+        break;
+    }
+    return "5KEf";
+#else
+    if ((eflags & EF_MIPS_ARCH) == EF_MIPS_ARCH_32R6) {
+        return "mips32r6-generic";
+    }
+    if (eflags & EF_MIPS_NAN2008) {
+        return "P5600";
+    }
+    return "24Kf";
+#endif
+}
+
 /* See arch/mips/include/uapi/asm/hwcap.h.  */
 enum {
     HWCAP_MIPS_R6           = (1 << 0),
diff --git a/linux-user/openrisc/elfload.c b/linux-user/openrisc/elfload.c
index 73fa78ef14..b92442dfeb 100644
--- a/linux-user/openrisc/elfload.c
+++ b/linux-user/openrisc/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "any";
+}
diff --git a/linux-user/ppc/elfload.c b/linux-user/ppc/elfload.c
index 3b2dcdfc47..a214675650 100644
--- a/linux-user/ppc/elfload.c
+++ b/linux-user/ppc/elfload.c
@@ -5,6 +5,15 @@
 #include "loader.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+#ifdef TARGET_PPC64
+    return "POWER9";
+#else
+    return "750";
+#endif
+}
+
 /*
  * Feature masks for the Aux Vector Hardware Capabilities (AT_HWCAP).
  * See arch/powerpc/include/asm/cputable.h.
diff --git a/linux-user/riscv/elfload.c b/linux-user/riscv/elfload.c
index 4e2ec3df5b..2e7d622232 100644
--- a/linux-user/riscv/elfload.c
+++ b/linux-user/riscv/elfload.c
@@ -5,6 +5,11 @@
 #include "loader.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "max";
+}
+
 abi_ulong get_elf_hwcap(CPUState *cs)
 {
 #define MISA_BIT(EXT) (1 << (EXT - 'A'))
diff --git a/linux-user/s390x/elfload.c b/linux-user/s390x/elfload.c
index 29dab42933..79ceaba51d 100644
--- a/linux-user/s390x/elfload.c
+++ b/linux-user/s390x/elfload.c
@@ -6,6 +6,11 @@
 #include "elf.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "qemu";
+}
+
 #define GET_FEATURE(_feat, _hwcap) \
     do { if (s390_has_feat(_feat)) { hwcap |= _hwcap; } } while (0)
 
diff --git a/linux-user/sh4/elfload.c b/linux-user/sh4/elfload.c
index 098ca44f80..99ad4f6334 100644
--- a/linux-user/sh4/elfload.c
+++ b/linux-user/sh4/elfload.c
@@ -5,6 +5,11 @@
 #include "loader.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "sh7785";
+}
+
 enum {
     SH_CPU_HAS_FPU            = 0x0001, /* Hardware FPU support */
     SH_CPU_HAS_P2_FLUSH_BUG   = 0x0002, /* Need to flush the cache in P2 area */
diff --git a/linux-user/sparc/elfload.c b/linux-user/sparc/elfload.c
index b4b8e4916e..ba6e4a38bc 100644
--- a/linux-user/sparc/elfload.c
+++ b/linux-user/sparc/elfload.c
@@ -6,6 +6,15 @@
 #include "elf.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+#ifdef TARGET_SPARC64
+    return "TI UltraSparc II";
+#else
+    return "Fujitsu MB86904";
+#endif
+}
+
 abi_ulong get_elf_hwcap(CPUState *cs)
 {
     /* There are not many sparc32 hwcap bits -- we have all of them. */
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index 98acca94ef..befaab7cb0 100644
--- a/linux-user/x86_64/elfload.c
+++ b/linux-user/x86_64/elfload.c
@@ -6,6 +6,11 @@
 #include "loader.h"
 
 
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return "max";
+}
+
 abi_ulong get_elf_hwcap(CPUState *cs)
 {
     return cpu_env(cs)->features[FEAT_1_EDX];
diff --git a/linux-user/xtensa/elfload.c b/linux-user/xtensa/elfload.c
index 73fa78ef14..e35ba69a10 100644
--- a/linux-user/xtensa/elfload.c
+++ b/linux-user/xtensa/elfload.c
@@ -1 +1,11 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "qemu.h"
+#include "loader.h"
+
+
+const char *get_elf_cpu_model(uint32_t eflags)
+{
+    return XTENSA_DEFAULT_CPU_MODEL;
+}
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (60 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 61/89] linux-user: Move get_elf_cpu_model to target/elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:22   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 63/89] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h Richard Henderson
                   ` (27 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Move the workaround out of linux-user/elfload.c, so that
we don't have to replicate it in many places.  Place it
immediately after the include of <signal.h>, which draws
in the relevant symbols.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/qemu/osdep.h | 8 ++++++++
 linux-user/elfload.c | 7 -------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 96fe51bc39..be3460b32f 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -133,6 +133,14 @@ QEMU_EXTERN_C int daemon(int, int);
 #include <setjmp.h>
 #include <signal.h>
 
+/*
+ * Avoid conflict with linux/arch/powerpc/include/uapi/asm/elf.h, included
+ * from <asm/sigcontext.h>, but we might as well do this unconditionally.
+ */
+#undef ELF_CLASS
+#undef ELF_DATA
+#undef ELF_ARCH
+
 #ifdef CONFIG_IOVEC
 #include <sys/uio.h>
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 1ac3a20813..70bfd18de6 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -35,13 +35,6 @@
 #include "target/arm/cpu-features.h"
 #endif
 
-#ifdef _ARCH_PPC64
-#undef ARCH_DLINFO
-#undef ELF_CLASS
-#undef ELF_DATA
-#undef ELF_ARCH
-#endif
-
 #ifndef TARGET_ARCH_HAS_SIGTRAMP_PAGE
 #define TARGET_ARCH_HAS_SIGTRAMP_PAGE 0
 #endif
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 63/89] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (61 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:24   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 64/89] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h Richard Henderson
                   ` (26 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/i386/target_elf.h   | 23 +++++++++++++++++++
 linux-user/x86_64/target_elf.h |  5 +++++
 linux-user/elfload.c           | 41 +---------------------------------
 3 files changed, 29 insertions(+), 40 deletions(-)

diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index e6f0d8fa4e..032abe5d24 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -8,4 +8,27 @@
 #ifndef I386_TARGET_ELF_H
 #define I386_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_386
+#define EXSTACK_DEFAULT         true
+#define VDSO_HEADER             "vdso.c.inc"
+#define USE_ELF_CORE_DUMP
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ */
+#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
+
+/*
+ * i386 is the only target which supplies AT_SYSINFO for the vdso.
+ * All others only supply AT_SYSINFO_EHDR.
+ */
+#define DLINFO_ARCH_ITEMS (vdso_info != NULL)
+#define ARCH_DLINFO                                     \
+    do {                                                \
+        if (vdso_info) {                                \
+            NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry);  \
+        }                                               \
+    } while (0)
+
 #endif
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index 5849f96350..7eac11e338 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -8,4 +8,9 @@
 #ifndef X86_64_TARGET_ELF_H
 #define X86_64_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS64
+#define ELF_ARCH                EM_X86_64
+#define VDSO_HEADER             "vdso.c.inc"
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 70bfd18de6..d071bca660 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -28,6 +28,7 @@
 #include "qemu/lockable.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
+#include "target_elf.h"
 #include "target_signal.h"
 #include "tcg/debuginfo.h"
 
@@ -137,46 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_I386
-
-#ifdef TARGET_X86_64
-#define ELF_CLASS      ELFCLASS64
-#define ELF_ARCH       EM_X86_64
-#else
-
-/*
- * This is used to ensure we don't load something for the wrong architecture.
- */
-#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
-
-/*
- * These are used to set parameters in the core dumps.
- */
-#define ELF_CLASS       ELFCLASS32
-#define ELF_ARCH        EM_386
-
-#define EXSTACK_DEFAULT true
-
-/*
- * i386 is the only target which supplies AT_SYSINFO for the vdso.
- * All others only supply AT_SYSINFO_EHDR.
- */
-#define DLINFO_ARCH_ITEMS (vdso_info != NULL)
-#define ARCH_DLINFO                                     \
-    do {                                                \
-        if (vdso_info) {                                \
-            NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry);  \
-        }                                               \
-    } while (0)
-
-#endif /* TARGET_X86_64 */
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#define USE_ELF_CORE_DUMP
-
-#endif /* TARGET_I386 */
-
 #ifdef TARGET_ARM
 
 #ifndef TARGET_AARCH64
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 64/89] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (62 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 63/89] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:24   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
                   ` (25 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/target_elf.h | 10 ++++++++++
 linux-user/arm/target_elf.h     |  5 +++++
 linux-user/elfload.c            | 29 -----------------------------
 3 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index d955b3d07f..8f704055ec 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -8,4 +8,14 @@
 #ifndef AARCH64_TARGET_ELF_H
 #define AARCH64_TARGET_ELF_H
 
+#define ELF_ARCH                EM_AARCH64
+#define ELF_CLASS               ELFCLASS64
+#define USE_ELF_CORE_DUMP
+
+#if TARGET_BIG_ENDIAN
+# define VDSO_HEADER            "vdso-be.c.inc"
+#else
+# define VDSO_HEADER            "vdso-le.c.inc"
+#endif
+
 #endif
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 209076284b..2f8564a484 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -8,6 +8,11 @@
 #ifndef ARM_TARGET_ELF_H
 #define ARM_TARGET_ELF_H
 
+#define ELF_ARCH                EM_ARM
+#define ELF_CLASS               ELFCLASS32
+#define EXSTACK_DEFAULT         true
+#define USE_ELF_CORE_DUMP
+
 #define HI_COMMPAGE (intptr_t)0xffff0f00u
 
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index d071bca660..dec27496ff 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,35 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_ARM
-
-#ifndef TARGET_AARCH64
-/* 32 bit ARM definitions */
-
-#define ELF_ARCH        EM_ARM
-#define ELF_CLASS       ELFCLASS32
-#define EXSTACK_DEFAULT true
-
-#define USE_ELF_CORE_DUMP
-
-#else
-/* 64 bit ARM definitions */
-
-#define ELF_ARCH        EM_AARCH64
-#define ELF_CLASS       ELFCLASS64
-
-#define USE_ELF_CORE_DUMP
-
-#if TARGET_BIG_ENDIAN
-# define VDSO_HEADER  "vdso-be.c.inc"
-#else
-# define VDSO_HEADER  "vdso-le.c.inc"
-#endif
-
-#endif /* not TARGET_AARCH64 */
-
-#endif /* TARGET_ARM */
-
 #ifdef TARGET_SPARC
 
 #ifndef TARGET_SPARC64
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (63 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 64/89] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:25   ` Peter Maydell
  2025-08-02 20:28   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 66/89] linux-user: Move elf parameters to ppc/target_elf.h Richard Henderson
                   ` (24 subsequent siblings)
  89 siblings, 2 replies; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/sparc/target_elf.h | 11 +++++++++++
 linux-user/elfload.c          | 15 ---------------
 2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index 7e46748d26..8bd6e3e427 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -8,4 +8,15 @@
 #ifndef SPARC_TARGET_ELF_H
 #define SPARC_TARGET_ELF_H
 
+#ifndef TARGET_SPARC64
+# define ELF_CLASS              ELFCLASS32
+# define ELF_ARCH               EM_SPARC
+#elif defined(TARGET_ABI32)
+# define ELF_CLASS              ELFCLASS32
+# define elf_check_arch(x)      ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
+#else
+# define ELF_CLASS              ELFCLASS64
+# define ELF_ARCH               EM_SPARCV9
+#endif
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index dec27496ff..429d343adc 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,21 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_SPARC
-
-#ifndef TARGET_SPARC64
-# define ELF_CLASS  ELFCLASS32
-# define ELF_ARCH   EM_SPARC
-#elif defined(TARGET_ABI32)
-# define ELF_CLASS  ELFCLASS32
-# define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
-#else
-# define ELF_CLASS  ELFCLASS64
-# define ELF_ARCH   EM_SPARCV9
-#endif
-
-#endif /* TARGET_SPARC */
-
 #ifdef TARGET_PPC
 
 #define ELF_MACHINE    PPC_ELF_MACHINE
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 66/89] linux-user: Move elf parameters to ppc/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (64 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:26   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 67/89] linux-user: Move elf parameters to loongarch64/target_elf.h Richard Henderson
                   ` (23 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/ppc/target_elf.h | 45 ++++++++++++++++++++++++++++++
 linux-user/elfload.c        | 55 -------------------------------------
 2 files changed, 45 insertions(+), 55 deletions(-)

diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index 8c0a8ea431..d42b9dc9cb 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -8,4 +8,49 @@
 #ifndef PPC_TARGET_ELF_H
 #define PPC_TARGET_ELF_H
 
+#define ELF_MACHINE             PPC_ELF_MACHINE
+
+#ifdef TARGET_PPC64
+# define elf_check_arch(x)      ((x) == EM_PPC64)
+# define ELF_CLASS              ELFCLASS64
+#else
+# define ELF_CLASS              ELFCLASS32
+# define EXSTACK_DEFAULT        true
+#endif
+#define ELF_ARCH                EM_PPC
+
+/*
+ * The requirements here are:
+ * - keep the final alignment of sp (sp & 0xf)
+ * - make sure the 32-bit value at the first 16 byte aligned position of
+ *   AUXV is greater than 16 for glibc compatibility.
+ *   AT_IGNOREPPC is used for that.
+ * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
+ *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
+ */
+#define DLINFO_ARCH_ITEMS       5
+#define ARCH_DLINFO                                     \
+    do {                                                \
+        PowerPCCPU *cpu = POWERPC_CPU(thread_cpu);              \
+        /*                                              \
+         * Handle glibc compatibility: these magic entries must \
+         * be at the lowest addresses in the final auxv.        \
+         */                                             \
+        NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
+        NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
+        NEW_AUX_ENT(AT_DCACHEBSIZE, cpu->env.dcache_line_size); \
+        NEW_AUX_ENT(AT_ICACHEBSIZE, cpu->env.icache_line_size); \
+        NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
+    } while (0)
+
+#define USE_ELF_CORE_DUMP
+
+#ifndef TARGET_PPC64
+# define VDSO_HEADER  "vdso-32.c.inc"
+#elif TARGET_BIG_ENDIAN
+# define VDSO_HEADER  "vdso-64.c.inc"
+#else
+# define VDSO_HEADER  "vdso-64le.c.inc"
+#endif
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 429d343adc..eae3260c9e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,61 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_PPC
-
-#define ELF_MACHINE    PPC_ELF_MACHINE
-
-#if defined(TARGET_PPC64)
-
-#define elf_check_arch(x) ( (x) == EM_PPC64 )
-
-#define ELF_CLASS       ELFCLASS64
-
-#else
-
-#define ELF_CLASS       ELFCLASS32
-#define EXSTACK_DEFAULT true
-
-#endif
-
-#define ELF_ARCH        EM_PPC
-
-/*
- * The requirements here are:
- * - keep the final alignment of sp (sp & 0xf)
- * - make sure the 32-bit value at the first 16 byte aligned position of
- *   AUXV is greater than 16 for glibc compatibility.
- *   AT_IGNOREPPC is used for that.
- * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
- *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
- */
-#define DLINFO_ARCH_ITEMS       5
-#define ARCH_DLINFO                                     \
-    do {                                                \
-        PowerPCCPU *cpu = POWERPC_CPU(thread_cpu);              \
-        /*                                              \
-         * Handle glibc compatibility: these magic entries must \
-         * be at the lowest addresses in the final auxv.        \
-         */                                             \
-        NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
-        NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);        \
-        NEW_AUX_ENT(AT_DCACHEBSIZE, cpu->env.dcache_line_size); \
-        NEW_AUX_ENT(AT_ICACHEBSIZE, cpu->env.icache_line_size); \
-        NEW_AUX_ENT(AT_UCACHEBSIZE, 0);                 \
-    } while (0)
-
-#define USE_ELF_CORE_DUMP
-
-#ifndef TARGET_PPC64
-# define VDSO_HEADER  "vdso-32.c.inc"
-#elif TARGET_BIG_ENDIAN
-# define VDSO_HEADER  "vdso-64.c.inc"
-#else
-# define VDSO_HEADER  "vdso-64le.c.inc"
-#endif
-
-#endif
-
 #ifdef TARGET_LOONGARCH64
 
 #define ELF_CLASS   ELFCLASS64
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 67/89] linux-user: Move elf parameters to loongarch64/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (65 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 66/89] linux-user: Move elf parameters to ppc/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:26   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 68/89] linux-user: Move elf parameters to {mips, mips64}/target_elf.h Richard Henderson
                   ` (22 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/loongarch64/target_elf.h |  7 +++++++
 linux-user/elfload.c                | 14 --------------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index 39a08d35d9..e99aa3df4c 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -6,4 +6,11 @@
 #ifndef LOONGARCH_TARGET_ELF_H
 #define LOONGARCH_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS64
+#define ELF_ARCH                EM_LOONGARCH
+#define EXSTACK_DEFAULT         true
+#define elf_check_arch(x)       ((x) == EM_LOONGARCH)
+#define VDSO_HEADER             "vdso.c.inc"
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index eae3260c9e..49fd098067 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,20 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_LOONGARCH64
-
-#define ELF_CLASS   ELFCLASS64
-#define ELF_ARCH    EM_LOONGARCH
-#define EXSTACK_DEFAULT true
-
-#define elf_check_arch(x) ((x) == EM_LOONGARCH)
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#define USE_ELF_CORE_DUMP
-
-#endif /* TARGET_LOONGARCH64 */
-
 #ifdef TARGET_MIPS
 
 #ifdef TARGET_MIPS64
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 68/89] linux-user: Move elf parameters to {mips, mips64}/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (66 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 67/89] linux-user: Move elf parameters to loongarch64/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:27   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 69/89] linux-user: Move elf parameters to microblaze/target_elf.h Richard Henderson
                   ` (21 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/mips/target_elf.h   |  5 +++++
 linux-user/mips64/target_elf.h | 12 ++++++++++++
 linux-user/elfload.c           | 20 --------------------
 3 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index febf710c7a..850a6d83cc 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -8,4 +8,9 @@
 #ifndef MIPS_TARGET_ELF_H
 #define MIPS_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_MIPS
+#define EXSTACK_DEFAULT         true
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index 02e6d14840..77f3b4685a 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -8,4 +8,16 @@
 #ifndef MIPS64_TARGET_ELF_H
 #define MIPS64_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS64
+#define ELF_ARCH                EM_MIPS
+#define EXSTACK_DEFAULT         true
+
+#ifdef TARGET_ABI_MIPSN32
+#define elf_check_abi(x)        ((x) & EF_MIPS_ABI2)
+#else
+#define elf_check_abi(x)        (!((x) & EF_MIPS_ABI2))
+#endif
+
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 49fd098067..609e9b99b5 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,26 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_MIPS
-
-#ifdef TARGET_MIPS64
-#define ELF_CLASS   ELFCLASS64
-#else
-#define ELF_CLASS   ELFCLASS32
-#endif
-#define ELF_ARCH    EM_MIPS
-#define EXSTACK_DEFAULT true
-
-#ifdef TARGET_ABI_MIPSN32
-#define elf_check_abi(x) ((x) & EF_MIPS_ABI2)
-#else
-#define elf_check_abi(x) (!((x) & EF_MIPS_ABI2))
-#endif
-
-#define USE_ELF_CORE_DUMP
-
-#endif /* TARGET_MIPS */
-
 #ifdef TARGET_MICROBLAZE
 
 #define elf_check_arch(x) ( (x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 69/89] linux-user: Move elf parameters to microblaze/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (67 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 68/89] linux-user: Move elf parameters to {mips, mips64}/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:28   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 70/89] linux-user: Move elf parameters to openrisc/target_elf.h Richard Henderson
                   ` (20 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/microblaze/target_elf.h |  5 +++++
 linux-user/elfload.c               | 10 ----------
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index bfe2997fd2..738a101f67 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -8,4 +8,9 @@
 #ifndef MICROBLAZE_TARGET_ELF_H
 #define MICROBLAZE_TARGET_ELF_H
 
+#define ELF_CLASS           ELFCLASS32
+#define ELF_ARCH            EM_MICROBLAZE
+#define elf_check_arch(x)   ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 609e9b99b5..aa05abec05 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,16 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_MICROBLAZE
-
-#define elf_check_arch(x) ( (x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
-
-#define ELF_CLASS   ELFCLASS32
-#define ELF_ARCH    EM_MICROBLAZE
-
-#define USE_ELF_CORE_DUMP
-#endif /* TARGET_MICROBLAZE */
-
 #ifdef TARGET_OPENRISC
 
 #define ELF_ARCH EM_OPENRISC
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 70/89] linux-user: Move elf parameters to openrisc/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (68 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 69/89] linux-user: Move elf parameters to microblaze/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:29   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 71/89] linux-user: Move elf parameters to sh4/target_elf.h Richard Henderson
                   ` (19 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/openrisc/target_elf.h |  4 ++++
 linux-user/elfload.c             | 10 ----------
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index b34f2ff672..0a2b3ef762 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -8,4 +8,8 @@
 #ifndef OPENRISC_TARGET_ELF_H
 #define OPENRISC_TARGET_ELF_H
 
+#define ELF_ARCH                EM_OPENRISC
+#define ELF_CLASS               ELFCLASS32
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index aa05abec05..a45d23b91d 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,16 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_OPENRISC
-
-#define ELF_ARCH EM_OPENRISC
-#define ELF_CLASS ELFCLASS32
-#define ELF_DATA  ELFDATA2MSB
-
-#define USE_ELF_CORE_DUMP
-
-#endif /* TARGET_OPENRISC */
-
 #ifdef TARGET_SH4
 
 #define ELF_CLASS ELFCLASS32
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 71/89] linux-user: Move elf parameters to sh4/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (69 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 70/89] linux-user: Move elf parameters to openrisc/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:29   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 72/89] linux-user: Move elf parameters to m68k/target_elf.h Richard Henderson
                   ` (18 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/sh4/target_elf.h | 4 ++++
 linux-user/elfload.c        | 9 ---------
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index d17011bd75..68b58beaa4 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -8,4 +8,8 @@
 #ifndef SH4_TARGET_ELF_H
 #define SH4_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_SH
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index a45d23b91d..38c5f2c4e9 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,15 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_SH4
-
-#define ELF_CLASS ELFCLASS32
-#define ELF_ARCH  EM_SH
-
-#define USE_ELF_CORE_DUMP
-
-#endif
-
 #ifdef TARGET_M68K
 
 #define ELF_CLASS       ELFCLASS32
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 72/89] linux-user: Move elf parameters to m68k/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (70 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 71/89] linux-user: Move elf parameters to sh4/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:30   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 73/89] linux-user: Move elf parameters to alpha/target_elf.h Richard Henderson
                   ` (17 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/m68k/target_elf.h | 4 ++++
 linux-user/elfload.c         | 9 ---------
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index 62ff9d38d4..baabc1c040 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -8,4 +8,8 @@
 #ifndef M68K_TARGET_ELF_H
 #define M68K_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_68K
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 38c5f2c4e9..c88fbdebb0 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,15 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_M68K
-
-#define ELF_CLASS       ELFCLASS32
-#define ELF_ARCH        EM_68K
-
-#define USE_ELF_CORE_DUMP
-
-#endif
-
 #ifdef TARGET_ALPHA
 
 #define ELF_CLASS      ELFCLASS64
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 73/89] linux-user: Move elf parameters to alpha/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (71 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 72/89] linux-user: Move elf parameters to m68k/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:30   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 74/89] linux-user: Move elf parameters to s390x/target_elf.h Richard Henderson
                   ` (16 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/alpha/target_elf.h | 3 +++
 linux-user/elfload.c          | 7 -------
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h
index 52b68680ad..f9d6372c9f 100644
--- a/linux-user/alpha/target_elf.h
+++ b/linux-user/alpha/target_elf.h
@@ -8,4 +8,7 @@
 #ifndef ALPHA_TARGET_ELF_H
 #define ALPHA_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS64
+#define ELF_ARCH                EM_ALPHA
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index c88fbdebb0..4294a6582e 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,13 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_ALPHA
-
-#define ELF_CLASS      ELFCLASS64
-#define ELF_ARCH       EM_ALPHA
-
-#endif /* TARGET_ALPHA */
-
 #ifdef TARGET_S390X
 
 #define ELF_CLASS	ELFCLASS64
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 74/89] linux-user: Move elf parameters to s390x/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (72 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 73/89] linux-user: Move elf parameters to alpha/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:30   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 75/89] linux-user: Move elf parameters to riscv/target_elf.h Richard Henderson
                   ` (15 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/s390x/target_elf.h |  6 ++++++
 linux-user/elfload.c          | 12 ------------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index e51b053339..aa12ecf36b 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -8,4 +8,10 @@
 #ifndef S390X_TARGET_ELF_H
 #define S390X_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS64
+#define ELF_DATA                ELFDATA2MSB
+#define ELF_ARCH                EM_S390
+#define VDSO_HEADER             "vdso.c.inc"
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 4294a6582e..28407a7a00 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,18 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_S390X
-
-#define ELF_CLASS	ELFCLASS64
-#define ELF_DATA	ELFDATA2MSB
-#define ELF_ARCH	EM_S390
-
-#define USE_ELF_CORE_DUMP
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#endif /* TARGET_S390X */
-
 #ifdef TARGET_RISCV
 
 #define ELF_ARCH  EM_RISCV
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 75/89] linux-user: Move elf parameters to riscv/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (73 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 74/89] linux-user: Move elf parameters to s390x/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:31   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 76/89] linux-user: Move elf parameters to hppa/target_elf.h Richard Henderson
                   ` (14 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/riscv/target_elf.h | 10 ++++++++++
 linux-user/elfload.c          | 14 --------------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h
index bfe86105d0..61446dd945 100644
--- a/linux-user/riscv/target_elf.h
+++ b/linux-user/riscv/target_elf.h
@@ -8,4 +8,14 @@
 #ifndef RISCV_TARGET_ELF_H
 #define RISCV_TARGET_ELF_H
 
+#define ELF_ARCH                EM_RISCV
+
+#ifdef TARGET_RISCV32
+#define ELF_CLASS               ELFCLASS32
+#define VDSO_HEADER             "vdso-32.c.inc"
+#else
+#define ELF_CLASS               ELFCLASS64
+#define VDSO_HEADER             "vdso-64.c.inc"
+#endif
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 28407a7a00..5b3bdf58cb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,20 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_RISCV
-
-#define ELF_ARCH  EM_RISCV
-
-#ifdef TARGET_RISCV32
-#define ELF_CLASS ELFCLASS32
-#define VDSO_HEADER "vdso-32.c.inc"
-#else
-#define ELF_CLASS ELFCLASS64
-#define VDSO_HEADER "vdso-64.c.inc"
-#endif
-
-#endif /* TARGET_RISCV */
-
 #ifdef TARGET_HPPA
 
 #define ELF_CLASS       ELFCLASS32
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 76/89] linux-user: Move elf parameters to hppa/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (74 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 75/89] linux-user: Move elf parameters to riscv/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:31   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 77/89] linux-user: Move elf parameters to xtensa/target_elf.h Richard Henderson
                   ` (13 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/hppa/target_elf.h |  6 ++++++
 linux-user/elfload.c         | 11 -----------
 2 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index a736bb9bb3..ed2ce895f5 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -8,6 +8,12 @@
 #ifndef HPPA_TARGET_ELF_H
 #define HPPA_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_PARISC
+#define STACK_GROWS_DOWN        0
+#define STACK_ALIGNMENT         64
+#define VDSO_HEADER             "vdso.c.inc"
+
 #define LO_COMMPAGE  0
 
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5b3bdf58cb..e6d49d982f 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,17 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_HPPA
-
-#define ELF_CLASS       ELFCLASS32
-#define ELF_ARCH        EM_PARISC
-#define STACK_GROWS_DOWN 0
-#define STACK_ALIGNMENT  64
-
-#define VDSO_HEADER "vdso.c.inc"
-
-#endif /* TARGET_HPPA */
-
 #ifdef TARGET_XTENSA
 
 #define ELF_CLASS       ELFCLASS32
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 77/89] linux-user: Move elf parameters to xtensa/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (75 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 76/89] linux-user: Move elf parameters to hppa/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:31   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 78/89] linux-user: Move elf parameters to hexagon/target_elf.h Richard Henderson
                   ` (12 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/xtensa/target_elf.h | 4 ++++
 linux-user/elfload.c           | 9 ---------
 2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index 2c55c22e14..cacfb6e81a 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -8,4 +8,8 @@
 #ifndef XTENSA_TARGET_ELF_H
 #define XTENSA_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_XTENSA
+#define USE_ELF_CORE_DUMP
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index e6d49d982f..b67bb7deab 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,15 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_XTENSA
-
-#define ELF_CLASS       ELFCLASS32
-#define ELF_ARCH        EM_XTENSA
-
-#define USE_ELF_CORE_DUMP
-
-#endif /* TARGET_XTENSA */
-
 #ifdef TARGET_HEXAGON
 
 #define ELF_CLASS       ELFCLASS32
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 78/89] linux-user: Move elf parameters to hexagon/target_elf.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (76 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 77/89] linux-user: Move elf parameters to xtensa/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:32   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 79/89] linux-user: Standardize on ELF_MACHINE not ELF_ARCH Richard Henderson
                   ` (11 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/hexagon/target_elf.h | 3 +++
 linux-user/elfload.c            | 7 -------
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/linux-user/hexagon/target_elf.h b/linux-user/hexagon/target_elf.h
index eccf207f6b..a9f6d77fc6 100644
--- a/linux-user/hexagon/target_elf.h
+++ b/linux-user/hexagon/target_elf.h
@@ -18,4 +18,7 @@
 #ifndef HEXAGON_TARGET_ELF_H
 #define HEXAGON_TARGET_ELF_H
 
+#define ELF_CLASS               ELFCLASS32
+#define ELF_ARCH                EM_HEXAGON
+
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index b67bb7deab..25a3d5c9cb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,13 +138,6 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifdef TARGET_HEXAGON
-
-#define ELF_CLASS       ELFCLASS32
-#define ELF_ARCH        EM_HEXAGON
-
-#endif /* TARGET_HEXAGON */
-
 #ifndef ELF_MACHINE
 #define ELF_MACHINE ELF_ARCH
 #endif
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 79/89] linux-user: Standardize on ELF_MACHINE not ELF_ARCH
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (77 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 78/89] linux-user: Move elf parameters to hexagon/target_elf.h Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:34   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 80/89] linux-user: Rename elf_check_arch Richard Henderson
                   ` (10 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

PowerPC was the one outlier that defined both ELF_ARCH and
ELF_MACHINE; ELF_ARCH was defined incorrectly, necessitating
the definition of elf_check_arch.

However, the elf file header field in question is called
e_machine, so ELF_MACHINE is in fact the better name.

Mechanically change most target/target_elf.h files,
then adjust ppc/target_elf.h manually.

Do not provide a default for ELF_MACHINE.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/target_elf.h     | 2 +-
 linux-user/alpha/target_elf.h       | 2 +-
 linux-user/arm/target_elf.h         | 2 +-
 linux-user/hexagon/target_elf.h     | 2 +-
 linux-user/hppa/target_elf.h        | 2 +-
 linux-user/i386/target_elf.h        | 2 +-
 linux-user/loongarch64/target_elf.h | 2 +-
 linux-user/m68k/target_elf.h        | 2 +-
 linux-user/microblaze/target_elf.h  | 2 +-
 linux-user/mips/target_elf.h        | 2 +-
 linux-user/mips64/target_elf.h      | 2 +-
 linux-user/openrisc/target_elf.h    | 2 +-
 linux-user/ppc/target_elf.h         | 5 +----
 linux-user/riscv/target_elf.h       | 2 +-
 linux-user/s390x/target_elf.h       | 2 +-
 linux-user/sh4/target_elf.h         | 2 +-
 linux-user/sparc/target_elf.h       | 4 ++--
 linux-user/x86_64/target_elf.h      | 2 +-
 linux-user/xtensa/target_elf.h      | 2 +-
 linux-user/elfload.c                | 6 +-----
 20 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index 8f704055ec..16acf6d47f 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -8,7 +8,7 @@
 #ifndef AARCH64_TARGET_ELF_H
 #define AARCH64_TARGET_ELF_H
 
-#define ELF_ARCH                EM_AARCH64
+#define ELF_MACHINE             EM_AARCH64
 #define ELF_CLASS               ELFCLASS64
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h
index f9d6372c9f..864dc6e2e6 100644
--- a/linux-user/alpha/target_elf.h
+++ b/linux-user/alpha/target_elf.h
@@ -9,6 +9,6 @@
 #define ALPHA_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS64
-#define ELF_ARCH                EM_ALPHA
+#define ELF_MACHINE             EM_ALPHA
 
 #endif
diff --git a/linux-user/arm/target_elf.h b/linux-user/arm/target_elf.h
index 2f8564a484..f769108adb 100644
--- a/linux-user/arm/target_elf.h
+++ b/linux-user/arm/target_elf.h
@@ -8,7 +8,7 @@
 #ifndef ARM_TARGET_ELF_H
 #define ARM_TARGET_ELF_H
 
-#define ELF_ARCH                EM_ARM
+#define ELF_MACHINE             EM_ARM
 #define ELF_CLASS               ELFCLASS32
 #define EXSTACK_DEFAULT         true
 #define USE_ELF_CORE_DUMP
diff --git a/linux-user/hexagon/target_elf.h b/linux-user/hexagon/target_elf.h
index a9f6d77fc6..f81ae3895a 100644
--- a/linux-user/hexagon/target_elf.h
+++ b/linux-user/hexagon/target_elf.h
@@ -19,6 +19,6 @@
 #define HEXAGON_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_HEXAGON
+#define ELF_MACHINE             EM_HEXAGON
 
 #endif
diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h
index ed2ce895f5..c2484230b0 100644
--- a/linux-user/hppa/target_elf.h
+++ b/linux-user/hppa/target_elf.h
@@ -9,7 +9,7 @@
 #define HPPA_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_PARISC
+#define ELF_MACHINE             EM_PARISC
 #define STACK_GROWS_DOWN        0
 #define STACK_ALIGNMENT         64
 #define VDSO_HEADER             "vdso.c.inc"
diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index 032abe5d24..f5eeb36b31 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -9,7 +9,7 @@
 #define I386_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_386
+#define ELF_MACHINE             EM_386
 #define EXSTACK_DEFAULT         true
 #define VDSO_HEADER             "vdso.c.inc"
 #define USE_ELF_CORE_DUMP
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index e99aa3df4c..a76aa9f56c 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -7,7 +7,7 @@
 #define LOONGARCH_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS64
-#define ELF_ARCH                EM_LOONGARCH
+#define ELF_MACHINE             EM_LOONGARCH
 #define EXSTACK_DEFAULT         true
 #define elf_check_arch(x)       ((x) == EM_LOONGARCH)
 #define VDSO_HEADER             "vdso.c.inc"
diff --git a/linux-user/m68k/target_elf.h b/linux-user/m68k/target_elf.h
index baabc1c040..77533a9086 100644
--- a/linux-user/m68k/target_elf.h
+++ b/linux-user/m68k/target_elf.h
@@ -9,7 +9,7 @@
 #define M68K_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_68K
+#define ELF_MACHINE             EM_68K
 #define USE_ELF_CORE_DUMP
 
 #endif
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index 738a101f67..037ff595b6 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -9,7 +9,7 @@
 #define MICROBLAZE_TARGET_ELF_H
 
 #define ELF_CLASS           ELFCLASS32
-#define ELF_ARCH            EM_MICROBLAZE
+#define ELF_MACHINE         EM_MICROBLAZE
 #define elf_check_arch(x)   ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/mips/target_elf.h b/linux-user/mips/target_elf.h
index 850a6d83cc..06a88fe254 100644
--- a/linux-user/mips/target_elf.h
+++ b/linux-user/mips/target_elf.h
@@ -9,7 +9,7 @@
 #define MIPS_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_MIPS
+#define ELF_MACHINE             EM_MIPS
 #define EXSTACK_DEFAULT         true
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/mips64/target_elf.h b/linux-user/mips64/target_elf.h
index 77f3b4685a..c0c7f3e97c 100644
--- a/linux-user/mips64/target_elf.h
+++ b/linux-user/mips64/target_elf.h
@@ -9,7 +9,7 @@
 #define MIPS64_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS64
-#define ELF_ARCH                EM_MIPS
+#define ELF_MACHINE             EM_MIPS
 #define EXSTACK_DEFAULT         true
 
 #ifdef TARGET_ABI_MIPSN32
diff --git a/linux-user/openrisc/target_elf.h b/linux-user/openrisc/target_elf.h
index 0a2b3ef762..d7a85cc0d0 100644
--- a/linux-user/openrisc/target_elf.h
+++ b/linux-user/openrisc/target_elf.h
@@ -8,7 +8,7 @@
 #ifndef OPENRISC_TARGET_ELF_H
 #define OPENRISC_TARGET_ELF_H
 
-#define ELF_ARCH                EM_OPENRISC
+#define ELF_MACHINE             EM_OPENRISC
 #define ELF_CLASS               ELFCLASS32
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/ppc/target_elf.h b/linux-user/ppc/target_elf.h
index d42b9dc9cb..c4cc40a4aa 100644
--- a/linux-user/ppc/target_elf.h
+++ b/linux-user/ppc/target_elf.h
@@ -8,16 +8,13 @@
 #ifndef PPC_TARGET_ELF_H
 #define PPC_TARGET_ELF_H
 
-#define ELF_MACHINE             PPC_ELF_MACHINE
-
 #ifdef TARGET_PPC64
-# define elf_check_arch(x)      ((x) == EM_PPC64)
 # define ELF_CLASS              ELFCLASS64
 #else
 # define ELF_CLASS              ELFCLASS32
 # define EXSTACK_DEFAULT        true
 #endif
-#define ELF_ARCH                EM_PPC
+#define ELF_MACHINE             PPC_ELF_MACHINE
 
 /*
  * The requirements here are:
diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h
index 61446dd945..ce8df23cd7 100644
--- a/linux-user/riscv/target_elf.h
+++ b/linux-user/riscv/target_elf.h
@@ -8,7 +8,7 @@
 #ifndef RISCV_TARGET_ELF_H
 #define RISCV_TARGET_ELF_H
 
-#define ELF_ARCH                EM_RISCV
+#define ELF_MACHINE             EM_RISCV
 
 #ifdef TARGET_RISCV32
 #define ELF_CLASS               ELFCLASS32
diff --git a/linux-user/s390x/target_elf.h b/linux-user/s390x/target_elf.h
index aa12ecf36b..a7c6e33300 100644
--- a/linux-user/s390x/target_elf.h
+++ b/linux-user/s390x/target_elf.h
@@ -10,7 +10,7 @@
 
 #define ELF_CLASS               ELFCLASS64
 #define ELF_DATA                ELFDATA2MSB
-#define ELF_ARCH                EM_S390
+#define ELF_MACHINE             EM_S390
 #define VDSO_HEADER             "vdso.c.inc"
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h
index 68b58beaa4..053ea53aa8 100644
--- a/linux-user/sh4/target_elf.h
+++ b/linux-user/sh4/target_elf.h
@@ -9,7 +9,7 @@
 #define SH4_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_SH
+#define ELF_MACHINE             EM_SH
 #define USE_ELF_CORE_DUMP
 
 #endif
diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index 8bd6e3e427..8071638e18 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -10,13 +10,13 @@
 
 #ifndef TARGET_SPARC64
 # define ELF_CLASS              ELFCLASS32
-# define ELF_ARCH               EM_SPARC
+# define ELF_MACHINE            EM_SPARC
 #elif defined(TARGET_ABI32)
 # define ELF_CLASS              ELFCLASS32
 # define elf_check_arch(x)      ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
 #else
 # define ELF_CLASS              ELFCLASS64
-# define ELF_ARCH               EM_SPARCV9
+# define ELF_MACHINE            EM_SPARCV9
 #endif
 
 #endif
diff --git a/linux-user/x86_64/target_elf.h b/linux-user/x86_64/target_elf.h
index 7eac11e338..13035a7a5b 100644
--- a/linux-user/x86_64/target_elf.h
+++ b/linux-user/x86_64/target_elf.h
@@ -9,7 +9,7 @@
 #define X86_64_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS64
-#define ELF_ARCH                EM_X86_64
+#define ELF_MACHINE             EM_X86_64
 #define VDSO_HEADER             "vdso.c.inc"
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/xtensa/target_elf.h b/linux-user/xtensa/target_elf.h
index cacfb6e81a..d8ecce6a96 100644
--- a/linux-user/xtensa/target_elf.h
+++ b/linux-user/xtensa/target_elf.h
@@ -9,7 +9,7 @@
 #define XTENSA_TARGET_ELF_H
 
 #define ELF_CLASS               ELFCLASS32
-#define ELF_ARCH                EM_XTENSA
+#define ELF_MACHINE             EM_XTENSA
 #define USE_ELF_CORE_DUMP
 
 #endif
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 25a3d5c9cb..41f022569b 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,12 +138,8 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifndef ELF_MACHINE
-#define ELF_MACHINE ELF_ARCH
-#endif
-
 #ifndef elf_check_arch
-#define elf_check_arch(x) ((x) == ELF_ARCH)
+#define elf_check_arch(x) ((x) == ELF_MACHINE)
 #endif
 
 #ifndef elf_check_abi
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 80/89] linux-user: Rename elf_check_arch
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (78 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 79/89] linux-user: Standardize on ELF_MACHINE not ELF_ARCH Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:35   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 81/89] linux-user: Remove ELIBBAD from elfload.c Richard Henderson
                   ` (9 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Rename to elf_check_machine to match ELF_MACHINE.
Remove the unnecessary definition for loongarch64.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/i386/target_elf.h        | 2 +-
 linux-user/loongarch64/target_elf.h | 1 -
 linux-user/microblaze/target_elf.h  | 2 +-
 linux-user/sparc/target_elf.h       | 2 +-
 linux-user/elfload.c                | 6 +++---
 5 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/linux-user/i386/target_elf.h b/linux-user/i386/target_elf.h
index f5eeb36b31..510fd53cd8 100644
--- a/linux-user/i386/target_elf.h
+++ b/linux-user/i386/target_elf.h
@@ -17,7 +17,7 @@
 /*
  * This is used to ensure we don't load something for the wrong architecture.
  */
-#define elf_check_arch(x) ( ((x) == EM_386) || ((x) == EM_486) )
+#define elf_check_machine(x)    ((x) == EM_386 || (x) == EM_486)
 
 /*
  * i386 is the only target which supplies AT_SYSINFO for the vdso.
diff --git a/linux-user/loongarch64/target_elf.h b/linux-user/loongarch64/target_elf.h
index a76aa9f56c..5f6c1c2808 100644
--- a/linux-user/loongarch64/target_elf.h
+++ b/linux-user/loongarch64/target_elf.h
@@ -9,7 +9,6 @@
 #define ELF_CLASS               ELFCLASS64
 #define ELF_MACHINE             EM_LOONGARCH
 #define EXSTACK_DEFAULT         true
-#define elf_check_arch(x)       ((x) == EM_LOONGARCH)
 #define VDSO_HEADER             "vdso.c.inc"
 #define USE_ELF_CORE_DUMP
 
diff --git a/linux-user/microblaze/target_elf.h b/linux-user/microblaze/target_elf.h
index 037ff595b6..ecf163d7e6 100644
--- a/linux-user/microblaze/target_elf.h
+++ b/linux-user/microblaze/target_elf.h
@@ -10,7 +10,7 @@
 
 #define ELF_CLASS           ELFCLASS32
 #define ELF_MACHINE         EM_MICROBLAZE
-#define elf_check_arch(x)   ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
+#define elf_check_machine(x) ((x) == EM_MICROBLAZE || (x) == EM_MICROBLAZE_OLD)
 #define USE_ELF_CORE_DUMP
 
 #endif
diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
index 8071638e18..3fa5d12e34 100644
--- a/linux-user/sparc/target_elf.h
+++ b/linux-user/sparc/target_elf.h
@@ -13,7 +13,7 @@
 # define ELF_MACHINE            EM_SPARC
 #elif defined(TARGET_ABI32)
 # define ELF_CLASS              ELFCLASS32
-# define elf_check_arch(x)      ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
+# define elf_check_machine(x)   ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
 #else
 # define ELF_CLASS              ELFCLASS64
 # define ELF_MACHINE            EM_SPARCV9
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 41f022569b..5185c84e58 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -138,8 +138,8 @@ typedef abi_uint        target_gid_t;
 #endif
 typedef abi_int         target_pid_t;
 
-#ifndef elf_check_arch
-#define elf_check_arch(x) ((x) == ELF_MACHINE)
+#ifndef elf_check_machine
+#define elf_check_machine(x) ((x) == ELF_MACHINE)
 #endif
 
 #ifndef elf_check_abi
@@ -364,7 +364,7 @@ static bool elf_check_ident(struct elfhdr *ehdr)
    This has to wait until after bswapping the header.  */
 static bool elf_check_ehdr(struct elfhdr *ehdr)
 {
-    return (elf_check_arch(ehdr->e_machine)
+    return (elf_check_machine(ehdr->e_machine)
             && elf_check_abi(ehdr->e_flags)
             && ehdr->e_ehsize == sizeof(struct elfhdr)
             && ehdr->e_phentsize == sizeof(struct elf_phdr)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 81/89] linux-user: Remove ELIBBAD from elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (79 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 80/89] linux-user: Rename elf_check_arch Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:37   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 82/89] linux-user: Remove MAP_DENYWRITE " Richard Henderson
                   ` (8 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

The last use of this fallback was removed in 8e62a71738bc.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 5185c84e58..6eb4e31bdb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -110,11 +110,6 @@ int info_is_fdpic(struct image_info *info)
 #define MAP_DENYWRITE 0
 #endif
 
-/* should probably go in elf.h */
-#ifndef ELIBBAD
-#define ELIBBAD 80
-#endif
-
 #if TARGET_BIG_ENDIAN
 #define ELF_DATA        ELFDATA2MSB
 #else
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 82/89] linux-user: Remove MAP_DENYWRITE from elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (80 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 81/89] linux-user: Remove ELIBBAD from elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:38   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 83/89] linux-user: Move arch_parse_elf_property to aarch64/elfload.c Richard Henderson
                   ` (7 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

The last use of this fallback was removed in bf858897b769.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 6eb4e31bdb..14d4502b3c 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -105,11 +105,6 @@ int info_is_fdpic(struct image_info *info)
     return info->personality == PER_LINUX_FDPIC;
 }
 
-/* this flag is uneffective under linux too, should be deleted */
-#ifndef MAP_DENYWRITE
-#define MAP_DENYWRITE 0
-#endif
-
 #if TARGET_BIG_ENDIAN
 #define ELF_DATA        ELFDATA2MSB
 #else
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 83/89] linux-user: Move arch_parse_elf_property to aarch64/elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (81 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 82/89] linux-user: Remove MAP_DENYWRITE " Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:39   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 84/89] linux-user: Remove a.out declarations from elfload.c Richard Henderson
                   ` (6 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/target_elf.h |  1 +
 linux-user/loader.h             |  5 +++++
 linux-user/aarch64/elfload.c    | 18 +++++++++++++++++
 linux-user/elfload.c            | 35 ++++++---------------------------
 4 files changed, 30 insertions(+), 29 deletions(-)

diff --git a/linux-user/aarch64/target_elf.h b/linux-user/aarch64/target_elf.h
index 16acf6d47f..2d396ad11a 100644
--- a/linux-user/aarch64/target_elf.h
+++ b/linux-user/aarch64/target_elf.h
@@ -11,6 +11,7 @@
 #define ELF_MACHINE             EM_AARCH64
 #define ELF_CLASS               ELFCLASS64
 #define USE_ELF_CORE_DUMP
+#define ARCH_USE_GNU_PROPERTY   1
 
 #if TARGET_BIG_ENDIAN
 # define VDSO_HEADER            "vdso-be.c.inc"
diff --git a/linux-user/loader.h b/linux-user/loader.h
index a4178ce2c1..95cbeed5d4 100644
--- a/linux-user/loader.h
+++ b/linux-user/loader.h
@@ -117,4 +117,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 */
diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
index 1030cb8094..d186b4685c 100644
--- a/linux-user/aarch64/elfload.c
+++ b/linux-user/aarch64/elfload.c
@@ -1,9 +1,11 @@
 /* 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 "elf.h"
 
 
 const char *get_elf_cpu_model(uint32_t eflags)
@@ -347,3 +349,19 @@ 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;
+}
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 14d4502b3c..54ea9221d9 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -184,41 +184,18 @@ const char * __attribute__((weak)) get_elf_base_platform(CPUState *cs)
     return NULL;
 }
 
-#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 ARCH_USE_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
-
 #endif
 
+#include "elf.h"
+
 struct exec
 {
     unsigned int a_info;   /* Use macros N_MAGIC, etc for access */
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 84/89] linux-user: Remove a.out declarations from elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (82 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 83/89] linux-user: Move arch_parse_elf_property to aarch64/elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:41   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 85/89] linux-user/sparc: Move target_pt_regs to signal.c Richard Henderson
                   ` (5 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/elfload.c | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 54ea9221d9..e8d5b56cfb 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -196,25 +196,6 @@ bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz,
 
 #include "elf.h"
 
-struct exec
-{
-    unsigned int a_info;   /* Use macros N_MAGIC, etc for access */
-    unsigned int a_text;   /* length of text, in bytes */
-    unsigned int a_data;   /* length of data, in bytes */
-    unsigned int a_bss;    /* length of uninitialized data area, in bytes */
-    unsigned int a_syms;   /* length of symbol table data in file, in bytes */
-    unsigned int a_entry;  /* start address */
-    unsigned int a_trsize; /* length of relocation info for text, in bytes */
-    unsigned int a_drsize; /* length of relocation info for data, in bytes */
-};
-
-
-#define N_MAGIC(exec) ((exec).a_info & 0xffff)
-#define OMAGIC 0407
-#define NMAGIC 0410
-#define ZMAGIC 0413
-#define QMAGIC 0314
-
 #define DLINFO_ITEMS 16
 
 static inline void memcpy_fromfs(void * to, const void * from, unsigned long n)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 85/89] linux-user/sparc: Move target_pt_regs to signal.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (83 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 84/89] linux-user: Remove a.out declarations from elfload.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:41   ` Peter Maydell
  2025-07-29 23:59 ` [PATCH 86/89] linux-user/microblaze: " Richard Henderson
                   ` (4 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

This structure is part of the sparc signal frame.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/sparc/target_syscall.h | 19 -------------------
 linux-user/sparc/signal.c         | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/linux-user/sparc/target_syscall.h b/linux-user/sparc/target_syscall.h
index e421165357..a90ed2983a 100644
--- a/linux-user/sparc/target_syscall.h
+++ b/linux-user/sparc/target_syscall.h
@@ -1,25 +1,6 @@
 #ifndef SPARC_TARGET_SYSCALL_H
 #define SPARC_TARGET_SYSCALL_H
 
-#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
-struct target_pt_regs {
-    abi_ulong u_regs[16];
-    abi_ulong tstate;
-    abi_ulong pc;
-    abi_ulong npc;
-    uint32_t y;
-    uint32_t magic;
-};
-#else
-struct target_pt_regs {
-    abi_ulong psr;
-    abi_ulong pc;
-    abi_ulong npc;
-    abi_ulong y;
-    abi_ulong u_regs[16];
-};
-#endif
-
 #ifdef TARGET_SPARC64
 # define UNAME_MACHINE "sparc64"
 #else
diff --git a/linux-user/sparc/signal.c b/linux-user/sparc/signal.c
index 8181b8b92c..944769a8de 100644
--- a/linux-user/sparc/signal.c
+++ b/linux-user/sparc/signal.c
@@ -22,6 +22,26 @@
 #include "signal-common.h"
 #include "linux-user/trace.h"
 
+
+#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
+struct target_pt_regs {
+    abi_ulong u_regs[16];
+    abi_ulong tstate;
+    abi_ulong pc;
+    abi_ulong npc;
+    uint32_t y;
+    uint32_t magic;
+};
+#else
+struct target_pt_regs {
+    abi_ulong psr;
+    abi_ulong pc;
+    abi_ulong npc;
+    abi_ulong y;
+    abi_ulong u_regs[16];
+};
+#endif
+
 /* A Sparc register window */
 struct target_reg_window {
     abi_ulong locals[8];
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 86/89] linux-user/microblaze: Move target_pt_regs to signal.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (84 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 85/89] linux-user/sparc: Move target_pt_regs to signal.c Richard Henderson
@ 2025-07-29 23:59 ` Richard Henderson
  2025-08-02 20:40   ` Peter Maydell
  2025-07-30  0:00 ` [PATCH 87/89] linux-user/openrisc: " Richard Henderson
                   ` (3 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-29 23:59 UTC (permalink / raw)
  To: qemu-devel

This structure is part of the microblaze signal frame.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/microblaze/target_syscall.h | 44 --------------------------
 linux-user/microblaze/signal.c         | 44 ++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/linux-user/microblaze/target_syscall.h b/linux-user/microblaze/target_syscall.h
index 43362a1664..66f5a9ebe2 100644
--- a/linux-user/microblaze/target_syscall.h
+++ b/linux-user/microblaze/target_syscall.h
@@ -4,50 +4,6 @@
 #define UNAME_MACHINE "microblaze"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
-/* We use microblaze_reg_t to keep things similar to the kernel sources.  */
-typedef uint32_t microblaze_reg_t;
-
-struct target_pt_regs {
-        microblaze_reg_t r0;
-        microblaze_reg_t r1;
-        microblaze_reg_t r2;
-        microblaze_reg_t r3;
-        microblaze_reg_t r4;
-        microblaze_reg_t r5;
-        microblaze_reg_t r6;
-        microblaze_reg_t r7;
-        microblaze_reg_t r8;
-        microblaze_reg_t r9;
-        microblaze_reg_t r10;
-        microblaze_reg_t r11;
-        microblaze_reg_t r12;
-        microblaze_reg_t r13;
-        microblaze_reg_t r14;
-        microblaze_reg_t r15;
-        microblaze_reg_t r16;
-        microblaze_reg_t r17;
-        microblaze_reg_t r18;
-        microblaze_reg_t r19;
-        microblaze_reg_t r20;
-        microblaze_reg_t r21;
-        microblaze_reg_t r22;
-        microblaze_reg_t r23;
-        microblaze_reg_t r24;
-        microblaze_reg_t r25;
-        microblaze_reg_t r26;
-        microblaze_reg_t r27;
-        microblaze_reg_t r28;
-        microblaze_reg_t r29;
-        microblaze_reg_t r30;
-        microblaze_reg_t r31;
-        microblaze_reg_t pc;
-        microblaze_reg_t msr;
-        microblaze_reg_t ear;
-        microblaze_reg_t esr;
-        microblaze_reg_t fsr;
-        uint32_t kernel_mode;
-};
-
 #define TARGET_CLONE_BACKWARDS
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
diff --git a/linux-user/microblaze/signal.c b/linux-user/microblaze/signal.c
index f6d47d76ff..add814acd6 100644
--- a/linux-user/microblaze/signal.c
+++ b/linux-user/microblaze/signal.c
@@ -22,6 +22,50 @@
 #include "signal-common.h"
 #include "linux-user/trace.h"
 
+/* We use microblaze_reg_t to keep things similar to the kernel sources.  */
+typedef uint32_t microblaze_reg_t;
+
+struct target_pt_regs {
+    microblaze_reg_t r0;
+    microblaze_reg_t r1;
+    microblaze_reg_t r2;
+    microblaze_reg_t r3;
+    microblaze_reg_t r4;
+    microblaze_reg_t r5;
+    microblaze_reg_t r6;
+    microblaze_reg_t r7;
+    microblaze_reg_t r8;
+    microblaze_reg_t r9;
+    microblaze_reg_t r10;
+    microblaze_reg_t r11;
+    microblaze_reg_t r12;
+    microblaze_reg_t r13;
+    microblaze_reg_t r14;
+    microblaze_reg_t r15;
+    microblaze_reg_t r16;
+    microblaze_reg_t r17;
+    microblaze_reg_t r18;
+    microblaze_reg_t r19;
+    microblaze_reg_t r20;
+    microblaze_reg_t r21;
+    microblaze_reg_t r22;
+    microblaze_reg_t r23;
+    microblaze_reg_t r24;
+    microblaze_reg_t r25;
+    microblaze_reg_t r26;
+    microblaze_reg_t r27;
+    microblaze_reg_t r28;
+    microblaze_reg_t r29;
+    microblaze_reg_t r30;
+    microblaze_reg_t r31;
+    microblaze_reg_t pc;
+    microblaze_reg_t msr;
+    microblaze_reg_t ear;
+    microblaze_reg_t esr;
+    microblaze_reg_t fsr;
+    uint32_t kernel_mode;
+};
+
 struct target_sigcontext {
     struct target_pt_regs regs;  /* needs to be first */
     uint32_t oldmask;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 87/89] linux-user/openrisc: Move target_pt_regs to signal.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (85 preceding siblings ...)
  2025-07-29 23:59 ` [PATCH 86/89] linux-user/microblaze: " Richard Henderson
@ 2025-07-30  0:00 ` Richard Henderson
  2025-08-02 20:43   ` Peter Maydell
  2025-07-30  0:00 ` [PATCH 88/89] linux-user/s390x: Move target_psw_t " Richard Henderson
                   ` (2 subsequent siblings)
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-30  0:00 UTC (permalink / raw)
  To: qemu-devel

This structure is part of the openrisc signal frame.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/openrisc/target_syscall.h | 11 -----------
 linux-user/openrisc/signal.c         | 12 ++++++++++++
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/linux-user/openrisc/target_syscall.h b/linux-user/openrisc/target_syscall.h
index 7fe5b73d3b..c8394e9dcd 100644
--- a/linux-user/openrisc/target_syscall.h
+++ b/linux-user/openrisc/target_syscall.h
@@ -1,17 +1,6 @@
 #ifndef OPENRISC_TARGET_SYSCALL_H
 #define OPENRISC_TARGET_SYSCALL_H
 
-/* Note that in linux/arch/openrisc/include/uapi/asm/ptrace.h,
- * this is called user_regs_struct.  Given that this is what
- * is used within struct sigcontext we need this definition.
- * However, elfload.c wants this name.
- */
-struct target_pt_regs {
-    abi_ulong gpr[32];
-    abi_ulong pc;
-    abi_ulong sr;
-};
-
 #define UNAME_MACHINE "openrisc"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c
index cb74a9fe5e..9242d06002 100644
--- a/linux-user/openrisc/signal.c
+++ b/linux-user/openrisc/signal.c
@@ -22,6 +22,18 @@
 #include "signal-common.h"
 #include "linux-user/trace.h"
 
+/*
+ * Note that in linux/arch/openrisc/include/uapi/asm/ptrace.h,
+ * this is called user_regs_struct.  Given that this is what
+ * is used within struct sigcontext we need this definition.
+ * However, elfload.c wants this name.
+ */
+struct target_pt_regs {
+    abi_ulong gpr[32];
+    abi_ulong pc;
+    abi_ulong sr;
+};
+
 typedef struct target_sigcontext {
     struct target_pt_regs regs;
     abi_ulong oldmask;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 88/89] linux-user/s390x: Move target_psw_t to signal.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (86 preceding siblings ...)
  2025-07-30  0:00 ` [PATCH 87/89] linux-user/openrisc: " Richard Henderson
@ 2025-07-30  0:00 ` Richard Henderson
  2025-08-02 20:42   ` Peter Maydell
  2025-07-30  0:00 ` [PATCH 89/89] linux-user: Remove struct target_pt_regs from target_syscall.h Richard Henderson
  2025-08-02 20:51 ` [PATCH for-10.2 00/89] linux-user: Split up elfload.c Peter Maydell
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-30  0:00 UTC (permalink / raw)
  To: qemu-devel

Remove struct target_pt_regs as unused.
Move target_psw_t to signal.c, as it is used there.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/s390x/target_syscall.h | 22 ----------------------
 linux-user/s390x/signal.c         |  5 +++++
 2 files changed, 5 insertions(+), 22 deletions(-)

diff --git a/linux-user/s390x/target_syscall.h b/linux-user/s390x/target_syscall.h
index 4018988a25..f01f9a0baa 100644
--- a/linux-user/s390x/target_syscall.h
+++ b/linux-user/s390x/target_syscall.h
@@ -1,28 +1,6 @@
 #ifndef S390X_TARGET_SYSCALL_H
 #define S390X_TARGET_SYSCALL_H
 
-/* this typedef defines how a Program Status Word looks like */
-typedef struct {
-    abi_ulong mask;
-    abi_ulong addr;
-} __attribute__ ((aligned(8))) target_psw_t;
-
-/*
- * The pt_regs struct defines the way the registers are stored on
- * the stack during a system call.
- */
-
-#define TARGET_NUM_GPRS        16
-
-struct target_pt_regs {
-    abi_ulong args[1];
-    target_psw_t psw;
-    abi_ulong gprs[TARGET_NUM_GPRS];
-    abi_ulong orig_gpr2;
-    unsigned short ilen;
-    unsigned short trap;
-};
-
 #define UNAME_MACHINE "s390x"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/s390x/signal.c b/linux-user/s390x/signal.c
index df49c24708..e964876123 100644
--- a/linux-user/s390x/signal.c
+++ b/linux-user/s390x/signal.c
@@ -33,6 +33,11 @@
 #define _SIGMASK_COPY_SIZE    (sizeof(unsigned long)*_SIGCONTEXT_NSIG_WORDS)
 #define S390_SYSCALL_OPCODE ((uint16_t)0x0a00)
 
+typedef struct {
+    abi_ulong mask;
+    abi_ulong addr;
+} __attribute__ ((aligned(8))) target_psw_t;
+
 typedef struct {
     target_psw_t psw;
     abi_ulong gprs[__NUM_GPRS];
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* [PATCH 89/89] linux-user: Remove struct target_pt_regs from target_syscall.h
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (87 preceding siblings ...)
  2025-07-30  0:00 ` [PATCH 88/89] linux-user/s390x: Move target_psw_t " Richard Henderson
@ 2025-07-30  0:00 ` Richard Henderson
  2025-08-02 20:45   ` Peter Maydell
  2025-08-02 20:51 ` [PATCH for-10.2 00/89] linux-user: Split up elfload.c Peter Maydell
  89 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-07-30  0:00 UTC (permalink / raw)
  To: qemu-devel

This structure is unused, and would only ever be used for the
ptrace syscall, which we will never implement for linux-user.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/aarch64/target_syscall.h     |  7 -----
 linux-user/alpha/target_syscall.h       | 40 -------------------------
 linux-user/arm/target_syscall.h         |  8 -----
 linux-user/hexagon/target_syscall.h     |  5 ----
 linux-user/hppa/target_syscall.h        | 18 -----------
 linux-user/i386/target_syscall.h        | 18 -----------
 linux-user/loongarch64/target_syscall.h | 23 --------------
 linux-user/m68k/target_syscall.h        | 16 ----------
 linux-user/mips/target_syscall.h        | 19 ------------
 linux-user/mips64/target_syscall.h      | 16 ----------
 linux-user/ppc/target_syscall.h         | 28 -----------------
 linux-user/riscv/target_syscall.h       | 35 ----------------------
 linux-user/sh4/target_syscall.h         | 11 -------
 linux-user/x86_64/target_syscall.h      | 28 -----------------
 linux-user/xtensa/target_syscall.h      | 35 ----------------------
 15 files changed, 307 deletions(-)

diff --git a/linux-user/aarch64/target_syscall.h b/linux-user/aarch64/target_syscall.h
index c055133725..bd05f6c7fe 100644
--- a/linux-user/aarch64/target_syscall.h
+++ b/linux-user/aarch64/target_syscall.h
@@ -1,13 +1,6 @@
 #ifndef AARCH64_TARGET_SYSCALL_H
 #define AARCH64_TARGET_SYSCALL_H
 
-struct target_pt_regs {
-    uint64_t        regs[31];
-    uint64_t        sp;
-    uint64_t        pc;
-    uint64_t        pstate;
-};
-
 #if TARGET_BIG_ENDIAN
 #define UNAME_MACHINE "aarch64_be"
 #else
diff --git a/linux-user/alpha/target_syscall.h b/linux-user/alpha/target_syscall.h
index fda3a49f29..53706b749f 100644
--- a/linux-user/alpha/target_syscall.h
+++ b/linux-user/alpha/target_syscall.h
@@ -1,46 +1,6 @@
 #ifndef ALPHA_TARGET_SYSCALL_H
 #define ALPHA_TARGET_SYSCALL_H
 
-/* default linux values for the selectors */
-#define __USER_DS	(1)
-
-struct target_pt_regs {
-	abi_ulong r0;
-	abi_ulong r1;
-	abi_ulong r2;
-	abi_ulong r3;
-	abi_ulong r4;
-	abi_ulong r5;
-	abi_ulong r6;
-	abi_ulong r7;
-	abi_ulong r8;
-	abi_ulong r19;
-	abi_ulong r20;
-	abi_ulong r21;
-	abi_ulong r22;
-	abi_ulong r23;
-	abi_ulong r24;
-	abi_ulong r25;
-	abi_ulong r26;
-	abi_ulong r27;
-	abi_ulong r28;
-	abi_ulong hae;
-/* JRP - These are the values provided to a0-a2 by PALcode */
-	abi_ulong trap_a0;
-	abi_ulong trap_a1;
-	abi_ulong trap_a2;
-/* These are saved by PAL-code: */
-	abi_ulong ps;
-	abi_ulong pc;
-	abi_ulong gp;
-	abi_ulong r16;
-	abi_ulong r17;
-	abi_ulong r18;
-/* Those is needed by qemu to temporary store the user stack pointer */
-        abi_ulong usp;
-        abi_ulong unique;
-};
-
 #define UNAME_MACHINE "alpha"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/arm/target_syscall.h b/linux-user/arm/target_syscall.h
index 412ad434cf..8c4ddba717 100644
--- a/linux-user/arm/target_syscall.h
+++ b/linux-user/arm/target_syscall.h
@@ -1,14 +1,6 @@
 #ifndef ARM_TARGET_SYSCALL_H
 #define ARM_TARGET_SYSCALL_H
 
-/* this struct defines the way the registers are stored on the
-   stack during a system call. */
-
-/* uregs[0..15] are r0 to r15; uregs[16] is CPSR; uregs[17] is ORIG_r0 */
-struct target_pt_regs {
-    abi_long uregs[18];
-};
-
 #define ARM_SYSCALL_BASE	0x900000
 #define ARM_THUMB_SYSCALL	0
 
diff --git a/linux-user/hexagon/target_syscall.h b/linux-user/hexagon/target_syscall.h
index 7f91a4abc7..d9c94737a5 100644
--- a/linux-user/hexagon/target_syscall.h
+++ b/linux-user/hexagon/target_syscall.h
@@ -18,11 +18,6 @@
 #ifndef HEXAGON_TARGET_SYSCALL_H
 #define HEXAGON_TARGET_SYSCALL_H
 
-struct target_pt_regs {
-    abi_long sepc;
-    abi_long sp;
-};
-
 #define UNAME_MACHINE "hexagon"
 #define UNAME_MINIMUM_RELEASE "4.15.0"
 
diff --git a/linux-user/hppa/target_syscall.h b/linux-user/hppa/target_syscall.h
index 9a8f8ca628..4b21e85371 100644
--- a/linux-user/hppa/target_syscall.h
+++ b/linux-user/hppa/target_syscall.h
@@ -1,24 +1,6 @@
 #ifndef HPPA_TARGET_SYSCALL_H
 #define HPPA_TARGET_SYSCALL_H
 
-struct target_pt_regs {
-    target_ulong gr[32];
-    uint64_t     fr[32];
-    target_ulong sr[8];
-    target_ulong iasq[2];
-    target_ulong iaoq[2];
-    target_ulong cr27;
-    target_ulong __pad0;
-    target_ulong orig_r28;
-    target_ulong ksp;
-    target_ulong kpc;
-    target_ulong sar;
-    target_ulong iir;
-    target_ulong isr;
-    target_ulong ior;
-    target_ulong ipsw;
-};
-
 #define UNAME_MACHINE "parisc"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 #define TARGET_CLONE_BACKWARDS
diff --git a/linux-user/i386/target_syscall.h b/linux-user/i386/target_syscall.h
index aaade06b13..c214a909a6 100644
--- a/linux-user/i386/target_syscall.h
+++ b/linux-user/i386/target_syscall.h
@@ -5,24 +5,6 @@
 #define __USER_CS	(0x23)
 #define __USER_DS	(0x2B)
 
-struct target_pt_regs {
-	long ebx;
-	long ecx;
-	long edx;
-	long esi;
-	long edi;
-	long ebp;
-	long eax;
-	int  xds;
-	int  xes;
-	long orig_eax;
-	long eip;
-	int  xcs;
-	long eflags;
-	long esp;
-	int  xss;
-};
-
 /* ioctls */
 
 #define TARGET_LDT_ENTRIES      8192
diff --git a/linux-user/loongarch64/target_syscall.h b/linux-user/loongarch64/target_syscall.h
index 39f229bb9c..f7ced7b2be 100644
--- a/linux-user/loongarch64/target_syscall.h
+++ b/linux-user/loongarch64/target_syscall.h
@@ -8,29 +8,6 @@
 
 #include "qemu/units.h"
 
-/*
- * this struct defines the way the registers are stored on the
- * stack during a system call.
- */
-
-struct target_pt_regs {
-    /* Saved main processor registers. */
-    target_ulong regs[32];
-
-    /* Saved special registers. */
-    struct {
-        target_ulong era;
-        target_ulong badv;
-        target_ulong crmd;
-        target_ulong prmd;
-        target_ulong euen;
-        target_ulong ecfg;
-        target_ulong estat;
-    } csr;
-    target_ulong orig_a0;
-    target_ulong __last[0];
-};
-
 #define UNAME_MACHINE "loongarch64"
 #define UNAME_MINIMUM_RELEASE "5.19.0"
 
diff --git a/linux-user/m68k/target_syscall.h b/linux-user/m68k/target_syscall.h
index 8d4ddbd76c..3ca0231c70 100644
--- a/linux-user/m68k/target_syscall.h
+++ b/linux-user/m68k/target_syscall.h
@@ -1,22 +1,6 @@
 #ifndef M68K_TARGET_SYSCALL_H
 #define M68K_TARGET_SYSCALL_H
 
-/* this struct defines the way the registers are stored on the
-   stack during a system call. */
-
-struct target_pt_regs {
-    abi_long d1, d2, d3, d4, d5, d6, d7;
-    abi_long a0, a1, a2, a3, a4, a5, a6;
-    abi_ulong d0;
-    abi_ulong usp;
-    abi_ulong orig_d0;
-    int16_t stkadj;
-    uint16_t sr;
-    abi_ulong pc;
-    uint16_t fntvex;
-    uint16_t __fill;
-};
-
 #define UNAME_MACHINE "m68k"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/mips/target_syscall.h b/linux-user/mips/target_syscall.h
index 08ead67810..dfcdf320b7 100644
--- a/linux-user/mips/target_syscall.h
+++ b/linux-user/mips/target_syscall.h
@@ -1,25 +1,6 @@
 #ifndef MIPS_TARGET_SYSCALL_H
 #define MIPS_TARGET_SYSCALL_H
 
-/* this struct defines the way the registers are stored on the
-   stack during a system call. */
-
-struct target_pt_regs {
-	/* Pad bytes for argument save space on the stack. */
-	abi_ulong pad0[6];
-
-	/* Saved main processor registers. */
-	abi_ulong regs[32];
-
-	/* Saved special registers. */
-	abi_ulong cp0_status;
-	abi_ulong lo;
-	abi_ulong hi;
-	abi_ulong cp0_badvaddr;
-	abi_ulong cp0_cause;
-	abi_ulong cp0_epc;
-};
-
 #define UNAME_MACHINE "mips"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/mips64/target_syscall.h b/linux-user/mips64/target_syscall.h
index 358dc2d64c..9135bf5e8b 100644
--- a/linux-user/mips64/target_syscall.h
+++ b/linux-user/mips64/target_syscall.h
@@ -1,22 +1,6 @@
 #ifndef MIPS64_TARGET_SYSCALL_H
 #define MIPS64_TARGET_SYSCALL_H
 
-/* this struct defines the way the registers are stored on the
-   stack during a system call. */
-
-struct target_pt_regs {
-        /* Saved main processor registers. */
-        target_ulong regs[32];
-
-        /* Saved special registers. */
-        target_ulong cp0_status;
-        target_ulong lo;
-        target_ulong hi;
-        target_ulong cp0_badvaddr;
-        target_ulong cp0_cause;
-        target_ulong cp0_epc;
-};
-
 #define UNAME_MACHINE "mips64"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/ppc/target_syscall.h b/linux-user/ppc/target_syscall.h
index 77b36d0b46..976b4bb7e9 100644
--- a/linux-user/ppc/target_syscall.h
+++ b/linux-user/ppc/target_syscall.h
@@ -20,34 +20,6 @@
 #ifndef PPC_TARGET_SYSCALL_H
 #define PPC_TARGET_SYSCALL_H
 
-/* XXX: ABSOLUTELY BUGGY:
- * for now, this is quite just a cut-and-paste from i386 target...
- */
-
-/* default linux values for the selectors */
-#define __USER_DS	(1)
-
-struct target_pt_regs {
-	abi_ulong gpr[32];
-	abi_ulong nip;
-	abi_ulong msr;
-	abi_ulong orig_gpr3;	/* Used for restarting system calls */
-	abi_ulong ctr;
-	abi_ulong link;
-	abi_ulong xer;
-	abi_ulong ccr;
-#if defined(TARGET_PPC64)
-        abi_ulong softe;
-#else
-	abi_ulong mq;		/* 601 only (not used at present) */
-#endif
-					/* Used on APUS to hold IPL value. */
-	abi_ulong trap;		/* Reason for being here */
-	abi_ulong dar;		/* Fault registers */
-	abi_ulong dsisr;
-	abi_ulong result; 		/* Result of a system call */
-};
-
 /* ioctls */
 struct target_revectored_struct {
 	abi_ulong __map[8];			/* 256 bits */
diff --git a/linux-user/riscv/target_syscall.h b/linux-user/riscv/target_syscall.h
index 7601f10c28..69a7b753eb 100644
--- a/linux-user/riscv/target_syscall.h
+++ b/linux-user/riscv/target_syscall.h
@@ -8,41 +8,6 @@
 #ifndef LINUX_USER_RISCV_TARGET_SYSCALL_H
 #define LINUX_USER_RISCV_TARGET_SYSCALL_H
 
-struct target_pt_regs {
-    abi_long sepc;
-    abi_long ra;
-    abi_long sp;
-    abi_long gp;
-    abi_long tp;
-    abi_long t0;
-    abi_long t1;
-    abi_long t2;
-    abi_long s0;
-    abi_long s1;
-    abi_long a0;
-    abi_long a1;
-    abi_long a2;
-    abi_long a3;
-    abi_long a4;
-    abi_long a5;
-    abi_long a6;
-    abi_long a7;
-    abi_long s2;
-    abi_long s3;
-    abi_long s4;
-    abi_long s5;
-    abi_long s6;
-    abi_long s7;
-    abi_long s8;
-    abi_long s9;
-    abi_long s10;
-    abi_long s11;
-    abi_long t3;
-    abi_long t4;
-    abi_long t5;
-    abi_long t6;
-};
-
 #ifdef TARGET_RISCV32
 #define UNAME_MACHINE "riscv32"
 #define UNAME_MINIMUM_RELEASE "5.4.0"
diff --git a/linux-user/sh4/target_syscall.h b/linux-user/sh4/target_syscall.h
index 148398855d..2f3557742d 100644
--- a/linux-user/sh4/target_syscall.h
+++ b/linux-user/sh4/target_syscall.h
@@ -1,17 +1,6 @@
 #ifndef SH4_TARGET_SYSCALL_H
 #define SH4_TARGET_SYSCALL_H
 
-struct target_pt_regs {
-        unsigned long regs[16];
-        unsigned long pc;
-        unsigned long pr;
-        unsigned long sr;
-        unsigned long gbr;
-        unsigned long mach;
-        unsigned long macl;
-        long tra;
-};
-
 #define UNAME_MACHINE "sh4"
 #define UNAME_MINIMUM_RELEASE "2.6.32"
 
diff --git a/linux-user/x86_64/target_syscall.h b/linux-user/x86_64/target_syscall.h
index fb558345d3..68f55f8e7b 100644
--- a/linux-user/x86_64/target_syscall.h
+++ b/linux-user/x86_64/target_syscall.h
@@ -4,34 +4,6 @@
 #define __USER_CS	(0x33)
 #define __USER_DS	(0x2B)
 
-struct target_pt_regs {
-	abi_ulong r15;
-	abi_ulong r14;
-	abi_ulong r13;
-	abi_ulong r12;
-	abi_ulong rbp;
-	abi_ulong rbx;
-/* arguments: non interrupts/non tracing syscalls only save up to here */
-	abi_ulong r11;
-	abi_ulong r10;
-	abi_ulong r9;
-	abi_ulong r8;
-	abi_ulong rax;
-	abi_ulong rcx;
-	abi_ulong rdx;
-	abi_ulong rsi;
-	abi_ulong rdi;
-	abi_ulong orig_rax;
-/* end of arguments */
-/* cpu exception frame or undefined */
-	abi_ulong rip;
-	abi_ulong cs;
-	abi_ulong eflags;
-	abi_ulong rsp;
-	abi_ulong ss;
-/* top of stack page */
-};
-
 /* Maximum number of LDT entries supported. */
 #define TARGET_LDT_ENTRIES	8192
 /* The size of each LDT entry. */
diff --git a/linux-user/xtensa/target_syscall.h b/linux-user/xtensa/target_syscall.h
index afc86a153f..5d4352a4d1 100644
--- a/linux-user/xtensa/target_syscall.h
+++ b/linux-user/xtensa/target_syscall.h
@@ -8,41 +8,6 @@
 
 #define MMAP_SHIFT TARGET_PAGE_BITS
 
-typedef uint32_t xtensa_reg_t;
-typedef struct {
-} xtregs_opt_t; /* TODO */
-
-struct target_pt_regs {
-    xtensa_reg_t pc;            /*   4 */
-    xtensa_reg_t ps;            /*   8 */
-    xtensa_reg_t depc;          /*  12 */
-    xtensa_reg_t exccause;      /*  16 */
-    xtensa_reg_t excvaddr;      /*  20 */
-    xtensa_reg_t debugcause;    /*  24 */
-    xtensa_reg_t wmask;         /*  28 */
-    xtensa_reg_t lbeg;          /*  32 */
-    xtensa_reg_t lend;          /*  36 */
-    xtensa_reg_t lcount;        /*  40 */
-    xtensa_reg_t sar;           /*  44 */
-    xtensa_reg_t windowbase;    /*  48 */
-    xtensa_reg_t windowstart;   /*  52 */
-    xtensa_reg_t syscall;       /*  56 */
-    xtensa_reg_t icountlevel;   /*  60 */
-    xtensa_reg_t scompare1;     /*  64 */
-    xtensa_reg_t threadptr;     /*  68 */
-
-    /* Additional configurable registers that are used by the compiler. */
-    xtregs_opt_t xtregs_opt;
-
-    /* Make sure the areg field is 16 bytes aligned. */
-    int align[0] __attribute__ ((aligned(16)));
-
-    /* current register frame.
-     * Note: The ESF for kernel exceptions ends after 16 registers!
-     */
-    xtensa_reg_t areg[16];
-};
-
 #define TARGET_MCL_CURRENT 1
 #define TARGET_MCL_FUTURE  2
 #define TARGET_MCL_ONFAULT 4
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 187+ messages in thread

* Re: [PATCH 01/89] linux-user: Create target/elfload.c files
  2025-07-29 23:58 ` [PATCH 01/89] linux-user: Create target/elfload.c files Richard Henderson
@ 2025-08-01 14:47   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:47 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:13, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Prepare to split the main linux-user/elfload.c.
> Create empty files for each target, and add the
> common build rule.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> diff --git a/linux-user/aarch64/elfload.c b/linux-user/aarch64/elfload.c
> new file mode 100644
> index 0000000000..73fa78ef14
> --- /dev/null
> +++ b/linux-user/aarch64/elfload.c
> @@ -0,0 +1 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */

No license info in the existing elfload.c so I guess
we can take LICENSE at its word that source files with
no licensing info are GPL2-or-later...

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 02/89] linux-user: Move get_elf_hwcap to {i386, x86_64}/elfload.c
  2025-07-29 23:58 ` [PATCH 02/89] linux-user: Move get_elf_hwcap to {i386, x86_64}/elfload.c Richard Henderson
@ 2025-08-01 14:51   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:51 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:18, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
> Duplicate the one line function between i386 and x86_64,
> as most other additions to elfload.c won't be common.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

AIUI the FEAT_1_EDX field only uses the bottom 32 bits
so the type change should be fine.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 03/89] linux-user: Move hwcap functions to {arm, aarch64}/elfload.c
  2025-07-29 23:58 ` [PATCH 03/89] linux-user: Move hwcap functions to {arm, aarch64}/elfload.c Richard Henderson
@ 2025-08-01 14:53   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:53 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:15, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> For get_elf_hwcap and get_elf_hwcap2, change the return type to
> abi_ulong, and pass in the cpu.  We must do these targets at the
> same time because of the ifdef dependency between TARGET_AARCH64
> and TARGET_ARM.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 04/89] linux-user: Move get_elf_hwcap to sparc/elfload.c
  2025-07-29 23:58 ` [PATCH 04/89] linux-user: Move get_elf_hwcap to sparc/elfload.c Richard Henderson
@ 2025-08-01 14:53   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:53 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:13, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loader.h        |  3 ++-
>  linux-user/elfload.c       | 30 +-----------------------------
>  linux-user/sparc/elfload.c | 32 ++++++++++++++++++++++++++++++++
>  3 files changed, 35 insertions(+), 30 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 05/89] linux-user: Move hwcap functions to ppc/elfload.c
  2025-07-29 23:58 ` [PATCH 05/89] linux-user: Move hwcap functions to ppc/elfload.c Richard Henderson
@ 2025-08-01 14:54   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:54 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:17, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 06/89] linux-user: Move get_elf_hwcap to loongarch64/elfload.c
  2025-07-29 23:58 ` [PATCH 06/89] linux-user: Move get_elf_hwcap to loongarch64/elfload.c Richard Henderson
@ 2025-08-01 14:54   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:54 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:16, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 07/89] linux-user: Move get_elf_hwcap to mips/elfload.c
  2025-07-29 23:58 ` [PATCH 07/89] linux-user: Move get_elf_hwcap to mips/elfload.c Richard Henderson
@ 2025-08-01 14:55   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:55 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:13, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loader.h       |  2 +-
>  linux-user/elfload.c      | 52 +-----------------------------------
>  linux-user/mips/elfload.c | 55 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 57 insertions(+), 52 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 08/89] linux-user: Move get_elf_hwcap to sh4/elfload.c
  2025-07-29 23:58 ` [PATCH 08/89] linux-user: Move get_elf_hwcap to sh4/elfload.c Richard Henderson
@ 2025-08-01 14:56   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:56 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:21, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loader.h      |  3 ++-
>  linux-user/elfload.c     | 29 +----------------------------
>  linux-user/sh4/elfload.c | 32 ++++++++++++++++++++++++++++++++
>  3 files changed, 35 insertions(+), 29 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 09/89] linux-user: Move hwcap functions to s390x/elfload.c
  2025-07-29 23:58 ` [PATCH 09/89] linux-user: Move hwcap functions to s390x/elfload.c Richard Henderson
@ 2025-08-01 14:56   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:56 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:15, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> For get_elf_hwcap, change the return type to abi_ulong
> and pass in the cpu.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 10/89] linux-user: Move get_elf_hwcap to riscv/elfload.c
  2025-07-29 23:58 ` [PATCH 10/89] linux-user: Move get_elf_hwcap to riscv/elfload.c Richard Henderson
@ 2025-08-01 14:57   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 14:57 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:15, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Change the return type to abi_ulong, and pass in the cpu.
> As this is the last instance of get_elf_hwcap to be converted,
> remove the ifdef around the declaration in loader.h.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 11/89] linux-user: Remove ELF_HWCAP
  2025-07-29 23:58 ` [PATCH 11/89] linux-user: Remove ELF_HWCAP Richard Henderson
@ 2025-08-01 15:06   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:06 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:49, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> All real definitions of ELF_HWCAP are now identical, and the stub
> definitions are 0.  Provide a weak stub as a fallback definition.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 34 ++++++++++------------------------
>  1 file changed, 10 insertions(+), 24 deletions(-)

> +/*
> + * Provide fallback definitions that the target may omit.
> + */
> +abi_ulong __attribute__((weak)) get_elf_hwcap(CPUState *cs)
> +{
> +    return 0;
> +}

We make very little use of the weak attribute elsewhere in the
codebase, so I'm not super enthusiastic about adding it, but I
guess for linux-user we don't have the portability problems
that it can create...

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 12/89] linux-user: Remove ELF_HWCAP2
  2025-07-29 23:58 ` [PATCH 12/89] linux-user: Remove ELF_HWCAP2 Richard Henderson
@ 2025-08-01 15:09   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:09 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:15, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> All definitions of ELF_HWCAP2 are now identical.  The only
> catch is whether or not a target defines it.  Unlike the
> primary AT_HWCAP, we'd like to omit AT_HWCAP2 entirely if
> there is no definition for it.
>
> Mark get_elf_hwcap2 as weak, so that the function may be omitted.
> Check that the function exists before calling it.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>


> +/*
> + * Locally declare get_elf_hwcap2 weak, so a target may omit it, and
> + * so that here in elfload.c we can tell that the target omitted it.
> + * The declaration in loader.h, used by the definitions in arch/hwcap.c,
> + * remains strong.
> + */
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wredundant-decls"
> +abi_ulong get_elf_hwcap2(CPUState *cs) __attribute__((weak));
> +#pragma GCC diagnostic pop

Having to do this dance with the GCC diagnostic pragma
doesn't look very nice. I would be inclined to go with
the more straightforward approach of having the target
define a TARGET_HAS_ELF_HWCAP2 somewhere if it implements
hwcap2.

-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 13/89] linux-user: Move get_elf_platform to {i386, x86_64}/elfload.c
  2025-07-29 23:58 ` [PATCH 13/89] linux-user: Move get_elf_platform to {i386, x86_64}/elfload.c Richard Henderson
@ 2025-08-01 15:26   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:26 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:15, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move get_elf_platform to i386/elfload.c; pass in CPUState.
> Create a simple get_elf_platform for x86_64.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loader.h         |  3 +++
>  linux-user/elfload.c        | 18 ++----------------
>  linux-user/i386/elfload.c   | 13 +++++++++++++
>  linux-user/x86_64/elfload.c |  5 +++++
>  4 files changed, 23 insertions(+), 16 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform
  2025-07-29 23:58 ` [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform Richard Henderson
@ 2025-08-01 15:28   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:28 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:34, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Rather than modify a static buffer, index into an array
> of const data.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/i386/elfload.c | 12 ++++--------

I was thinking as I reviewed the previous patch that the
implementation of that function was pretty ugly :-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 15/89] linux-user: Move get_elf_platform to arm/elfload.c
  2025-07-29 23:58 ` [PATCH 15/89] linux-user: Move get_elf_platform to arm/elfload.c Richard Henderson
@ 2025-08-01 15:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:18, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the aarch32 get_elf_platform to arm/elfload.c; pass in CPUState.
> Create a simple version in aarch64/elfload.c, which we must do at the
> same time because of the ifdef dependency between TARGET_AARCH64
> and TARGET_ARM.
>
> Since all versions of get_elf_platform now have the same
> signature, remove the ifdef from the declaration in loader.h
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 16/89] linux-user/loongarch64: Create get_elf_platform
  2025-07-29 23:58 ` [PATCH 16/89] linux-user/loongarch64: Create get_elf_platform Richard Henderson
@ 2025-08-01 15:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:35, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the string literal to a new function.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 17/89] linux-user/hppa: Create get_elf_platform
  2025-07-29 23:58 ` [PATCH 17/89] linux-user/hppa: " Richard Henderson
@ 2025-08-01 15:32   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:32 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the string literal to a new function.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c      |  2 +-
>  linux-user/hppa/elfload.c | 10 ++++++++++
>  2 files changed, 11 insertions(+), 1 deletion(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 18/89] linux-user: Remove ELF_PLATFORM
  2025-07-29 23:58 ` [PATCH 18/89] linux-user: Remove ELF_PLATFORM Richard Henderson
@ 2025-08-01 15:33   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:33 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:27, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> All real definitions of ELF_PLATFORM are now identical, and the stub
> definitions are NULL.  Provide a weak stub as a fallback definition.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 19/89] linux-user: Move get_elf_base_platform to mips/elfload.c
  2025-07-29 23:58 ` [PATCH 19/89] linux-user: Move get_elf_base_platform to mips/elfload.c Richard Henderson
@ 2025-08-01 15:35   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:35 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:31, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Pass in CPUState.  Since this was the only instance of ELF_BASE_PLATFORM,
> go ahead provide a weak fallback for all other targets.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 20/89] linux-user: Move target_cpu_copy_regs decl to qemu.h
  2025-07-29 23:58 ` [PATCH 20/89] linux-user: Move target_cpu_copy_regs decl to qemu.h Richard Henderson
@ 2025-08-01 15:36   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 15:36 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The function is not used by bsd-user, so placement
> within include/user/cpu_loop.h is not ideal.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState
  2025-07-29 23:58 ` [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState Richard Henderson
@ 2025-08-01 16:05   ` Peter Maydell
  2025-08-01 21:04     ` Richard Henderson
  0 siblings, 1 reply; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 16:05 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:48, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Initialize all 3 fields in main(), rather than in 4 different
> target-specific functions.  Adjust the ifdef to be function
> rather than target specific.  Include stack_base in the ifdef.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/qemu.h             |  4 ++--
>  linux-user/aarch64/cpu_loop.c |  8 --------
>  linux-user/arm/cpu_loop.c     | 37 +++++++++++++++--------------------
>  linux-user/m68k/cpu_loop.c    |  9 ---------
>  linux-user/main.c             |  5 +++++
>  linux-user/riscv/cpu_loop.c   |  5 -----
>  6 files changed, 23 insertions(+), 45 deletions(-)
>
> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
> index 6c97ab221f..dff7767bc8 100644
> --- a/linux-user/qemu.h
> +++ b/linux-user/qemu.h
> @@ -122,12 +122,12 @@ struct TaskState {
>  #ifdef TARGET_M68K
>      abi_ulong tp_value;
>  #endif
> -#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_RISCV)
> +#ifdef CONFIG_SEMIHOSTING
>      /* Extra fields for semihosted binaries.  */
>      abi_ulong heap_base;
>      abi_ulong heap_limit;
> -#endif
>      abi_ulong stack_base;
> +#endif
>      int used; /* non zero if used */
>      struct image_info *info;
>      struct linux_binprm *bprm;

> diff --git a/linux-user/main.c b/linux-user/main.c
> index 68972f00a1..4def4be1c1 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -1050,6 +1050,11 @@ int main(int argc, char **argv, char **envp)
>
>  #ifdef CONFIG_SEMIHOSTING
>      qemu_semihosting_guestfd_init();
> +
> +    ts->stack_base = info->start_stack;
> +    ts->heap_base = info->brk;
> +    /* This will be filled in on the first SYS_HEAPINFO call.  */
> +    ts->heap_limit = 0;
>  #endif

Do we need to hide the struct fields and their initialization
behind an ifdef at all? We allocate our TaskState structs on
the heap so we don't care too much about their size, and
the init code here is trivial.

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 22/89] linux-user: Create do_init_main_thread
  2025-07-29 23:58 ` [PATCH 22/89] linux-user: Create do_init_main_thread Richard Henderson
@ 2025-08-01 16:13   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 16:13 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:19, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Provide a unified function to initialize the main thread.
> Keep target_pt_regs isolated to this function.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 23/89] linux-user/i386: Create init_main_thread
  2025-07-29 23:58 ` [PATCH 23/89] linux-user/i386: Create init_main_thread Richard Henderson
@ 2025-08-01 16:17   ` Peter Maydell
  2025-08-01 21:14     ` Richard Henderson
  0 siblings, 1 reply; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 16:17 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:19, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
> Temporarily introduce HAVE_INIT_MAIN_THREAD during conversion.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/qemu.h          |  1 +
>  linux-user/elfload.c       | 29 ++++++-----------------------
>  linux-user/i386/cpu_loop.c | 31 ++++++-------------------------
>  3 files changed, 13 insertions(+), 48 deletions(-)

> -static inline void init_thread(struct target_pt_regs *regs,
> -                               struct image_info *infop)
> -{
> -    regs->esp = infop->start_stack;
> -    regs->eip = infop->entry;
> -
> -    /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
> -       starts %edx contains a pointer to a function which might be
> -       registered using `atexit'.  This provides a mean for the
> -       dynamic linker to call DT_FINI functions for shared libraries
> -       that have been loaded before the code runs.
> -
> -       A value of 0 tells we have no such handler.  */

This seems like a useful comment to retain -- it's nice
to know whether we're zeroing a register as an ABI requirement
versus just being tidy.

> -    regs->edx = 0;
> -}

> +    memset(env->regs, 0, sizeof(env->regs));

Are we not allowed to assume the regs are zero out of reset ?

> +    env->regs[R_ESP] = info->start_stack;
> +    env->eip = info->entry;

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 24/89] linux-user/arm: Create init_main_thread
  2025-07-29 23:58 ` [PATCH 24/89] linux-user/arm: " Richard Henderson
@ 2025-08-01 16:33   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 16:33 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:21, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/arm/cpu_loop.c | 53 ++++++++++++++++++++++++++++++++-------
>  linux-user/elfload.c      | 41 +-----------------------------
>  2 files changed, 45 insertions(+), 49 deletions(-)
>
> diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c
> index 1f3bb96484..8974b35e8d 100644
> --- a/linux-user/arm/cpu_loop.c
> +++ b/linux-user/arm/cpu_loop.c
> @@ -480,19 +480,54 @@ void cpu_loop(CPUARMState *env)
>      }
>  }
>
> -void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs)
> +void init_main_thread(CPUState *cs, struct image_info *info)
>  {
> -    cpsr_write(env, regs->uregs[16], CPSR_USER | CPSR_EXEC,
> -               CPSRWriteByInstr);
> -    for (int i = 0; i < 16; i++) {
> -        env->regs[i] = regs->uregs[i];
> +    CPUARMState *env = cpu_env(cs);
> +    abi_ptr stack = info->start_stack;
> +    abi_ptr entry = info->entry;
> +
> +    cpsr_write(env, ARM_CPU_MODE_USR | (entry & 1 ? CPSR_T : 0),
> +               CPSR_USER | CPSR_EXEC, CPSRWriteByInstr);
> +
> +    env->regs[15] = entry & 0xfffffffe;
> +    env->regs[13] = stack;
> +
> +    /* FIXME - what to for failure of get_user()? */
> +    /* FIXME - a modern kernel does not do this? */
> +    get_user_ual(env->regs[2], stack + 8); /* envp */
> +    get_user_ual(env->regs[1], stack + 4); /* envp */

This seems to have originally been in the kernel as
a half-hearted attempt to support a.out format:
kernel commit acfdd4b1f7590d0 from 2013 removed the
setting up of r1 and r2 along with the rest of that
partial a.out handling. (The commit message explains the
confused kernel handling of r0 which is the origin of our
"/* XXX: it seems that r0 is zeroed after ! */" comment.)

QEMU has never supported a.out binaries, so we should
clean this up too...

Anyway, this patch is just moving code around, so
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 25/89] linux-user/aarch64: Create init_main_thread
  2025-07-29 23:58 ` [PATCH 25/89] linux-user/aarch64: " Richard Henderson
@ 2025-08-01 16:33   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 16:33 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 26/89] linux-user/sparc: Create init_main_thread
  2025-07-29 23:58 ` [PATCH 26/89] linux-user/sparc: " Richard Henderson
@ 2025-08-01 17:24   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:24 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:21, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 27/89] linux-user/ppc: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 27/89] linux-user/ppc: " Richard Henderson
@ 2025-08-01 17:26   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:26 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:20, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 28/89] linux-user/loongarch64: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 28/89] linux-user/loongarch64: " Richard Henderson
@ 2025-08-01 17:27   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:27 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:25, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Note that init_thread had set crmd in target_pt_regs, but
> target_cpu_copy_regs did not copy to env.  This turns out to be
> ok because loongarch_cpu_reset_hold initializes CRMD properly.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 29/89] linux-user/mips: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 29/89] linux-user/mips: " Richard Henderson
@ 2025-08-01 17:27   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:27 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Note that init_thread had set cp0_status in target_pt_regs, but
> target_cpu_copy_regs did not copy to env.  This turns out to be
> ok because mips_cpu_reset_hold initializes CP0_Status properly.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 30/89] linux-user/microblaze: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 30/89] linux-user/microblaze: " Richard Henderson
@ 2025-08-01 17:28   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:28 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c             |  8 +------
>  linux-user/microblaze/cpu_loop.c | 39 ++++----------------------------
>  2 files changed, 6 insertions(+), 41 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 31/89] linux-user/openrisc: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 31/89] linux-user/openrisc: " Richard Henderson
@ 2025-08-01 17:29   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:29 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:25, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c           |  7 +------
>  linux-user/openrisc/cpu_loop.c | 11 ++++-------
>  2 files changed, 5 insertions(+), 13 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 32/89] linux-user/sh4: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 32/89] linux-user/sh4: " Richard Henderson
@ 2025-08-01 17:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:42, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 33/89] linux-user/m68k: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 33/89] linux-user/m68k: " Richard Henderson
@ 2025-08-01 17:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 34/89] linux-user/alpha: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 34/89] linux-user/alpha: " Richard Henderson
@ 2025-08-01 17:31   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:31 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:19, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Note that init_thread had set ps in target_pt_regs, but
> target_cpu_copy_regs did not copy to env.  This turns out to be
> ok because alpha_cpu_initfn initializes flags properly.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 35/89] linux-user/s390x: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 35/89] linux-user/s390x: " Richard Henderson
@ 2025-08-01 17:32   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:32 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:23, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 36/89] linux-user/riscv: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 36/89] linux-user/riscv: " Richard Henderson
@ 2025-08-01 17:32   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:32 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:22, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 37/89] linux-user/hppa: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 37/89] linux-user/hppa: " Richard Henderson
@ 2025-08-01 17:33   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:33 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:22, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 38/89] linux-user/xtensa: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 38/89] linux-user/xtensa: " Richard Henderson
@ 2025-08-01 17:34   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:34 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:18, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 39/89] linux-user/hexagon: Create init_main_thread
  2025-07-29 23:59 ` [PATCH 39/89] linux-user/hexagon: " Richard Henderson
@ 2025-08-01 17:35   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:35 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Merge init_thread and target_cpu_copy_regs.
> There's no point going through a target_pt_regs intermediate.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 40/89] linux-user: Remove do_init_main_thread
  2025-07-29 23:59 ` [PATCH 40/89] linux-user: Remove do_init_main_thread Richard Henderson
@ 2025-08-01 17:37   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:37 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:31, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> All targets have been converted, so we can call init_main_thread
> directly.  Remove do_init_main_thread and HAVE_INIT_MAIN_THREAD.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc Richard Henderson
@ 2025-08-01 17:45   ` Peter Maydell
  2025-08-01 21:44     ` Richard Henderson
  0 siblings, 1 reply; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:45 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                    | 41 +-----------------------
>  linux-user/x86_64/target_coredump.c.inc | 42 +++++++++++++++++++++++++
>  2 files changed, 43 insertions(+), 40 deletions(-)
>  create mode 100644 linux-user/x86_64/target_coredump.c.inc
>

Maybe we can come back to this at some point to convert the
.c.inc into a proper .c / .h file.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 42/89] linux-user/i386: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 42/89] linux-user/i386: " Richard Henderson
@ 2025-08-01 17:46   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:46 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:43, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                  | 31 +-------------------------
>  linux-user/i386/target_coredump.c.inc | 32 +++++++++++++++++++++++++++
>  2 files changed, 33 insertions(+), 30 deletions(-)
>  create mode 100644 linux-user/i386/target_coredump.c.inc

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 43/89] linux-user/arm: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 43/89] linux-user/arm: " Richard Henderson
@ 2025-08-01 17:46   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:46 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                 | 27 +--------------------------
>  linux-user/arm/target_coredump.c.inc | 28 ++++++++++++++++++++++++++++
>  2 files changed, 29 insertions(+), 26 deletions(-)
>  create mode 100644 linux-user/arm/target_coredump.c.inc
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 44/89] linux-user/aarch64: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 44/89] linux-user/aarch64: " Richard Henderson
@ 2025-08-01 17:46   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:46 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                     | 16 +---------------
>  linux-user/aarch64/target_coredump.c.inc | 14 ++++++++++++++
>  2 files changed, 15 insertions(+), 15 deletions(-)
>  create mode 100644 linux-user/aarch64/target_coredump.c.inc
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 45/89] linux-user/ppc: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 45/89] linux-user/ppc: " Richard Henderson
@ 2025-08-01 17:46   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:46 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:36, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                 | 24 +-----------------------
>  linux-user/ppc/target_coredump.c.inc | 24 ++++++++++++++++++++++++
>  2 files changed, 25 insertions(+), 23 deletions(-)
>  create mode 100644 linux-user/ppc/target_coredump.c.inc
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 46/89] linux-user/loongarch64: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 46/89] linux-user/loongarch64: " Richard Henderson
@ 2025-08-01 17:47   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:47 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                         | 26 +-------------------
>  linux-user/loongarch64/target_coredump.c.inc | 24 ++++++++++++++++++
>  2 files changed, 25 insertions(+), 25 deletions(-)
>  create mode 100644 linux-user/loongarch64/target_coredump.c.inc
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 47/89] linux-user/mips: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 47/89] linux-user/mips: " Richard Henderson
@ 2025-08-01 17:47   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:47 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                    | 46 +------------------------
>  linux-user/mips/target_coredump.c.inc   | 46 +++++++++++++++++++++++++
>  linux-user/mips64/target_coredump.c.inc |  1 +
>  3 files changed, 48 insertions(+), 45 deletions(-)
>  create mode 100644 linux-user/mips/target_coredump.c.inc
>  create mode 100644 linux-user/mips64/target_coredump.c.inc
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 48/89] linux-user/microblaze: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 48/89] linux-user/microblaze: " Richard Henderson
@ 2025-08-01 17:47   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:47 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:29, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                        | 21 +--------------------
>  linux-user/microblaze/target_coredump.c.inc | 21 +++++++++++++++++++++
>  2 files changed, 22 insertions(+), 20 deletions(-)
>  create mode 100644 linux-user/microblaze/target_coredump.c.inc

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 49/89] target/openrisc: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 49/89] target/openrisc: " Richard Henderson
@ 2025-08-01 17:48   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:48 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:

Subject line should say "linux-user/openrisc" for
consistency with the other patches here. Otherwise

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 50/89] target/sh4: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 50/89] target/sh4: " Richard Henderson
@ 2025-08-01 17:49   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:49 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:26, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Subject line should say "linux-user/sh4". Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 51/89] linux-user/m68k: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 51/89] linux-user/m68k: " Richard Henderson
@ 2025-08-01 17:49   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:49 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:33, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                  | 29 +-------------------------
>  linux-user/m68k/target_coredump.c.inc | 30 +++++++++++++++++++++++++++
>  2 files changed, 31 insertions(+), 28 deletions(-)
>  create mode 100644 linux-user/m68k/target_coredump.c.inc
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 52/89] linux-user/s390x: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 52/89] linux-user/s390x: " Richard Henderson
@ 2025-08-01 17:49   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:49 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:28, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                   | 31 +-------------------------
>  linux-user/s390x/target_coredump.c.inc | 31 ++++++++++++++++++++++++++
>  2 files changed, 32 insertions(+), 30 deletions(-)
>  create mode 100644 linux-user/s390x/target_coredump.c.inc

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 53/89] linux-user/xtensa: Split out target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 53/89] linux-user/xtensa: " Richard Henderson
@ 2025-08-01 17:50   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:50 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:29, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c                    | 38 +------------------------
>  linux-user/xtensa/target_coredump.c.inc | 38 +++++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 37 deletions(-)
>  create mode 100644 linux-user/xtensa/target_coredump.c.inc

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 54/89] linux-user: Unify the include of target_coredump.c.inc
  2025-07-29 23:59 ` [PATCH 54/89] linux-user: Unify the include of target_coredump.c.inc Richard Henderson
@ 2025-08-01 17:50   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 17:50 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:42, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Now that all target_coredump.c.inc files have been created,
> USE_ELF_CORE_DUMP signals that it is available.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 55/89] linux-user: Move init_guest_commpage to x86_64/elfload.c
  2025-07-29 23:59 ` [PATCH 55/89] linux-user: Move init_guest_commpage to x86_64/elfload.c Richard Henderson
@ 2025-08-01 18:07   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 18:07 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loader.h         |  3 +++
>  linux-user/elfload.c        | 20 --------------------
>  linux-user/x86_64/elfload.c | 20 ++++++++++++++++++++
>  3 files changed, 23 insertions(+), 20 deletions(-)
>
> diff --git a/linux-user/loader.h b/linux-user/loader.h
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 56/89] linux-user: Move init_guest_commpage to arm/elfload.c
  2025-07-29 23:59 ` [PATCH 56/89] linux-user: Move init_guest_commpage to arm/elfload.c Richard Henderson
@ 2025-08-01 18:08   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 18:08 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:32, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/arm/target_elf.h |  4 ++++
>  linux-user/loader.h         |  2 +-
>  linux-user/arm/elfload.c    | 46 +++++++++++++++++++++++++++++++++++
>  linux-user/elfload.c        | 48 -------------------------------------
>  4 files changed, 51 insertions(+), 49 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 57/89] linux-user: Move init_guest_commpage to hppa/elfload.c
  2025-07-29 23:59 ` [PATCH 57/89] linux-user: Move init_guest_commpage to hppa/elfload.c Richard Henderson
@ 2025-08-01 18:08   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 18:08 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:32, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/hppa/target_elf.h |  4 ++++
>  linux-user/loader.h          |  2 --
>  linux-user/elfload.c         | 32 --------------------------------
>  linux-user/hppa/elfload.c    | 31 +++++++++++++++++++++++++++++++
>  4 files changed, 35 insertions(+), 34 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 58/89] linux-user: Remove INIT_GUEST_COMMPAGE
  2025-07-29 23:59 ` [PATCH 58/89] linux-user: Remove INIT_GUEST_COMMPAGE Richard Henderson
@ 2025-08-01 18:09   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 18:09 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:36, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Provide a weak stub version of init_guest_commpage
> instead of using the preprocessor.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 59/89] linux-user: Move get_vdso_image_info to arm/elfload.c
  2025-07-29 23:59 ` [PATCH 59/89] linux-user: Move get_vdso_image_info to arm/elfload.c Richard Henderson
@ 2025-08-01 18:11   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 18:11 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:27, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Rename from vdso_image_info to avoid a symbol clash.
> Provide fallback versions for other targets.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loader.h      | 12 ++++++++++++
>  linux-user/arm/elfload.c | 20 ++++++++++++++++++++
>  linux-user/elfload.c     | 41 ++++++++++------------------------------
>  3 files changed, 42 insertions(+), 31 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 60/89] linux-user: Remove ELF_EXEC_PAGESIZE
  2025-07-29 23:59 ` [PATCH 60/89] linux-user: Remove ELF_EXEC_PAGESIZE Richard Henderson
@ 2025-08-01 18:12   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-01 18:12 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:27, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Use TARGET_PAGE_SIZE instead.  If the target page size may vary,
> using a different fixed size is wrong.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 21 ++-------------------
>  1 file changed, 2 insertions(+), 19 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState
  2025-08-01 16:05   ` Peter Maydell
@ 2025-08-01 21:04     ` Richard Henderson
  0 siblings, 0 replies; 187+ messages in thread
From: Richard Henderson @ 2025-08-01 21:04 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 8/2/25 02:05, Peter Maydell wrote:
> On Wed, 30 Jul 2025 at 01:48, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Initialize all 3 fields in main(), rather than in 4 different
>> target-specific functions.  Adjust the ifdef to be function
>> rather than target specific.  Include stack_base in the ifdef.
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   linux-user/qemu.h             |  4 ++--
>>   linux-user/aarch64/cpu_loop.c |  8 --------
>>   linux-user/arm/cpu_loop.c     | 37 +++++++++++++++--------------------
>>   linux-user/m68k/cpu_loop.c    |  9 ---------
>>   linux-user/main.c             |  5 +++++
>>   linux-user/riscv/cpu_loop.c   |  5 -----
>>   6 files changed, 23 insertions(+), 45 deletions(-)
>>
>> diff --git a/linux-user/qemu.h b/linux-user/qemu.h
>> index 6c97ab221f..dff7767bc8 100644
>> --- a/linux-user/qemu.h
>> +++ b/linux-user/qemu.h
>> @@ -122,12 +122,12 @@ struct TaskState {
>>   #ifdef TARGET_M68K
>>       abi_ulong tp_value;
>>   #endif
>> -#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_RISCV)
>> +#ifdef CONFIG_SEMIHOSTING
>>       /* Extra fields for semihosted binaries.  */
>>       abi_ulong heap_base;
>>       abi_ulong heap_limit;
>> -#endif
>>       abi_ulong stack_base;
>> +#endif
>>       int used; /* non zero if used */
>>       struct image_info *info;
>>       struct linux_binprm *bprm;
> 
>> diff --git a/linux-user/main.c b/linux-user/main.c
>> index 68972f00a1..4def4be1c1 100644
>> --- a/linux-user/main.c
>> +++ b/linux-user/main.c
>> @@ -1050,6 +1050,11 @@ int main(int argc, char **argv, char **envp)
>>
>>   #ifdef CONFIG_SEMIHOSTING
>>       qemu_semihosting_guestfd_init();
>> +
>> +    ts->stack_base = info->start_stack;
>> +    ts->heap_base = info->brk;
>> +    /* This will be filled in on the first SYS_HEAPINFO call.  */
>> +    ts->heap_limit = 0;
>>   #endif
> 
> Do we need to hide the struct fields and their initialization
> behind an ifdef at all? We allocate our TaskState structs on
> the heap so we don't care too much about their size, and
> the init code here is trivial.

I guess not.  A comment about "this is to support semihosting" would do as well.

Looking again, these ts->heap_* fields look actively wrong, because the real values are in

   static abi_ulong target_brk, initial_target_brk;

in syscall.c.

The original thread's stack_base can always be had via ts->info->start_stack.  I guess the 
semihosting api has no concept of threads and per-thread stacks.


r~


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 23/89] linux-user/i386: Create init_main_thread
  2025-08-01 16:17   ` Peter Maydell
@ 2025-08-01 21:14     ` Richard Henderson
  0 siblings, 0 replies; 187+ messages in thread
From: Richard Henderson @ 2025-08-01 21:14 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 8/2/25 02:17, Peter Maydell wrote:
>> -static inline void init_thread(struct target_pt_regs *regs,
>> -                               struct image_info *infop)
>> -{
>> -    regs->esp = infop->start_stack;
>> -    regs->eip = infop->entry;
>> -
>> -    /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
>> -       starts %edx contains a pointer to a function which might be
>> -       registered using `atexit'.  This provides a mean for the
>> -       dynamic linker to call DT_FINI functions for shared libraries
>> -       that have been loaded before the code runs.
>> -
>> -       A value of 0 tells we have no such handler.  */
> 
> This seems like a useful comment to retain -- it's nice
> to know whether we're zeroing a register as an ABI requirement
> versus just being tidy.

Fair.

>> +    memset(env->regs, 0, sizeof(env->regs));
> 
> Are we not allowed to assume the regs are zero out of reset ?

For whatever reason, x86 doesn't do that.
Eliding this line causes failures.

I think the SVR4 comment applies to x86_64 as well.  Yep, glibc/sysdeps/x86_64/start.S 
contains the same comment, although the linux kernel source does not.  The kernel simply 
zeros all registers regardless of normal (x64) vs compat (x32).

I'll move the one comment and expand it.


r~


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc
  2025-08-01 17:45   ` Peter Maydell
@ 2025-08-01 21:44     ` Richard Henderson
  2025-08-02 11:13       ` Peter Maydell
  0 siblings, 1 reply; 187+ messages in thread
From: Richard Henderson @ 2025-08-01 21:44 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 8/2/25 03:45, Peter Maydell wrote:
> On Wed, 30 Jul 2025 at 01:24, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>>
>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
>> ---
>>   linux-user/elfload.c                    | 41 +-----------------------
>>   linux-user/x86_64/target_coredump.c.inc | 42 +++++++++++++++++++++++++
>>   2 files changed, 43 insertions(+), 40 deletions(-)
>>   create mode 100644 linux-user/x86_64/target_coredump.c.inc
>>
> 
> Maybe we can come back to this at some point to convert the
> .c.inc into a proper .c / .h file.

Are you thinking of something like ELF_NREG + target_elf_gregset_t in the header and 
elf_core_copy_regs in the c file?

I suppose there's no reason not to do that now, putting the function in the new 
target/elfload.c, and the one or two declarations in target_elf.h.


r~


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc
  2025-08-01 21:44     ` Richard Henderson
@ 2025-08-02 11:13       ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 11:13 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Fri, 1 Aug 2025 at 22:44, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 8/2/25 03:45, Peter Maydell wrote:
> > On Wed, 30 Jul 2025 at 01:24, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> >>
> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> >> ---
> >>   linux-user/elfload.c                    | 41 +-----------------------
> >>   linux-user/x86_64/target_coredump.c.inc | 42 +++++++++++++++++++++++++
> >>   2 files changed, 43 insertions(+), 40 deletions(-)
> >>   create mode 100644 linux-user/x86_64/target_coredump.c.inc
> >>
> >
> > Maybe we can come back to this at some point to convert the
> > .c.inc into a proper .c / .h file.
>
> Are you thinking of something like ELF_NREG + target_elf_gregset_t in the header and
> elf_core_copy_regs in the c file?
>
> I suppose there's no reason not to do that now, putting the function in the new
> target/elfload.c, and the one or two declarations in target_elf.h.

I hadn't looked closely enough at the details to have a concrete
idea; this was just my preference for avoiding .c.inc files
unless we really need them (e.g. we're including the same file
multiple times or it's just too painful to split a huge file
any other way).

If it's easy to put the function in the .c file and the declarations
in the .h file then I think that's better than the .c.inc approach.

-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 61/89] linux-user: Move get_elf_cpu_model to target/elfload.c
  2025-07-29 23:59 ` [PATCH 61/89] linux-user: Move get_elf_cpu_model to target/elfload.c Richard Henderson
@ 2025-08-02 20:14   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:14 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Rename from cpu_get_model to emphasize that this is
> an elf-specific function.  Declare the function once
> in loader.h.
>
> This frees up target_elf.h for other uses.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>


> @@ -805,7 +804,7 @@ int main(int argc, char **argv, char **envp)
>      }
>
>      if (cpu_model == NULL) {
> -        cpu_model = cpu_get_model(get_elf_eflags(execfd));
> +        cpu_model = get_elf_cpu_model(get_elf_eflags(execfd));
>      }
>      cpu_type = parse_cpu_option(cpu_model);

Since this patch is just moving stuff around
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

but this got me wondering how the bflt loader works -- it
looks like get_elf_eflags() will always return 0 for a
bflt executable, and because most of the cpu_get_model()
functions for bflt architectures[*] return a fixed string
it all works out, but this seems more like we get lucky
than we actually intended this.

[*] arm, aarch64, m68k, microblaze, sh4, xtensa:
all except m68k return a fixed string; m68k handles
eflags == 0 as "m68040", which may or may not be the
best choice.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h
  2025-07-29 23:59 ` [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h Richard Henderson
@ 2025-08-02 20:22   ` Peter Maydell
  2025-08-02 22:00     ` Richard Henderson
  0 siblings, 1 reply; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:22 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:42, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the workaround out of linux-user/elfload.c, so that
> we don't have to replicate it in many places.  Place it
> immediately after the include of <signal.h>, which draws
> in the relevant symbols.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  include/qemu/osdep.h | 8 ++++++++
>  linux-user/elfload.c | 7 -------
>  2 files changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
> index 96fe51bc39..be3460b32f 100644
> --- a/include/qemu/osdep.h
> +++ b/include/qemu/osdep.h
> @@ -133,6 +133,14 @@ QEMU_EXTERN_C int daemon(int, int);
>  #include <setjmp.h>
>  #include <signal.h>
>
> +/*
> + * Avoid conflict with linux/arch/powerpc/include/uapi/asm/elf.h, included
> + * from <asm/sigcontext.h>, but we might as well do this unconditionally.
> + */
> +#undef ELF_CLASS
> +#undef ELF_DATA
> +#undef ELF_ARCH
> +

This should allow us also to remove the hw/core/loader.c

#ifdef ELF_CLASS
#undef ELF_CLASS
#endif

(added in commit 3efa9a672e4a in 2009 with a commit message
and other PPC related changes suggesting it was for the same
ppc include problem).


> -#ifdef _ARCH_PPC64
> -#undef ARCH_DLINFO
> -#undef ELF_CLASS
> -#undef ELF_DATA
> -#undef ELF_ARCH
> -#endif

Your osdep.h change is missing ARCH_DLINFO -- did our uses of
that symbol get renamed to something else in an earlier patch?

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 63/89] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h
  2025-07-29 23:59 ` [PATCH 63/89] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h Richard Henderson
@ 2025-08-02 20:24   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:24 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:25, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/i386/target_elf.h   | 23 +++++++++++++++++++
>  linux-user/x86_64/target_elf.h |  5 +++++
>  linux-user/elfload.c           | 41 +---------------------------------
>  3 files changed, 29 insertions(+), 40 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 64/89] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h
  2025-07-29 23:59 ` [PATCH 64/89] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h Richard Henderson
@ 2025-08-02 20:24   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:24 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:24, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/aarch64/target_elf.h | 10 ++++++++++
>  linux-user/arm/target_elf.h     |  5 +++++
>  linux-user/elfload.c            | 29 -----------------------------
>  3 files changed, 15 insertions(+), 29 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h
  2025-07-29 23:59 ` [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
@ 2025-08-02 20:25   ` Peter Maydell
  2025-08-02 20:28   ` Peter Maydell
  1 sibling, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:25 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:34, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/sparc/target_elf.h | 11 +++++++++++
>  linux-user/elfload.c          | 15 ---------------
>  2 files changed, 11 insertions(+), 15 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 66/89] linux-user: Move elf parameters to ppc/target_elf.h
  2025-07-29 23:59 ` [PATCH 66/89] linux-user: Move elf parameters to ppc/target_elf.h Richard Henderson
@ 2025-08-02 20:26   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:26 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:43, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/ppc/target_elf.h | 45 ++++++++++++++++++++++++++++++
>  linux-user/elfload.c        | 55 -------------------------------------
>  2 files changed, 45 insertions(+), 55 deletions(-)
>


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 67/89] linux-user: Move elf parameters to loongarch64/target_elf.h
  2025-07-29 23:59 ` [PATCH 67/89] linux-user: Move elf parameters to loongarch64/target_elf.h Richard Henderson
@ 2025-08-02 20:26   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:26 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:31, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/loongarch64/target_elf.h |  7 +++++++
>  linux-user/elfload.c                | 14 --------------
>  2 files changed, 7 insertions(+), 14 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 68/89] linux-user: Move elf parameters to {mips, mips64}/target_elf.h
  2025-07-29 23:59 ` [PATCH 68/89] linux-user: Move elf parameters to {mips, mips64}/target_elf.h Richard Henderson
@ 2025-08-02 20:27   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:27 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:43, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/mips/target_elf.h   |  5 +++++
>  linux-user/mips64/target_elf.h | 12 ++++++++++++
>  linux-user/elfload.c           | 20 --------------------

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h
  2025-07-29 23:59 ` [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
  2025-08-02 20:25   ` Peter Maydell
@ 2025-08-02 20:28   ` Peter Maydell
  2025-08-02 22:05     ` Richard Henderson
  1 sibling, 1 reply; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:28 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:34, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/sparc/target_elf.h | 11 +++++++++++
>  linux-user/elfload.c          | 15 ---------------
>  2 files changed, 11 insertions(+), 15 deletions(-)
>
> diff --git a/linux-user/sparc/target_elf.h b/linux-user/sparc/target_elf.h
> index 7e46748d26..8bd6e3e427 100644
> --- a/linux-user/sparc/target_elf.h
> +++ b/linux-user/sparc/target_elf.h
> @@ -8,4 +8,15 @@
>  #ifndef SPARC_TARGET_ELF_H
>  #define SPARC_TARGET_ELF_H
>
> +#ifndef TARGET_SPARC64
> +# define ELF_CLASS              ELFCLASS32
> +# define ELF_ARCH               EM_SPARC
> +#elif defined(TARGET_ABI32)
> +# define ELF_CLASS              ELFCLASS32
> +# define elf_check_arch(x)      ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
> +#else
> +# define ELF_CLASS              ELFCLASS64
> +# define ELF_ARCH               EM_SPARCV9
> +#endif

Why does sparc share 64 and 32 bit in one header file with an ifdef
when the other archs like mips and arm have separate headers,
by the way ?

-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 69/89] linux-user: Move elf parameters to microblaze/target_elf.h
  2025-07-29 23:59 ` [PATCH 69/89] linux-user: Move elf parameters to microblaze/target_elf.h Richard Henderson
@ 2025-08-02 20:28   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:28 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:29, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 70/89] linux-user: Move elf parameters to openrisc/target_elf.h
  2025-07-29 23:59 ` [PATCH 70/89] linux-user: Move elf parameters to openrisc/target_elf.h Richard Henderson
@ 2025-08-02 20:29   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:29 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:45, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 71/89] linux-user: Move elf parameters to sh4/target_elf.h
  2025-07-29 23:59 ` [PATCH 71/89] linux-user: Move elf parameters to sh4/target_elf.h Richard Henderson
@ 2025-08-02 20:29   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:29 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:44, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/sh4/target_elf.h | 4 ++++
>  linux-user/elfload.c        | 9 ---------
>  2 files changed, 4 insertions(+), 9 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 72/89] linux-user: Move elf parameters to m68k/target_elf.h
  2025-07-29 23:59 ` [PATCH 72/89] linux-user: Move elf parameters to m68k/target_elf.h Richard Henderson
@ 2025-08-02 20:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:23, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/m68k/target_elf.h | 4 ++++
>  linux-user/elfload.c         | 9 ---------
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 73/89] linux-user: Move elf parameters to alpha/target_elf.h
  2025-07-29 23:59 ` [PATCH 73/89] linux-user: Move elf parameters to alpha/target_elf.h Richard Henderson
@ 2025-08-02 20:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:27, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/alpha/target_elf.h | 3 +++
>  linux-user/elfload.c          | 7 -------
>  2 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/linux-user/alpha/target_elf.h b/linux-user/alpha/target_elf.h
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 74/89] linux-user: Move elf parameters to s390x/target_elf.h
  2025-07-29 23:59 ` [PATCH 74/89] linux-user: Move elf parameters to s390x/target_elf.h Richard Henderson
@ 2025-08-02 20:30   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:30 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:23, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/s390x/target_elf.h |  6 ++++++
>  linux-user/elfload.c          | 12 ------------
>  2 files changed, 6 insertions(+), 12 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 75/89] linux-user: Move elf parameters to riscv/target_elf.h
  2025-07-29 23:59 ` [PATCH 75/89] linux-user: Move elf parameters to riscv/target_elf.h Richard Henderson
@ 2025-08-02 20:31   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:31 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/riscv/target_elf.h | 10 ++++++++++
>  linux-user/elfload.c          | 14 --------------
>  2 files changed, 10 insertions(+), 14 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 76/89] linux-user: Move elf parameters to hppa/target_elf.h
  2025-07-29 23:59 ` [PATCH 76/89] linux-user: Move elf parameters to hppa/target_elf.h Richard Henderson
@ 2025-08-02 20:31   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:31 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:23, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/hppa/target_elf.h |  6 ++++++
>  linux-user/elfload.c         | 11 -----------
>  2 files changed, 6 insertions(+), 11 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 77/89] linux-user: Move elf parameters to xtensa/target_elf.h
  2025-07-29 23:59 ` [PATCH 77/89] linux-user: Move elf parameters to xtensa/target_elf.h Richard Henderson
@ 2025-08-02 20:31   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:31 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:42, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/xtensa/target_elf.h | 4 ++++
>  linux-user/elfload.c           | 9 ---------
>  2 files changed, 4 insertions(+), 9 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 78/89] linux-user: Move elf parameters to hexagon/target_elf.h
  2025-07-29 23:59 ` [PATCH 78/89] linux-user: Move elf parameters to hexagon/target_elf.h Richard Henderson
@ 2025-08-02 20:32   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:32 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:31, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/hexagon/target_elf.h | 3 +++
>  linux-user/elfload.c            | 7 -------
>  2 files changed, 3 insertions(+), 7 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 79/89] linux-user: Standardize on ELF_MACHINE not ELF_ARCH
  2025-07-29 23:59 ` [PATCH 79/89] linux-user: Standardize on ELF_MACHINE not ELF_ARCH Richard Henderson
@ 2025-08-02 20:34   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:34 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:22, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> PowerPC was the one outlier that defined both ELF_ARCH and
> ELF_MACHINE; ELF_ARCH was defined incorrectly, necessitating
> the definition of elf_check_arch.
>
> However, the elf file header field in question is called
> e_machine, so ELF_MACHINE is in fact the better name.
>
> Mechanically change most target/target_elf.h files,
> then adjust ppc/target_elf.h manually.
>
> Do not provide a default for ELF_MACHINE.
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 80/89] linux-user: Rename elf_check_arch
  2025-07-29 23:59 ` [PATCH 80/89] linux-user: Rename elf_check_arch Richard Henderson
@ 2025-08-02 20:35   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:35 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Rename to elf_check_machine to match ELF_MACHINE.
> Remove the unnecessary definition for loongarch64.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 81/89] linux-user: Remove ELIBBAD from elfload.c
  2025-07-29 23:59 ` [PATCH 81/89] linux-user: Remove ELIBBAD from elfload.c Richard Henderson
@ 2025-08-02 20:37   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:37 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:39, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The last use of this fallback was removed in 8e62a71738bc.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 5 -----
>  1 file changed, 5 deletions(-)
>
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index 5185c84e58..6eb4e31bdb 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -110,11 +110,6 @@ int info_is_fdpic(struct image_info *info)
>  #define MAP_DENYWRITE 0
>  #endif
>
> -/* should probably go in elf.h */
> -#ifndef ELIBBAD
> -#define ELIBBAD 80
> -#endif

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

(The existence of an unguarded "E(ELIBBAD)" in errnos.c.inc suggests
that all our supported hosts define ELIBBAD in the system headers
anyway.)

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 82/89] linux-user: Remove MAP_DENYWRITE from elfload.c
  2025-07-29 23:59 ` [PATCH 82/89] linux-user: Remove MAP_DENYWRITE " Richard Henderson
@ 2025-08-02 20:38   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:38 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:42, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The last use of this fallback was removed in bf858897b769.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 5 -----
>  1 file changed, 5 deletions(-)
>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 83/89] linux-user: Move arch_parse_elf_property to aarch64/elfload.c
  2025-07-29 23:59 ` [PATCH 83/89] linux-user: Move arch_parse_elf_property to aarch64/elfload.c Richard Henderson
@ 2025-08-02 20:39   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:39 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:29, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/aarch64/target_elf.h |  1 +
>  linux-user/loader.h             |  5 +++++
>  linux-user/aarch64/elfload.c    | 18 +++++++++++++++++
>  linux-user/elfload.c            | 35 ++++++---------------------------
>  4 files changed, 30 insertions(+), 29 deletions(-)


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 86/89] linux-user/microblaze: Move target_pt_regs to signal.c
  2025-07-29 23:59 ` [PATCH 86/89] linux-user/microblaze: " Richard Henderson
@ 2025-08-02 20:40   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:40 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:36, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> This structure is part of the microblaze signal frame.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 84/89] linux-user: Remove a.out declarations from elfload.c
  2025-07-29 23:59 ` [PATCH 84/89] linux-user: Remove a.out declarations from elfload.c Richard Henderson
@ 2025-08-02 20:41   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:41 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:46, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/elfload.c | 19 -------------------
>  1 file changed, 19 deletions(-)
>


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 85/89] linux-user/sparc: Move target_pt_regs to signal.c
  2025-07-29 23:59 ` [PATCH 85/89] linux-user/sparc: Move target_pt_regs to signal.c Richard Henderson
@ 2025-08-02 20:41   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:41 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:39, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> This structure is part of the sparc signal frame.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 88/89] linux-user/s390x: Move target_psw_t to signal.c
  2025-07-30  0:00 ` [PATCH 88/89] linux-user/s390x: Move target_psw_t " Richard Henderson
@ 2025-08-02 20:42   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:42 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Remove struct target_pt_regs as unused.
> Move target_psw_t to signal.c, as it is used there.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/s390x/target_syscall.h | 22 ----------------------
>  linux-user/s390x/signal.c         |  5 +++++
>  2 files changed, 5 insertions(+), 22 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 87/89] linux-user/openrisc: Move target_pt_regs to signal.c
  2025-07-30  0:00 ` [PATCH 87/89] linux-user/openrisc: " Richard Henderson
@ 2025-08-02 20:43   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:43 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:38, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> This structure is part of the openrisc signal frame.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/openrisc/target_syscall.h | 11 -----------
>  linux-user/openrisc/signal.c         | 12 ++++++++++++
>  2 files changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/linux-user/openrisc/target_syscall.h b/linux-user/openrisc/target_syscall.h
> index 7fe5b73d3b..c8394e9dcd 100644
> --- a/linux-user/openrisc/target_syscall.h
> +++ b/linux-user/openrisc/target_syscall.h
> @@ -1,17 +1,6 @@
>  #ifndef OPENRISC_TARGET_SYSCALL_H
>  #define OPENRISC_TARGET_SYSCALL_H
>
> -/* Note that in linux/arch/openrisc/include/uapi/asm/ptrace.h,
> - * this is called user_regs_struct.  Given that this is what
> - * is used within struct sigcontext we need this definition.
> - * However, elfload.c wants this name.
> - */
> -struct target_pt_regs {
> -    abi_ulong gpr[32];
> -    abi_ulong pc;
> -    abi_ulong sr;
> -};
> -
>  #define UNAME_MACHINE "openrisc"
>  #define UNAME_MINIMUM_RELEASE "2.6.32"
>
> diff --git a/linux-user/openrisc/signal.c b/linux-user/openrisc/signal.c
> index cb74a9fe5e..9242d06002 100644
> --- a/linux-user/openrisc/signal.c
> +++ b/linux-user/openrisc/signal.c
> @@ -22,6 +22,18 @@
>  #include "signal-common.h"
>  #include "linux-user/trace.h"
>
> +/*
> + * Note that in linux/arch/openrisc/include/uapi/asm/ptrace.h,
> + * this is called user_regs_struct.  Given that this is what
> + * is used within struct sigcontext we need this definition.
> + * However, elfload.c wants this name.

Is this bit about elfload.c still relevant? (Presumably not as
it won't be able to see the definition now we've moved it.)

> + */
> +struct target_pt_regs {
> +    abi_ulong gpr[32];
> +    abi_ulong pc;
> +    abi_ulong sr;
> +};
> +
>  typedef struct target_sigcontext {
>      struct target_pt_regs regs;
>      abi_ulong oldmask;

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 89/89] linux-user: Remove struct target_pt_regs from target_syscall.h
  2025-07-30  0:00 ` [PATCH 89/89] linux-user: Remove struct target_pt_regs from target_syscall.h Richard Henderson
@ 2025-08-02 20:45   ` Peter Maydell
  0 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:45 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:39, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> This structure is unused, and would only ever be used for the
> ptrace syscall, which we will never implement for linux-user.

It's not 100% impossible -- IIRC valgrind does it -- but yeah,
if we haven't implemented ptrace in all these years we're likely
never going to do so.


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH for-10.2 00/89] linux-user: Split up elfload.c
  2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
                   ` (88 preceding siblings ...)
  2025-07-30  0:00 ` [PATCH 89/89] linux-user: Remove struct target_pt_regs from target_syscall.h Richard Henderson
@ 2025-08-02 20:51 ` Peter Maydell
  89 siblings, 0 replies; 187+ messages in thread
From: Peter Maydell @ 2025-08-02 20:51 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel

On Wed, 30 Jul 2025 at 01:15, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> The goal is to kill the massive target ifdef ladder in elfload.c.
>
> The functions get moved to linux-user/target/elfload.c.
> Define weak functions to provide a default value, or a
> weak reference to determine if the function is provided.
>
> The core dump types and functions are moved to
> linux-user/target/target_coredump.h.
>
> The macros get moved to linux-user/target/target_elf.h.
> These are mostly use to parameterize include/elf.h, but
> there are some other outliers.
>
> The init_thread functions, storing into target_pt_regs, have been
> merged with target_cpu_copy_regs, copying out of target_pt_regs
> into CPUArchState.  Merging these found a few bits of silliness
> where pt_regs fields were initialized but not used.  To encourage
> this never to return, remove most target_pt_regs and hide the rest
> within the relevant signal.c.

Thanks for doing this -- it's one of those cleanups that's
been lingering around not done for years. I think I've
reviewed (or commented on) all the patches in the series now.

A quick grep suggests that about the only remaining target ifdef
ladder we have in the codebase is in linux-user/syscall_defs.h
(where we have things like "struct target_stat for each architecture,
and some of them get to share the asm-generic version".)

-- PMM


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h
  2025-08-02 20:22   ` Peter Maydell
@ 2025-08-02 22:00     ` Richard Henderson
  0 siblings, 0 replies; 187+ messages in thread
From: Richard Henderson @ 2025-08-02 22:00 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 8/3/25 06:22, Peter Maydell wrote:
> This should allow us also to remove the hw/core/loader.c
> 
> #ifdef ELF_CLASS
> #undef ELF_CLASS
> #endif

Oh, excellent.  I forgot about that.

>> -#ifdef _ARCH_PPC64
>> -#undef ARCH_DLINFO
>> -#undef ELF_CLASS
>> -#undef ELF_DATA
>> -#undef ELF_ARCH
>> -#endif
> 
> Your osdep.h change is missing ARCH_DLINFO -- did our uses of
> that symbol get renamed to something else in an earlier patch?
My osdep.h change includes the symbols in the actual 
linux/arch/powerpc/include/uapi/asm/elf.h file.  The undef of ARCH_DLINFO here was 
knee-jerk, I think.


r~


^ permalink raw reply	[flat|nested] 187+ messages in thread

* Re: [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h
  2025-08-02 20:28   ` Peter Maydell
@ 2025-08-02 22:05     ` Richard Henderson
  0 siblings, 0 replies; 187+ messages in thread
From: Richard Henderson @ 2025-08-02 22:05 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

On 8/3/25 06:28, Peter Maydell wrote:
> Why does sparc share 64 and 32 bit in one header file with an ifdef
> when the other archs like mips and arm have separate headers,
> by the way ?

Hysterical raisins?  PPC and RISC-V also share a header for 32+64 bit.


r~


^ permalink raw reply	[flat|nested] 187+ messages in thread

end of thread, other threads:[~2025-08-02 22:06 UTC | newest]

Thread overview: 187+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-29 23:58 [PATCH for-10.2 00/89] linux-user: Split up elfload.c Richard Henderson
2025-07-29 23:58 ` [PATCH 01/89] linux-user: Create target/elfload.c files Richard Henderson
2025-08-01 14:47   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 02/89] linux-user: Move get_elf_hwcap to {i386, x86_64}/elfload.c Richard Henderson
2025-08-01 14:51   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 03/89] linux-user: Move hwcap functions to {arm, aarch64}/elfload.c Richard Henderson
2025-08-01 14:53   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 04/89] linux-user: Move get_elf_hwcap to sparc/elfload.c Richard Henderson
2025-08-01 14:53   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 05/89] linux-user: Move hwcap functions to ppc/elfload.c Richard Henderson
2025-08-01 14:54   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 06/89] linux-user: Move get_elf_hwcap to loongarch64/elfload.c Richard Henderson
2025-08-01 14:54   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 07/89] linux-user: Move get_elf_hwcap to mips/elfload.c Richard Henderson
2025-08-01 14:55   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 08/89] linux-user: Move get_elf_hwcap to sh4/elfload.c Richard Henderson
2025-08-01 14:56   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 09/89] linux-user: Move hwcap functions to s390x/elfload.c Richard Henderson
2025-08-01 14:56   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 10/89] linux-user: Move get_elf_hwcap to riscv/elfload.c Richard Henderson
2025-08-01 14:57   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 11/89] linux-user: Remove ELF_HWCAP Richard Henderson
2025-08-01 15:06   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 12/89] linux-user: Remove ELF_HWCAP2 Richard Henderson
2025-08-01 15:09   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 13/89] linux-user: Move get_elf_platform to {i386, x86_64}/elfload.c Richard Henderson
2025-08-01 15:26   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 14/89] linux-user/i386: Return const data from get_elf_platform Richard Henderson
2025-08-01 15:28   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 15/89] linux-user: Move get_elf_platform to arm/elfload.c Richard Henderson
2025-08-01 15:30   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 16/89] linux-user/loongarch64: Create get_elf_platform Richard Henderson
2025-08-01 15:30   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 17/89] linux-user/hppa: " Richard Henderson
2025-08-01 15:32   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 18/89] linux-user: Remove ELF_PLATFORM Richard Henderson
2025-08-01 15:33   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 19/89] linux-user: Move get_elf_base_platform to mips/elfload.c Richard Henderson
2025-08-01 15:35   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 20/89] linux-user: Move target_cpu_copy_regs decl to qemu.h Richard Henderson
2025-08-01 15:36   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 21/89] linux-user: Unify init of semihosting fields in TaskState Richard Henderson
2025-08-01 16:05   ` Peter Maydell
2025-08-01 21:04     ` Richard Henderson
2025-07-29 23:58 ` [PATCH 22/89] linux-user: Create do_init_main_thread Richard Henderson
2025-08-01 16:13   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 23/89] linux-user/i386: Create init_main_thread Richard Henderson
2025-08-01 16:17   ` Peter Maydell
2025-08-01 21:14     ` Richard Henderson
2025-07-29 23:58 ` [PATCH 24/89] linux-user/arm: " Richard Henderson
2025-08-01 16:33   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 25/89] linux-user/aarch64: " Richard Henderson
2025-08-01 16:33   ` Peter Maydell
2025-07-29 23:58 ` [PATCH 26/89] linux-user/sparc: " Richard Henderson
2025-08-01 17:24   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 27/89] linux-user/ppc: " Richard Henderson
2025-08-01 17:26   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 28/89] linux-user/loongarch64: " Richard Henderson
2025-08-01 17:27   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 29/89] linux-user/mips: " Richard Henderson
2025-08-01 17:27   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 30/89] linux-user/microblaze: " Richard Henderson
2025-08-01 17:28   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 31/89] linux-user/openrisc: " Richard Henderson
2025-08-01 17:29   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 32/89] linux-user/sh4: " Richard Henderson
2025-08-01 17:30   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 33/89] linux-user/m68k: " Richard Henderson
2025-08-01 17:30   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 34/89] linux-user/alpha: " Richard Henderson
2025-08-01 17:31   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 35/89] linux-user/s390x: " Richard Henderson
2025-08-01 17:32   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 36/89] linux-user/riscv: " Richard Henderson
2025-08-01 17:32   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 37/89] linux-user/hppa: " Richard Henderson
2025-08-01 17:33   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 38/89] linux-user/xtensa: " Richard Henderson
2025-08-01 17:34   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 39/89] linux-user/hexagon: " Richard Henderson
2025-08-01 17:35   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 40/89] linux-user: Remove do_init_main_thread Richard Henderson
2025-08-01 17:37   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 41/89] linux-user/x86_64: Split out target_coredump.c.inc Richard Henderson
2025-08-01 17:45   ` Peter Maydell
2025-08-01 21:44     ` Richard Henderson
2025-08-02 11:13       ` Peter Maydell
2025-07-29 23:59 ` [PATCH 42/89] linux-user/i386: " Richard Henderson
2025-08-01 17:46   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 43/89] linux-user/arm: " Richard Henderson
2025-08-01 17:46   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 44/89] linux-user/aarch64: " Richard Henderson
2025-08-01 17:46   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 45/89] linux-user/ppc: " Richard Henderson
2025-08-01 17:46   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 46/89] linux-user/loongarch64: " Richard Henderson
2025-08-01 17:47   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 47/89] linux-user/mips: " Richard Henderson
2025-08-01 17:47   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 48/89] linux-user/microblaze: " Richard Henderson
2025-08-01 17:47   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 49/89] target/openrisc: " Richard Henderson
2025-08-01 17:48   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 50/89] target/sh4: " Richard Henderson
2025-08-01 17:49   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 51/89] linux-user/m68k: " Richard Henderson
2025-08-01 17:49   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 52/89] linux-user/s390x: " Richard Henderson
2025-08-01 17:49   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 53/89] linux-user/xtensa: " Richard Henderson
2025-08-01 17:50   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 54/89] linux-user: Unify the include of target_coredump.c.inc Richard Henderson
2025-08-01 17:50   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 55/89] linux-user: Move init_guest_commpage to x86_64/elfload.c Richard Henderson
2025-08-01 18:07   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 56/89] linux-user: Move init_guest_commpage to arm/elfload.c Richard Henderson
2025-08-01 18:08   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 57/89] linux-user: Move init_guest_commpage to hppa/elfload.c Richard Henderson
2025-08-01 18:08   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 58/89] linux-user: Remove INIT_GUEST_COMMPAGE Richard Henderson
2025-08-01 18:09   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 59/89] linux-user: Move get_vdso_image_info to arm/elfload.c Richard Henderson
2025-08-01 18:11   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 60/89] linux-user: Remove ELF_EXEC_PAGESIZE Richard Henderson
2025-08-01 18:12   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 61/89] linux-user: Move get_elf_cpu_model to target/elfload.c Richard Henderson
2025-08-02 20:14   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 62/89] linux-user: Move ppc uabi/asm/elf.h workaround to osdep.h Richard Henderson
2025-08-02 20:22   ` Peter Maydell
2025-08-02 22:00     ` Richard Henderson
2025-07-29 23:59 ` [PATCH 63/89] linux-user: Move elf parameters to {i386, x86_64}/target_elf.h Richard Henderson
2025-08-02 20:24   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 64/89] linux-user: Move elf parameters to {arm, aarch64}/target_elf.h Richard Henderson
2025-08-02 20:24   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 65/89] linux-user: Move elf parameters to sparc/target_elf.h Richard Henderson
2025-08-02 20:25   ` Peter Maydell
2025-08-02 20:28   ` Peter Maydell
2025-08-02 22:05     ` Richard Henderson
2025-07-29 23:59 ` [PATCH 66/89] linux-user: Move elf parameters to ppc/target_elf.h Richard Henderson
2025-08-02 20:26   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 67/89] linux-user: Move elf parameters to loongarch64/target_elf.h Richard Henderson
2025-08-02 20:26   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 68/89] linux-user: Move elf parameters to {mips, mips64}/target_elf.h Richard Henderson
2025-08-02 20:27   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 69/89] linux-user: Move elf parameters to microblaze/target_elf.h Richard Henderson
2025-08-02 20:28   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 70/89] linux-user: Move elf parameters to openrisc/target_elf.h Richard Henderson
2025-08-02 20:29   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 71/89] linux-user: Move elf parameters to sh4/target_elf.h Richard Henderson
2025-08-02 20:29   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 72/89] linux-user: Move elf parameters to m68k/target_elf.h Richard Henderson
2025-08-02 20:30   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 73/89] linux-user: Move elf parameters to alpha/target_elf.h Richard Henderson
2025-08-02 20:30   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 74/89] linux-user: Move elf parameters to s390x/target_elf.h Richard Henderson
2025-08-02 20:30   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 75/89] linux-user: Move elf parameters to riscv/target_elf.h Richard Henderson
2025-08-02 20:31   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 76/89] linux-user: Move elf parameters to hppa/target_elf.h Richard Henderson
2025-08-02 20:31   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 77/89] linux-user: Move elf parameters to xtensa/target_elf.h Richard Henderson
2025-08-02 20:31   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 78/89] linux-user: Move elf parameters to hexagon/target_elf.h Richard Henderson
2025-08-02 20:32   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 79/89] linux-user: Standardize on ELF_MACHINE not ELF_ARCH Richard Henderson
2025-08-02 20:34   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 80/89] linux-user: Rename elf_check_arch Richard Henderson
2025-08-02 20:35   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 81/89] linux-user: Remove ELIBBAD from elfload.c Richard Henderson
2025-08-02 20:37   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 82/89] linux-user: Remove MAP_DENYWRITE " Richard Henderson
2025-08-02 20:38   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 83/89] linux-user: Move arch_parse_elf_property to aarch64/elfload.c Richard Henderson
2025-08-02 20:39   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 84/89] linux-user: Remove a.out declarations from elfload.c Richard Henderson
2025-08-02 20:41   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 85/89] linux-user/sparc: Move target_pt_regs to signal.c Richard Henderson
2025-08-02 20:41   ` Peter Maydell
2025-07-29 23:59 ` [PATCH 86/89] linux-user/microblaze: " Richard Henderson
2025-08-02 20:40   ` Peter Maydell
2025-07-30  0:00 ` [PATCH 87/89] linux-user/openrisc: " Richard Henderson
2025-08-02 20:43   ` Peter Maydell
2025-07-30  0:00 ` [PATCH 88/89] linux-user/s390x: Move target_psw_t " Richard Henderson
2025-08-02 20:42   ` Peter Maydell
2025-07-30  0:00 ` [PATCH 89/89] linux-user: Remove struct target_pt_regs from target_syscall.h Richard Henderson
2025-08-02 20:45   ` Peter Maydell
2025-08-02 20:51 ` [PATCH for-10.2 00/89] linux-user: Split up elfload.c Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).