{"id":15683816,"url":"https://github.com/eunomia-bpf/bpf-compatible","last_synced_at":"2025-05-07T14:25:32.339Z","repository":{"id":167506603,"uuid":"643043551","full_name":"eunomia-bpf/bpf-compatible","owner":"eunomia-bpf","description":"compatible library for ebpf programs to improve BTF portability","archived":false,"fork":false,"pushed_at":"2023-10-11T08:28:31.000Z","size":2090,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-30T21:18:33.992Z","etag":null,"topics":["btf","co-re","ebpf","linux"],"latest_commit_sha":null,"homepage":"https://eunomia.dev/others/bpf-compatible/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eunomia-bpf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["yunwei37","Officeyutong"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-05-20T00:19:40.000Z","updated_at":"2025-04-18T08:29:06.000Z","dependencies_parsed_at":"2024-10-23T16:46:08.062Z","dependency_job_id":"edc9aabf-f84d-4707-9f7d-5e5921cc4eab","html_url":"https://github.com/eunomia-bpf/bpf-compatible","commit_stats":{"total_commits":20,"total_committers":4,"mean_commits":5.0,"dds":"0.30000000000000004","last_synced_commit":"0041b588e05e99cbcf419d0fc058a46b796b4b21"},"previous_names":["eunomia-bpf/bpf-compatible"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eunomia-bpf%2Fbpf-compatible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eunomia-bpf%2Fbpf-compatible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eunomia-bpf%2Fbpf-compatible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eunomia-bpf%2Fbpf-compatible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eunomia-bpf","download_url":"https://codeload.github.com/eunomia-bpf/bpf-compatible/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252893672,"owners_count":21820860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["btf","co-re","ebpf","linux"],"created_at":"2024-10-03T17:08:50.161Z","updated_at":"2025-05-07T14:25:32.314Z","avatar_url":"https://github.com/eunomia-bpf.png","language":"C","funding_links":["https://github.com/sponsors/yunwei37","https://github.com/sponsors/Officeyutong"],"categories":[],"sub_categories":[],"readme":"# bpf-compatible\n\n## Brief description\n\nThis repo contains a set of toolchain to simplify the building and running eBPF program on kernels without native BTF support.\nIt utilitizes [btfhub](https://github.com/aquasecurity/btfhub-archive) to drop the depencency of native BTF\n\n## What's in it\n\nThis repo mainly contains three parts:\n\n- A shell script `script/btfgen`, which can be used to clone the `btfhub` repo, or create stripped btf based on the compiled eBPF program and pack the btf archives into `.tar.gz`\n- A Rust crate `bpf-compatible-rs`, which were used by [eunomia-bpf](https://github.com/eunomia-bpf/eunomia-bpf/) to implement the unpacking and loading of the package that `btfgen` generated\n- A Rust crate `bpf-compatible-sys` and its C binding `btf_helpers.h`, which could be linked to other programs. It implements the unpacking and loading of the tar archive that `btfgen` generates. It can load tar archive either embedded into the executable, or provided by an external source. Used together with the `btf_helpers.h`, it can conveniently modify `struct bpf_object_open_opts*` and set the `custom_btf_path`.\n\n## Usage - Manually use the toolchain\n\nUsually the `prepare` steps could only be run once.\n\n### Prepare - `btfhub-archive`\n\nYou will need a git repo like [btfhub-archive](https://github.com/aquasecurity/btfhub-archive), which contains prebuilt btf archive of various releases, archs, and kernels. We also provided a repo for demonstrating only (It contains a little number of kernel btf archives) [https://github.com/eunomia-bpf/btfhub-archive](https://github.com/eunomia-bpf/btfhub-archive).\n\nThe repo should have the structure like:\n```plain\n|- ubuntu \u003cID in os-release\u003e\n|- ---- 22.04 \u003cVERSION in os-release\u003e\n|- ---- ---- x86_64 \u003cmachine in uname\u003e\n|- ---- ---- ---- 5.15.0-71-generic.btf \u003ckernel-release in uname\u003e\n```\n- Note: words in `\u003c\u003e` are explanation of the folder name.\n\n### Prepare - build `bpf-compatible-sys`\n\nRun `make` in the `bpf-compatible-sys` folder. It will build `libbpf_compatible.a` for you, which is a static library used to linked to libbpf programs\n\n### Prepare - Use `btfgen` to fetch `btfhub-archive`\n\nRun `./script/btfgen fetch` to download the `https://github.com/aquasecurity/btfhub-archive` repo to `~/.cache/eunomia/btfhub`. You can use `BTFHUB_REPO_URL` to override the repo url, or use `BTFHUB_CACHE_DIR` to override the local directory.\n\n### Write your kernel program\n\nSince generating the btf tar requires the compiled kernel program, so you should provide that first. \n\n### Create a btf tar archive with `btfgen`\n\nRun `./script/btfgen btfgen xxx.o -o min_core_btfs.tar.gz` to pack the tailored btf archive into `min_core_btfs.tar.gz`. `xxx.o` is the name of the compiled kernel program.\n\n### Create a linkable object of the btf archive\n\nRun `ld -r -b binary min_core_btfs.tar.gz -o min_core_btfs_tar.o` to generate a linkable `min_core_btfs_tar.o`. This file declares symbols named `_binary_min_core_btfs_tar_gz_start` and `_binary_min_core_btfs_tar_gz_end`, indicating the range of the embed tar.gz file\n\n### Write the userspace program with `btf_helpers.h`\n\nCall `int ensure_core_btf(struct bpf_object_open_opts*)` before opening the skeleton. For example:\n```c\n\tlibbpf_set_print(libbpf_print_fn);\n\n\terr = ensure_core_btf(\u0026open_opts);\n\tif (err) {\n\t\tfprintf(stderr, \"failed to fetch necessary BTF for CO-RE: %s\\n\", strerror(-err));\n\t\treturn 1;\n\t}\n\n\tobj = execsnoop_bpf__open_opts(\u0026open_opts);\n\tif (!obj) {\n\t\tfprintf(stderr, \"failed to open BPF object\\n\");\n\t\treturn 1;\n\t}\n```\n\nAnd call `void clean_core_btf(struct bpf_object_open_opts*)` before exiting. For example:\n```c\ncleanup:\n\tcleanup_core_btf(\u0026open_opts);\n```\n\n### Link your userspace program, `libbpf_compatible.a`, and `min_core_btfs_tar.o` together\n\nIt can be directly done by calling `clang \u003cyour_program\u003e libbpf_compatible.a min_core_btf.tar.o`\n\n## Usage - more simply\n\nWe have adapted the `libbpf-bootstrap` to the `bpf-compatible` toolchain. So there is a more simpler way:\n- Put your `xxx.c` (userspace space program) and `xxx.bpf.c`(kernel program) in the `example/c` folder, or directly modify an exist one\n- Add the name (`xxx` in the last row) to line 27 of `example/c/Makefile`, e.g `APPS = bootstrap execsnoop xxx`\n- Run `make xxx` in `example/cs`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feunomia-bpf%2Fbpf-compatible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feunomia-bpf%2Fbpf-compatible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feunomia-bpf%2Fbpf-compatible/lists"}