Building a sample eBPF program

Hi!

I'm trying to build a basic eBPF program based on the libbpf-bootstrap project's minimal example, but for the GL.iNet GL-AR750S. It's architecture is mips_24kc and I'm trying to cross-compile from x86_64.

When I try to run my built package I get:

root@OpenWrt:~# filter
libbpf: loading object 'filter_bpf' from buffer
libbpf: elf: endianness mismatch in filter_bpf.
libbpf: failed to initialize skeleton BPF object 'filter_bpf': -4003
Failed to open BPF skeleton

I build the kernel myself for the router and I turned on all the necessary kernel configs:

BPF=y
BPF_EVENTS=y
BPF_JIT=y
CGROUP_BPF=y
BPF_SYSCALL=y
...

I have filter.c as my userspace program and filter.bpf.c is my eBPF program. These are exactly the same as the libbpf-bootrstrap/minimal, I just changed the name of the project from minimal to filter.

filter.bpf.c:

// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright (c) 2020 Facebook */
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>

char LICENSE[] SEC("license") = "Dual BSD/GPL";

int my_pid = 0;

SEC("tp/syscalls/sys_enter_write")
int handle_tp(void *ctx)
{
    int pid = bpf_get_current_pid_tgid() >> 32;

    if (pid != my_pid)
        return 0;

    bpf_printk("BPF triggered from PID %d.\n", pid);

    return 0;
}

===============================================

filter.c:

// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
/* Copyright (c) 2020 Facebook */
#include <stdio.h>
#include <unistd.h>
#include <sys/resource.h>
#include <bpf/libbpf.h>
#include "filter.skel.h"

static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)
{
    return vfprintf(stderr, format, args);
}

int main(int argc, char **argv)
{
    struct filter_bpf *skel;
    int err;

    /* Set up libbpf errors and debug info callback */
    libbpf_set_print(libbpf_print_fn);

    /* Open BPF application */
    skel = filter_bpf__open();
    if (!skel)
    {
        fprintf(stderr, "Failed to open BPF skeleton\n");
        return 1;
    }

    /* ensure BPF program only handles write() syscalls from our process */
    skel->bss->my_pid = getpid();

    /* Load & verify BPF programs */
    err = filter_bpf__load(skel);
    if (err)
    {
        fprintf(stderr, "Failed to load and verify BPF skeleton\n");
        goto cleanup;
    }

    /* Attach tracepoint handler */
    err = filter_bpf__attach(skel);
    if (err)
    {
        fprintf(stderr, "Failed to attach BPF skeleton\n");
        goto cleanup;
    }

    printf("Successfully started! Please run `sudo cat /sys/kernel/debug/tracing/trace_pipe` "
           "to see output of the BPF programs.\n");

    for (;;)
    {
        /* trigger our BPF program */
        fprintf(stderr, ".");
        sleep(1);
    }

cleanup:
    filter_bpf__destroy(skel);
    return -err;
}

This is my Makefile located in my feed directory:

include $(TOPDIR)/rules.mk

# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=filter
PKG_VERSION:=1.0
PKG_RELEASE:=1

# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below

SOURCE_DIR:=/home/build/src

PKG_BUILDDIR := $(BUILD_DIR)/$(PKG_NAME)

TARGET_BPF_CC := clang

TARGET_LDFLAGS += -lbpf

TARGET_CLANGFLAGS := -I/home/build/source/staging_dir/target-mips_24kc_musl/usr/include \
					 -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include \
					 -I/home/build/source/build_dir/target-mips_24kc_musl/bpftools-lib/bpftools-2022-03-08-04c465fd/libbpf/include/uapi \
					 --no-standard-includes \
					 -mlittle-endian

include $(INCLUDE_DIR)/package.mk

# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/filter
	CATEGORY:=Examples
	TITLE:=filter
	DEPENDS:=+libbpf
endef

# Package description; a more verbose description on what our package does
define Package/filter/description
	Filtering binaries from network traffic with eBPF.
endef

# Package preparation instructions; create the build directory and copy the source code. 
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	cp -r $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
	$(Build/Patch)
endef

# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
	$(MAKE) filter -C $(PKG_BUILD_DIR) \
	CC="$(TARGET_CC)" \
	BPF_CC="$(TARGET_BPF_CC)" \
	CFLAGS="$(TARGET_CFLAGS)" \
	LDFLAGS="$(TARGET_LDFLAGS)" \
	CPPFLAGS="$(TARGET_CPPFLAGS)" \
	CLANGFLAGS="$(TARGET_CLANGFLAGS)"
endef

# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/filter/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/filter $(1)/usr/bin
endef
# This command is always the last, it uses the definitions and variables we give above in order to get the job done
$(eval $(call BuildPackage,filter))

