diff --git a/0005-add-LoongArch64-support-implementation.patch b/0005-add-LoongArch64-support-implementation.patch new file mode 100644 index 0000000000000000000000000000000000000000..16b1430577921d7b88b16bb333d0a1674d5d8b81 --- /dev/null +++ b/0005-add-LoongArch64-support-implementation.patch @@ -0,0 +1,269 @@ +From fd0028b160dd57018a81aa82ab60a0df31cd0d47 Mon Sep 17 00:00:00 2001 +From: lijian1 +Date: Thu, 23 Oct 2025 15:08:28 +0800 +Subject: [PATCH] add LoongArch64 support implementation + +This patch adds LoongArch64 support for the crash-gcore-command extension. +1. Add LoongArch64 support to gcore: + The constructor and destructor are now explicitly declared in src/gcore.c + to ensure proper use of the .init_array section, as the previous approach + did not take effect on LoongArch64. + +2. Implement LoongArch64 backend logic: + Introduce src/libgcore/gcore_loongarch64.c to enable core dump generation + under the crash context. The generated core files are now compatible with GDB. + +3. Adjust build rules for LoongArch64: + The original build support was based on a patch from Zhang Kai + , but its UAPI definitions contained an error. These issues have been corrected in this version. + +Based-on-patch-by: laokz +Signed-off-by: lijian1 +--- + src/gcore.c | 13 ++++- + src/gcore.mk | 6 +- + src/libgcore/gcore_coredump.c | 2 +- + src/libgcore/gcore_defs.h | 18 +++--- + src/libgcore/gcore_loongarch64.c | 94 ++++++++++++++++++++++++++++++++ + 5 files changed, 120 insertions(+), 13 deletions(-) + create mode 100644 src/libgcore/gcore_loongarch64.c + +diff --git a/src/gcore.c b/src/gcore.c +index 47a9c0d..69783d4 100644 +--- a/src/gcore.c ++++ b/src/gcore.c +@@ -30,8 +30,13 @@ static struct command_table_entry command_table[] = { + { (char *)NULL } + }; + ++#ifdef LOONGARCH64 ++int __attribute__((constructor)) ++_init(void) ++#else + int + _init(void) /* Register the command set. */ ++#endif + { + gcore_offset_table_init(); + gcore_size_table_init(); +@@ -42,9 +47,13 @@ _init(void) /* Register the command set. */ + register_extension(command_table); + return 1; + } +- ++#ifdef LOONGARCH64 ++int __attribute__((destructor)) ++_fini(void) ++#else + int +-_fini(void) ++_fini(void) ++#endif + { + return 1; + } +diff --git a/src/gcore.mk b/src/gcore.mk +index 34962a2..fc6e7d5 100644 +--- a/src/gcore.mk ++++ b/src/gcore.mk +@@ -43,7 +43,7 @@ ifeq ($(shell arch), aarch64) + endif + + ifeq ($(shell arch), loongarch64) +- TARGET=loongarch64 ++ TARGET=LOONGARCH64 + TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64 + ARCH=SUPPORTED + endif +@@ -115,6 +115,10 @@ ifneq (,$(findstring $(TARGET), RISCV64)) + GCORE_CFILES += libgcore/gcore_riscv64.c + endif + ++ifneq (,$(findstring $(TARGET), LOONGARCH64)) ++GCORE_CFILES += libgcore/gcore_loongarch64.c ++endif ++ + GCORE_OFILES = $(patsubst %.c,%.o,$(GCORE_CFILES)) + + COMMON_CFLAGS=-Wall -I$(INCDIR) -I./libgcore -fPIC -D$(TARGET) \ +diff --git a/src/libgcore/gcore_coredump.c b/src/libgcore/gcore_coredump.c +index 5f0723e..a4411ce 100644 +--- a/src/libgcore/gcore_coredump.c ++++ b/src/libgcore/gcore_coredump.c +@@ -889,7 +889,7 @@ fill_prstatus_note(struct elf_note_info *info, struct task_context *tc, + struct memelfnote *memnote) + { + struct elf_prstatus *prstatus; +-#if defined(X86) || defined(X86_64) || defined(ARM) || defined(loongarch64) || defined(MIPS) || defined(PPC64) || defined(RISCV64) ++#if defined(X86) || defined(X86_64) || defined(ARM) || defined(LOONGARCH64) || defined(MIPS) || defined(PPC64) || defined(RISCV64) + struct user_regs_struct *regs = (struct user_regs_struct *)memnote->data; + #endif + #ifdef ARM64 +diff --git a/src/libgcore/gcore_defs.h b/src/libgcore/gcore_defs.h +index 1a79b8f..b6f3823 100644 +--- a/src/libgcore/gcore_defs.h ++++ b/src/libgcore/gcore_defs.h +@@ -194,7 +194,7 @@ + #define Elf_Nhdr Elf64_Nhdr + #endif + +-#ifdef loongarch64 ++#ifdef LOONGARCH64 + #define ELF_EXEC_PAGESIZE PAGESIZE() + + #define ELF_MACHINE EM_LOONGARCH +@@ -367,7 +367,7 @@ extern void gcore_default_regsets_init(void); + #define REGSET_VIEW_MACHINE EM_AARCH64 + #endif + +-#ifdef loongarch64 ++#ifdef LOONGARCH64 + #define REGSET_VIEW_NAME "loongarch64" + #define REGSET_VIEW_MACHINE EM_LOONGARCH + #endif +@@ -695,21 +695,21 @@ struct user_regs_struct32{ + #endif /* GCORE_ARCH_COMPAT */ + #endif + +-#ifdef loongarch64 ++#ifdef LOONGARCH64 + struct user_regs_struct { + /* Saved main processor registers. */ + unsigned long regs[32]; + + /* Saved special registers. */ ++ unsigned long orig_a0; ++ unsigned long csr_era; ++ unsigned long csr_badvaddr; + unsigned long csr_crmd; + unsigned long csr_prmd; + unsigned long csr_euen; + unsigned long csr_ecfg; + unsigned long csr_estat; +- unsigned long csr_epc; +- unsigned long csr_badvaddr; +- unsigned long orig_a0; +- unsigned long __last[0]; ++ unsigned long reserved[5]; + } __attribute__ ((aligned (8))); + #endif + +@@ -751,13 +751,13 @@ struct user_regs_struct { + }; + #endif + +-#if defined(X86) || defined(X86_64) || defined(ARM) || defined(loongarch64) || defined(MIPS) || defined(RISCV64) ++#if defined(X86) || defined(X86_64) || defined(ARM) || defined(LOONGARCH64) || defined(MIPS) || defined(RISCV64) + typedef ulong elf_greg_t; + #define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t)) + typedef elf_greg_t elf_gregset_t[ELF_NGREG]; + #endif + +-#if defined(X86) || defined(ARM) || defined(loongarch64) || defined(MIPS) ++#if defined(X86) || defined(ARM) || defined(LOONGARCH64) || defined(MIPS) + #define PAGE_SIZE 4096 + #endif + #if defined(ARM64) || defined(PPC64) || defined(RISCV64) +diff --git a/src/libgcore/gcore_loongarch64.c b/src/libgcore/gcore_loongarch64.c +new file mode 100644 +index 0000000..921ab52 +--- /dev/null ++++ b/src/libgcore/gcore_loongarch64.c +@@ -0,0 +1,94 @@ ++/* Minimal LoongArch64 backend for crash-gcore-command ++ * ++ * This file provides the arch hooks referenced by the core dumper so that ++ * the extension can load without undefined symbols on __loongarch64. ++ * ++ * Keep behavior aligned with other minimal backends (e.g. riscv64): ++ * - no special VMA naming ++ * - no forced alwaysdump for vsyscall ++ * - no 32-bit emulation ++ * - no 32-bit emulation ++ */ ++#include "defs.h" ++#include ++#include ++#include ++ ++static int gpr_get(struct task_context *target, ++ const struct user_regset *regset, ++ unsigned int size, void *buf) ++{ ++ struct user_regs_struct *regs = (struct user_regs_struct *)buf; ++ ++ BZERO(regs, sizeof(*regs)); ++ ++ readmem(machdep->get_stacktop(target->task) - ++ SIZE(pt_regs), KVADDR, ++ regs, SIZE(pt_regs), "gpr_get: pt_regs", ++ gcore_verbose_error_handle()); ++ ++ return 0; ++} ++ ++enum gcore_regset { ++ REGSET_GPR, ++}; ++ ++static struct user_regset loongarch64_regsets[] = { ++ [REGSET_GPR] = { ++ .core_note_type = NT_PRSTATUS, ++ .name = "CORE", ++ .size = ELF_NGREG * sizeof(unsigned long), ++ .get = gpr_get, ++ }, ++}; ++ ++static const struct user_regset_view loongarch64_regset_view = { ++ .name = "loongarch64", ++ .regsets = loongarch64_regsets, ++ .n = 1, ++ .e_machine = EM_LOONGARCH, ++}; ++ ++const struct user_regset_view * ++task_user_regset_view(void) ++{ ++ return &loongarch64_regset_view; ++} ++ ++int gcore_is_arch_32bit_emulation(struct task_context *tc) ++{ ++ /* loongarch64: no 32-bit compat emulation in this context */ ++ (void)tc; ++ return FALSE; ++} ++ ++ulong gcore_arch_get_gate_vma(void) ++{ ++ /* ++ * Follow other arches' convention: if kernel exports a symbol marking ++ * VDSO/vsyscall gate, return its address; otherwise 0 (not used). ++ */ ++ if (symbol_exists("gate_vma")) ++ return symbol_value("gate_vma"); ++ return 0; ++} ++ ++char *gcore_arch_vma_name(ulong vma) ++{ ++ /* ++ * Minimal implementation: do not name VMAs specially. ++ * Returning NULL makes the generic logic fall back to defaults. ++ */ ++ (void)vma; ++ return NULL; ++} ++ ++int gcore_arch_vsyscall_has_vm_alwaysdump_flag(void) ++{ ++ /* ++ * Minimal implementation: do not force alwaysdump for vsyscall. ++ * The generic dumpfilter logic will decide based on flags. ++ */ ++ return FALSE; ++} +-- +2.43.0 + diff --git a/crash-gcore-command.spec b/crash-gcore-command.spec index 25bf35a1374266d354fb7f763fb8877b9e18028c..320d96c8b7bbb10a3e3ca045ef700ba3d570c95f 100644 --- a/crash-gcore-command.spec +++ b/crash-gcore-command.spec @@ -1,7 +1,7 @@ %global reponame crash-gcore Name: crash-gcore-command Version: 1.6.4 -Release: 6 +Release: 7 Summary: Command of Gcore for Crash utility License: GPLv2 @@ -17,6 +17,7 @@ Patch1: 0001-add-stdbool.h-to-fix-build-error.patch Patch2: 0002-add-riscv64-support.patch Patch3: 0003-support-clang-build.patch Patch4: 0004-add-loongarch64-support.patch +Patch5: 0005-add-LoongArch64-support-implementation.patch %description The crash-gcore-command packages contain an extension module for the crash utility @@ -38,6 +39,9 @@ install -D %{_builddir}/%{reponame}-%{version}/src/gcore.so %{buildroot}%{_libdi %{_libdir}/crash/extensions/gcore.so %changelog +* Thu Oct 23 2025 lijian1 - 1.6.4-7 +- add-LoongArch64-support-implementation in patch5. + * Mon Apr 07 2025 laokz - 1.6.4-6 - Fix missed riscv macro in patch4