From a34238448b93cd48373aaac53ba07695326cb134 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 1 Nov 2024 18:24:44 +0800 Subject: [PATCH] add sw64 architecture --- bpftrace-0.16.0-support-for-sw.patch | 176 +++++++++++++++++++++++++++ bpftrace.spec | 11 +- 2 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 bpftrace-0.16.0-support-for-sw.patch diff --git a/bpftrace-0.16.0-support-for-sw.patch b/bpftrace-0.16.0-support-for-sw.patch new file mode 100644 index 0000000..572ed8d --- /dev/null +++ b/bpftrace-0.16.0-support-for-sw.patch @@ -0,0 +1,176 @@ +diff -uNar bpftrace-0.16.0/src/arch/CMakeLists.txt bpftrace-0.16.0.sw/src/arch/CMakeLists.txt +--- bpftrace-0.16.0/src/arch/CMakeLists.txt 2024-11-01 18:20:55.311541302 +0800 ++++ bpftrace-0.16.0.sw/src/arch/CMakeLists.txt 2024-11-01 18:21:56.862543700 +0800 +@@ -14,6 +14,8 @@ + add_library(arch riscv64.cpp) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "loongarch64") + add_library(arch loongarch64.cpp) ++elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "sw_64") ++ add_library(arch sw_64.cpp) + else() + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") + endif() +diff -uNar bpftrace-0.16.0/src/arch/sw_64.cpp bpftrace-0.16.0.sw/src/arch/sw_64.cpp +--- bpftrace-0.16.0/src/arch/sw_64.cpp 1970-01-01 08:00:00.000000000 +0800 ++++ bpftrace-0.16.0.sw/src/arch/sw_64.cpp 2024-11-01 18:22:42.819545490 +0800 +@@ -0,0 +1,148 @@ ++#include "arch.h" ++ ++#include ++#include ++ ++// SP points to the first argument that is passed on the stack ++#define ARG0_STACK 0 ++ ++namespace bpftrace { ++namespace arch { ++ ++// clang-format off ++static std::array registers = { ++ "v0", ++ "t0", ++ "t1", ++ "t2", ++ "t3", ++ "t4", ++ "t5", ++ "t6", ++ "t7", ++ "s0", ++ "s1", ++ "s2", ++ "s3", ++ "s4", ++ "s5", ++ "s6/fp", ++ "a0", ++ "a1", ++ "a2", ++ "a3", ++ "a4", ++ "a5", ++ "t8", ++ "t9", ++ "t10", ++ "t11", ++ "ra", ++ "pv", ++ "at", ++ "gp", ++ "sp", ++ "zero", ++ "pc", ++ "pstate", ++}; ++// Alternative register names that match struct pt_regs ++static std::array ptrace_registers = { ++ "regs[0]", ++ "regs[1]", ++ "regs[2]", ++ "regs[3]", ++ "regs[4]", ++ "regs[5]", ++ "regs[6]", ++ "regs[7]", ++ "regs[8]", ++ "regs[9]", ++ "regs[10]", ++ "regs[11]", ++ "regs[12]", ++ "regs[13]", ++ "regs[14]", ++ "regs[15]", ++ "regs[16]", ++ "regs[17]", ++ "regs[18]", ++ "regs[19]", ++ "regs[20]", ++ "regs[21]", ++ "regs[22]", ++ "regs[23]", ++ "regs[24]", ++ "regs[25]", ++ "regs[26]", ++ "regs[27]", ++ "regs[28]", ++ "regs[29]", ++ "regs[30]", ++ "regs[31]", ++ "pc", ++ "pstate", ++}; ++static std::array arg_registers = { ++ "a0", ++ "a1", ++ "a2", ++ "a3", ++ "a4", ++ "a5", ++}; ++// clang-format on ++ ++int offset(std::string reg_name) ++{ ++ auto it = find(registers.begin(), registers.end(), reg_name); ++ if (it == registers.end()) ++ { ++ return -1; ++ } ++ return distance(registers.begin(), it); ++} ++ ++int max_arg() ++{ ++ return arg_registers.size() - 1; ++} ++ ++int arg_offset(int arg_num) ++{ ++ return offset(arg_registers.at(arg_num)); ++} ++ ++int pc_offset() ++{ ++ return offset("pc"); ++} ++ ++int ret_offset() ++{ ++ return offset("v0"); ++} ++ ++int sp_offset() ++{ ++ return offset("sp"); ++} ++ ++int arg_stack_offset() ++{ ++ return ARG0_STACK / 8; ++} ++ ++std::string name() ++{ ++ return std::string("sw_64"); ++} ++ ++std::vector invalid_watchpoint_modes() ++{ ++ throw std::runtime_error( ++ "Watchpoints are not supported on this architecture"); ++} ++ ++} // namespace arch ++} // namespace bpftrace +diff -uNar bpftrace-0.16.0/src/utils.cpp bpftrace-0.16.0.sw/src/utils.cpp +--- bpftrace-0.16.0/src/utils.cpp 2024-11-01 18:20:55.311541302 +0800 ++++ bpftrace-0.16.0.sw/src/utils.cpp 2024-11-01 18:21:56.863543700 +0800 +@@ -344,6 +344,8 @@ + arch = "arm64"; + } else if (!strncmp(uname_machine, "loongarch", 9)) { + arch = "loongarch"; ++ } else if (!strncmp(uname_machine, "sw_64", 5)) { ++ arch = "sw_64"; + } + + // If ARCH env is defined, use it over uname diff --git a/bpftrace.spec b/bpftrace.spec index be9f8e4..60a470f 100644 --- a/bpftrace.spec +++ b/bpftrace.spec @@ -2,7 +2,7 @@ Name: bpftrace Version: 0.16.0 -Release: 6%{?dist} +Release: 7%{?dist} Summary: High-level tracing language for Linux eBPF License: ASL 2.0 @@ -30,12 +30,12 @@ Patch12: %{name}-%{version}-aotrt-is-generated-by-default.patch Patch1000: 1000-tests-runtime-fix-kprobe_offset_module-on-aarch64.patch # https://github.com/iovisor/bpftrace/commit/cf54d1682c19c0b2ebc7f81160282345c0aded79 -Patch1001: %{name}-%{version}-Add-support-for-loongarch.patch - +Patch1001: %{name}-%{version}-Add-support-for-loongarch.patch +Patch1002: bpftrace-0.16.0-support-for-sw.patch # Arches will be included as upstream support is added and dependencies are # satisfied in the respective arches -ExclusiveArch: x86_64 %{power64} aarch64 s390x loongarch64 +ExclusiveArch: x86_64 %{power64} aarch64 s390x loongarch64 sw_64 BuildRequires: gcc-c++ BuildRequires: bison @@ -131,6 +131,9 @@ cp %{buildroot}/%{_datadir}/%{name}/tools/old/mdflush.bt %{buildroot}/%{_datadir %exclude %{_datadir}/%{name}/tools/old %changelog +* Mon Jul 29 2024 wxiat - 0.16.0-7 +- add sw pacth support for sw arch + * Thu Jan 11 2024 HUi Li - 0.16.0-6 - add support for loongarch64 -- Gitee