It just calls the Makefile located in my src directory which actually builds the executable:

# Global target; when 'make' is run without arguments, this is what it should do
all: filter

CFLAGS = -Wall
CLANG = clang
BPFTOOL = bpftool

# location of openwrt's source dir
SOURCE_DIR = $(AV_ROOT)/source

# 1. vmlinux.h is generated on the target machine, the target kernel must be compiled with CONFIG_DEBUG_INFO_BTF=y
VMLINUX = vmlinux_ar750s.h

# 2. use clang to compile the bpf source code to bytecode

BPF_SRC = filter.bpf.c
BPF_TMP_OBJ = filter.bpf.tmp.o
BPF_OBJ = filter.bpf.o
	
$(BPF_OBJ): $(BPF_SRC) $(VMLINUX)
	$(CLANG) -g -target bpf -O2 -D__TARGET_ARCH_mips -c -o $(BPF_TMP_OBJ) $< -I . $(CLANGFLAGS)
	cp $(BPF_TMP_OBJ) ~/src
	$(BPFTOOL) gen object $(BPF_OBJ) $(BPF_TMP_OBJ)
	cp $(BPF_OBJ) ~/src

	
# 3. create bpf skeleton header
filter.skel.h: filter.bpf.o
	bpftool gen skeleton $< > $@
	cp filter.skel.h ~/src


# 4. compile the userspace program
filter.o: filter.c filter.skel.h
	$(CC) $(CFLAGS) -c -o $@ $<


# 5. link the userspace program with libbpf
filter: clean filter.o $(VMLINUX)
	$(CC) $(CFLAGS) -o $@ filter.o $(LDFLAGS)

# To clean build artifacts, we specify a 'clean' rule, and use PHONY to indicate that this rule never matches with a potential file in the directory
.PHONY: clean
clean:
	rm -f filter *.o

In step 2 I use clang locally available on my x86 build system to build the bpf bytecode from the filter.bpf.c file. The target is bpf. I know that openwrt has an llvm buildtool for bpf programs, but I don't really know how to use that and the bytecode should be the same as far as I know.

I use bpftool directly compiled from the github repo, because the package available on debian-bullseye is outdated by several versions.

This is the output of my build process:

