# gcc-bpf-example **Repository Path**: rtoax/gcc-bpf-example ## Basic Information - **Project Name**: gcc-bpf-example - **Description**: Fork from https://git.sr.ht/~brianwitte/gcc-bpf-example, sync https://github.com/Rtoax/gcc-bpf-example - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-04 - **Last Updated**: 2026-08-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### gcc-bpf-example - a simple bpf program using only gcc [![builds.sr.ht status](https://builds.sr.ht/~brianwitte/current-working-gcc-bpf-toolchain.svg)](https://builds.sr.ht/~brianwitte/current-working-gcc-bpf-toolchain?) - toolchain provided in this repo [![builds.sr.ht status](https://builds.sr.ht/~brianwitte/upstream-gcc-bpf-toolchain.svg)](https://builds.sr.ht/~brianwitte/upstream-gcc-bpf-toolchain?) - upstream toolchain master build For more information on the GCC backend for BPF, see the wiki: https://gcc.gnu.org/wiki/BPFBackEnd ``` # SUMMARY `gcc-bpf-example` is a tested and documented bpf program example, distinguished by its exclusive use of gcc (gnu compiler collection) for all compilation stages, including the generation of bpf bytecode. this approach is a notable deviation from the traditional reliance on clang for bpf bytecode compilation, showcasing the versatility and capability of gcc in handling bpf programs written in c. this project aims to provide an accessible and instructive example for those interested in bpf development with gcc. ## SETUP ### Requirements: - newer bpf enabled kernel - make - curl - gcc-bpf (use `make toolchain` - documented below) - gcc >= 10 #### Optional: - git - clang ### Installation: 0. Clone the repository: git clone https://git.sr.ht/~brianwitte/gcc-bpf-example 1. Compile standalone gcc compiler toolchain for bpf targets: cd gcc-bpf-example make toolchain # install: $HOME/root-bpf, build: $HOME/gcc-bpf-build 2. Fetch libbpf and bpftool standalone deps: make fetch-libs 3. Build `gcc-bpf-example` from source: make If compilation succeeds, a `example-gcc-bpf` binary will be in project root. ## USAGE ### Command: Run `sudo ./example-gcc-bpf` to start... Follow output from there. ## LICENSE `gcc-bpf-example` is licensed under the GPL-2.0 license. All source files within this project are GPL-2.0-or-later unless specified otherwise at top of file via SPDX-License-Identifier. See LICENSE file in project root accompanying this README. ```