From nobody Sat May 30 17:43:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1779628846; cv=none; d=zohomail.com; s=zohoarc; b=Y7RdYVVNwvlaaDZocN1iX/feq+MII3jwU5u5JtdlFzOFAlFLXm+2feSmxbFNJvM4MKUiIRUkiZkVk8f0nFagn1KN+T1CeAKkfIm3edLOyEyJF11V4t77xoOGcKSy7UAU4W08qR4bNtN7kEd82QaFeFuNwpdDDhJinOd7ITWX1JU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779628846; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=onghrVOPoumr7ZF+G1gVbfqOC70FeH6HaXRyKPpvS2g=; b=Jwzu4OrW8Pr9W5IkzgBUH46IvMl2lf/ZamjVmTjEYRPd4e/9yBboO9KQMpUGLg6W9auSD5Xx36HTEfuhwsgCUmQAzEHKIyHuVKohHhpENhObkKJrWSiX9dXh8X6b4Gk/VxhRZnMgUr06lCmg2HP8mPiBnpSP86GK8h3UU4b/nY0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779628846925415.77909319607954; Sun, 24 May 2026 06:20:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wR8je-0006ZN-7z; Sun, 24 May 2026 09:19:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jd-0006Z3-7b for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:17 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jb-0005Xc-Ip for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:16 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 8776E41A8C; Sun, 24 May 2026 13:19:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 087C71F000E9; Sun, 24 May 2026 13:19:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779628754; bh=onghrVOPoumr7ZF+G1gVbfqOC70FeH6HaXRyKPpvS2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UJ6wi9ebliFQ0Nn2qo5EkrwM9TvJra24ZTadSwvVYupXTJ9yZlAC2Ofet4voocx7T rvY+jIUES20bldJwv03QpDQgUWIktjmOdCJ4dKG3AJzCR19tScLWCAz7lk4OzaJpRc apX4BYhMwu6uqui/Ui8DHaTsFwCwGMBIxjq/ZFf8v5CLHsxBWP1cyN0SsIAmjEhmtA ccXQAw0Pg+pQXsGlzOm4AliZFYXS5LtR5D6mfAoedp23zkOjUwNl3Gs9HG0pmzmQlg I/uNsPEwhzw1D16MkMUyVLHxZGVralNYMX0F4NpcG5thniZn9m8+8mqjNEnNtTogf4 QJyDg3niCaYow== From: Helge Deller To: qemu-devel@nongnu.org Cc: Matt Turner , Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Pierrick Bouvier Subject: [PULL 1/6] linux-user/hppa: add coredump support Date: Sun, 24 May 2026 15:19:03 +0200 Message-ID: <20260524131909.162990-2-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260524131909.162990-1-deller@kernel.org> References: <20260524131909.162990-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1779628849852154100 Content-Type: text/plain; charset="utf-8" From: Matt Turner Add HAVE_ELF_CORE_DUMP, target_elf_gregset_t (80 entries matching arch/parisc/include/uapi/asm/ptrace.h), and elf_core_copy_regs(). The struct layout matches the kernel's struct user_regs_struct: gr[0..31] at indices [0..31] (PSW in gr[0]) sr[0..7] at indices [32..39] iaoq[0..1] at indices [40..41] (instruction address queue) iasq[0..1] at indices [42..43] sar at index [44] (shift amount / CR11) iir at index [45] (interrupt instruction register) isr at index [46] (interrupt space register) ior at index [47] (interrupt offset register) ipsw at index [48] (interrupt PSW / CR22) cr0 at index [49] (recovery counter) cr24_31[8] at indices [50..57] cr8_15[6] at indices [58..63] pad[16] at indices [64..79] elf_core_copy_regs() saves GRs, IAOQ (front/back), and SAR. Signed-off-by: Matt Turner Reviewed-by: Helge Deller Signed-off-by: Helge Deller --- linux-user/hppa/elfload.c | 13 +++++++++++++ linux-user/hppa/target_elf.h | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/linux-user/hppa/elfload.c b/linux-user/hppa/elfload.c index 7f7ece6dc1..3354e1b840 100644 --- a/linux-user/hppa/elfload.c +++ b/linux-user/hppa/elfload.c @@ -16,6 +16,19 @@ const char *get_elf_platform(CPUState *cs) return "PARISC"; } =20 +void elf_core_copy_regs(target_elf_gregset_t *r, const CPUArchState *env) +{ + int i; + + memset(r, 0, sizeof(*r)); + for (i =3D 0; i < 32; i++) { + r->gr[i] =3D tswapal(env->gr[i]); + } + r->iaoq[0] =3D tswapal(env->iaoq_f); + r->iaoq[1] =3D tswapal(env->iaoq_b); + r->sar =3D tswapal(env->cr[CR_SAR]); +} + bool init_guest_commpage(void) { /* If reserved_va, then we have already mapped 0 page on the host. */ diff --git a/linux-user/hppa/target_elf.h b/linux-user/hppa/target_elf.h index 76930c9369..e1c5033242 100644 --- a/linux-user/hppa/target_elf.h +++ b/linux-user/hppa/target_elf.h @@ -12,6 +12,27 @@ #define ELF_MACHINE EM_PARISC =20 #define HAVE_ELF_PLATFORM 1 +#define HAVE_ELF_CORE_DUMP 1 + +/* + * Matches struct user_regs_struct from arch/parisc/include/uapi/asm/ptrac= e.h. + * ELF_NGREG =3D 80; register indices match those used by libunwind and gd= b. + */ +typedef struct target_elf_gregset_t { + abi_ulong gr[32]; /* gr[0..31]; PSW in gr[0] [0..31] */ + abi_ulong sr[8]; /* space registers [32..39] = */ + abi_ulong iaoq[2]; /* instruction address offset [40..41] = */ + abi_ulong iasq[2]; /* instruction address space [42..43] = */ + abi_ulong sar; /* shift amount register (CR11) [44] */ + abi_ulong iir; /* interrupt instruction register [45] */ + abi_ulong isr; /* interrupt space register [46] */ + abi_ulong ior; /* interrupt offset register [47] */ + abi_ulong ipsw; /* interrupt PSW (CR22) [48] */ + abi_ulong cr0; /* recovery counter [49] */ + abi_ulong cr24_31[8]; /* cr24..cr31 [50..57] = */ + abi_ulong cr8_15[6]; /* cr8, cr9, cr12, cr13, cr10, cr15 [58..63] */ + abi_ulong pad[16]; /* pad to 80 elements [64..79] = */ +} target_elf_gregset_t; =20 #define LO_COMMPAGE 0 #define STACK_GROWS_DOWN 0 --=20 2.54.0 From nobody Sat May 30 17:43:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1779628850; cv=none; d=zohomail.com; s=zohoarc; b=RNHY/Gb9LhFDQMLwYf/veVtbNDlzRLnXOqabljealNnQ4Hl9ReKHFtynxY8oKb404i9IzrcZ8dBa5+/1DlvXNinqFGGW3FiqTMLyWk8LTls1mv+UIE+C8IGDuTCRFk/4xZIsENV3etbEzjtpfE5VevzPfuJjNGIIrfJVIEcoJ9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779628850; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4jUD/iUmIk0WZSVuI4UggbN0ekm9NJMZB34COoCbZKM=; b=bdhjbqfbTKhG9gPJWRaY7fRzKjovEmldg166TL2lE4pdaOMd8csap2QsogAzPLtnmjU1f0OGNX5O8kQ48SbwwyA2z8OH+mm8YQ5MapBiVsNsN81LcTgkGgmgvCpZ4IIEELLULtANNzTlkQ7qHEjSO9s8R8ULBQ+Dz2tXZi6v/mY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779628850779553.8294125155131; Sun, 24 May 2026 06:20:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wR8jg-0006aJ-7r; Sun, 24 May 2026 09:19:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jf-0006Zb-0E for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:19 -0400 Received: from sea.source.kernel.org ([172.234.252.31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jd-0005Xj-9Y for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:18 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 6366640294; Sun, 24 May 2026 13:19:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D943F1F000E9; Sun, 24 May 2026 13:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779628756; bh=4jUD/iUmIk0WZSVuI4UggbN0ekm9NJMZB34COoCbZKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MmljiueBRk8lVtkc+5SNSJfq0x+8a2JSoAF2zI6sAlFK5z8mbscaojKPE2AmO1phH /y78ajjBgZXnCcTFGU8N9OmLIZ+jdTCjh4xulGYkG/sRHkeOW0tbvFe0BRRK3Txf71 8+PcTCPTFav0MnYOjgu8E+AgOStoi+jFw8tYmxH73fCty2NCG2dup65dnH3uZt0kMw LTkrIZsx8fJfOs/+ZTVRxkiE4tEYGYVoP6kRiozX/6IDzzFNwQ2bjPisTBaTBp3eOt JzrAYY3w9rbCEiXK9vy+cTx1HD3Kxjx2pt/83F6udR4NTi362t1xQ8suwDKT7CRsRN FCKJZ1/MUfkbA== From: Helge Deller To: qemu-devel@nongnu.org Cc: Matt Turner , Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Pierrick Bouvier Subject: [PULL 2/6] linux-user/mips64: fix elf_core_copy_regs register layout in core files Date: Sun, 24 May 2026 15:19:04 +0200 Message-ID: <20260524131909.162990-3-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260524131909.162990-1-deller@kernel.org> References: <20260524131909.162990-1-deller@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.234.252.31; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1779628854086154100 From: Matt Turner mips64/elfload.c uses #include "../mips/elfload.c" to share code. When the compiler processes mips/elfload.c the quoted #include "target_elf.h" resolves relative to the including file's directory, so it picks up mips/target_elf.h instead of mips64/target_elf.h. mips/target_elf.h pulls in mips/target_ptrace.h, whose target_pt_regs has a pad0[6] field before regs[]. As a result elf_core_copy_regs writes: r->pt.regs[i] -> reserved[6+i] (shifted by 6 from the correct index) r->pt.cp0_epc -> reserved[40] (correct mips64 N64 index is 34) The Linux kernel and glibc both use the mips64 N64 layout (no pad0): EPC at reserved[34]. Debuggers and libunwind reading the core with N64 constants therefore see a completely wrong register set =E2=80=94 EPC point= s to GP, RA holds the branch target instead of the link address, etc. Fix by: - Guarding the mips32 elf_core_copy_regs in mips/elfload.c with #ifndef TARGET_MIPS64 so it is not compiled for mips64/mipsn32 targets. - Providing a mips64-specific elf_core_copy_regs in mips64/elfload.c that writes directly to r->reserved[i] with the correct N64 indices, bypassing the struct field names that are tainted by the wrong header include. The mipsn32 (TARGET_ABI_MIPSN32) and mips64el targets are covered by the same mips64/elfload.c and benefit from the same fix. Signed-off-by: Matt Turner Cc: qemu-stable@nongnu.org Signed-off-by: Helge Deller --- linux-user/mips/elfload.c | 2 ++ linux-user/mips64/elfload.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c index cc5bbf05ab..1a46e180cf 100644 --- a/linux-user/mips/elfload.c +++ b/linux-user/mips/elfload.c @@ -131,6 +131,7 @@ const char *get_elf_base_platform(CPUState *cs) #undef MATCH_PLATFORM_INSN =20 /* See linux kernel: arch/mips/kernel/process.c:elf_dump_regs. */ +#ifndef TARGET_MIPS64 void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env) { for (int i =3D 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) { @@ -146,3 +147,4 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const = CPUMIPSState *env) r->pt.cp0_status =3D tswapl(env->CP0_Status); r->pt.cp0_cause =3D tswapl(env->CP0_Cause); } +#endif diff --git a/linux-user/mips64/elfload.c b/linux-user/mips64/elfload.c index b719555e65..9081ae8111 100644 --- a/linux-user/mips64/elfload.c +++ b/linux-user/mips64/elfload.c @@ -1 +1,30 @@ #include "../mips/elfload.c" + +/* + * mips/elfload.c defines elf_core_copy_regs guarded by #ifndef TARGET_MIP= S64. + * + * We must provide the mips64 version here. We cannot use r->pt.regs[] be= cause + * when mips/elfload.c is #include'd above its "#include "target_elf.h"" r= esolves + * to mips/target_elf.h (compiler searches the including file's directory = first), + * which pulls in mips/target_ptrace.h. That struct has pad0[6] before re= gs[], + * so r->pt.regs[i] writes to reserved[6+i] =E2=80=94 offset by 6 from wha= t the kernel + * and glibc expect for the N64 ABI (EPC at reserved[34], not reserved[40]= ). + * + * Write directly to reserved[] using the mips64 N64 index layout: + * R0-R31 at reserved[0..31], LO at [32], HI at [33], EPC at [34]. + */ +void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env) +{ + /* R0 is always 0; r->reserved is zero-initialised by the caller */ + for (int i =3D 1; i < 32; i++) { + r->reserved[i] =3D tswap64(env->active_tc.gpr[i]); + } + r->reserved[26] =3D 0; /* k0 */ + r->reserved[27] =3D 0; /* k1 */ + r->reserved[32] =3D tswap64(env->active_tc.LO[0]); + r->reserved[33] =3D tswap64(env->active_tc.HI[0]); + r->reserved[34] =3D tswap64(env->active_tc.PC); + r->reserved[35] =3D tswap64(env->CP0_BadVAddr); + r->reserved[36] =3D tswap64(env->CP0_Status); + r->reserved[37] =3D tswap64(env->CP0_Cause); +} --=20 2.54.0 From nobody Sat May 30 17:43:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1779628797; cv=none; d=zohomail.com; s=zohoarc; b=OxS9p/aUGg0BZOZ1vwjsNt9kbGMx+XwxayZu4bmlm8ZrE7SuqgjR7MGosOXEBCc4gwivjxFGrKql3A8qJ7u2DS3t8rp+ewwigzqvNc1Bm+CaNTjrcUbAEszojkPfgwsyaC/P1H+kvvwpg4vd+3TsBewhNNHhXtL6Qnb/rPVG0q0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779628797; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ifiygSmbabe2jO4uzD1XzeVPxD+W8BIivTY1oJ4LwRE=; b=gs2G5Zh1GhNGP9xS1huoaytCXotVSMoZ4mQBBA5N0+KkjYlGSfh7hdlNs+f/zDYprp5y50BHX0h1zYc1mn/m/SMiFHyPKA+oDtKPt2Th373/pdE9fc31VDIVllXzMrfAtsBTyGV5V0Ove4o3L1kxIIeDe0trJLrwaVqCykDdeK8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779628797425690.1028711712494; Sun, 24 May 2026 06:19:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wR8jh-0006aV-RX; Sun, 24 May 2026 09:19:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jg-0006aM-TY for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:20 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jf-0005aE-6R for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:20 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3FD4C429EB; Sun, 24 May 2026 13:19:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B57B41F000E9; Sun, 24 May 2026 13:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779628758; bh=ifiygSmbabe2jO4uzD1XzeVPxD+W8BIivTY1oJ4LwRE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GeCRz8w5vsiZcdlyjQYASWEQPiHoHkMzZ9rHYv8wMXdItDCGdaEzYf/h77eCsoctk dEKDuEYQqlW72KOXk7oQxC0w/Wrt7Hqggc19VdpYLUzhAeLLnwNT0ae3NN0/Xr7q2d yOekRdfXBSOue7YlhIYX7ell5cyQG1/8hSMHPOQd6HK0VwFMUASUuv4mnHtm6TNdGu iWGR+PiwPildHEHVtY4U3w2z6y8TSoc3pOY4VLtXD7TNkEVYG6Hg7eO/rujcBihzVG 525L2qJRELAX6px6Ci7Vrc3zaihJgaL3O40CxNuAur8oeeuiOBoA35qXEILpK7pF03 EzcjfkKvqFvvw== From: Helge Deller To: qemu-devel@nongnu.org Cc: Matt Turner , Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Pierrick Bouvier Subject: [PULL 3/6] linux-user/mips64: fix mipsn32 elf_core_copy_regs entry width Date: Sun, 24 May 2026 15:19:05 +0200 Message-ID: <20260524131909.162990-4-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260524131909.162990-1-deller@kernel.org> References: <20260524131909.162990-1-deller@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1779628799632154100 From: Matt Turner For mipsn32 (TARGET_ABI32=3Dy, TARGET_LONG_BITS=3D64): abi_ulong =3D uint32_t (4 bytes) =E2=80=94 for pointers and ABI-sized fie= lds target_ulong =3D uint64_t (8 bytes) =E2=80=94 for general-purpose registe= rs linux-user/elfload.c allocates target_elf_prstatus using the mips64/target_elf.h definition where target_elf_gregset_t has target_ulong reserved[45] (8 bytes each, 360 bytes total). However, in linux-user/mips64/elfload.c, #include "target_elf.h" inside the included mips/elfload.c resolves to mips/target_elf.h (compiler searches the file's own directory first), where the union uses abi_ulong reserved[45]. For mipsn32 this gives 4-byte entries (180 bytes), not the 8-byte entries (360 bytes) that elfload.c actually allocated. Writing via r->reserved[34] therefore lands at byte offset 34*4=3D136 instead of the correct 34*8=3D272, silently zeroing the EPC in the core file. Fix by casting the pointer to target_ulong * so writes always use 8-byte slots and land at the offsets matching the allocated layout. This does not change behavior for mips64 (N64) where abi_ulong already equals target_ulong (both 8 bytes). Signed-off-by: Matt Turner Cc: qemu-stable@nongnu.org Signed-off-by: Helge Deller --- linux-user/mips64/elfload.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/linux-user/mips64/elfload.c b/linux-user/mips64/elfload.c index 9081ae8111..e4d84a7bd6 100644 --- a/linux-user/mips64/elfload.c +++ b/linux-user/mips64/elfload.c @@ -15,16 +15,31 @@ */ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env) { - /* R0 is always 0; r->reserved is zero-initialised by the caller */ + /* + * linux-user/elfload.c allocates target_elf_prstatus using the + * definition from mips64/target_elf.h, where target_elf_gregset_t + * has target_ulong reserved[45] (8 bytes each =3D 360 bytes total). + * + * But in this compilation unit, "#include target_elf.h" resolved to + * mips/target_elf.h (wrong directory), so our local target_elf_gregse= t_t + * has abi_ulong reserved[45] which is only 4 bytes each for mipsn32. + * Using r->reserved[i] would write to the wrong offsets for mipsn32. + * + * Cast to target_ulong * to always write 8-byte entries at the correct + * positions, matching the layout that elfload.c allocated. + */ + target_ulong *regs =3D (target_ulong *)r; + + /* R0 is always 0; buffer is zero-initialised by the caller */ for (int i =3D 1; i < 32; i++) { - r->reserved[i] =3D tswap64(env->active_tc.gpr[i]); + regs[i] =3D tswap64(env->active_tc.gpr[i]); } - r->reserved[26] =3D 0; /* k0 */ - r->reserved[27] =3D 0; /* k1 */ - r->reserved[32] =3D tswap64(env->active_tc.LO[0]); - r->reserved[33] =3D tswap64(env->active_tc.HI[0]); - r->reserved[34] =3D tswap64(env->active_tc.PC); - r->reserved[35] =3D tswap64(env->CP0_BadVAddr); - r->reserved[36] =3D tswap64(env->CP0_Status); - r->reserved[37] =3D tswap64(env->CP0_Cause); + regs[26] =3D 0; /* k0 */ + regs[27] =3D 0; /* k1 */ + regs[32] =3D tswap64(env->active_tc.LO[0]); + regs[33] =3D tswap64(env->active_tc.HI[0]); + regs[34] =3D tswap64(env->active_tc.PC); + regs[35] =3D tswap64(env->CP0_BadVAddr); + regs[36] =3D tswap64(env->CP0_Status); + regs[37] =3D tswap64(env->CP0_Cause); } --=20 2.54.0 From nobody Sat May 30 17:43:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1779628847; cv=none; d=zohomail.com; s=zohoarc; b=HW/xIBV20yxf/zA7fWIVOo2JwHeoqJ+4MtM2djOr1P8cKlf2O/F+Yy3PyGb+WpEllXSLhD0qDDarDWAY4h00WfnXCMw5z6uWXFIFtdeaA6Vitc3WTx8Z3RcBrR2DtCyCF0tnR3nleBrNJuhouEpBKZ/bR80Mykc0++JjT+1J4CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779628847; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=53stOSPzY4yCMB1+R3XmVCXAcTk/eugwWFbVqsrGjYM=; b=dvOK+EZWNNuiUfAtIDcDl0J3hoIzW8bJ9WxI1S7NscqWYT+tkJeqlnJSQv/sVwxEGs1ci6yPVbgQNMZzl8s2PEW7krF0S3IHxY1pUgUaFyTTd9nzqrJMFLCSVuicQdd9KMtFDBoDpthgEsd4Fl5fLNRghZRq+k2nsBxML74Bjbc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779628847114989.3453470896789; Sun, 24 May 2026 06:20:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wR8jk-0006aw-3V; Sun, 24 May 2026 09:19:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8ji-0006am-Mr for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:22 -0400 Received: from tor.source.kernel.org ([172.105.4.254]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jh-0005aV-9L for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:22 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 7C0E0600AE; Sun, 24 May 2026 13:19:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 915E91F000E9; Sun, 24 May 2026 13:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779628760; bh=53stOSPzY4yCMB1+R3XmVCXAcTk/eugwWFbVqsrGjYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QGfnkduHbymEOrRqDyZn6b3oIM02JD+UywPTicCP0lcuaUbu+dqYxuYpjjGyt3h0U NIS//f2t/GniqKQW0TNbPrn81p4rNAzT+W0IPPv/SByobfm8belfh6KqQ9P4JWHFHK dFnWfrWxjj3iZ20TumFCqmdx1bfUMNUnR5suwKGYN4YD2GX52ca5Cuh3tRImApVOTI FaItXtPUAPI658oQx59Pdlqmvzqv8/dj6Ybr5iLA3qlFM4cWfJTXIJ/q+IIbJQYfMb jisolk5I6EvPJEVenZRGUthzyFHO8NrRqsrve4P96ikg4+HdlNrMNEtatOTizsHxaI WEuR7AEP/31BA== From: Helge Deller To: qemu-devel@nongnu.org Cc: Matt Turner , Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Pierrick Bouvier Subject: [PULL 4/6] linux-user/mips: use tswap32 in elf_core_copy_regs Date: Sun, 24 May 2026 15:19:06 +0200 Message-ID: <20260524131909.162990-5-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260524131909.162990-1-deller@kernel.org> References: <20260524131909.162990-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=172.105.4.254; envelope-from=deller@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1779628849143158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner Signed-off-by: Matt Turner Signed-off-by: Helge Deller --- linux-user/mips/elfload.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/linux-user/mips/elfload.c b/linux-user/mips/elfload.c index 1a46e180cf..ce2c4514f3 100644 --- a/linux-user/mips/elfload.c +++ b/linux-user/mips/elfload.c @@ -135,16 +135,16 @@ const char *get_elf_base_platform(CPUState *cs) void elf_core_copy_regs(target_elf_gregset_t *r, const CPUMIPSState *env) { for (int i =3D 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) { - r->pt.regs[i] =3D tswapl(env->active_tc.gpr[i]); + r->pt.regs[i] =3D tswap32(env->active_tc.gpr[i]); } =20 r->pt.regs[26] =3D 0; r->pt.regs[27] =3D 0; - r->pt.lo =3D tswapl(env->active_tc.LO[0]); - r->pt.hi =3D tswapl(env->active_tc.HI[0]); - r->pt.cp0_epc =3D tswapl(env->active_tc.PC); - r->pt.cp0_badvaddr =3D tswapl(env->CP0_BadVAddr); - r->pt.cp0_status =3D tswapl(env->CP0_Status); - r->pt.cp0_cause =3D tswapl(env->CP0_Cause); + r->pt.lo =3D tswap32(env->active_tc.LO[0]); + r->pt.hi =3D tswap32(env->active_tc.HI[0]); + r->pt.cp0_epc =3D tswap32(env->active_tc.PC); + r->pt.cp0_badvaddr =3D tswap32(env->CP0_BadVAddr); + r->pt.cp0_status =3D tswap32(env->CP0_Status); + r->pt.cp0_cause =3D tswap32(env->CP0_Cause); } #endif --=20 2.54.0 From nobody Sat May 30 17:43:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1779628798; cv=none; d=zohomail.com; s=zohoarc; b=kT8OLNOzerWTE7UgXjlT1AVEvdkNzpFkuw2tjPrCI67BfiiwxsZ2KfgvofEXjrZgU2h3zG9o154aGo/oxcVvajpd85EgMRHsaCk/HEStK4V4A8pGN3szzKNHbptvdyaCw74Oxywojd6DHXcK6pOTBV5laEYR+JPyF1qeuADGYOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779628798; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7B3sC2FvVNUkuJyuRL95Tb66TxfppTszcuAs1pXXHCM=; b=SuGbBZjGhjeV0q+R/YCk4p7SXojHk3W1jQxEAWSIm6b2BBcRTmgARUj+tDEpJaZkQsV7bLXOxf73RJnY6WmA6ZXXWWwI96sfPiWIUoV1DchoWYrZuM7lFy+HpsieJ9Jkl6ZDNSHOQnXejtQbkdHtPFluBcRnfJ7FBge3wD2eD5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779628798340174.79900255266887; Sun, 24 May 2026 06:19:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wR8jm-0006bY-Gf; Sun, 24 May 2026 09:19:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jl-0006bI-6U for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:25 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jj-0005ai-Lq for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:24 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id EC519409B3; Sun, 24 May 2026 13:19:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DF211F00A3C; Sun, 24 May 2026 13:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779628761; bh=7B3sC2FvVNUkuJyuRL95Tb66TxfppTszcuAs1pXXHCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=k5/fZrkWPxr0Pb71+VVydsvEA4ttpyJrtCs9Sz+wOh94kCGLSiWFhRz8S44l7SCf/ 8ioCg1ZOKC5NgGsKPk+fDQr5FOWVEdrvxtnFRVYxnPc+YVbOECExy5hfE4cYPPT4mt mQA1SkPvN8/rS5D3DolaORo7rwf7NJaZgLSWiltOizAtY4XDFT2nlVxNyZqovHws0U XPK6azYHs6a1HGLKvQKjzPuxGR+lEqYAXobZHhHPnfkG1V9l9lRozl8hknpwr0h+5n o/M3nfeaLsWWS22ILcJVTUAAanMbu28dBvvc26EElstUgPv0ZAhnQ2Pi+RsQUSLMRT 803UJgrbF2rgg== From: Helge Deller To: qemu-devel@nongnu.org Cc: Matt Turner , Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Pierrick Bouvier Subject: [PULL 5/6] linux-user/riscv: add coredump support Date: Sun, 24 May 2026 15:19:07 +0200 Message-ID: <20260524131909.162990-6-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260524131909.162990-1-deller@kernel.org> References: <20260524131909.162990-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1779628801238158500 Content-Type: text/plain; charset="utf-8" From: Matt Turner Define HAVE_ELF_CORE_DUMP and target_elf_gregset_t in target_elf.h, mirroring struct user_regs_struct: pc followed by x1 (ra) through x31 (t6). Implement elf_core_copy_regs() in elfload.c to populate the gregset from CPURISCVState. Without this, bprm->core_dump is NULL for RISC-V targets. When a guest signal goes unhandled, dump_core_and_abort() skips the core write and falls through to die_with_signal(), which re-raises the signal to the host. The host kernel then writes an x86-64 core file for the qemu-riscv64 process instead of a RISC-V guest core. Signed-off-by: Matt Turner Signed-off-by: Helge Deller --- linux-user/riscv/elfload.c | 9 +++++++++ linux-user/riscv/target_elf.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/linux-user/riscv/elfload.c b/linux-user/riscv/elfload.c index 2e7d622232..afe103a631 100644 --- a/linux-user/riscv/elfload.c +++ b/linux-user/riscv/elfload.c @@ -3,6 +3,7 @@ #include "qemu/osdep.h" #include "qemu.h" #include "loader.h" +#include "target_elf.h" =20 =20 const char *get_elf_cpu_model(uint32_t eflags) @@ -10,6 +11,14 @@ const char *get_elf_cpu_model(uint32_t eflags) return "max"; } =20 +void elf_core_copy_regs(target_elf_gregset_t *r, const CPURISCVState *env) +{ + r->pc =3D tswapal(env->pc); + for (int i =3D 0; i < 31; i++) { + r->regs[i] =3D tswapal(env->gpr[i + 1]); + } +} + abi_ulong get_elf_hwcap(CPUState *cs) { #define MISA_BIT(EXT) (1 << (EXT - 'A')) diff --git a/linux-user/riscv/target_elf.h b/linux-user/riscv/target_elf.h index dbbfdf54d3..859f726578 100644 --- a/linux-user/riscv/target_elf.h +++ b/linux-user/riscv/target_elf.h @@ -19,5 +19,12 @@ #endif =20 #define HAVE_ELF_HWCAP 1 +#define HAVE_ELF_CORE_DUMP 1 + +/* Mirrors struct user_regs_struct: pc followed by x1 (ra) .. x31 (t6). */ +typedef struct target_elf_gregset_t { + abi_ulong pc; + abi_ulong regs[31]; +} target_elf_gregset_t; =20 #endif --=20 2.54.0 From nobody Sat May 30 17:43:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1779628799; cv=none; d=zohomail.com; s=zohoarc; b=ZK+4LBskiq8RyG6daS8JvMJEgasHDgQto6PbX2jxJUTvrHfinxofLpPDOsb1ekE5IMW+6qd/JpGTQfww7wj+ZDOIJ83hm0aKSp8iW1U9Dculsrk1rwiY55xPtCUL694HBhcnG5jtUuvn/sPbk9RktB0TEKxe1jQa5bDo4RKrOEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779628799; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3hTlR2HXTg4t6KJwyF7+/pZQRaoeKdmU/Dmqul6G4Zc=; b=dQpAvXYDEjkhmtKMXLML+uMlii/+ZwZYaYeEXx7orAzRWoFocJuUxLyGrrfTe+E+zqJZHcgKok50HAUpIyX7n486I0WHfqUAYGpWuzcP7+C5PQpQE1Bi84BychvanwUr1RPEtZBWHKw+hrS/SCBO2D/MJlxRiLJWvXJb2J5+YpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779628799718498.156608121673; Sun, 24 May 2026 06:19:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wR8jp-0006cL-0o; Sun, 24 May 2026 09:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jn-0006bt-Cf for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:27 -0400 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wR8jk-0005b0-Mb for qemu-devel@nongnu.org; Sun, 24 May 2026 09:19:27 -0400 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id CA956439BB; Sun, 24 May 2026 13:19:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B1841F000E9; Sun, 24 May 2026 13:19:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779628763; bh=3hTlR2HXTg4t6KJwyF7+/pZQRaoeKdmU/Dmqul6G4Zc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M9vQl9gwAigHgXnZ/0YuRTVcDUFgiNW0RwKql6u0BhGppuWAuwrMyxpXtlx2SZKit fRA9pcAXawHxinJj3XuTpF62S2dnpkxHO0CWH35xeiuO/bWfBfAjPdcuihXYqLRWy1 bXX8FnZHzTGYGvODc+N1GKdLgqeTCG+jzfIHQDVXKSVlJcNTz9MzbZpV67V5iR4c85 /7i9xkRFT/fYbR/wgrqTYm2KsdvO+3NmN1lazhFpMjjX3h2goXHqXGWTrUi5o5ZPiO cm9aYIMtsXADMntKc+yYfh7pa4Lz84ZKsRn5UWEu4gu+YECq9esc8cjBdDLuqZf8LU KEKcO3Y+Caimg== From: Helge Deller To: qemu-devel@nongnu.org Cc: Matt Turner , Helge Deller , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Pierrick Bouvier Subject: [PULL 6/6] linux-user/sh4: add VDSO support for sh4 and sh4eb Date: Sun, 24 May 2026 15:19:08 +0200 Message-ID: <20260524131909.162990-7-deller@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260524131909.162990-1-deller@kernel.org> References: <20260524131909.162990-1-deller@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2600:3c0a:e001:78e:0:1991:8:25; envelope-from=deller@kernel.org; helo=sea.source.kernel.org X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1779628801225154100 Content-Type: text/plain; charset="utf-8" From: Matt Turner Provides replacement VDSO with sigreturn trampolines (__kernel_sigreturn, __kernel_rt_sigreturn) and syscall stubs (clock_gettime, clock_gettime64, clock_getres, gettimeofday). Both LE and BE blobs are committed and selected at compile time via TARGET_BIG_ENDIAN. The BE variant requires an sh4eb-unknown-linux-gnu toolchain; sh4-unknown-linux-gnu does not support -mb. CFI register numbers follow GCC's SH_DEBUGGER_REGNO: PR=3D17, GBR=3D18, MACH=3D20, MACL=3D21, FPUL=3D23, FPSCR=3D24, FR0-15=3D25= -40. Signed-off-by: Matt Turner Signed-off-by: Helge Deller --- linux-user/sh4/Makefile.vdso | 18 ++++ linux-user/sh4/elfload.c | 14 ++++ linux-user/sh4/meson.build | 12 +++ linux-user/sh4/target_elf.h | 1 + linux-user/sh4/vdso-asmoffset.h | 45 ++++++++++ linux-user/sh4/vdso-be.so | Bin 0 -> 2704 bytes linux-user/sh4/vdso-le.so | Bin 0 -> 2704 bytes linux-user/sh4/vdso.S | 142 ++++++++++++++++++++++++++++++++ linux-user/sh4/vdso.ld | 67 +++++++++++++++ 9 files changed, 299 insertions(+) create mode 100644 linux-user/sh4/Makefile.vdso create mode 100644 linux-user/sh4/vdso-asmoffset.h create mode 100755 linux-user/sh4/vdso-be.so create mode 100755 linux-user/sh4/vdso-le.so create mode 100644 linux-user/sh4/vdso.S create mode 100644 linux-user/sh4/vdso.ld diff --git a/linux-user/sh4/Makefile.vdso b/linux-user/sh4/Makefile.vdso new file mode 100644 index 0000000000..272c5d262d --- /dev/null +++ b/linux-user/sh4/Makefile.vdso @@ -0,0 +1,18 @@ +include $(BUILD_DIR)/tests/tcg/sh4-linux-user/config-target.mak + +SUBDIR =3D $(SRC_PATH)/linux-user/sh4 +VPATH +=3D $(SUBDIR) + +all: $(SUBDIR)/vdso-le.so $(SUBDIR)/vdso-be.so + +LDFLAGS =3D -nostdlib -shared -Wl,-h,linux-gate.so.1 \ + -Wl,--build-id=3Dsha1 -Wl,--hash-style=3Dboth \ + -Wl,-T,$(SUBDIR)/vdso.ld + +$(SUBDIR)/vdso-le.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC) -o $@ $(LDFLAGS) -ml $< + +CC_BE =3D sh4eb-unknown-linux-gnu-gcc + +$(SUBDIR)/vdso-be.so: vdso.S vdso.ld vdso-asmoffset.h + $(CC_BE) -o $@ $(LDFLAGS) $< diff --git a/linux-user/sh4/elfload.c b/linux-user/sh4/elfload.c index ddf2aaaed7..f03ce49e7d 100644 --- a/linux-user/sh4/elfload.c +++ b/linux-user/sh4/elfload.c @@ -5,6 +5,20 @@ #include "loader.h" #include "target_elf.h" =20 +#if TARGET_BIG_ENDIAN +# include "vdso-be.c.inc" +#else +# include "vdso-le.c.inc" +#endif + +const VdsoImageInfo *get_vdso_image_info(uint32_t elf_flags G_GNUC_UNUSED) +{ +#if TARGET_BIG_ENDIAN + return &vdso_be_image_info; +#else + return &vdso_le_image_info; +#endif +} =20 const char *get_elf_cpu_model(uint32_t eflags) { diff --git a/linux-user/sh4/meson.build b/linux-user/sh4/meson.build index 3bc3a6924a..611bce050b 100644 --- a/linux-user/sh4/meson.build +++ b/linux-user/sh4/meson.build @@ -3,3 +3,15 @@ syscall_nr_generators +=3D { arguments: [ meson.current_source_dir() / 'syscallhdr.s= h', '@INPUT@', '@OUTPUT@', '@EXTRA_ARGS@' ], output: '@BASENAME@_nr.h') } + +vdso_le_inc =3D gen_vdso.process('vdso-le.so', + extra_args: ['-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn', + '-p', 'vdso_le']) + +vdso_be_inc =3D gen_vdso.process('vdso-be.so', + extra_args: ['-s', '__kernel_sigreturn', + '-r', '__kernel_rt_sigreturn', + '-p', 'vdso_be']) + +linux_user_ss.add(when: 'TARGET_SH4', if_true: [vdso_le_inc, vdso_be_inc]) diff --git a/linux-user/sh4/target_elf.h b/linux-user/sh4/target_elf.h index d9e253d425..3fcb63d409 100644 --- a/linux-user/sh4/target_elf.h +++ b/linux-user/sh4/target_elf.h @@ -15,6 +15,7 @@ =20 #define HAVE_ELF_HWCAP 1 #define HAVE_ELF_CORE_DUMP 1 +#define HAVE_VDSO_IMAGE_INFO 1 =20 /* * See linux kernel: arch/sh/include/asm/elf.h, where diff --git a/linux-user/sh4/vdso-asmoffset.h b/linux-user/sh4/vdso-asmoffse= t.h new file mode 100644 index 0000000000..8ca96dce16 --- /dev/null +++ b/linux-user/sh4/vdso-asmoffset.h @@ -0,0 +1,45 @@ +/* + * Offsets into target signal frames for sh4 vdso. + * + * From linux-user/sh4/signal.c: + * + * struct target_sigcontext { + * target_ulong oldmask; // 0 + * target_ulong sc_gregs[16]; // 4 + * target_ulong sc_pc; // 68 + * target_ulong sc_pr; // 72 + * target_ulong sc_sr; // 76 + * target_ulong sc_gbr; // 80 + * target_ulong sc_mach; // 84 + * target_ulong sc_macl; // 88 + * target_ulong sc_fpregs[16]; // 92 + * target_ulong sc_xfpregs[16]; // 156 + * unsigned int sc_fpscr; // 220 + * unsigned int sc_fpul; // 224 + * unsigned int sc_ownedfp; // 228 + * }; // sizeof =3D 232 + * + * struct sigframe { sigcontext sc; ... } + * struct rt_sigframe { siginfo info[128]; ucontext uc; } + * ucontext =3D { flags[4], link[4], stack[12], sigcontext mcontext; ...= } + * =3D> mcontext at rt_sigframe + 128 + 20 =3D rt_sigframe + 148 + */ + +/* Offset of sigcontext within sigframe (CFA base for sigreturn). */ +#define SIGFRAME_SC_OFFSET 0 + +/* Offset of tuc_mcontext within rt_sigframe (CFA base for rt_sigreturn). = */ +#define RT_SIGFRAME_SC_OFFSET 148 + +/* Offsets within struct sigcontext. */ +#define SC_GREGS 4 +#define SC_PC 68 +#define SC_PR 72 +#define SC_SR 76 +#define SC_GBR 80 +#define SC_MACH 84 +#define SC_MACL 88 +#define SC_FPREGS 92 +#define SC_XFPREGS 156 +#define SC_FPSCR 220 +#define SC_FPUL 224 diff --git a/linux-user/sh4/vdso-be.so b/linux-user/sh4/vdso-be.so new file mode 100755 index 0000000000000000000000000000000000000000..4f50143f8284ab63693c1117e68= f3efa886155e3 GIT binary patch literal 2704 zcmbtWU1%It6#iy*limF9EvdGq*2LCYiXGAtN{c?YX?`_LB~7TU)#-M3vb#;P6K5xB zw#GIOA`!t_74e~nVqcZwlY-zw!9PTViVq^VqQqGxFWJcQd=3DmgWwr1Gw0kh z_vhU6efL}(92+uB167G(4*+fG1ClAJ_n{jN*o_oA05k&ZtF|`)+2Vj~`hO+ypCKC( zs>cNIN2I+7$R_{K`9D4a#0qPzI*%To@2?_lCm>t2zY{=3Dgczg=3D;uO6Qtc)0T6H*aRH ze*EnF`wq3;oCMGg;6k`wv(pX!`3*2f05kyRYPd&(?`8n60cZh`a)aP6AlB;!!QX(~ z$94coHwgY@oZKL|1;o1b&i{v`f%qo?S~mf$0QLg$4S)np911vbG^#H0K~uN z+LUep@v9O47xdZ$f?w5HXo>MZb(R#KHzlERgXc#dN`rb+=3Dee`5u_w7Xv64(asBH8} zTuj;Ku(UUy@g1w|TKh0IIzIKN zz27>(t(i5C5k4JX+`0_N9NVVyNblZ=3Dy|eJU>Z8aw8(p#c0rZCPG9Cah0vODmG5+7y**F)mqyJ@& zbB<#$ms4^Qfs4YpAk3#lY+1yg5)J1?V?`vEMDmc#%9pow%W=3DE$Yk% z>Rclh~HL)e+v6|D9+V-Rh0ihjd>&dKdt9ioHq%z zU)6tB51{zMuj8lHI=3D*?mj<4RWo;(lZQ^^@|KG#dTr0i7u}Lw_A{Qp z-t3feum?_zr;m&thHVdzPuYVb_RvK7$e=3DwkFadjb>}Y>_%sx6abZl_ao=3Do?T4cZZ` zD+=3D0}LTdP;o~$ASR6}4JaFybQU3ih;@nRDzy&Rf%9`OcEB&-Xt{m%0y# z6@3?zv$QCTphw*wydU(PPmC)}NI&9=3DbqDj@3~?v1w-UK?I3BUQU*$ewnp8Qexs0M~ z0CFsGX@)qJSY^$k?=3D9_j&_v=3D?S`mL%OfpvivjmL-FAPBsmxCZ)N37aALN{RMk%|pM&5PyUQWJQv<|Rgr%G0%o^*^#A|> literal 0 HcmV?d00001 diff --git a/linux-user/sh4/vdso-le.so b/linux-user/sh4/vdso-le.so new file mode 100755 index 0000000000000000000000000000000000000000..c41cb5831b9e5883a64564da8b2= 149a33e199f4f GIT binary patch literal 2704 zcmbtWU1%It6#iy+lk6sGvbUt#nzkl3))MRxODuwYXwv*_N|H*NXw~X;yF1z4{Or`( z*)$ttn+G2vg0<>HA4C*=3D@u4O7AU^n35fu@k>XV3|;txJFf<^FWLZ6DVKp*z@kSHx|At z{Wc;deja@L%MW^+09;W1wnTv6|M8tv1gHV996=3DD{vH{csxB{SoYXRUd-*>vAz~8>_ zFpj+d;sE~ieTQ-1^nIs|KmMQS0q{`_XaukwjW`J4{g8eefR&Iw0pP2c^q2kf0KSb$ z->B2Kw?h422>BT^Fd=3DssiOdJ^1kg8RpL7`G0Q>qSu4ZR}sSBi?>A9$%u3eS*FJ zq;+NNQdhqB^Y^y>`03J1zg(KXyz9+l#pgRe+z-o|%a$A~Gvj2Yt(@(7g;{$`2hB7R;Z=3D0ts2Gr#XvCk46Pl~&r5c^Mydma}D z9uv2x#LgiEHA^m_-@*C~G`+$#HEtxYHz0w8vHtyX=3D(|4jJqjQZj7Z=3D-W4n>OepSU- z4RQz(4R%g)lGK^u2z22F7|u`mI#o7_7nJ6TLmd)`@|Ell|k?cu((ezZI%=3D zML}Cr$OgWsCaVwuZ6L5MxJvQbCSrnFs?2)nvoK4ZE8ltjRdhTXX0}pH&lWPlN2xLk zGn@9(FmuJSnNOGU((bv^GH1J`f>Yd}SXr2M-kNmNv$mDby6YND&z|R&{%5o*PG^ei zvzX_whEBzHb$&3F^_kBamlYw;7@jqq>Wt-lJa;KesvkLk^O5HcDW2tg%ukBuGJ^dm zM-ybo#Ue%w5H{z%>+cf_?*q4{{{p_vTD`v9d+PZsK@ q=3DhEOEZp8q2Zz4DIzl@8_rDG$m)B>w|kop%Ps`@=3DwC(k+!?drcIxqF)c literal 0 HcmV?d00001 diff --git a/linux-user/sh4/vdso.S b/linux-user/sh4/vdso.S new file mode 100644 index 0000000000..4fb5ee9d31 --- /dev/null +++ b/linux-user/sh4/vdso.S @@ -0,0 +1,142 @@ +/* + * sh4 linux replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include "vdso-asmoffset.h" + + .text + +.macro endf name + .globl \name + .type \name, @function + .size \name, . - \name +.endm + +/* + * SH4 syscall convention: + * Syscall number in r3 (caller-saved, so no save/restore needed) + * Arguments in r4-r7 + * Return value in r0 + * Syscall instruction: trapa #0x10 + */ + +.macro vdso_syscall name, nr +\name: + .cfi_startproc + mov.l 1f, r3 + trapa #0x10 + rts + nop + .align 2 +1: .long \nr + .cfi_endproc +endf \name +.endm + +vdso_syscall __vdso_clock_gettime, __NR_clock_gettime +vdso_syscall __vdso_clock_gettime64, __NR_clock_gettime64 +vdso_syscall __vdso_clock_getres, __NR_clock_getres +vdso_syscall __vdso_gettimeofday, __NR_gettimeofday + +/* + * Signal return trampolines. + * + * For sigreturn: r15 points to struct sigframe; sigcontext is at + * offset SIGFRAME_SC_OFFSET (0). + * For rt_sigreturn: r15 points to struct rt_sigframe; sigcontext is at + * offset RT_SIGFRAME_SC_OFFSET (148). + * + * A single CFI region covers both trampolines. The CFA is set to the + * start of the relevant sigcontext; all register offsets are then + * identical for both trampolines. Between the two trampolines we use + * .cfi_def_cfa_offset to update the CFA base for the different layout. + */ + +/* + * Start the unwind info at least one instruction before the signal + * trampoline, because the unwinder will assume we are returning + * after a call site. + */ + .cfi_startproc simple + .cfi_signal_frame + .cfi_return_column 16 /* return column is PC */ + + /* CFA =3D r15 + SIGFRAME_SC_OFFSET =3D r15 (sigcontext base, sigreturn).= */ + .cfi_def_cfa 15, SIGFRAME_SC_OFFSET + + /* Integer registers r0-r15: sc_gregs[n] at sigcontext + SC_GREGS + n*4. = */ + .cfi_offset 0, SC_GREGS + 0 * 4 + .cfi_offset 1, SC_GREGS + 1 * 4 + .cfi_offset 2, SC_GREGS + 2 * 4 + .cfi_offset 3, SC_GREGS + 3 * 4 + .cfi_offset 4, SC_GREGS + 4 * 4 + .cfi_offset 5, SC_GREGS + 5 * 4 + .cfi_offset 6, SC_GREGS + 6 * 4 + .cfi_offset 7, SC_GREGS + 7 * 4 + .cfi_offset 8, SC_GREGS + 8 * 4 + .cfi_offset 9, SC_GREGS + 9 * 4 + .cfi_offset 10, SC_GREGS + 10 * 4 + .cfi_offset 11, SC_GREGS + 11 * 4 + .cfi_offset 12, SC_GREGS + 12 * 4 + .cfi_offset 13, SC_GREGS + 13 * 4 + .cfi_offset 14, SC_GREGS + 14 * 4 + .cfi_offset 15, SC_GREGS + 15 * 4 + + /* PC (return column). */ + .cfi_offset 16, SC_PC + + /* Control registers. */ + .cfi_offset 17, SC_PR + .cfi_offset 18, SC_GBR + .cfi_offset 20, SC_MACH + .cfi_offset 21, SC_MACL + + /* FP registers fr0-fr15: sc_fpregs[n] at sigcontext + SC_FPREGS + n*4. */ + .cfi_offset 25, SC_FPREGS + 0 * 4 + .cfi_offset 26, SC_FPREGS + 1 * 4 + .cfi_offset 27, SC_FPREGS + 2 * 4 + .cfi_offset 28, SC_FPREGS + 3 * 4 + .cfi_offset 29, SC_FPREGS + 4 * 4 + .cfi_offset 30, SC_FPREGS + 5 * 4 + .cfi_offset 31, SC_FPREGS + 6 * 4 + .cfi_offset 32, SC_FPREGS + 7 * 4 + .cfi_offset 33, SC_FPREGS + 8 * 4 + .cfi_offset 34, SC_FPREGS + 9 * 4 + .cfi_offset 35, SC_FPREGS + 10 * 4 + .cfi_offset 36, SC_FPREGS + 11 * 4 + .cfi_offset 37, SC_FPREGS + 12 * 4 + .cfi_offset 38, SC_FPREGS + 13 * 4 + .cfi_offset 39, SC_FPREGS + 14 * 4 + .cfi_offset 40, SC_FPREGS + 15 * 4 + + /* FPUL, FPSCR. */ + .cfi_offset 23, SC_FPUL + .cfi_offset 24, SC_FPSCR + + nop + +sigreturn_region_start: +__kernel_sigreturn: + mov.l 1f, r3 + trapa #0x10 + .align 2 +1: .long __NR_sigreturn +endf __kernel_sigreturn + + /* Update CFA base for the rt_sigreturn frame layout. */ + .cfi_def_cfa_offset RT_SIGFRAME_SC_OFFSET + +__kernel_rt_sigreturn: + mov.l 2f, r3 + trapa #0x10 + .align 2 +2: .long __NR_rt_sigreturn +endf __kernel_rt_sigreturn +sigreturn_region_end: + + .cfi_endproc diff --git a/linux-user/sh4/vdso.ld b/linux-user/sh4/vdso.ld new file mode 100644 index 0000000000..3a6cb65d08 --- /dev/null +++ b/linux-user/sh4/vdso.ld @@ -0,0 +1,67 @@ +/* + * Linker script for linux sh4 replacement vdso. + * + * Copyright 2023 Linaro, Ltd. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +VERSION { + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_clock_gettime64; + __vdso_clock_getres; + __vdso_gettimeofday; + __kernel_sigreturn; + __kernel_rt_sigreturn; + local: *; + }; +} + +PHDRS { + phdr PT_PHDR FLAGS(4) PHDRS; + load PT_LOAD FLAGS(7) FILEHDR PHDRS; /* FLAGS=3DRWX */ + dynamic PT_DYNAMIC FLAGS(4); + eh_frame_hdr PT_GNU_EH_FRAME; + note PT_NOTE FLAGS(4); +} + +SECTIONS { + . =3D SIZEOF_HEADERS; + + /* + * The following, including the FILEHDRS and PHDRS, are modified + * when we relocate the binary. We want them to be initially + * writable for the relocation; we'll force them read-only after. + */ + .note : { *(.note*) } :load :note + .dynamic : { *(.dynamic) } :load :dynamic + .dynsym : { *(.dynsym) } :load + .data : { + /* + * There ought not be any real read-write data. + * But since we manipulated the segment layout, + * we have to put these sections somewhere. + */ + *(.data*) + *(.sdata*) + *(.got.plt) *(.got) + *(.gnu.linkonce.d.*) + *(.bss*) + *(.dynbss*) + *(.gnu.linkonce.b.*) + } + + .rodata : { *(.rodata*) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .eh_frame_hdr : { *(.eh_frame_hdr) } :load :eh_frame_hdr + .eh_frame : { *(.eh_frame) } :load + + .text : { *(.text*) } :load +} --=20 2.54.0