build@878480a623c5:~/source$ make package/filter/{clean,compile} -j1 V=s
make[2]: Entering directory '/home/build/source/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/home/build/source/scripts/config'
make[1]: Entering directory '/home/build/source'
cd "/home/build/source"; git log --format=%h -1 toolchain > /home/build/source/tmp/.ver_check
cmp -s /home/build/source/tmp/.ver_check /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check || { \
        rm -rf /home/build/source/build_dir/target-mips_24kc_musl /home/build/source/staging_dir/target-mips_24kc_musl /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl /home/build/source/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl; \
        mkdir -p /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp; \
        mv /home/build/source/tmp/.ver_check /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check; \
}
make[2]: Entering directory '/home/build/feed/examples/filter'
rm -rf /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0
/home/build/source/scripts/ipkg-remove filter /home/build/source/bin/packages/mips_24kc/mypackages/filter_1.0-1_mips_24kc.ipk
removed '/home/build/source/bin/packages/mips_24kc/mypackages/filter_1.0-1_mips_24kc.ipk'
rm -f /home/build/source/staging_dir/target-mips_24kc_musl/stamp/.filter_installed
rm -f /home/build/source/staging_dir/target-mips_24kc_musl/packages/filter.list
make[2]: Leaving directory '/home/build/feed/examples/filter'
time: package/feeds/mypackages/filter/clean#0.10#0.10#0.22
make[1]: Leaving directory '/home/build/source'
make[2]: Entering directory '/home/build/source/scripts/config'
make[2]: 'conf' is up to date.
make[2]: Leaving directory '/home/build/source/scripts/config'
make[1]: Entering directory '/home/build/source'
cd "/home/build/source"; git log --format=%h -1 toolchain > /home/build/source/tmp/.ver_check
cmp -s /home/build/source/tmp/.ver_check /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check || { \
        rm -rf /home/build/source/build_dir/target-mips_24kc_musl /home/build/source/staging_dir/target-mips_24kc_musl /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl /home/build/source/build_dir/toolchain-mips_24kc_gcc-11.2.0_musl; \
        mkdir -p /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp; \
        mv /home/build/source/tmp/.ver_check /home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/stamp/.ver_check; \
}
make[2]: Entering directory '/home/build/source/package/libs/toolchain'
Makefile:735: WARNING: skipping libgomp -- package has no install section
echo "libc" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/toolchain.default.install
echo "libgcc" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/toolchain.default.install
echo "libpthread" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/toolchain.default.install
make[2]: Leaving directory '/home/build/source/package/libs/toolchain'
time: package/libs/toolchain/compile#0.19#0.11#0.28
make[2]: Entering directory '/home/build/source/package/libs/zlib'
echo "zlib" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/zlib.default.install
make[2]: Leaving directory '/home/build/source/package/libs/zlib'
time: package/libs/zlib/compile#0.11#0.12#0.21
make[2]: Entering directory '/home/build/source/package/libs/libiconv'
make[2]: Leaving directory '/home/build/source/package/libs/libiconv'
time: package/libs/libiconv/compile#0.45#0.15#0.55
make[2]: Entering directory '/home/build/source/package/devel/binutils'
make[2]: Leaving directory '/home/build/source/package/devel/binutils'
time: package/devel/binutils/compile#0.46#1.05#1.29
make[2]: Entering directory '/home/build/source/package/utils/bzip2'
make[2]: Leaving directory '/home/build/source/package/utils/bzip2'
time: package/utils/bzip2/compile#0.32#0.17#0.45
make[2]: Entering directory '/home/build/source/package/libs/argp-standalone'
make[2]: Leaving directory '/home/build/source/package/libs/argp-standalone'
time: package/libs/argp-standalone/compile#0.18#0.17#0.28
make[2]: Entering directory '/home/build/source/package/libs/musl-fts'
make[2]: Leaving directory '/home/build/source/package/libs/musl-fts'
time: package/libs/musl-fts/compile#0.15#0.14#0.25
make[2]: Entering directory '/home/build/source/package/libs/elfutils'
echo "libelf" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/elfutils.default.install
make[2]: Leaving directory '/home/build/source/package/libs/elfutils'
time: package/libs/elfutils/compile#0.28#0.30#0.51
make[2]: Entering directory '/home/build/source/package/network/utils/bpftools'
echo "libbpf" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/bpftools.lib.install
make[2]: Leaving directory '/home/build/source/package/network/utils/bpftools'
time: package/network/utils/bpftools/lib/compile#0.15#0.13#0.25
make[2]: Entering directory '/home/build/feed/examples/filter'
touch /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.prepared_f1c9b5940a43981fd963f5c87f50d975_6664517399ebbbc92a37c5bb081b5c53_check
mkdir -p /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0
cp -r /home/build/src/* /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0
touch /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.prepared_f1c9b5940a43981fd963f5c87f50d975_6664517399ebbbc92a37c5bb081b5c53
rm -f /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.configured_*
rm -f /home/build/source/staging_dir/target-mips_24kc_musl/stamp/.filter_installed
(cd /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/./; if [ -x ./configure ]; then find /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ -name config.guess | xargs -r chmod u+w; find /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ -name config.guess | xargs -r -n1 cp --remove-destination /home/build/source/scripts/config.guess; find /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ -name config.sub | xargs -r chmod u+w; find /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ -name config.sub | xargs -r -n1 cp --remove-destination /home/build/source/scripts/config.sub; AR="mips-openwrt-linux-musl-gcc-ar" AS="mips-openwrt-linux-musl-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -ffile-prefix-map=/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0=filter-1.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LD=mips-openwrt-linux-musl-ld NM="mips-openwrt-linux-musl-gcc-nm" CC="mips-openwrt-linux-musl-gcc" GCC="mips-openwrt-linux-musl-gcc" CXX="mips-openwrt-linux-musl-g++" RANLIB="mips-openwrt-linux-musl-gcc-ranlib" STRIP=mips-openwrt-linux-musl-strip OBJCOPY=mips-openwrt-linux-musl-objcopy OBJDUMP=mips-openwrt-linux-musl-objdump SIZE=mips-openwrt-linux-musl-size CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -ffile-prefix-map=/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0=filter-1.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CXXFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -ffile-prefix-map=/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0=filter-1.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro " CPPFLAGS="-I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/usr/include -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include/fortify -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include " LDFLAGS="-L/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/usr/lib -L/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib -lbpf -znow -zrelro "   ./configure --target=mips-openwrt-linux --host=mips-openwrt-linux --build=x86_64-pc-linux-gnu --program-prefix="" --program-suffix="" --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls  ; fi; )
touch /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.configured_68b329da9893e34099c7d8ad5cb9c940
rm -f /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.built
touch /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.built_check
make filter -C /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0 CC="mips-openwrt-linux-musl-gcc" BPF_CC="clang" CFLAGS="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -ffile-prefix-map=/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0=filter-1.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro" LDFLAGS="-L/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/usr/lib -L/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib -lbpf -znow -zrelro" CPPFLAGS="-I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/usr/include -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include/fortify -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include" CLANGFLAGS="-I/home/build/source/staging_dir/target-mips_24kc_musl/usr/include -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include -I/home/build/source/build_dir/target-mips_24kc_musl/bpftools-lib/bpftools-2022-03-08-04c465fd/libbpf/include/uapi --no-standard-includes -mlittle-endian"
make[3]: Entering directory '/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0'
rm -f filter *.o tlshc/*.o
clang -g -target bpf -O2 -D__TARGET_ARCH_mips -c -o filter.bpf.tmp.o filter.bpf.c -I . -I/home/build/source/staging_dir/target-mips_24kc_musl/usr/include -I/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/include -I/home/build/source/build_dir/target-mips_24kc_musl/bpftools-lib/bpftools-2022-03-08-04c465fd/libbpf/include/uapi --no-standard-includes -mlittle-endian
cp filter.bpf.tmp.o ~/src
bpftool gen object filter.bpf.o filter.bpf.tmp.o
cp filter.bpf.o ~/src
bpftool gen skeleton filter.bpf.o > filter.skel.h
cp filter.skel.h ~/src
mips-openwrt-linux-musl-gcc -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -ffile-prefix-map=/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0=filter-1.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -c -o filter.o filter.c
mips-openwrt-linux-musl-gcc -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -ffile-prefix-map=/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0=filter-1.0 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -o filter filter.o -L/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/usr/lib -L/home/build/source/staging_dir/toolchain-mips_24kc_gcc-11.2.0_musl/lib -lbpf -znow -zrelro
make[3]: Leaving directory '/home/build/source/build_dir/target-mips_24kc_musl/filter-1.0'
touch /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.built
rm -rf /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter.installed /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter
mkdir -p /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter
install -d -m0755 /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter/usr/bin
install -m0755 /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/filter /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter/usr/bin
touch /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter.installed
mkdir -p /home/build/source/staging_dir/target-mips_24kc_musl/root-ath79/stamp
SHELL= flock /home/build/source/tmp/.root-copy.flock -c 'cp -fpR /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/.pkgdir/filter/. /home/build/source/staging_dir/target-mips_24kc_musl/root-ath79/'
touch /home/build/source/staging_dir/target-mips_24kc_musl/root-ath79/stamp/.filter_installed
mkdir -p /home/build/source/bin/targets/ath79/nand/packages /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter/CONTROL /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo
install -d -m0755 /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter/usr/bin
install -m0755 /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/filter /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter/usr/bin
find /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| xargs -r rm -rf
export CROSS="mips-openwrt-linux-musl-"   ; NM="mips-openwrt-linux-musl-nm" STRIP="/home/build/source/staging_dir/host/bin/sstrip -z" STRIP_KMOD="/home/build/source/scripts/strip-kmod.sh" PATCHELF="/home/build/source/staging_dir/host/bin/patchelf" /home/build/source/scripts/rstrip.sh /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter
rstrip.sh: /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter/usr/bin/filter: executable
(cd /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter/CONTROL; ( echo "$CONTROL"; printf "Description: "; echo "$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; ) > control; chmod 644 control; ( echo "#!/bin/sh"; echo "[ \"\${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; echo "[ -s "\${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; echo ". \${IPKG_INSTROOT}/lib/functions.sh"; echo "default_postinst \$0 \$@"; ) > postinst; ( echo "#!/bin/sh"; echo "[ -s "\${IPKG_INSTROOT}/lib/functions.sh" ] || exit 0"; echo ". \${IPKG_INSTROOT}/lib/functions.sh"; echo "default_prerm \$0 \$@"; ) > prerm; chmod 0755 postinst prerm;  )
install -d -m0755 /home/build/source/bin/packages/mips_24kc/mypackages
/home/build/source/staging_dir/host/bin/fakeroot /home/build/source/staging_dir/host/bin/bash /home/build/source/scripts/ipkg-build -m "" /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter /home/build/source/bin/packages/mips_24kc/mypackages
Packaged contents of /home/build/source/build_dir/target-mips_24kc_musl/filter-1.0/ipkg-mips_24kc/filter into /home/build/source/bin/packages/mips_24kc/mypackages/filter_1.0-1_mips_24kc.ipk
echo "filter" >> /home/build/source/staging_dir/target-mips_24kc_musl/pkginfo/filter.default.install
make[2]: Leaving directory '/home/build/feed/examples/filter'
time: package/feeds/mypackages/filter/compile#0.47#0.45#1.22
make[1]: Leaving directory '/home/build/source'

Sorry if I missed some obvious step, I'm quite new to building Linux kernel/programs from source. eBPF would be useful for my BSc thesis work.

Thanks a lot!
Gergo