2023-01-17 23:59:04 +03:00
|
|
|
# The development version of clang is distributed as the 'clang' binary,
|
|
|
|
# while stable/released versions have a version number attached.
|
|
|
|
# Pin the default clang to a stable version.
|
2023-04-03 12:16:17 +03:00
|
|
|
CLANG ?= clang-14
|
|
|
|
STRIP ?= llvm-strip-14
|
|
|
|
OBJCOPY ?= llvm-objcopy-14
|
|
|
|
CFLAGS := -O2 -g -Wall -Werror $(CFLAGS)
|
|
|
|
|
|
|
|
CI_KERNEL_URL ?= https://github.com/cilium/ci-kernels/raw/master/
|
2023-01-17 23:59:04 +03:00
|
|
|
|
|
|
|
# Obtain an absolute path to the directory of the Makefile.
|
|
|
|
# Assume the Makefile is in the root of the repository.
|
|
|
|
REPODIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
|
|
|
UIDGID := $(shell stat -c '%u:%g' ${REPODIR})
|
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
# Prefer podman if installed, otherwise use docker.
|
|
|
|
# Note: Setting the var at runtime will always override.
|
|
|
|
CONTAINER_ENGINE ?= $(if $(shell command -v podman), podman, docker)
|
|
|
|
CONTAINER_RUN_ARGS ?= $(if $(filter ${CONTAINER_ENGINE}, podman), --log-driver=none, --user "${UIDGID}")
|
|
|
|
|
2023-01-17 23:59:04 +03:00
|
|
|
IMAGE := $(shell cat ${REPODIR}/testdata/docker/IMAGE)
|
|
|
|
VERSION := $(shell cat ${REPODIR}/testdata/docker/VERSION)
|
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
|
2023-01-17 23:59:04 +03:00
|
|
|
# clang <8 doesn't tag relocs properly (STT_NOTYPE)
|
|
|
|
# clang 9 is the first version emitting BTF
|
|
|
|
TARGETS := \
|
|
|
|
testdata/loader-clang-7 \
|
|
|
|
testdata/loader-clang-9 \
|
2023-04-03 12:16:17 +03:00
|
|
|
testdata/loader-$(CLANG) \
|
|
|
|
testdata/btf_map_init \
|
2023-01-17 23:59:04 +03:00
|
|
|
testdata/invalid_map \
|
|
|
|
testdata/raw_tracepoint \
|
|
|
|
testdata/invalid_map_static \
|
2023-04-03 12:16:17 +03:00
|
|
|
testdata/invalid_btf_map_init \
|
2023-01-17 23:59:04 +03:00
|
|
|
testdata/strings \
|
2023-04-03 12:16:17 +03:00
|
|
|
testdata/freplace \
|
|
|
|
testdata/iproute2_map_compat \
|
|
|
|
testdata/map_spin_lock \
|
|
|
|
testdata/subprog_reloc \
|
|
|
|
testdata/fwd_decl \
|
|
|
|
btf/testdata/relocs \
|
|
|
|
btf/testdata/relocs_read \
|
|
|
|
btf/testdata/relocs_read_tgt
|
2023-01-17 23:59:04 +03:00
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
.PHONY: all clean container-all container-shell generate
|
2023-01-17 23:59:04 +03:00
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
.DEFAULT_TARGET = container-all
|
2023-01-17 23:59:04 +03:00
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
# Build all ELF binaries using a containerized LLVM toolchain.
|
|
|
|
container-all:
|
|
|
|
${CONTAINER_ENGINE} run --rm ${CONTAINER_RUN_ARGS} \
|
2023-01-17 23:59:04 +03:00
|
|
|
-v "${REPODIR}":/ebpf -w /ebpf --env MAKEFLAGS \
|
2023-04-03 12:16:17 +03:00
|
|
|
--env CFLAGS="-fdebug-prefix-map=/ebpf=." \
|
|
|
|
--env HOME="/tmp" \
|
2023-01-17 23:59:04 +03:00
|
|
|
"${IMAGE}:${VERSION}" \
|
2023-04-03 12:16:17 +03:00
|
|
|
$(MAKE) all
|
2023-01-17 23:59:04 +03:00
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
# (debug) Drop the user into a shell inside the container as root.
|
|
|
|
container-shell:
|
|
|
|
${CONTAINER_ENGINE} run --rm -ti \
|
2023-01-17 23:59:04 +03:00
|
|
|
-v "${REPODIR}":/ebpf -w /ebpf \
|
|
|
|
"${IMAGE}:${VERSION}"
|
|
|
|
|
|
|
|
clean:
|
|
|
|
-$(RM) testdata/*.elf
|
2023-04-03 12:16:17 +03:00
|
|
|
-$(RM) btf/testdata/*.elf
|
|
|
|
|
|
|
|
format:
|
|
|
|
find . -type f -name "*.c" | xargs clang-format -i
|
|
|
|
|
|
|
|
all: format $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) generate
|
|
|
|
ln -srf testdata/loader-$(CLANG)-el.elf testdata/loader-el.elf
|
|
|
|
ln -srf testdata/loader-$(CLANG)-eb.elf testdata/loader-eb.elf
|
2023-01-17 23:59:04 +03:00
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
# $BPF_CLANG is used in go:generate invocations.
|
|
|
|
generate: export BPF_CLANG := $(CLANG)
|
|
|
|
generate: export BPF_CFLAGS := $(CFLAGS)
|
|
|
|
generate:
|
|
|
|
go generate ./cmd/bpf2go/test
|
|
|
|
go generate ./internal/sys
|
|
|
|
cd examples/ && go generate ./...
|
2023-01-17 23:59:04 +03:00
|
|
|
|
|
|
|
testdata/loader-%-el.elf: testdata/loader.c
|
2023-04-03 12:16:17 +03:00
|
|
|
$* $(CFLAGS) -target bpfel -c $< -o $@
|
|
|
|
$(STRIP) -g $@
|
2023-01-17 23:59:04 +03:00
|
|
|
|
|
|
|
testdata/loader-%-eb.elf: testdata/loader.c
|
2023-04-03 12:16:17 +03:00
|
|
|
$* $(CFLAGS) -target bpfeb -c $< -o $@
|
|
|
|
$(STRIP) -g $@
|
2023-01-17 23:59:04 +03:00
|
|
|
|
|
|
|
%-el.elf: %.c
|
2023-04-03 12:16:17 +03:00
|
|
|
$(CLANG) $(CFLAGS) -target bpfel -c $< -o $@
|
|
|
|
$(STRIP) -g $@
|
2023-01-17 23:59:04 +03:00
|
|
|
|
|
|
|
%-eb.elf : %.c
|
2023-04-03 12:16:17 +03:00
|
|
|
$(CLANG) $(CFLAGS) -target bpfeb -c $< -o $@
|
|
|
|
$(STRIP) -g $@
|
2023-01-17 23:59:04 +03:00
|
|
|
|
2023-04-03 12:16:17 +03:00
|
|
|
.PHONY: generate-btf
|
|
|
|
generate-btf: KERNEL_VERSION?=5.18
|
|
|
|
generate-btf:
|
|
|
|
$(eval TMP := $(shell mktemp -d))
|
|
|
|
curl -fL "$(CI_KERNEL_URL)/linux-$(KERNEL_VERSION).bz" -o "$(TMP)/bzImage"
|
|
|
|
./testdata/extract-vmlinux "$(TMP)/bzImage" > "$(TMP)/vmlinux"
|
|
|
|
$(OBJCOPY) --dump-section .BTF=/dev/stdout "$(TMP)/vmlinux" /dev/null | gzip > "btf/testdata/vmlinux.btf.gz"
|
|
|
|
curl -fL "$(CI_KERNEL_URL)/linux-$(KERNEL_VERSION)-selftests-bpf.tgz" -o "$(TMP)/selftests.tgz"
|
|
|
|
tar -xf "$(TMP)/selftests.tgz" --to-stdout tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.ko | \
|
|
|
|
$(OBJCOPY) --dump-section .BTF="btf/testdata/btf_testmod.btf" - /dev/null
|
|
|
|
$(RM) -r "$(TMP)"
|