diff --git a/1001-bpftrace-anolis-fix-build-failed-on-aarch64.patch b/1001-bpftrace-anolis-fix-build-failed-on-aarch64.patch new file mode 100644 index 0000000000000000000000000000000000000000..c15dd4f6a26bcb216234924dceef57537b10101f --- /dev/null +++ b/1001-bpftrace-anolis-fix-build-failed-on-aarch64.patch @@ -0,0 +1,87 @@ +From 330953c11190c23a12f98d374d1b5eb6d7aad1fe Mon Sep 17 00:00:00 2001 +From: Chunmei Xu +Date: Wed, 11 Nov 2020 16:23:19 +0800 +Subject: [PATCH] fix build failed on aarch64 + +since linux has drop __NR_open on aarch64, syscall.c will build +failed on aarch64 without __NR_open defined. + +Signed-off-by: Chunmei Xu +--- + tests/testprogs/syscall.c | 31 ++++++++++++++++++++++++------- + 1 file changed, 24 insertions(+), 7 deletions(-) + +diff --git a/tests/testprogs/syscall.c b/tests/testprogs/syscall.c +index c212466..ca1f699 100644 +--- a/tests/testprogs/syscall.c ++++ b/tests/testprogs/syscall.c +@@ -15,7 +15,9 @@ void usage() + printf("\t./syscall []\n"); + printf("Supported Syscalls:\n"); + printf("\t nanosleep [$N] (default args: 100ns)\n"); ++#if defined(SYS_open) + printf("\t open\n"); ++#endif + printf("\t openat\n"); + printf("\t read\n"); + printf("\t execve [] (at most 128 arguments)\n"); +@@ -82,8 +84,19 @@ int gen_open_openat(bool is_sys_open) + { + char *file_path = get_tmp_file_path( + "/bpftrace_runtime_test_syscall_gen_open_temp"); +- int fd = is_sys_open ? syscall(SYS_open, file_path, O_CREAT) +- : syscall(SYS_openat, AT_FDCWD, file_path, O_CREAT); ++ int fd = -1; ++ ++ if (is_sys_open) ++ { ++#if defined(SYS_open) ++ fd = syscall(SYS_open, file_path, O_CREAT); ++#endif ++ } ++ else ++ { ++ fd = syscall(SYS_openat, AT_FDCWD, file_path, O_CREAT); ++ } ++ + if (fd < 0) + { + perror("Error in syscall open/openat"); +@@ -154,7 +167,6 @@ int main(int argc, char *argv[]) + return 1; + } + const char *syscall_name = argv[1]; +- bool is_sys_open = false; + int r = 0; + + if (strcmp("--help", syscall_name) == 0 || strcmp("-h", syscall_name) == 0) +@@ -165,11 +177,16 @@ int main(int argc, char *argv[]) + { + r = gen_nanosleep(argc, argv); + } +- else if ((is_sys_open = (strcmp("open", syscall_name) == 0)) || +- strcmp("openat", syscall_name) == 0) ++ else if (strcmp("openat", syscall_name) == 0) + { +- r = gen_open_openat(is_sys_open); ++ r = gen_open_openat(false); + } ++#if defined(SYS_open) ++ else if (strcmp("open", syscall_name) == 0) ++ { ++ r = gen_open_openat(true); ++ } ++#endif + else if (strcmp("read", syscall_name) == 0) + { + r = gen_read(); +@@ -186,4 +203,4 @@ int main(int argc, char *argv[]) + } + + return r; +-} +\ No newline at end of file ++} +-- +2.19.1.6.gb485710b + diff --git a/1002-bpftrace-anolis-tests-Add-architecture-specific-testcase-support.patch b/1002-bpftrace-anolis-tests-Add-architecture-specific-testcase-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..a225a20d62a0ed00c35c6b83f2bbcb2b9ca918ae --- /dev/null +++ b/1002-bpftrace-anolis-tests-Add-architecture-specific-testcase-support.patch @@ -0,0 +1,130 @@ +From 2aa294b12568978eca1251100e149e830b23c097 Mon Sep 17 00:00:00 2001 +From: Jeffle Xu +Date: Mon, 26 Oct 2020 22:19:11 +0800 +Subject: [PATCH] tests: Add architecture specific testcase support + +commit 48d405133160 ("bpftrace: Add architecture specific testcase +support") added architecture specific support for runtime tests. +Still there are architecture specific testcases in semantic_analyser, +where 'ip' register is hard coded in semantic_analyser.call_reg and +semantic_analyser.builtin_functions. + +Besides registers such as 'ip' and 'bp' are also hard codes in some +codegen tests. + +These testcases are all c/c++ files and thus we need conditional compiling. + +Signed-off-by: Jeffle Xu +--- + tests/CMakeLists.txt | 12 ++++++++++++ + tests/codegen/call_reg.cpp | 2 ++ + tests/codegen/intptrcast_assign_var.cpp | 2 ++ + tests/codegen/intptrcast_call.cpp | 2 ++ + tests/semantic_analyser.cpp | 4 ++++ + 5 files changed, 22 insertions(+) + +diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt +index 332eba2..3b843e7 100644 +--- a/tests/CMakeLists.txt ++++ b/tests/CMakeLists.txt +@@ -108,6 +108,18 @@ if(HAVE_BFD_DISASM) + endif(STATIC_LINKING) + endif(HAVE_BFD_DISASM) + ++if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") ++ target_compile_definitions(bpftrace_test PRIVATE ARCH_AARCH64) ++elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64" OR ++ CMAKE_SYSTEM_PROCESSOR STREQUAL "ppc64le") ++ target_compile_definitions(bpftrace_test PRIVATE ARCH_PPC64) ++elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "s390" OR ++ CMAKE_SYSTEM_PROCESSOR STREQUAL "s390x") ++ target_compile_definitions(bpftrace_test PRIVATE ARCH_S390) ++elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") ++ target_compile_definitions(bpftrace_test PRIVATE ARCH_X86_64) ++endif() ++ + target_link_libraries(bpftrace_test arch ast parser resources) + + target_link_libraries(bpftrace_test ${LIBBCC_LIBRARIES}) +diff --git a/tests/codegen/call_reg.cpp b/tests/codegen/call_reg.cpp +index 3f4c790..c660451 100644 +--- a/tests/codegen/call_reg.cpp ++++ b/tests/codegen/call_reg.cpp +@@ -4,12 +4,14 @@ namespace bpftrace { + namespace test { + namespace codegen { + ++#ifdef ARCH_X86_64 + TEST(codegen, call_reg) // Identical to builtin_func apart from variable names + { + test("kprobe:f { @x = reg(\"ip\") }", + + NAME); + } ++#endif + + } // namespace codegen + } // namespace test +diff --git a/tests/codegen/intptrcast_assign_var.cpp b/tests/codegen/intptrcast_assign_var.cpp +index a536a90..53e4a5a 100644 +--- a/tests/codegen/intptrcast_assign_var.cpp ++++ b/tests/codegen/intptrcast_assign_var.cpp +@@ -4,10 +4,12 @@ namespace bpftrace { + namespace test { + namespace codegen { + ++#ifdef ARCH_X86_64 + TEST(codegen, intptrcast_assign_var) + { + test("kretprobe:f { @=*(int8*)(reg(\"bp\")-1) }", NAME); + } ++#endif + + } // namespace codegen + } // namespace test +diff --git a/tests/codegen/intptrcast_call.cpp b/tests/codegen/intptrcast_call.cpp +index 70e73ea..5ccceae 100644 +--- a/tests/codegen/intptrcast_call.cpp ++++ b/tests/codegen/intptrcast_call.cpp +@@ -4,11 +4,13 @@ namespace bpftrace { + namespace test { + namespace codegen { + ++#ifdef ARCH_X86_64 + TEST(codegen, intptrcast_call) + { + // Casting should work inside a call + test("kretprobe:f { @=sum(*(int8*)(reg(\"bp\")-1)) }", NAME); + } ++#endif + + } // namespace codegen + } // namespace test +diff --git a/tests/semantic_analyser.cpp b/tests/semantic_analyser.cpp +index b51313a..e7345c3 100644 +--- a/tests/semantic_analyser.cpp ++++ b/tests/semantic_analyser.cpp +@@ -188,7 +188,9 @@ TEST(semantic_analyser, builtin_functions) + test("kprobe:f { kaddr(\"sym\") }", 0); + test("kprobe:f { ntop(0xffff) }", 0); + test("kprobe:f { ntop(2, 0xffff) }", 0); ++#ifdef ARCH_X86_64 + test("kprobe:f { reg(\"ip\") }", 0); ++#endif + test("kprobe:f { kstack(1) }", 0); + test("kprobe:f { ustack(1) }", 0); + test("kprobe:f { cat(\"/proc/uptime\") }", 0); +@@ -684,8 +686,10 @@ TEST(semantic_analyser, call_cgroupid) + + TEST(semantic_analyser, call_reg) + { ++#ifdef ARCH_X86_64 + test("kprobe:f { reg(\"ip\"); }", 0); + test("kprobe:f { @x = reg(\"ip\"); }", 0); ++#endif + test("kprobe:f { reg(\"blah\"); }", 1); + test("kprobe:f { reg(); }", 1); + test("kprobe:f { reg(123); }", 1); +-- +2.19.1.6.gb485710b + diff --git a/1003-bpftrace-anolis-tests-fix-semantic_analyser.type_ctx-failed-on-aarch64.patch b/1003-bpftrace-anolis-tests-fix-semantic_analyser.type_ctx-failed-on-aarch64.patch new file mode 100644 index 0000000000000000000000000000000000000000..105508bb02657075c048d1621c8c74d489abe4dc --- /dev/null +++ b/1003-bpftrace-anolis-tests-fix-semantic_analyser.type_ctx-failed-on-aarch64.patch @@ -0,0 +1,52 @@ +From 3ed572dd5564ae043331862a3afc4c1e3843c1db Mon Sep 17 00:00:00 2001 +From: Chunmei Xu +Date: Thu, 24 Dec 2020 09:48:14 +0800 +Subject: [PATCH] tests: fix semantic_analyser.type_ctx failed on aarch64 + +char is default to signed on x86_64, but default to unsigned on aarch64, +powerpc and s390. + +Signed-off-by: Chunmei Xu +--- + tests/semantic_analyser.cpp | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +diff --git a/tests/semantic_analyser.cpp b/tests/semantic_analyser.cpp +index 8ea7028..a7612b6 100644 +--- a/tests/semantic_analyser.cpp ++++ b/tests/semantic_analyser.cpp +@@ -1646,11 +1646,17 @@ TEST(semantic_analyser, type_ctx) + var = static_cast(unop->expr); + EXPECT_EQ(SizedType(Type::ctx, 8, false), var->type); + ++#if ARCH_X86_64 ++ auto chartype = CreateInt8(); ++#else ++ auto chartype = CreateUInt8(); ++#endif ++ + // $c = $x->c.c; + assignment = static_cast(stmts->at(3)); +- EXPECT_EQ(CreateInt8(), assignment->var->type); ++ EXPECT_EQ(chartype, assignment->var->type); + fieldaccess = static_cast(assignment->expr); +- EXPECT_EQ(CreateInt8(), fieldaccess->type); ++ EXPECT_EQ(chartype, fieldaccess->type); + fieldaccess = static_cast(fieldaccess->expr); + EXPECT_EQ(SizedType(Type::ctx, 1, false), fieldaccess->type); + unop = static_cast(fieldaccess->expr); +@@ -1660,9 +1666,9 @@ TEST(semantic_analyser, type_ctx) + + // $d = $x->d->c; + assignment = static_cast(stmts->at(4)); +- EXPECT_EQ(CreateInt8(), assignment->var->type); ++ EXPECT_EQ(chartype, assignment->var->type); + fieldaccess = static_cast(assignment->expr); +- EXPECT_EQ(CreateInt8(), fieldaccess->type); ++ EXPECT_EQ(chartype, fieldaccess->type); + unop = static_cast(fieldaccess->expr); + EXPECT_EQ(CreateCast(8), unop->type); + fieldaccess = static_cast(unop->expr); +-- +2.18.1 + diff --git a/1004-bpftrace-anolis-tests-childproc-resume-SIGHUP-to-SIG_DFL-before-test.patch b/1004-bpftrace-anolis-tests-childproc-resume-SIGHUP-to-SIG_DFL-before-test.patch new file mode 100644 index 0000000000000000000000000000000000000000..6dd9f36f95892852d3a6e6379becb3d95395066c --- /dev/null +++ b/1004-bpftrace-anolis-tests-childproc-resume-SIGHUP-to-SIG_DFL-before-test.patch @@ -0,0 +1,28 @@ +From 9458ab3415cd4c7d2476da71def2314da96b6ba8 Mon Sep 17 00:00:00 2001 +From: Chunmei Xu +Date: Wed, 6 Jan 2021 12:38:57 +0800 +Subject: [PATCH] tests/childproc: resume SIGHUP to SIG_DFL before test + +since SIGHUP could be set SIG_IGN in parent process, +test will get failed, so resume SIGHUP before test. + +Signed-off-by: Chunmei Xu +--- + tests/child.cpp | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/tests/child.cpp b/tests/child.cpp +index adab527..8dedca0 100644 +--- a/tests/child.cpp ++++ b/tests/child.cpp +@@ -110,6 +110,7 @@ TEST(childproc, destructor_destroy_child) + + TEST(childproc, child_kill_before_exec) + { ++ signal(SIGHUP, SIG_DFL); + auto child = getChild(TEST_BIN_SLOW); + + EXPECT_EQ(kill(child->pid(), SIGHUP), 0); +-- +2.19.1.6.gb485710b + diff --git a/bpftrace.spec b/bpftrace.spec index cafc44aea23338b9c53ad8ad773d9deda2da8046..e6c1235e68736cae42a6bdc083a89a6e29fbb0e8 100755 --- a/bpftrace.spec +++ b/bpftrace.spec @@ -1,8 +1,9 @@ +%define anolis_release .0.2 %bcond_without llvm_static Name: bpftrace Version: 0.12.1 -Release: 3%{?dist} +Release: 3%{anolis_release}%{?dist} Summary: High-level tracing language for Linux eBPF License: ASL 2.0 @@ -13,6 +14,11 @@ Patch0: %{name}-%{version}-RHEL-8-fixes.patch # Remember to patch accordingly Patch10: %{name}-%{version}-RHEL-8-aarch64-fixes-statsnoop-and-opensnoop.patch +Patch1001: 1001-bpftrace-anolis-fix-build-failed-on-aarch64.patch +Patch1002: 1002-bpftrace-anolis-tests-Add-architecture-specific-testcase-support.patch +Patch1003: 1003-bpftrace-anolis-tests-fix-semantic_analyser.type_ctx-failed-on-aarch64.patch +Patch1004: 1004-bpftrace-anolis-tests-childproc-resume-SIGHUP-to-SIG_DFL-before-test.patch + # Arches will be included as upstream support is added and dependencies are # satisfied in the respective arches ExclusiveArch: x86_64 %{power64} aarch64 s390x @@ -56,6 +62,11 @@ and predecessor tracers such as DTrace and SystemTap %patch10 -p1 %endif +%patch1001 -p1 +%patch1002 -p1 +%patch1003 -p1 +%patch1004 -p1 + %build %cmake . \ -DCMAKE_BUILD_TYPE=RelWithDebInfo \ @@ -96,6 +107,15 @@ find %{buildroot}%{_datadir}/%{name}/tools -type f -exec \ %endif %changelog +* Wed Feb 16 2022 Weitao Zhou - 0.12.1-3.0.2 +- Rebuild on LLVM12 + +* Tue Jan 18 2022 Chunmei Xu - 0.12.1-3.0.1 +- fix build failed on aarch64 +- tests: Add architecture specific testcase support +- tests: fix semantic_analyser.type_ctx failed on aarch64 +- tests/childproc: resume SIGHUP to SIG_DFL before test + * Thu Jun 24 2021 Jerome Marchand - 0.12.1-3 - Have threadsnoop points to libpthread.so.0