From 12903027c29efb9f9abc912c042c5de546083106 Mon Sep 17 00:00:00 2001 From: baiguo Date: Thu, 30 May 2024 15:20:51 +0800 Subject: [PATCH] Fix tcpconnect.bt to not need libc headers installed if BTF is available --- ...t-to-not-need-libc-headers-installed.patch | 113 ++++++++++++++++++ bpftrace.spec | 6 +- 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-tcpconnect.bt-to-not-need-libc-headers-installed.patch diff --git a/backport-Fix-tcpconnect.bt-to-not-need-libc-headers-installed.patch b/backport-Fix-tcpconnect.bt-to-not-need-libc-headers-installed.patch new file mode 100644 index 0000000..a4ba93c --- /dev/null +++ b/backport-Fix-tcpconnect.bt-to-not-need-libc-headers-installed.patch @@ -0,0 +1,113 @@ +From ea478c7e1669b2a692c9ea4a111073d998a80575 Mon Sep 17 00:00:00 2001 +From: Bernhard Kaindl +Date: Fri, 3 May 2024 12:00:00 +0000 +Subject: [PATCH] Fix tcpconnect.bt to not need libc headers installed if BTF + is available +Reference:https://github.com/bpftrace/bpftrace/pull/3152/ + +--- + tools/tcpaccept.bt | 8 +++++++- + tools/tcpconnect.bt | 8 +++++++- + tools/tcpdrop.bt | 8 +++++++- + tools/tcplife.bt | 8 +++++++- + tools/tcpretrans.bt | 8 +++++++- + 5 files changed, 35 insertions(+), 5 deletions(-) + +diff --git a/tools/tcpaccept.bt b/tools/tcpaccept.bt +index 08e6af0..cbffe36 100755 +--- a/tools/tcpaccept.bt ++++ b/tools/tcpaccept.bt +@@ -20,7 +20,13 @@ + #include + #include + #else +-#include ++/* ++ * With BTF providing types, socket headers are not needed. ++ * We only need to supply the preprocessor defines in this script. ++ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI ++ */ ++#define AF_INET 2 ++#define AF_INET6 10 + #endif + + BEGIN +diff --git a/tools/tcpconnect.bt b/tools/tcpconnect.bt +index 1ac1eb9..6363372 100755 +--- a/tools/tcpconnect.bt ++++ b/tools/tcpconnect.bt +@@ -22,7 +22,13 @@ + #include + #include + #else +-#include ++/* ++ * BTF provides the types, we just need to define AF_INET and AF_INET6. ++ * These are Linux ABI defines, and are not architecture-specific. ++ * With BTF, this allows tcpconnect.bt to work without glibc headers: ++ */ ++#define AF_INET 2 /* IPv4 */ ++#define AF_INET6 10 /* IPv6 */ + #endif + + BEGIN +diff --git a/tools/tcpdrop.bt b/tools/tcpdrop.bt +index fd3e55f..a56bf69 100755 +--- a/tools/tcpdrop.bt ++++ b/tools/tcpdrop.bt +@@ -24,7 +24,13 @@ + #include + #include + #else +-#include ++/* ++ * With BTF providing types, socket headers are not needed. ++ * We only need to supply the preprocessor defines in this script. ++ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI ++ */ ++#define AF_INET 2 ++#define AF_INET6 10 + #endif + + BEGIN +diff --git a/tools/tcplife.bt b/tools/tcplife.bt +index dd4c1d6..d5a09c4 100755 +--- a/tools/tcplife.bt ++++ b/tools/tcplife.bt +@@ -19,7 +19,13 @@ + #include + #include + #else +-#include ++/* ++ * With BTF providing types, socket headers are not needed. ++ * We only need to supply the preprocessor defines in this script. ++ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI ++ */ ++#define AF_INET 2 ++#define AF_INET6 10 + #endif + + BEGIN +diff --git a/tools/tcpretrans.bt b/tools/tcpretrans.bt +index ee2975d..32a11bf 100755 +--- a/tools/tcpretrans.bt ++++ b/tools/tcpretrans.bt +@@ -21,7 +21,13 @@ + #include + #include + #else +-#include ++/* ++ * With BTF providing types, socket headers are not needed. ++ * We only need to supply the preprocessor defines in this script. ++ * AF_INET/AF_INET6 are part of the stable arch-independent Linux ABI ++ */ ++#define AF_INET 2 ++#define AF_INET6 10 + #endif + + BEGIN +-- +2.27.0 + diff --git a/bpftrace.spec b/bpftrace.spec index 39fab9a..f74817b 100644 --- a/bpftrace.spec +++ b/bpftrace.spec @@ -1,11 +1,12 @@ Name: bpftrace Version: 0.20.1 -Release: 1 +Release: 2 Summary: High-level tracing language for Linux eBPF License: ASL 2.0 URL: https://github.com/iovisor/bpftrace Source0: %{url}/archive/refs/tags/%{name}-%{version}.tar.gz +Patch0001: backport-Fix-tcpconnect.bt-to-not-need-libc-headers-installed.patch # Arches will be included as upstream support is added and dependencies are # satisfied in the respective arches @@ -68,6 +69,9 @@ find %{buildroot}%{_datadir}/%{name}/tools -type f -exec \ %changelog +* Tue Feb 18 2025 baiguo - 0.20.1-2 +- Fix tcpconnect.bt to not need libc headers installed if BTF is available + * Mon Nov 04 2024 fu-shanqing - 0.20.1-1 - update to 0.20.1 -- Gitee