Skip to content

Commit

Permalink
new package: bcc
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 committed Jun 13, 2023
1 parent c464d70 commit 70dd2c9
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tur/bcc/0001-fix-include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--- a/src/cc/libbpf/include/linux/compiler.h
+++ b/src/cc/libbpf/include/linux/compiler.h
@@ -3,6 +3,10 @@
#ifndef __LINUX_COMPILER_H
#define __LINUX_COMPILER_H

+#ifdef __ANDROID__
+#include_next <linux/compiler.h>
+#endif
+
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)

--- a/src/cc/libbpf/include/linux/types.h
+++ b/src/cc/libbpf/include/linux/types.h
@@ -22,6 +22,10 @@
typedef __u64 __bitwise __le64;
typedef __u64 __bitwise __be64;

+#ifdef __ANDROID__
+typedef unsigned __bitwise __poll_t;
+#endif
+
#ifndef __aligned_u64
# define __aligned_u64 __u64 __attribute__((aligned(8)))
#endif
--- a/introspection/bps.c
+++ b/introspection/bps.c
@@ -9,6 +9,10 @@
#include <ctype.h>
#include <sysexits.h>

+#ifdef __ANDROID__
+#include <strings.h>
+#endif
+
#include "libbpf.h"

// TODO: Remove this when CentOS 6 support is not needed anymore
64 changes: 64 additions & 0 deletions tur/bcc/0002-adapt-to-bionic-libc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
--- ./src/python/bcc/__init__.py
+++ ./src/python/bcc/__init__.py
@@ -323,7 +323,7 @@
class timespec(ct.Structure):
_fields_ = [('tv_sec', ct.c_long), ('tv_nsec', ct.c_long)]

- _librt = ct.CDLL('librt.so.1', use_errno=True)
+ _librt = ct.CDLL('libc.so', use_errno=True)
_clock_gettime = _librt.clock_gettime
_clock_gettime.argtypes = [ct.c_int, ct.POINTER(timespec)]

--- ./src/python/bcc/libbcc.py
+++ ./src/python/bcc/libbcc.py
@@ -14,7 +14,7 @@

import ctypes as ct

-lib = ct.CDLL("libbcc.so.0", use_errno=True)
+lib = ct.CDLL("libbcc.so", use_errno=True)

# needed for perf_event_attr() ctype
from .perf import Perf
--- ./src/python/bcc/perf.py
+++ ./src/python/bcc/perf.py
@@ -147,7 +147,7 @@
PERF_EVENT_IOC_ENABLE = 9216

# fetch syscall routines
- libc = ct.CDLL('libc.so.6', use_errno=True)
+ libc = ct.CDLL('libc.so', use_errno=True)
syscall = libc.syscall # not declaring vararg types
ioctl = libc.ioctl # not declaring vararg types

--- ./tests/python/test_clang.py
+++ ./tests/python/test_clang.py
@@ -928,7 +928,7 @@
b[b"dummy"][ct.c_ulong(0)] = c_val
b[b"dummy"][ct.c_ulong(1)] = c_val
b.attach_kprobe(event=b.get_syscall_fnname(b"sync"), fn_name=b"do_trace")
- libc = ct.CDLL("libc.so.6")
+ libc = ct.CDLL("libc.so")
libc.sync()
self.assertEqual(1, b[b"dummy"][ct.c_ulong(0)].value)
self.assertEqual(2, b[b"dummy"][ct.c_ulong(1)].value)
--- ./tests/python/test_uprobes.py
+++ ./tests/python/test_uprobes.py
@@ -33,7 +33,7 @@
b = bcc.BPF(text=text)
b.attach_uprobe(name=b"c", sym=b"malloc_stats", fn_name=b"count", pid=test_pid)
b.attach_uretprobe(name=b"c", sym=b"malloc_stats", fn_name=b"count", pid=test_pid)
- libc = ctypes.CDLL("libc.so.6")
+ libc = ctypes.CDLL("libc.so")
libc.malloc_stats.restype = None
libc.malloc_stats.argtypes = []
libc.malloc_stats()
@@ -83,7 +83,7 @@
return 0;
}"""
# Need to import libc from ctypes to access unshare(2)
- libc = ctypes.CDLL("libc.so.6", use_errno=True)
+ libc = ctypes.CDLL("libc.so", use_errno=True)

# Need to find path to libz.so.1
libz_path = None
6 changes: 6 additions & 0 deletions tur/bcc/bcc-tools.subpackage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TERMUX_SUBPKG_DESCRIPTION="BPF Compiler Collection - Tools"
TERMUX_SUBPKG_DEPENDS="libedit, python, python-bcc"
TERMUX_SUBPKG_INCLUDE="
share/bcc/man
share/bcc/tools
"
26 changes: 26 additions & 0 deletions tur/bcc/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TERMUX_PKG_HOMEPAGE=https://github.com/iovisor/bcc
TERMUX_PKG_DESCRIPTION="Tools for BPF-based Linux IO analysis, networking, monitoring, and more"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@termux-user-repository"
TERMUX_PKG_VERSION=0.27.0
TERMUX_PKG_SRCURL=https://github.com/iovisor/bcc/releases/download/v$TERMUX_PKG_VERSION/bcc-src-with-submodule.tar.gz
TERMUX_PKG_SHA256=157208df3c8c0473b5dbedd57648fb98b5d07e5565984affc4e3e84a3df601bc
TERMUX_PKG_DEPENDS="clang, libc++, libdebuginfod, libelf, liblzma, ncurses, zlib, zstd"
TERMUX_PKG_BUILD_DEPENDS="libllvm-static"
TERMUX_PKG_EXTRA_CONFIGURE_ARGS="
-DREVISION=$TERMUX_PKG_VERSION
-DPYTHON_CMD=python$TERMUX_PYTHON_VERSION
-DENABLE_TESTS=OFF
-DRUN_LUA_TESTS=OFF
-DBCC_PROG_TAG_DIR=$TERMUX_PREFIX/var/tmp/bcc
"

termux_step_post_make_install() {
termux_setup_python_pip

pushd $TERMUX_PKG_BUILDDIR/src/python/bcc-python$TERMUX_PYTHON_VERSION
pip install --prefix=$TERMUX_PREFIX .
popd

rm -rf $TERMUX_PREFIX/lib/python3/
}
5 changes: 5 additions & 0 deletions tur/bcc/python-bcc.subpackage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TERMUX_SUBPKG_DESCRIPTION="BPF Compiler Collection - Python 3 bindings"
TERMUX_SUBPKG_DEPENDS="python"
TERMUX_SUBPKG_INCLUDE="
lib/python3.11
"

0 comments on commit 70dd2c9

Please sign in to comment.