-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3889 from kinvolk/mauricio/btfgen-integration
libbpf-tools: Add experimental BTFGen integration
- Loading branch information
Showing
31 changed files
with
609 additions
and
29 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "src/cc/libbpf"] | ||
path = src/cc/libbpf | ||
url = https://github.com/libbpf/libbpf.git | ||
[submodule "libbpf-tools/bpftool"] | ||
path = libbpf-tools/bpftool | ||
url = https://github.com/libbpf/bpftool |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/.output | ||
/btfhub-archive | ||
/bashreadline | ||
/bindsnoop | ||
/biolatency | ||
|
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,40 @@ | ||
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) | ||
SOURCE_BTF_FILES = $(shell find $(BTFHUB_ARCHIVE)/ -iregex ".*$(subst x86,x86_64,$(ARCH)).*" -type f -name '*.btf.tar.xz') | ||
MIN_CORE_BTF_FILES = $(patsubst $(BTFHUB_ARCHIVE)/%.btf.tar.xz, $(OUTPUT)/min_core_btfs/%.btf, $(SOURCE_BTF_FILES)) | ||
BPF_O_FILES = $(patsubst %,$(OUTPUT)/%.bpf.o,$(APPS)) | ||
|
||
.PHONY: all | ||
all: $(OUTPUT)/min_core_btf_tar.o | ||
|
||
ifeq ($(V),1) | ||
Q = | ||
msg = | ||
else | ||
Q = @ | ||
msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; | ||
MAKEFLAGS += --no-print-directory | ||
endif | ||
|
||
$(BTFHUB_ARCHIVE)/%.btf: $(BTFHUB_ARCHIVE)/%.btf.tar.xz | ||
$(call msg,UNTAR,$@) | ||
$(Q)tar xvfJ $< -C "$(@D)" > /dev/null | ||
$(Q)touch $@ | ||
|
||
$(MIN_CORE_BTF_FILES): $(BPF_O_FILES) | ||
|
||
# Create reduced version of BTF files to be embedded within the tools executables | ||
$(OUTPUT)/min_core_btfs/%.btf: $(BTFHUB_ARCHIVE)/%.btf | ||
$(call msg,BTFGEN,$@) | ||
$(Q)mkdir -p "$(@D)" | ||
$(Q)$(BPFTOOL) gen min_core_btf $< $@ $(OUTPUT)/*.bpf.o | ||
|
||
# Compress reduced BTF files and create an object file with its content | ||
$(OUTPUT)/min_core_btf_tar.o: $(MIN_CORE_BTF_FILES) | ||
$(call msg,TAR,$@) | ||
$(Q)tar c --gz -f $(OUTPUT)/min_core_btfs.tar.gz -C $(OUTPUT)/min_core_btfs/ . | ||
$(Q)cd $(OUTPUT) && ld -r -b binary min_core_btfs.tar.gz -o $@ | ||
|
||
# delete failed targets | ||
.DELETE_ON_ERROR: | ||
# keep intermediate (.skel.h, .bpf.o, etc) targets | ||
.SECONDARY: |
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 |
---|---|---|
|
@@ -16,12 +16,12 @@ directory. `make clean` will clean up all the build artifacts, including | |
generated binaries. | ||
|
||
Given that the libbpf package might not be available across wide variety of | ||
distributions, all libbpf-based tools are linked statically against a version | ||
distributions, all libbpf-based tools are linked statically against a version | ||
of libbpf that BCC links against (from submodule under src/cc/libbpf). This | ||
results in binaries with minimal amount of dependencies (libc, libelf, and | ||
libz are linked dynamically, though, given their widespread availability). | ||
If your build fails because the libbpf submodule is outdated, try running `git | ||
submodule update --init --recursive`. | ||
libz are linked dynamically, though, given their widespread availability). | ||
If your build fails because the libbpf submodule is outdated, try running `git | ||
submodule update --init --recursive`. | ||
|
||
Tools are expected to follow a simple naming convention: | ||
- <tool>.c contains userspace C code of a tool. | ||
|
@@ -92,3 +92,30 @@ CONFIG_DEBUG_INFO=y | |
kernel build (it comes from dwarves package). Without it, BTF won't be | ||
generated, and on older kernels you'd get only warning, but still would | ||
build kernel successfully | ||
|
||
Running in kernels without CONFIG_DEBUG_INFO_BTF=y | ||
-------------------------------------------------- | ||
|
||
It's possible to run some tools in kernels that don't expose | ||
`/sys/kernel/btf/vmlinux`. For those cases, | ||
[BTFGen](https://lore.kernel.org/bpf/[email protected]) | ||
and [BTFHub](https://github.com/aquasecurity/btfhub) can be used to | ||
generate small BTF files for the most popular Linux distributions that | ||
are shipped with the tools in order to provide the needed information to | ||
perform the CO-RE relocations when loading the eBPF programs. | ||
|
||
If you haven't cloned the | ||
[btfhub-archive](https://github.com/aquasecurity/btfhub) repository, you | ||
can run make and it'll clone it for you into the `$HOME/.local/share` | ||
directory: | ||
|
||
```bash | ||
make ENABLE_MIN_CORE_BTFS=1 -j$(nproc) | ||
``` | ||
|
||
If you have a local copy of such repository, you can pass it's location | ||
to avoid cloning it again: | ||
|
||
```bash | ||
make ENABLE_MIN_CORE_BTFS=1 BTF_HUB_ARCHIVE=<path_to_btfhub-archive> -j$(nproc) | ||
``` |
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
Binary file not shown.
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
Oops, something went wrong.