-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libbpftime.a archive when BPFTIME_BUILD_STATIC_LIB on (#294)
* hp77 | Add option for BPFTIME_BUILD_STATIC_LIB * hp77 | Add function to archive and fix an ARCH variable issue * hp77 | add targets to the archiving function * hp77 | Change destination to bpftime root folder * hp77 | Add example program to test libbpftime.a * hp77 | Add lib-*.a to main file * hp77 | fix path for libubpf * fix: bash stucks when injected by bpftime agent (#295) * update * Update * hp77 | change name of variables * hp77 | Add script to change logic for same object file * hp77 | fix script * hp77 | add option for llvm jit * hp77 | add libubpf to condition and add target in makefile * hp77 | add makefile for examples * hp77 | Add libbpf * Add better example and remove libtool * Fix Makefile command Signed-off-by: Himanshu Pandey <24816726+hp77-creator@users.noreply.github.com> * Fix example * Fix spdlog include --------- Signed-off-by: Himanshu Pandey <24816726+hp77-creator@users.noreply.github.com> Co-authored-by: Officeyutong <yt.xyxx@gmail.com>
- Loading branch information
1 parent
f8db2dc
commit 6c60ff1
Showing
9 changed files
with
233 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
# Check if the correct number of arguments is provided | ||
if [[ $# -ne 2 ]]; then | ||
echo "Usage: $0 <archive> <output_dir>" | ||
exit 1 | ||
fi | ||
|
||
archive=$1 | ||
output_dir=$2 | ||
|
||
# Ensure the output directory exists | ||
mkdir -p "$output_dir" | ||
|
||
# List files in the archive | ||
files=$(ar t "$archive") | ||
|
||
# Declare an associative array to count occurrences of each file | ||
declare -A file_count | ||
|
||
# Count occurrences of each file | ||
for file in $files; do | ||
((file_count["$file"]++)) | ||
done | ||
|
||
# Extract files individually, renaming duplicates | ||
for file in "${!file_count[@]}"; do | ||
count=${file_count["$file"]} | ||
if [[ $count -gt 1 ]]; then | ||
for ((i = 1; i <= count; i++)); do | ||
ar xN $i "$archive" "$file" | ||
new_file="${file%.o}.$i.o" | ||
mv "$file" "$output_dir/$new_file" | ||
done | ||
else | ||
ar x "$archive" "$file" | ||
mv "$file" "$output_dir/$file" | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CXX = g++ | ||
|
||
CXXFLAGS = -I../../runtime/include \ | ||
-I../../vm/compat/include \ | ||
-I../../third_party/spdlog/include \ | ||
-I../../vm/vm-core/include | ||
|
||
.DEFAULT_GOAL := help | ||
|
||
LDFLAGS = -L$(HOME)/.bpftime | ||
LDLIBS = -lbpftime -lboost_system -lrt -lbpf | ||
|
||
SHM_SRC = main.cpp | ||
|
||
SHM_TARGET = shm_example | ||
|
||
help: | ||
@echo "Available targets:" | ||
@grep -E '^[a-zA-Z_-]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*## "}; {printf " %-20s %s\n", $$1, $$2}' | ||
|
||
|
||
shm_example: $(SHM_SRC) ## build shared memory example | ||
$(CXX) -o $(SHM_TARGET) $(SHM_SRC) $(CXXFLAGS) $(LDFLAGS) $(LDLIBS) | ||
|
||
.PHONY: clean | ||
clean: ## clean the build | ||
rm -f $(SHM_TARGET) example_shm.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Example program | ||
|
||
This is a sample program showcasing the use of libbpftime. | ||
|
||
I am using headers from runtime and I am linking `libbpftime.a` which is installed in `~/.bpftime` | ||
|
||
|
||
### Prerequisites | ||
|
||
following command should have been run, so that `libbpftime.a` exists in `~/.bpftime` directory | ||
|
||
```shell | ||
cmake -Bbuild -DCMAKE_BUILD_TYPE:STRING=Release \ | ||
-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO -DBPFTIME_BUILD_STATIC_LIB=ON | ||
cmake --build build --config Release --target install | ||
``` | ||
|
||
|
||
### Build | ||
|
||
- Makefile | ||
|
||
You can make examples using makefile: | ||
|
||
> Using make to run examples is preferred | ||
run `make` and you will see the following output | ||
|
||
```shell | ||
Available targets: | ||
shm_example build shared memory example | ||
clean clean the build | ||
``` | ||
|
||
command to execute the code: | ||
when not using llvm-jit | ||
```shell | ||
g++ -o example main.cpp -I../../runtime/include -I../../vm/compat/include/ -I../../third_party/spdlog/include -I../../vm/vm-core/include -L~/.bpftime -lbpftime -lboost_system -lrt -lbpf | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"1": { | ||
"type": "bpf_prog_handler", | ||
"name": "example_prog", | ||
"attr": { | ||
"insns": "abcd1234ef567890", | ||
"type": 1, | ||
"cnt": 1, | ||
"attach_fds": [2, 3] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <iostream> | ||
#include "bpftime_shm.hpp" | ||
#include "spdlog/spdlog.h" | ||
|
||
int main() { | ||
bpftime_initialize_global_shm(bpftime::shm_open_type::SHM_CREATE_OR_OPEN); | ||
const char* jsonFileName = "example_shm.json"; | ||
const char* importJsonName = "ebpf.json"; | ||
SPDLOG_INFO("GLOBAL memory initialized "); | ||
// load json program to shm | ||
bpftime_import_global_shm_from_json(importJsonName); | ||
// export it to another json file | ||
bpftime_export_global_shm_to_json(jsonFileName); | ||
// remove content from global shm | ||
bpftime_remove_global_shm(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters