diff --git a/libbpf-support-for-sw.patch b/libbpf-support-for-sw.patch new file mode 100644 index 0000000000000000000000000000000000000000..a4c6f4d277380a93c44bc05242785ffd14c117b5 --- /dev/null +++ b/libbpf-support-for-sw.patch @@ -0,0 +1,83 @@ +diff -uNar linux-5.10.134-15.al8/tools/lib/bpf/bpf.c linux-5.10.134-15.al8.new/tools/lib/bpf/bpf.c +--- linux-5.10.134-15.al8/tools/lib/bpf/bpf.c 2023-07-19 23:07:59.000000000 +0800 ++++ linux-5.10.134-15.al8.new/tools/lib/bpf/bpf.c 2024-07-24 08:45:14.313101126 +0800 +@@ -49,6 +49,8 @@ + # define __NR_bpf 351 + # elif defined(__arc__) + # define __NR_bpf 280 ++# elif defined(__sw_64__) ++# define __NR_bpf 170 + # else + # error __NR_bpf not defined. libbpf does not support your arch. + # endif +diff -uNar linux-5.10.134-15.al8/tools/lib/bpf/bpf_tracing.h linux-5.10.134-15.al8.new/tools/lib/bpf/bpf_tracing.h +--- linux-5.10.134-15.al8/tools/lib/bpf/bpf_tracing.h 2023-07-19 23:07:59.000000000 +0800 ++++ linux-5.10.134-15.al8.new/tools/lib/bpf/bpf_tracing.h 2024-07-24 08:43:47.083134626 +0800 +@@ -24,6 +24,9 @@ + #elif defined(__TARGET_ARCH_sparc) + #define bpf_target_sparc + #define bpf_target_defined ++#elif defined(__TARGET_ARCH_sw_64) ++ #define bpf_target_sw_64 ++ #define bpf_target_defined + #else + #undef bpf_target_defined + #endif +@@ -44,6 +47,8 @@ + #define bpf_target_powerpc + #elif defined(__sparc__) + #define bpf_target_sparc ++#elif defined(__sw_64__) ++ #define bpf_target_sw_64 + #endif + #endif + +@@ -278,6 +283,32 @@ + #define PT_REGS_IP(x) ((x)->pc) + #define PT_REGS_IP_CORE(x) BPF_CORE_READ((x), pc) + #endif ++/* sw_64 */ ++#elif defined(bpf_target_sw_64) ++/* sw_64 provides struct user_pt_regs instead of struct pt_regs to userspace */ ++struct pt_regs; ++#define PT_REGS_SW64 const volatile struct user_pt_regs ++#define PT_REGS_PARM1(x) (((PT_REGS_SW64 *)(x))->regs[16]) ++#define PT_REGS_PARM2(x) (((PT_REGS_SW64 *)(x))->regs[17]) ++#define PT_REGS_PARM3(x) (((PT_REGS_SW64 *)(x))->regs[18]) ++#define PT_REGS_PARM4(x) (((PT_REGS_SW64 *)(x))->regs[19]) ++#define PT_REGS_PARM5(x) (((PT_REGS_SW64 *)(x))->regs[20]) ++#define PT_REGS_RET(x) (((PT_REGS_SW64 *)(x))->regs[26]) ++#define PT_REGS_FP(x) (((PT_REGS_SW64 *)(x))->regs[15]) ++#define PT_REGS_RC(x) (((PT_REGS_SW64 *)(x))->regs[0]) ++#define PT_REGS_SP(x) (((PT_REGS_SW64 *)(x))->regs[30]) ++#define PT_REGS_IP(x) (((PT_REGS_SW64 *)(x))->pc) ++ ++#define PT_REGS_PARM1_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[16]) ++#define PT_REGS_PARM2_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[17]) ++#define PT_REGS_PARM3_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[18]) ++#define PT_REGS_PARM4_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[19]) ++#define PT_REGS_PARM5_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[20]) ++#define PT_REGS_RET_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[26]) ++#define PT_REGS_FP_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[15]) ++#define PT_REGS_RC_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[0]) ++#define PT_REGS_SP_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), regs[30]) ++#define PT_REGS_IP_CORE(x) BPF_CORE_READ((PT_REGS_SW64 *)(x), pc) + + #endif + +diff -uNar linux-5.10.134-15.al8/tools/lib/bpf/Makefile linux-5.10.134-15.al8.new/tools/lib/bpf/Makefile +--- linux-5.10.134-15.al8/tools/lib/bpf/Makefile 2023-07-19 23:07:59.000000000 +0800 ++++ linux-5.10.134-15.al8.new/tools/lib/bpf/Makefile 2024-07-24 08:55:05.642853244 +0800 +@@ -40,6 +40,12 @@ + libdir_relative = lib + endif + ++# sw use lib ++OS_ARCH :=$(shell uname -m) ++ifeq ($(OS_ARCH),sw_64) ++ libdir_relative = lib ++endif ++ + prefix ?= /usr/local + libdir = $(prefix)/$(libdir_relative) + man_dir = $(prefix)/share/man diff --git a/libbpf.spec b/libbpf.spec index 93a27c3b734efa6982e813d5d4d1a5d85a885baa..9bfa42ec6f6f024285e362670a0b766984a260a2 100644 --- a/libbpf.spec +++ b/libbpf.spec @@ -1,4 +1,4 @@ -%global anolis_release .2 +%global anolis_release .3 # We build libbpf from RHEL kernel sources, that's why we use # directly kernel tar for RHEL kernel build. # We update libbpf's 'sources' file with proper hash that's @@ -19,6 +19,8 @@ Source0: %{source}.tar.xz BuildRequires: gcc elfutils-libelf-devel elfutils-devel python3 Conflicts: bcc < 0.10 +Patch1: libbpf-support-for-sw.patch + %description A mirror of bpf-next linux tree bpf-next/tools/lib/bpf directory plus its supporting header files. The version of the package reflects the version of @@ -46,6 +48,7 @@ developing applications that use %{name} %prep %setup -n %{source} +%patch1 -p1 %build pushd tools/lib/bpf @@ -70,6 +73,9 @@ popd %{_libdir}/libbpf.a %changelog +* Wed Jul 19 2024 wxiat - 0.6.0-1.3 +- add sw arch support for sw arch + * Fri May 31 2024 Shenglong Zhu - 0.6.0-1.2 - Fix kernel header requirement