Skip to content

Commit

Permalink
fix cli
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwei37 committed Aug 30, 2024
1 parent ba5f4c4 commit e166d40
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test-aot-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBPFTIME_ENABLE_UNIT_TESTING=1 -DBUILD_LLVM_AOT_CLI=1 -G Ninja
cmake --build build --target all -j
- name: test emit llvm
run: |
./build/cli/bpftime-vm build -emit-llvm .github/assets/sum.bpf.o
- name: Do compilation & run
run: |
export PATH=$PATH:~/.bpftime
Expand All @@ -53,5 +57,6 @@ jobs:
echo "Not found!"
exit 1
fi
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ This library is optimized for performance, flexibility, and minimal dependencies

For a comprehensive userspace eBPF runtime that includes support for maps, helpers, and seamless execution of Uprobe, syscall trace, XDP, and other eBPF programs—similar to kernel functionality but in userspace—please refer to the [bpftime](https://github.com/eunomia-bpf/bpftime) project.

## build
- [Userspace eBPF VM with LLVM JIT/AOT Compiler](#userspace-ebpf-vm-with-llvm-jitaot-compiler)
- [build project](#build-project)
- [Use llvmbpf as a library](#use-llvmbpf-as-a-library)
- [Use llvmbpf as a AOT compiler](#use-llvmbpf-as-a-aot-compiler)
- [Test with bpf-conformance](#test-with-bpf-conformance)
- [License](#license)

## build project

```sh
sudo apt install llvm-15-dev libzstd-dev
Expand Down
3 changes: 1 addition & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ Subcommands:

A CLI compiler for AOT of llvm-jit.

It can build ebpf ELF into native elf, or execute compiled native ELF. **Helpers and relocations are not supported**
It can build ebpf ELF into native elf, or execute compiled native ELF. **Helpers and relocations are not supported. For helpers and maps, please use bpftime aot cli in the [bpftime/tools](https://github.com/eunomia-bpf/bpftime)**

This program might be installed by running `make release-with-llvm-jit` in the project root.
8 changes: 6 additions & 2 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ static int build_ebpf_program(const std::string &ebpf_elf,
i, "helper_" + std::to_string(i), nullptr);
}
auto result = vm.do_aot_compile(emit_llvm);

if (!result) {
SPDLOG_ERROR("Failed to compile program {}: {}",
name, vm.get_error_message());
return 1;
}
auto out_path = output / (std::string(name) + ".o");
std::ofstream ofs(out_path, std::ios::binary);
ofs.write((const char *)result.data(), result.size());
ofs.write((const char *)result->data(), result->size());
if (!emit_llvm)
SPDLOG_INFO("Program {} written to {}", name,
out_path.c_str());
Expand Down

0 comments on commit e166d40

Please sign in to comment.