diff options
| author | Paul Buetow <paul@buetow.org> | 2024-02-04 10:45:19 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-02-04 10:45:19 +0200 |
| commit | 86df1706e25d945aad671d3bf9f89f1d057eb616 (patch) | |
| tree | b9a86cdb3133c83e7cccec76fbf133dc20b01c8f | |
| parent | 6f0b9a473ab8e3fd8ac58724e907809da36b1bd1 (diff) | |
can compile
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | Makefile | 87 | ||||
| -rw-r--r-- | README.md | 8 | ||||
| -rwxr-xr-x | build.sh | 13 | ||||
| -rwxr-xr-x | clean.sh | 6 | ||||
| -rw-r--r-- | go.mod | 6 | ||||
| -rw-r--r-- | go.sum | 4 | ||||
| -rwxr-xr-x | run.sh | 21 |
8 files changed, 35 insertions, 112 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3412421 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ioriotng +*.o diff --git a/Makefile b/Makefile deleted file mode 100644 index 00aee0a..0000000 --- a/Makefile +++ /dev/null @@ -1,87 +0,0 @@ -BASEDIR = $(abspath ../../) - -OUTPUT = ../../output - -LIBBPF_SRC = $(abspath ../../libbpf/src) -LIBBPF_OBJ = $(abspath $(OUTPUT)/libbpf.a) - -CLANG = clang -CC = $(CLANG) -GO = go - -ARCH := $(shell uname -m | sed 's/x86_64/amd64/g; s/aarch64/arm64/g') - -CFLAGS = -g -O2 -Wall -fpie -I$(abspath ../common) -LDFLAGS = - -CGO_CFLAGS_STATIC = "-I$(abspath $(OUTPUT)) -I$(abspath ../common)" -CGO_LDFLAGS_STATIC = "-lelf -lzstd $(LIBBPF_OBJ)" -CGO_EXTLDFLAGS_STATIC = '-w -extldflags "-static"' - -CGO_CFLAGS_DYN = "-I. -I/usr/include/" -CGO_LDFLAGS_DYN = "-lelf -lz -lbpf" - -MAIN = main - -.PHONY: $(MAIN) -.PHONY: $(MAIN).go -.PHONY: $(MAIN).bpf.c - -all: $(MAIN)-static - -.PHONY: libbpfgo -.PHONY: libbpfgo-static -.PHONY: libbpfgo-dynamic - -## libbpfgo - -libbpfgo-static: - $(MAKE) -C $(BASEDIR) libbpfgo-static - -libbpfgo-dynamic: - $(MAKE) -C $(BASEDIR) libbpfgo-dynamic - -outputdir: - $(MAKE) -C $(BASEDIR) outputdir - -## test bpf dependency - -$(MAIN).bpf.o: $(MAIN).bpf.c - $(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -I$(abspath ../common) -c $< -o $@ - -## test - -.PHONY: $(MAIN)-static -.PHONY: $(MAIN)-dynamic - -$(MAIN)-static: libbpfgo-static | $(MAIN).bpf.o - CC=$(CLANG) \ - CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \ - CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \ - GOOS=linux GOARCH=$(ARCH) \ - $(GO) build \ - -tags netgo -ldflags $(CGO_EXTLDFLAGS_STATIC) \ - -o $(MAIN)-static ./$(MAIN).go - -$(MAIN)-dynamic: libbpfgo-dynamic | $(MAIN).bpf.o - CC=$(CLANG) \ - CGO_CFLAGS=$(CGO_CFLAGS_DYN) \ - CGO_LDFLAGS=$(CGO_LDFLAGS_DYN) \ - $(GO) build -o ./$(MAIN)-dynamic ./$(MAIN).go - -## run - -.PHONY: run -.PHONY: run-static -.PHONY: run-dynamic - -run: run-static - -run-static: $(MAIN)-static - sudo ./run.sh $(MAIN)-static - -run-dynamic: $(MAIN)-dynamic - sudo ./run.sh $(MAIN)-dynamic - -clean: - rm -f *.o *-static *-dynamic @@ -9,7 +9,13 @@ Maybe a spiritual successor of one of my previous projects, I/O Riot https://cod To get this running on Fedora 39, run: ```shell -sudo dnf install zlib-static glibc-static libzstd-static +mkdir ~/git +git clone https://codeberg.org/snonux/ioriotng +git clone https://github.com/aquasecurity/libbpfgo +sudo dnf install -y zlib-static glibc-static libzstd-static +cd libbpfgo +make +make libbpfgo-static ``` Need libelf static, which isn't in any repos. So we need to compile it ourselves. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a6d5e27 --- /dev/null +++ b/build.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -xeuf -o pipefail + +clang -g -O2 -Wall -fpie -I../libbpfgo/selftest/common -target bpf -D__TARGET_ARCH_amd64 -I../libbpfgo/output -I../libbpfgo/selftest/common -c main.bpf.c -o main.bpf.o + +export CC=clang +export CGO_CFLAGS="-I/home/paul/git/libbpfgo/output -I/home/paul/git/libbpfgo/selftest/common" +export CGO_LDFLAGS="-lelf -lzstd /home/paul/git/libbpfgo/output/libbpf.a" +export GOOS=linux +export GOARCH=amd64 + +go build -tags netgo -ldflags '-w -extldflags "-static"' -o ioriotng ./main.go diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..0c7aeb8 --- /dev/null +++ b/clean.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -xeuf -o pipefail + +find . -name ioriotng -exec rm -v {} \; +find . -name \*.o -exec rm -v {} \; @@ -1,7 +1,5 @@ -module github.com/aquasecurity/libbpfgo/selftest/map-update +module ioriotng go 1.18 -require github.com/aquasecurity/libbpfgo v0.4.7-libbpf-1.2.0-b2e29a1 - -replace github.com/aquasecurity/libbpfgo => ../../ +require github.com/aquasecurity/libbpfgo v0.6.0-libbpf-1.3.0.20240111220235-90dbffffbdab @@ -1,4 +1,6 @@ +github.com/aquasecurity/libbpfgo v0.6.0-libbpf-1.3.0.20240111220235-90dbffffbdab h1:w74AraWsnj+AgEOk2uERlLtECCWutMtuwCGCCWzpBBs= +github.com/aquasecurity/libbpfgo v0.6.0-libbpf-1.3.0.20240111220235-90dbffffbdab/go.mod h1:0rEApF1YBHGuZ4C8OYI9q5oDBVpgqtRqYATePl9mCDk= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= @@ -1,22 +1,5 @@ #!/bin/bash -# SETTINGS +set -xeuf -o pipefail -TEST=$(dirname $0)/$1 # execute -TIMEOUT=10 # seconds - -# COMMON - -COMMON="$(dirname $0)/../common/common.sh" -[[ -f $COMMON ]] && { . $COMMON; } || { error "no common"; exit 1; } - -# MAIN - -kern_version gt 4.18 - -check_build -check_ppid -test_exec -test_finish - -exit 0 +sudo ./ioriotng |
