!92 Resolve loongarch64 patch add error and add support for loongarch64

From: @dpdwaj 
Reviewed-by: @wangbin224 
Signed-off-by: @wangbin224
This commit is contained in:
openeuler-ci-bot 2024-04-23 08:33:47 +00:00 committed by Gitee
commit 0c06ccda6b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 371 additions and 350 deletions

View File

@ -1,125 +1,175 @@
From b9e0a25e29a897161360a44b1c206368f7d99310 Mon Sep 17 00:00:00 2001
From: Ming Wang <wangming01@loongson.cn>
Date: Mon, 10 Jul 2023 14:04:37 +0800
Subject: [PATCH] crash: add loongarch support.
From 0630f9aac4a41f14d1f30862ae41dd28aeb61d0e Mon Sep 17 00:00:00 2001
From: doupengda <doupengda@loongson.cn>
Date: Tue, 16 Apr 2024 01:44:30 +0000
Subject: [PATCH] crash 8.0.4 add support for loongarch64
Signed-off-by: Ming Wang <wangming01@loongson.cn>
---
Makefile | 9 +-
README | 4 +-
configure.c | 27 +-
.rh_rpm_package | 1 -
Makefile | 26 +-
README | 2 +-
configure.c | 28 +-
crash.8 | 2 +-
defs.h | 160 +-
diskdump.c | 26 +-
defs.h | 162 +-
diskdump.c | 22 +-
gdb-10.2-loongarch.patch | 15207 +++++++++++++++++++++++++++++++++++++
gdb_interface.c | 1 -
help.c | 9 +-
lkcd_vmdump_v1.h | 2 +
help.c | 2 +-
lkcd_vmdump_v1.h | 2 +-
lkcd_vmdump_v2_v3.h | 4 +-
loongarch64.c | 1347 ++++
main.c | 3 +-
netdump.c | 28 +-
netdump.c | 26 +-
ramdump.c | 2 +
symbols.c | 26 +-
16 files changed, 16836 insertions(+), 21 deletions(-)
symbols.c | 23 +-
16 files changed, 16831 insertions(+), 28 deletions(-)
delete mode 100644 .rh_rpm_package
create mode 100644 gdb-10.2-loongarch.patch
create mode 100644 loongarch64.c
diff --git a/.rh_rpm_package b/.rh_rpm_package
deleted file mode 100644
index 50c496d..0000000
--- a/.rh_rpm_package
+++ /dev/null
@@ -1 +0,0 @@
-8.0.4
diff --git a/Makefile b/Makefile
index 79aef17..d26d2e2 100644
index 6f94f25..83cff8f 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
@@ -24,7 +24,7 @@ PROGRAM=crash
# Supported targets: X86 ALPHA PPC IA64 PPC64 SPARC64
# TARGET and GDB_CONF_FLAGS will be configured automatically by configure
#
-TARGET=
+TARGET=LOONGARCH64
GDB_CONF_FLAGS=
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
@@ -35,10 +35,10 @@ endif
#
# GDB, GDB_FILES, GDB_OFILES and GDB_PATCH_FILES will be configured automatically by configure
#
-GDB=
-GDB_FILES=
-GDB_OFILES=
-GDB_PATCH_FILES=
+GDB=gdb-10.2
+GDB_FILES=${GDB_10.2_FILES}
+GDB_OFILES=${GDB_10.2_OFILES}
+GDB_PATCH_FILES=gdb-10.2.patch
#
# Default installation directory
@@ -65,7 +65,7 @@ CFILES=main.c tools.c global_data.c memory.c filesys.c help.c task.c \
kernel.c test.c gdb_interface.c configure.c net.c dev.c bpf.c \
printk.c \
alpha.c x86.c ppc.c ia64.c s390.c s390x.c s390dbf.c ppc64.c x86_64.c \
- arm.c arm64.c mips.c mips64.c sparc64.c \
+ arm.c arm64.c mips.c mips64.c sparc64.c loongarch64.c\
- arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c \
+ arm.c arm64.c mips.c mips64.c riscv64.c sparc64.c loongarch64.c \
extensions.c remote.c va_server.c va_server_v1.c symbols.c cmdline.c \
lkcd_common.c lkcd_v1.c lkcd_v2_v3.c lkcd_v5.c lkcd_v7.c lkcd_v8.c\
lkcd_fix_mem.c s390_dump.c lkcd_x86_trace.c \
@@ -84,7 +84,7 @@ OBJECT_FILES=main.o tools.o global_data.o memory.o filesys.o help.o task.o \
@@ -85,7 +85,7 @@ OBJECT_FILES=main.o tools.o global_data.o memory.o filesys.o help.o task.o \
build_data.o kernel.o test.o gdb_interface.o net.o dev.o bpf.o \
printk.o \
alpha.o x86.o ppc.o ia64.o s390.o s390x.o s390dbf.o ppc64.o x86_64.o \
- arm.o arm64.o mips.o mips64.o sparc64.o \
+ arm.o arm64.o mips.o mips64.o sparc64.o loongarch64.o\
- arm.o arm64.o mips.o mips64.o riscv64.o sparc64.o \
+ arm.o arm64.o mips.o mips64.o riscv64.o sparc64.o loongarch64.o \
extensions.o remote.o va_server.o va_server_v1.o symbols.o cmdline.o \
lkcd_common.o lkcd_v1.o lkcd_v2_v3.o lkcd_v5.o lkcd_v7.o lkcd_v8.o \
lkcd_fix_mem.o s390_dump.o netdump.o diskdump.o makedumpfile.o xendump.o \
@@ -292,6 +292,8 @@ gdb_unzip:
@@ -190,7 +190,7 @@ GDB_10.2_OFILES=${GDB}/gdb/symtab.o crash_target.o
#
# GDB_FLAGS is passed up from the gdb Makefile.
#
-GDB_FLAGS=
+GDB_FLAGS=-DGDB_10_2
#
# WARNING_OPTIONS and WARNING_ERROR are both applied on a per-file basis.
@@ -207,7 +207,7 @@ TARGET_CFLAGS=
CRASH_CFLAGS=-g -D${TARGET} ${TARGET_CFLAGS} ${GDB_FLAGS} ${CFLAGS}
-GPL_FILES=
+GPL_FILES=COPYING3
TAR_FILES=${SOURCE_FILES} Makefile ${GPL_FILES} README .rh_rpm_package crash.8 \
${EXTENSION_SOURCE_FILES} ${MEMORY_DRIVER_FILES}
CSCOPE_FILES=${SOURCE_FILES}
@@ -292,7 +292,9 @@ gdb_unzip:
gdb_patch:
if [ -f ${GDB}.patch ] && [ -s ${GDB}.patch ]; then \
patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
- patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
+ patch -p0 < ${GDB}.patch; cp ${GDB}.patch ${GDB}; fi
+ if [ -f ${GDB}-loongarch.patch ] && [ -s ${GDB}-loongarch.patch ]; then \
+ patch -p0 < ${GDB}-loongarch.patch; cp ${GDB}-loongarch.patch ${GDB}; fi
library: ${OBJECT_FILES}
ar -rs ${PROGRAM}lib.a ${OBJECT_FILES}
@@ -441,6 +443,9 @@ mips64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} mips64.c
@@ -445,6 +447,10 @@ riscv64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} riscv64.c
sparc64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} sparc64.c
${CC} -c ${CRASH_CFLAGS} sparc64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+loongarch64.o: ${GENERIC_HFILES} ${REDHAT_HFILES} loongarch64.c
+ ${CC} -c ${CRASH_CFLAGS} loongarch64.c ${WARNING_OPTIONS} ${WARNING_ERROR}
+
+
s390.o: ${GENERIC_HFILES} ${IBM_HFILES} s390.c
${CC} -c ${CRASH_CFLAGS} s390.c ${WARNING_OPTIONS} ${WARNING_ERROR}
diff --git a/README b/README
index 1f98fbf..de3bdf9 100644
index 6ecdd10..4392712 100644
--- a/README
+++ b/README
@@ -37,8 +37,8 @@
@@ -37,7 +37,7 @@
These are the current prerequisites:
o At this point, x86, ia64, x86_64, ppc64, ppc, arm, arm64, alpha, mips,
- mips64, s390 and s390x-based kernels are supported. Other architectures
- may be addressed in the future.
+ mips64, loongarch64, s390 and s390x-based kernels are supported. Other
+ architectures may be addressed in the future.
- mips64, riscv64, s390 and s390x-based kernels are supported. Other
+ mips64, riscv64, loongarch64, s390 and s390x-based kernels are supported. Other
architectures may be addressed in the future.
o One size fits all -- the utility can be run on any Linux kernel version
version dating back to 2.2.5-15. A primary design goal is to always
diff --git a/configure.c b/configure.c
index 5188851..9d038f5 100644
index 08b52be..a6895ec 100644
--- a/configure.c
+++ b/configure.c
@@ -107,6 +107,7 @@ void add_extra_lib(char *);
#undef MIPS
@@ -108,6 +108,7 @@ void add_extra_lib(char *);
#undef SPARC64
#undef MIPS64
#undef RISCV64
+#undef LOONGARCH64
#define UNKNOWN 0
#define X86 1
@@ -122,6 +123,7 @@ void add_extra_lib(char *);
#define MIPS 11
@@ -124,6 +125,7 @@ void add_extra_lib(char *);
#define SPARC64 12
#define MIPS64 13
+#define LOONGARCH64 14
#define RISCV64 14
+#define LOONGARCH64 15
#define TARGET_X86 "TARGET=X86"
#define TARGET_ALPHA "TARGET=ALPHA"
@@ -136,6 +138,7 @@ void add_extra_lib(char *);
#define TARGET_MIPS "TARGET=MIPS"
@@ -139,6 +141,7 @@ void add_extra_lib(char *);
#define TARGET_MIPS64 "TARGET=MIPS64"
#define TARGET_SPARC64 "TARGET=SPARC64"
#define TARGET_RISCV64 "TARGET=RISCV64"
+#define TARGET_LOONGARCH64 "TARGET=LOONGARCH64"
#define TARGET_CFLAGS_X86 "TARGET_CFLAGS=-D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_ALPHA "TARGET_CFLAGS="
@@ -158,6 +161,7 @@ void add_extra_lib(char *);
#define TARGET_CFLAGS_MIPS_ON_X86_64 "TARGET_CFLAGS=-m32 -D_FILE_OFFSET_BITS=64"
#define TARGET_CFLAGS_MIPS64 "TARGET_CFLAGS="
@@ -163,6 +166,7 @@ void add_extra_lib(char *);
#define TARGET_CFLAGS_SPARC64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_RISCV64 "TARGET_CFLAGS="
#define TARGET_CFLAGS_RISCV64_ON_X86_64 "TARGET_CFLAGS="
+#define TARGET_CFLAGS_LOONGARCH64 "TARGET_CFLAGS="
#define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS="
#define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux"
@@ -404,6 +408,9 @@ get_current_configuration(struct supported_gdb_version *sp)
#ifdef __sparc_v9__
target_data.target = SPARC64;
@@ -413,6 +417,9 @@ get_current_configuration(struct supported_gdb_version *sp)
#if defined(__riscv) && (__riscv_xlen == 64)
target_data.target = RISCV64;
#endif
+#ifdef __loongarch64
+ target_data.target = LOONGARCH64;
@ -127,20 +177,21 @@ index 5188851..9d038f5 100644
set_initial_target(sp);
@@ -497,6 +504,10 @@ get_current_configuration(struct supported_gdb_version *sp)
(target_data.target != MIPS64))
arch_mismatch(sp);
+ if ((target_data.initial_gdb_target == LOONGARCH64) &&
+ (target_data.target != LOONGARCH64))
@@ -472,7 +479,10 @@ get_current_configuration(struct supported_gdb_version *sp)
* Build an RISCV64 crash binary on an X86_64 host.
*/
target_data.target = RISCV64;
- } else {
+ } else if ((target_data.initial_gdb_target == LOONGARCH64) &&
+ (target_data.target != LOONGARCH64)) {
+ arch_mismatch(sp);
+
if ((target_data.initial_gdb_target == X86) &&
(target_data.target != X86)) {
if (target_data.target == X86_64)
@@ -660,6 +671,9 @@ show_configuration(void)
case SPARC64:
printf("TARGET: SPARC64\n");
+ } else {
fprintf(stderr,
"\ntarget=%s is not supported on the %s host architecture\n\n",
target_data.target_as_param,
@@ -686,6 +696,9 @@ show_configuration(void)
case RISCV64:
printf("TARGET: RISCV64\n");
break;
+ case LOONGARCH64:
+ printf("TARGET: LOONGARCH64\n");
@ -148,9 +199,9 @@ index 5188851..9d038f5 100644
}
if (strlen(target_data.program)) {
@@ -777,6 +791,10 @@ build_configure(struct supported_gdb_version *sp)
target = TARGET_SPARC64;
target_CFLAGS = TARGET_CFLAGS_SPARC64;
@@ -811,6 +824,10 @@ build_configure(struct supported_gdb_version *sp)
} else
target_CFLAGS = TARGET_CFLAGS_RISCV64;
break;
+ case LOONGARCH64:
+ target = TARGET_LOONGARCH64;
@ -159,36 +210,36 @@ index 5188851..9d038f5 100644
}
ldflags = get_extra_flags("LDFLAGS.extra", NULL);
@@ -1374,7 +1392,7 @@ make_spec_file(struct supported_gdb_version *sp)
@@ -1408,7 +1425,7 @@ make_spec_file(struct supported_gdb_version *sp)
printf("Vendor: Red Hat, Inc.\n");
printf("Packager: Dave Anderson <anderson@redhat.com>\n");
printf("ExclusiveOS: Linux\n");
- printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64\n");
+ printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 loongarch64\n");
- printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64\n");
+ printf("ExclusiveArch: %%{ix86} alpha ia64 ppc ppc64 ppc64pseries ppc64iseries x86_64 s390 s390x arm aarch64 ppc64le mips mipsel mips64el sparc64 riscv64 loongarch64\n");
printf("Buildroot: %%{_tmppath}/%%{name}-root\n");
printf("BuildRequires: ncurses-devel zlib-devel bison\n");
printf("Requires: binutils\n");
@@ -1613,6 +1631,8 @@ set_initial_target(struct supported_gdb_version *sp)
target_data.initial_gdb_target = MIPS;
else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0)
target_data.initial_gdb_target = SPARC64;
@@ -1643,6 +1660,8 @@ set_initial_target(struct supported_gdb_version *sp)
target_data.initial_gdb_target = ARM;
else if (strncmp(buf, "MIPS64", strlen("MIPS64")) == 0)
target_data.initial_gdb_target = MIPS64;
+ else if (strncmp(buf, "LOONGARCH64", strlen("LOONGARCH64")) == 0)
+ target_data.initial_gdb_target = LOONGARCH64;
}
char *
@@ -1633,6 +1653,7 @@ target_to_name(int target)
case MIPS: return("MIPS");
else if (strncmp(buf, "MIPS", strlen("MIPS")) == 0)
target_data.initial_gdb_target = MIPS;
else if (strncmp(buf, "SPARC64", strlen("SPARC64")) == 0)
@@ -1670,6 +1689,7 @@ target_to_name(int target)
case MIPS64: return("MIPS64");
case SPARC64: return("SPARC64");
case RISCV64: return("RISCV64");
+ case LOONGARCH64: return("LOONGARCH64");
}
return "UNKNOWN";
@@ -1697,6 +1718,10 @@ name_to_target(char *name)
return MIPS64;
else if (strncmp(name, "sparc64", strlen("sparc64")) == 0)
return SPARC64;
@@ -1738,6 +1758,10 @@ name_to_target(char *name)
return RISCV64;
else if (strncmp(name, "riscv64", strlen("riscv64")) == 0)
return RISCV64;
+ else if (strncmp(name, "loongarch64", strlen("loongarch64")) == 0)
+ return LOONGARCH64;
+ else if (strncmp(name, "LOONGARCH64", strlen("LOONGARCH64")) == 0)
@ -197,7 +248,7 @@ index 5188851..9d038f5 100644
return UNKNOWN;
}
diff --git a/crash.8 b/crash.8
index e553a0b..0662f92 100644
index e553a0b..bcd492d 100644
--- a/crash.8
+++ b/crash.8
@@ -491,7 +491,7 @@ Search for the kernel source code in directory instead of in the
@ -205,44 +256,44 @@ index e553a0b..0662f92 100644
.TP
.BI --kaslr \ offset | auto
-If an x86_64 kernel was configured with
+If an x86, x86_64, s390x or loongarch64 kernel was configured with
+If an x86_64 loongarch64 kernel was configured with
.B CONFIG_RANDOMIZE_BASE,
the offset value is equal to the difference between the symbol values
compiled into the vmlinux file and their relocated KASLR values. If set to
diff --git a/defs.h b/defs.h
index afdcf6c..dc8f2e0 100644
index deef1d5..2d1ef9a 100644
--- a/defs.h
+++ b/defs.h
@@ -76,7 +76,7 @@
#if !defined(X86) && !defined(X86_64) && !defined(ALPHA) && !defined(PPC) && \
!defined(IA64) && !defined(PPC64) && !defined(S390) && !defined(S390X) && \
!defined(ARM) && !defined(ARM64) && !defined(MIPS) && !defined(MIPS64) && \
- !defined(SPARC64)
+ !defined(SPARC64) && !defined(LOONGARCH64)
- !defined(RISCV64) && !defined(SPARC64)
+ !defined(RISCV64) && !defined(SPARC64) && !defined(LOONGARCH64)
#ifdef __alpha__
#define ALPHA
#endif
@@ -118,6 +118,9 @@
#ifdef __sparc_v9__
#define SPARC64
@@ -108,6 +108,9 @@
#ifdef __aarch64__
#define ARM64
#endif
+#ifdef __loongarch64
+#define LOONGARCH64
+#endif
#endif
#ifdef X86
#ifdef __mipsel__
#ifndef __mips64
#define MIPS
@@ -159,6 +162,9 @@
#ifdef SPARC64
#define NR_CPUS (4096)
#ifdef MIPS64
#define NR_CPUS (256)
#endif
+#ifdef LOONGARCH64
+#define NR_CPUS (256)
+#endif
#define NR_DEVICE_DUMPS (64)
@@ -2005,6 +2011,8 @@ struct offset_table { /* stash of commonly-used offsets */
#ifdef SPARC64
#define NR_CPUS (4096)
#endif
@@ -2016,6 +2022,8 @@ struct offset_table { /* stash of commonly-used offsets */
long atomic_t_counter;
long percpu_counter_count;
long mm_struct_mm_count;
@ -251,9 +302,9 @@ index afdcf6c..dc8f2e0 100644
long task_struct_thread_reg29;
long task_struct_thread_reg31;
long pt_regs_regs;
@@ -3484,6 +3492,43 @@ struct arm64_stackframe {
#define _MAX_PHYSMEM_BITS 48
#endif /* MIPS64 */
@@ -3498,6 +3506,44 @@ struct arm64_stackframe {
#endif /* ARM64 */
+#ifdef LOONGARCH64
+#define _64BIT_
@ -292,10 +343,11 @@ index afdcf6c..dc8f2e0 100644
+#define _MAX_PHYSMEM_BITS 48
+#endif /* LOONGARCH64 */
+
#ifdef X86
+
#ifdef MIPS
#define _32BIT_
#define MACHINE_TYPE "X86"
@@ -4532,6 +4577,10 @@ struct machine_specific {
#define MACHINE_TYPE "MIPS"
@@ -4770,6 +4816,10 @@ struct machine_specific {
#define MAX_HEXADDR_STRLEN (16)
#define UVADDR_PRLEN (16)
#endif
@ -306,19 +358,20 @@ index afdcf6c..dc8f2e0 100644
#define BADADDR ((ulong)(-1))
#define BADVAL ((ulong)(-1))
@@ -5130,6 +5179,9 @@ void dump_build_data(void);
@@ -5391,6 +5441,10 @@ void dump_build_data(void);
#ifdef SPARC64
#define machdep_init(X) sparc64_init(X)
#endif
+#ifdef LOONGARCH64
+#define machdep_init(X) loongarch64_init(X)
+#endif
+
int clean_exit(int);
int untrusted_file(FILE *, char *);
char *readmem_function_name(void);
@@ -5607,6 +5659,9 @@ void display_help_screen(char *);
#ifdef SPARC64
#define dump_machdep_table(X) sparc64_dump_machdep_table(X)
@@ -5882,6 +5936,9 @@ void display_help_screen(char *);
#ifdef RISCV64
#define dump_machdep_table(X) riscv64_dump_machdep_table(X)
#endif
+#ifdef LOONGARCH64
+#define dump_machdep_table(X) loongarch64_dump_machdep_table(X)
@ -326,7 +379,7 @@ index afdcf6c..dc8f2e0 100644
extern char *help_pointer[];
extern char *help_alias[];
extern char *help_ascii[];
@@ -6695,6 +6750,109 @@ int sparc64_vmalloc_addr(ulong);
@@ -7086,6 +7143,109 @@ int sparc64_vmalloc_addr(ulong);
error(FATAL, "The -d option is not applicable to sparc64.\n")
#endif
@ -437,12 +490,12 @@ index afdcf6c..dc8f2e0 100644
* netdump.c
*/
diff --git a/diskdump.c b/diskdump.c
index 2c1f9be..b3fbe8f 100644
index 7fbbbf5..8a20f5d 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -622,6 +622,9 @@ restart:
else if (STRNEQ(header->utsname.machine, "aarch64") &&
machine_type_mismatch(file, "ARM64", NULL, 0))
@@ -686,6 +686,9 @@ restart:
else if (STRNEQ(header->utsname.machine, "riscv64") &&
machine_type_mismatch(file, "RISCV64", NULL, 0))
goto err;
+ else if (STRNEQ(header->utsname.machine, "loongarch64") &&
+ machine_type_mismatch(file, "LOONGARCH64", NULL, 0))
@ -450,16 +503,16 @@ index 2c1f9be..b3fbe8f 100644
if (header->block_size != block_size) {
block_size = header->block_size;
@@ -780,6 +783,8 @@ restart:
dd->machine_type = EM_AARCH64;
else if (machine_type("SPARC64"))
@@ -846,6 +849,8 @@ restart:
dd->machine_type = EM_SPARCV9;
else if (machine_type("RISCV64"))
dd->machine_type = EM_RISCV;
+ else if (machine_type("LOONGARCH64"))
+ dd->machine_type = EM_LOONGARCH;
else {
error(INFO, "%s: unsupported machine type: %s\n",
DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
@@ -1526,6 +1531,12 @@ get_diskdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
@@ -1600,6 +1605,12 @@ get_diskdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
machdep->get_stack_frame(bt, eip, esp);
}
@ -470,30 +523,28 @@ index 2c1f9be..b3fbe8f 100644
+}
+
static void
get_diskdump_regs_sparc64(struct bt_info *bt, ulong *eip, ulong *esp)
get_diskdump_regs_riscv64(struct bt_info *bt, ulong *eip, ulong *esp)
{
@@ -1605,6 +1616,10 @@ get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
get_diskdump_regs_sparc64(bt, eip, esp);
@@ -1688,6 +1699,9 @@ get_diskdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
case EM_RISCV:
get_diskdump_regs_riscv64(bt, eip, esp);
break;
+ case EM_LOONGARCH:
+ get_diskdump_regs_loongarch64(bt, eip, esp);
+ break;
+
default:
error(FATAL, "%s: unsupported machine type: %s\n",
DISKDUMP_VALID() ? "diskdump" : "compressed kdump",
@@ -1751,7 +1766,8 @@ dump_note_offsets(FILE *fp)
qemu = FALSE;
@@ -1836,7 +1850,7 @@ dump_note_offsets(FILE *fp)
if (machine_type("X86_64") || machine_type("S390X") ||
machine_type("ARM64") || machine_type("PPC64") ||
- machine_type("SPARC64") || machine_type("MIPS64")) {
+ machine_type("SPARC64") || machine_type("MIPS64") ||
+ machine_type("LOONGARCH64")) {
machine_type("SPARC64") || machine_type("MIPS64") ||
- machine_type("RISCV64")) {
+ machine_type("RISCV64") || machine_type("LOONGARCH64")) {
note64 = (void *)dd->notes_buf + tot;
len = sizeof(Elf64_Nhdr);
if (STRNEQ((char *)note64 + len, "QEMU"))
@@ -1862,6 +1878,8 @@ __diskdump_memory_dump(FILE *fp)
@@ -1947,6 +1961,8 @@ __diskdump_memory_dump(FILE *fp)
fprintf(fp, "(EM_AARCH64)\n"); break;
case EM_SPARCV9:
fprintf(fp, "(EM_SPARCV9)\n"); break;
@ -502,23 +553,21 @@ index 2c1f9be..b3fbe8f 100644
default:
fprintf(fp, "(unknown)\n"); break;
}
@@ -2548,6 +2566,9 @@ diskdump_display_regs(int cpu, FILE *ofp)
@@ -2633,6 +2649,8 @@ diskdump_display_regs(int cpu, FILE *ofp)
if (machine_type("MIPS64"))
mips64_display_regs_from_elf_notes(cpu, ofp);
+
+ if (machine_type("LOONGARCH64"))
+ loongarch64_display_regs_from_elf_notes(cpu, ofp);
}
void
@@ -2558,7 +2579,8 @@ dump_registers_for_compressed_kdump(void)
if (!KDUMP_CMPRS_VALID() || (dd->header->header_version < 4) ||
@@ -2644,7 +2662,7 @@ dump_registers_for_compressed_kdump(void)
!(machine_type("X86") || machine_type("X86_64") ||
machine_type("ARM64") || machine_type("PPC64") ||
- machine_type("MIPS") || machine_type("MIPS64")))
+ machine_type("MIPS") || machine_type("MIPS64") ||
+ machine_type("LOONGARCH64")))
machine_type("MIPS") || machine_type("MIPS64") ||
- machine_type("RISCV64")))
+ machine_type("RISCV64") || machine_type("LOONGARCH64")))
error(FATAL, "-r option not supported for this dumpfile\n");
if (machine_type("ARM64") && (kt->cpus != dd->num_prstatus_notes))
@ -15735,80 +15784,53 @@ index 0000000..d5a65d0
+--
+2.33.0
+
diff --git a/gdb_interface.c b/gdb_interface.c
index b14319c..e7b65ac 100644
--- a/gdb_interface.c
+++ b/gdb_interface.c
@@ -973,7 +973,6 @@ gdb_error_debug(void)
}
-
/*
* gdb callback to access debug mode.
*/
diff --git a/help.c b/help.c
index 99214c1..3662dad 100644
index cc7ab20..c36a6f1 100644
--- a/help.c
+++ b/help.c
@@ -336,10 +336,11 @@ char *program_usage_info[] = {
@@ -336,7 +336,7 @@ char *program_usage_info[] = {
" and verification. The default count is 32768.",
"",
" --kaslr offset | auto",
- " If x86, x86_64 or s390x kernel was configured with CONFIG_RANDOMIZE_BASE,",
- " the offset value is equal to the difference between the symbol values ",
- " compiled into the vmlinux file and their relocated KASLR value. If",
- " set to auto, the KASLR offset value will be automatically calculated.",
+ " If x86, x86_64, s390x or loongarch64 kernel was configured with",
+ " CONFIG_RANDOMIZE_BASE, the offset value is equal to the difference",
+ " between the symbol values compiled into the vmlinux file and their",
+ " relocated KASLR value. If set to auto, the KASLR offset value will",
+ " be automatically calculated.",
"",
" --minimal",
" Bring up a session that is restricted to the log, dis, rd, sym,",
+ " If x86, x86_64 loongarch64 or s390x kernel was configured with CONFIG_RANDOMIZE_BASE,",
" the offset value is equal to the difference between the symbol values ",
" compiled into the vmlinux file and their relocated KASLR value. If",
" set to auto, the KASLR offset value will be automatically calculated.",
diff --git a/lkcd_vmdump_v1.h b/lkcd_vmdump_v1.h
index 4933427..841f150 100644
index 98ee094..3ffb219 100644
--- a/lkcd_vmdump_v1.h
+++ b/lkcd_vmdump_v1.h
@@ -118,10 +118,12 @@ typedef struct _dump_header_s {
#ifndef S390
#ifndef S390X
#ifndef ARM64
+#ifndef LOONGARCH64
@@ -114,7 +114,7 @@ typedef struct _dump_header_s {
struct new_utsname dh_utsname;
/* the dump registers */
-#if !defined(IA64) && !defined(S390) && !defined(S390X) && !defined(ARM64) && !defined(RISCV64)
+#if !defined(IA64) && !defined(S390) && !defined(S390X) && !defined(ARM64) && !defined(RISCV64) && !defined(LOONGARCH64)
struct pt_regs dh_regs;
#endif
#endif
#endif
+#endif
#endif
/* the address of the current task */
diff --git a/lkcd_vmdump_v2_v3.h b/lkcd_vmdump_v2_v3.h
index 984c2c2..ab395ea 100644
index ef3067f..2113c59 100644
--- a/lkcd_vmdump_v2_v3.h
+++ b/lkcd_vmdump_v2_v3.h
@@ -37,7 +37,7 @@
#if defined(ARM) || defined(X86) || defined(PPC) || defined(S390) || \
defined(S390X) || defined(ARM64) || defined(MIPS) || \
- defined(MIPS64) || defined(SPARC64)
+ defined(MIPS64) || defined(SPARC64) || defined(LOONGARCH64)
- defined(MIPS64) || defined(SPARC64) || defined(RISCV64)
+ defined(MIPS64) || defined(SPARC64) || defined(RISCV64) || defined(LOONGARCH64)
/*
* Kernel header file for Linux crash dumps.
@@ -87,10 +87,12 @@ typedef struct _dump_header_asm_s {
#ifndef S390
#ifndef S390X
#ifndef ARM64
+#ifndef LOONGARCH64
@@ -84,7 +84,7 @@ typedef struct _dump_header_asm_s {
uint32_t dha_eip;
/* the dump registers */
-#if !defined(S390) && !defined(S390X) && !defined(ARM64) && !defined(RISCV64)
+#if !defined(S390) && !defined(S390X) && !defined(ARM64) && !defined(RISCV64) && !defined(LOONGARCH64)
struct pt_regs dha_regs;
#endif
#endif
#endif
+#endif
} dump_header_asm_t;
diff --git a/loongarch64.c b/loongarch64.c
new file mode 100644
@ -17164,45 +17186,44 @@ index 0000000..09df05a
+
+#endif /* !LOONGARCH64 */
diff --git a/main.c b/main.c
index b278c22..a70fd5e 100644
index 4fd4ca5..71bcc15 100644
--- a/main.c
+++ b/main.c
@@ -228,7 +228,8 @@ main(int argc, char **argv)
} else if (STREQ(long_options[option_index].name, "kaslr")) {
if (!machine_type("X86_64") &&
!machine_type("ARM64") && !machine_type("X86") &&
- !machine_type("S390X"))
+ !machine_type("S390X") &&
- !machine_type("S390X") && !machine_type("RISCV64"))
+ !machine_type("S390X") && !machine_type("RISCV64") &&
+ !machine_type("LOONGARCH64"))
error(INFO, "--kaslr not valid "
"with this machine type.\n");
else if (STREQ(optarg, "auto"))
diff --git a/netdump.c b/netdump.c
index ff273b4..f8ce939 100644
index 3907863..e977ae8 100644
--- a/netdump.c
+++ b/netdump.c
@@ -42,6 +42,7 @@ static void get_netdump_regs_ppc64(struct bt_info *, ulong *, ulong *);
static void get_netdump_regs_arm(struct bt_info *, ulong *, ulong *);
@@ -43,6 +43,7 @@ static void get_netdump_regs_arm(struct bt_info *, ulong *, ulong *);
static void get_netdump_regs_arm64(struct bt_info *, ulong *, ulong *);
static void get_netdump_regs_mips(struct bt_info *, ulong *, ulong *);
static void get_netdump_regs_riscv(struct bt_info *, ulong *, ulong *);
+static void get_netdump_regs_loongarch64(struct bt_info *, ulong *, ulong *);
static void check_dumpfile_size(char *);
static int proc_kcore_init_32(FILE *, int);
static int proc_kcore_init_64(FILE *, int);
@@ -300,6 +301,12 @@ is_netdump(char *file, ulong source_query)
@@ -217,6 +218,11 @@ is_netdump(char *file, ulong source_query)
source_query))
goto bailout;
break;
+ case EM_LOONGARCH:
+ if (machine_type_mismatch(file, "LOONGARCH64", NULL,
+ source_query))
+ goto bailout;
+ break;
+
default:
if (machine_type_mismatch(file, "(unknown)", NULL,
source_query))
@@ -1482,6 +1489,9 @@ dump_Elf32_Ehdr(Elf32_Ehdr *elf)
@@ -1493,6 +1499,9 @@ dump_Elf32_Ehdr(Elf32_Ehdr *elf)
case EM_MIPS:
netdump_print("(EM_MIPS)\n");
break;
@ -17212,7 +17233,7 @@ index ff273b4..f8ce939 100644
default:
netdump_print("(unsupported)\n");
break;
@@ -1644,6 +1654,9 @@ dump_Elf64_Ehdr(Elf64_Ehdr *elf)
@@ -1655,6 +1664,9 @@ dump_Elf64_Ehdr(Elf64_Ehdr *elf)
case EM_AARCH64:
netdump_print("(EM_AARCH64)\n");
break;
@ -17222,8 +17243,8 @@ index ff273b4..f8ce939 100644
default:
netdump_print("(unsupported)\n");
break;
@@ -2669,6 +2682,10 @@ get_netdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
return get_netdump_regs_mips(bt, eip, esp);
@@ -2684,6 +2696,10 @@ get_netdump_regs(struct bt_info *bt, ulong *eip, ulong *esp)
get_netdump_regs_riscv(bt, eip, esp);
break;
+ case EM_LOONGARCH:
@ -17233,26 +17254,25 @@ index ff273b4..f8ce939 100644
default:
error(FATAL,
"support for ELF machine type %d not available\n",
@@ -2925,6 +2942,8 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
mips_display_regs_from_elf_notes(cpu, ofp);
} else if (machine_type("MIPS64")) {
@@ -2942,6 +2958,8 @@ display_regs_from_elf_notes(int cpu, FILE *ofp)
mips64_display_regs_from_elf_notes(cpu, ofp);
} else if (machine_type("RISCV64")) {
riscv64_display_regs_from_elf_notes(cpu, ofp);
+ } else if (machine_type("LOONGARCH64")) {
+ loongarch64_display_regs_from_elf_notes(cpu, ofp);
}
}
@@ -2935,7 +2954,8 @@ dump_registers_for_elf_dumpfiles(void)
@@ -2953,7 +2971,7 @@ dump_registers_for_elf_dumpfiles(void)
if (!(machine_type("X86") || machine_type("X86_64") ||
machine_type("ARM64") || machine_type("PPC64") ||
- machine_type("MIPS") || machine_type("MIPS64")))
+ machine_type("MIPS") || machine_type("MIPS64") ||
+ machine_type("LOONGARCH64")))
machine_type("MIPS") || machine_type("MIPS64") ||
- machine_type("RISCV64")))
+ machine_type("RISCV64") || machine_type("LOONGARCH64")))
error(FATAL, "-r option not supported for this dumpfile\n");
if (NETDUMP_DUMPFILE()) {
@@ -3870,6 +3890,12 @@ get_netdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
@@ -3888,6 +3906,12 @@ get_netdump_regs_mips(struct bt_info *bt, ulong *eip, ulong *esp)
machdep->get_stack_frame(bt, eip, esp);
}
@ -17262,46 +17282,45 @@ index ff273b4..f8ce939 100644
+ machdep->get_stack_frame(bt, eip, esp);
+}
+
int
is_partial_netdump(void)
static void
get_netdump_regs_riscv(struct bt_info *bt, ulong *eip, ulong *esp)
{
diff --git a/ramdump.c b/ramdump.c
index a206fcb..c32d9fd 100644
index d2bd7ff..4b03f0f 100644
--- a/ramdump.c
+++ b/ramdump.c
@@ -188,6 +188,8 @@ char *ramdump_to_elf(void)
e_machine = EM_MIPS;
else if (machine_type("X86_64"))
@@ -190,6 +190,8 @@ char *ramdump_to_elf(void)
e_machine = EM_X86_64;
else if (machine_type("RISCV64"))
e_machine = EM_RISCV;
+ else if (machine_type("LOONGARCH64"))
+ e_machine = EM_LOONGARCH;
else
error(FATAL, "ramdump: unsupported machine type: %s\n",
MACHINE_TYPE);
diff --git a/symbols.c b/symbols.c
index 42c4eb4..4bdeaf7 100644
index 8e8b4c3..83fa061 100644
--- a/symbols.c
+++ b/symbols.c
@@ -593,7 +593,8 @@ kaslr_init(void)
@@ -629,7 +629,7 @@ kaslr_init(void)
char *string;
if ((!machine_type("X86_64") && !machine_type("ARM64") && !machine_type("X86") &&
- !machine_type("S390X")) || (kt->flags & RELOC_SET))
+ !machine_type("S390X") && !machine_type("LOONGARCH64")) ||
+ (kt->flags & RELOC_SET))
- !machine_type("S390X") && !machine_type("RISCV64")) || (kt->flags & RELOC_SET))
+ !machine_type("S390X") && !machine_type("RISCV64") && !machine_type("LOONGARCH64")) || (kt->flags & RELOC_SET))
return;
if (!kt->vmcoreinfo._stext_SYMBOL &&
@@ -759,7 +760,7 @@ store_symbols(bfd *abfd, int dynamic, void *minisyms, long symcount,
@@ -795,7 +795,7 @@ store_symbols(bfd *abfd, int dynamic, void *minisyms, long symcount,
} else if (!(kt->flags & RELOC_SET))
kt->flags |= RELOC_FORCE;
} else if (machine_type("X86_64") || machine_type("ARM64") ||
- machine_type("S390X")) {
+ machine_type("S390X") || machine_type("LOONGARCH64")) {
- machine_type("S390X") || machine_type("RISCV64")) {
+ machine_type("S390X") || machine_type("RISCV64") || machine_type("LOONGARCH64")) {
if ((kt->flags2 & RELOC_AUTO) && !(kt->flags & RELOC_SET))
derive_kaslr_offset(abfd, dynamic, from,
fromend, size, store);
@@ -831,7 +832,8 @@ store_sysmap_symbols(void)
@@ -867,7 +867,8 @@ store_sysmap_symbols(void)
strerror(errno));
if (!machine_type("X86") && !machine_type("X86_64") &&
@ -17311,7 +17330,7 @@ index 42c4eb4..4bdeaf7 100644
kt->flags &= ~RELOC_SET;
first = 0;
@@ -2490,9 +2492,11 @@ store_module_kallsyms_v2(struct load_module *lm, int start, int curr,
@@ -2976,9 +2977,11 @@ store_module_kallsyms_v2(struct load_module *lm, int start, int curr,
/*
* On ARM/ARM64 we have linker mapping symbols like '$a'
* or '$x' for ARM64, and '$d'.
@ -17324,23 +17343,21 @@ index 42c4eb4..4bdeaf7 100644
!machdep->verify_symbol(nameptr, ec->st_value, ec->st_info))
continue;
@@ -3694,6 +3698,11 @@ is_kernel(char *file)
@@ -4228,6 +4231,10 @@ is_kernel(char *file)
if (machine_type_mismatch(file, "SPARC64", NULL, 0))
goto bailout;
break;
+ case EM_LOONGARCH:
+ if (machine_type_mismatch(file, "LOONGARCH64", NULL, 0))
+ goto bailout;
+ break;
+
default:
if (machine_type_mismatch(file, "(unknown)", NULL, 0))
goto bailout;
@@ -4002,6 +4011,11 @@ is_shared_object(char *file)
if (machine_type("MIPS64"))
@@ -4495,6 +4502,10 @@ is_shared_object(char *file)
if (machine_type("PPC"))
return TRUE;
break;
+
+ case EM_LOONGARCH:
+ if (machine_type("LOONGARCH64"))
+ return TRUE;
@ -17348,17 +17365,17 @@ index 42c4eb4..4bdeaf7 100644
}
if (CRASHDEBUG(1))
@@ -8818,6 +8832,10 @@ dump_offset_table(char *spec, ulong makestruct)
OFFSET(task_struct_thread_esp));
fprintf(fp, " task_struct_thread_ksp: %ld\n",
OFFSET(task_struct_thread_ksp));
@@ -9786,6 +9797,10 @@ dump_offset_table(char *spec, ulong makestruct)
OFFSET(task_struct_tss_esp));
fprintf(fp, " task_struct_tss_ksp: %ld\n",
OFFSET(task_struct_tss_ksp));
+ fprintf(fp, " task_struct_thread_reg01: %ld\n",
+ OFFSET(task_struct_thread_reg01));
+ fprintf(fp, " task_struct_thread_reg03: %ld\n",
+ OFFSET(task_struct_thread_reg03));
fprintf(fp, " task_struct_thread_reg29: %ld\n",
OFFSET(task_struct_thread_reg29));
fprintf(fp, " task_struct_thread_reg31: %ld\n",
fprintf(fp, " task_struct_thread_eip: %ld\n",
OFFSET(task_struct_thread_eip));
fprintf(fp, " inactive_task_frame_bp: %ld\n", OFFSET(inactive_task_frame_bp));
--
2.33.0
2.43.0

View File

@ -1,6 +1,6 @@
Name: crash
Version: 8.0.4
Release: 1
Release: 2
Summary: Linux kernel crash utility.
License: GPLv3
URL: https://crash-utility.github.io
@ -13,7 +13,7 @@ Patch1: 0001-add-SDEI-stack-resolution.patch
Patch2: 0002-crash-8.0.2-sw.patch
%endif
%ifarch loongarch64
Patch3: 0003-crash-add-loongarch-support.patch
Patch3: 0003-crash-8.0.4-add-support-for-loongarch64.patch
%endif
BuildRequires: ncurses-devel zlib-devel lzo-devel snappy-devel texinfo libzstd-devel
@ -80,6 +80,10 @@ install -D -m 0644 defs.h %{buildroot}%{_includedir}/%{name}/defs.h
%{_mandir}/man8/crash.8*
%changelog
* Tue Apr 16 2024 Pengda Dou <doupengda@loongson.cn> - 8.0.4-2
- Resolve loongarch64 patch add error
- add support for loongarch64
* Thu Jan 25 2024 chenhaixiang<chenhaixiang3@huawei.com> - 8.0.4-1
- Upgrade to crash-8.0.4