@samitouri / QOSamiQemu / commits / 88dfd97b8a

linux-user: support writing floating-point registers to a core dump

Write an NT_FPREGSET note for targets that opt in: a target_elf.h that defines HAVE_ELF_CORE_FPREGS and target_elf_fpregset_t, and supplies an elf_core_copy_fpregs() beside the existing elf_core_copy_regs(). Signed-off-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Helge Deller <deller@gmx.de> Signed-off-by: Helge Deller <deller@gmx.de>

Matt Turner committed Aug 5, 2026 at 13:23 UTC 88dfd97b8acfe41cac7304fa1b6034952f046d1d
2 files changed +22
linux-user/elfload.c
+19
@@ -1887,6 +1887,17 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, size_t sz, off_t offset)
1887 bswap_phdr(phdr, 1);
1888 }
1889
1890 +#ifdef HAVE_ELF_CORE_FPREGS
1891 +static void fill_fpregset_note(void *data, CPUState *cpu)
1892 +{
1893 + /* Fill locally and copy: note memory is only aligned to 4. */
1894 + target_elf_fpregset_t fpregs = {};
1895 +
1896 + elf_core_copy_fpregs(&fpregs, cpu_env(cpu));
1897 + memcpy(data, &fpregs, sizeof(fpregs));
1898 +}
1899 +#endif
1900 +
1901 static void fill_prstatus_note(void *data, CPUState *cpu, int signr)
1902 {
1903 /*
@@ -2166,6 +2177,9 @@ static int elf_core_dump(int signr, const CPUArchState *env)
2177 offset += size_note("CORE", ts->info->auxv_len);
2178 offset += size_note("CORE", sizeof(struct target_elf_prpsinfo));
2179 offset += size_note("CORE", sizeof(struct target_elf_prstatus)) * cpus;
2180 +#ifdef HAVE_ELF_CORE_FPREGS
2181 + offset += size_note("CORE", sizeof(target_elf_fpregset_t)) * cpus;
2182 +#endif
2183 note_size = offset - note_offset;
2184 data_offset = TARGET_PAGE_ALIGN(offset);
2185
@@ -2222,6 +2236,11 @@ static int elf_core_dump(int signr, const CPUArchState *env)
2236 dptr = fill_note(&hptr, NT_PRSTATUS, "CORE",
2237 sizeof(struct target_elf_prstatus));
2238 fill_prstatus_note(dptr, cpu_iter, cpu_iter == cpu ? signr : 0);
2239 +#ifdef HAVE_ELF_CORE_FPREGS
2240 + dptr = fill_note(&hptr, NT_FPREGSET, "CORE",
2241 + sizeof(target_elf_fpregset_t));
2242 + fill_fpregset_note(dptr, cpu_iter);
2243 +#endif
2244 }
2245
2246 if (dump_write(fd, header, data_offset) < 0) {
linux-user/loader.h
+3
@@ -109,6 +109,9 @@ bool init_guest_commpage(void);
109
110 struct target_elf_gregset_t;
111 void elf_core_copy_regs(struct target_elf_gregset_t *, const CPUArchState *);
112 +/* Only defined by a target whose target_elf.h sets HAVE_ELF_CORE_FPREGS. */
113 +struct target_elf_fpregset_t;
114 +void elf_core_copy_fpregs(struct target_elf_fpregset_t *, const CPUArchState *);
115
116 typedef struct {
117 const uint8_t *image;