From 870371fbce4740402e532b17254cb58e3c9baa11 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Fri, 30 Jun 2023 17:18:15 +0800 Subject: [PATCH] add riscv64 support Co-authored-by: EastDong (cherry picked from commit 35c6cdd3c4a73368f1409a8067647cf606bbb411) --- 0002-add-riscv64-support.patch | 78 ++++++++++++++++++++++++++++++++++ memleax.spec | 6 ++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 0002-add-riscv64-support.patch diff --git a/0002-add-riscv64-support.patch b/0002-add-riscv64-support.patch new file mode 100644 index 0000000..0fef6da --- /dev/null +++ b/0002-add-riscv64-support.patch @@ -0,0 +1,78 @@ +diff -ur memleax-1.1.1/configure memleax-1.1.1/configure +--- memleax-1.1.1/configure 2023-06-30 16:52:49.401032162 +0800 ++++ memleax-1.1.1/configure 2023-06-30 16:56:52.793616961 +0800 +@@ -63,9 +63,13 @@ + machine="loongarch64" + CFLAGS="$CFLAGS -DMLX_LOONGARCH64" + ;; ++'riscv64') ++ machine="riscv" ++ CFLAGS="$CFLAGS -DMLX_RISCV64" ++ ;; + *) + echo "Error: unsupported machine: `uname -m`." +- echo "Only x86, x86_64, arm, loongarch and aarch64 are supported." ++ echo "Only x86, x86_64, arm, loongarch, riscv and aarch64 are supported." + exit 2 + ;; + esac +@@ -159,7 +163,7 @@ + + cat << EOF > Makefile + CFLAGS = $CFLAGS -g -O2 -Wall +-LDLIBS = $LDLIBS ++LDLIBS = $LDLIBS -llzma + LDFLAGS = $LDFLAGS + PREFIX = $prefix + DESTDIR = +diff -ur memleax-1.1.1/machines.h memleax-1.1.1/machines.h +--- memleax-1.1.1/machines.h 2023-06-30 16:52:49.401032162 +0800 ++++ memleax-1.1.1/machines.h 2023-06-30 16:30:58.889630806 +0800 +@@ -177,6 +177,35 @@ + { + return ptrace_get_data(pid, address) == 0xd4200000; + } ++#elif defined(MLX_RISCV64) ++static inline uintptr_t call_return_address(pid_t pid, registers_info_t *regs) ++{ ++ return regs->ra; ++} ++static inline uintptr_t call_return_value(registers_info_t *regs) ++{ ++ return regs->a0; ++} ++static inline uintptr_t call_arg1(pid_t pid, registers_info_t *regs) ++{ ++ return regs->a0; ++} ++static inline uintptr_t call_arg2(pid_t pid, registers_info_t *regs) ++{ ++ return regs->a1; ++} ++static inline uintptr_t pc_unwind(pid_t pid, registers_info_t *regs) ++{ ++ return regs->pc; ++} ++static inline void set_breakpoint(pid_t pid, uintptr_t address, uintptr_t code) ++{ ++ ptrace_set_data(pid, address, 0x00100073); ++} ++static inline int is_breakpoint(pid_t pid, uintptr_t address) ++{ ++ return ptrace_get_data(pid, address) == 0x00100073; ++} + #endif + + #endif +diff -ur memleax-1.1.1/ptrace_utils.h memleax-1.1.1/ptrace_utils.h +--- memleax-1.1.1/ptrace_utils.h 2018-01-04 06:05:08.000000000 +0800 ++++ memleax-1.1.1/ptrace_utils.h 2023-06-30 16:31:47.693773352 +0800 +@@ -16,7 +16,7 @@ + + #include + #include +- ++#include + #ifdef MLX_ARMv7 + typedef struct user_regs registers_info_t; + #else diff --git a/memleax.spec b/memleax.spec index d2aee0d..d9bd01a 100644 --- a/memleax.spec +++ b/memleax.spec @@ -1,11 +1,12 @@ Name: memleax Version: 1.1.1 -Release: 6 +Release: 7 Summary: Memory lead detection tool License: GPLv2 URL: https://github.com/WuBingzheng/memleax Source0: https://github.com/WuBingzheng/memleax/archive/v%{version}.tar.gz#/memleax-%{version}.tar.gz Patch0: 0001-add-loongarch64-support.patch +Patch1: 0002-add-riscv64-support.patch BuildRequires: make libunwind-devel elfutils-devel gcc @@ -48,6 +49,9 @@ make install DESTDIR="%{buildroot}" %{_mandir}/man1/%{name}.1* %changelog +* Fri Jun 30 2023 zhangxiang - 1.1.1-7 +- add riscv64 support + * Wed Dec 14 2022 doupengda - 1.1.1-6 - add loongarch64 support -- Gitee