|Sep 1, 2022
#931 in Development tools
Userspace eBPF VM
This project aims to create an Apache-licensed library for executing eBPF programs. The primary implementation of eBPF lives in the Linux kernel, but due to its GPL license it can't be used in many projects.
This project includes an eBPF assembler, disassembler, interpreter (for all platforms), and JIT compiler (for x86-64 and Arm64 targets).
git submodule init
git submodule update --recursive
Building with CMake
A build system for compiling and testing ubpf is generated for Windows, Linux and macOS platforms using
cmake -S . -B build -DUBPF_ENABLE_TESTS=true
cmake --build build --config Debug
In order to prepare your system to successfully generate the build system using CMake, follow the platform-specific instructions below.
Building, compiling and testing on Windows requires an installation of Visual Studio (not VS Code -- the MSVC compiler is necessary!).
Note: There are free-to-use versions of Visual Studio for individual developers. These versions are known as the community version.
You can build, compile and test uBPF using VS Code but Visual Studio is still required.
The other requirement is that you have
nuget.exe in your
PATH. You can determine if your host meets this criteria by testing whether
produces output about how to execute the program. With
nuget.exe installed, the
cmake configuration system will download all the required developer libraries as it configures the build system.
First, make sure that you have the XCode Command Line Tools installed:
$ xcode-select -install
Installing the XCode Command Linux Tools will install Apple's version of the Clang compiler and other developer-support tools.
uBpf requires that your host have several support libraries installed. The easiest way to configure your host to meet these requirements,
$ brew install boost
- Install LLVM (and related tools):
$ brew install llvm cmake
$ brew install clang-format
Installing LLVM from Homebrew is optional for developing and using uBPF on macOS. It is required if you plan on compiling/creating eBPF programs by compiling LLVM and storing them in ELF files. If you do install LLVM from Homebrew, add
-DUBPF_ALTERNATE_LLVM_PATH=/opt/homebrew/opt/llvm/bin to the
cmake configuration command:
cmake -S . -B build -DUBPF_ENABLE_TESTS=true -DUBPF_ALTERNATE_LLVM_PATH=/opt/homebrew/opt/llvm/bin
Running the tests
Linux and MacOS
cmake --build build --target test --
ctest --test-dir build
Building with make (Linux)
make -C vm to build the VM. This produces a static library
and a simple executable used by the testsuite. After building the
library you can install using
make -C vm install via either root or
Running the tests (Linux)
To run the tests, you first need to build the vm code then use nosetests to execute the tests. Note: The tests have some dependencies that need to be present. See the .travis.yml for details.
Before running the test (assuming Debian derived distro)
sudo apt-get update
sudo apt-get -y install python python-pip python-setuptools python-wheel python-nose
python2 -m pip install --upgrade "pip<21.0"
python2 -m pip install -r requirements.txt
python2 -m pip install cpp-coveralls
Running the test
make -C vm COVERAGE=1
nosetests -v # run tests
After running the test
coveralls --gcov-options '\-lp' -i $PWD/vm/ubpf_vm.c -i $PWD/vm/ubpf_jit_x86_64.c -i $PWD/vm/ubpf_loader.c
Compiling C to eBPF
You'll need Clang 3.7.
clang-3.7 -O2 -target bpf -c prog.c -o prog.o
You can then pass the contents of
ubpf_load_elf, or to the stdin of
Please fork the project on GitHub and open a pull request. You can run all the
Copyright 2015, Big Switch Networks, Inc. Licensed under the Apache License, Version 2.0 <LICENSE.txt or http://www.apache.org/licenses/LICENSE-2.0>.