-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libbpf-tools: Add experimental BTFGen integration #3889
Merged
davemarchevsky
merged 4 commits into
iovisor:master
from
inspektor-gadget:mauricio/btfgen-integration
Apr 7, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6230695
libbpf-tools: Include bpftool as a submodule
mauriciovasquezbernal 37d703d
libbpf-tools: Add experimental integration with BTFGen
mauriciovasquezbernal a416a82
libbpf-tools: Update tools to use BTFGen integration
mauriciovasquezbernal b95542c
libbpf-tools: Add documentation about BTFGen integration
mauriciovasquezbernal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's call it just "btfhub"? archive implies it's outdated and not maintained anymore. So for consistency with MAkefile, let's call it "btf-hub" here and $BTF_HUB in Makefile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this one. There are two repositories related to btfhub: https://github.com/aquasecurity/btfhub & https://github.com/aquasecurity/btfhub-archive/. We are only using the later, so I think it's fine to call it BTFHUB_ARCHIVE to avoid confusion with the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's confusing, but ok, no problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we've split the scripts/tooling/docs from the actual archive. There were major discussion where to keep the BTF files back then, and, to be honest, github was what made it to have a higher reach (among projects)... Unfortunately we don't keep different arches (maybe they could be kept as diff branches). I'm just afraid of breaking other projects (as we currently have 4 or 5 projects relying in BTFHUB now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, separate branches is an interesting idea! You can still master branch that merge all the arch-specific branches each time you get an update. So no one should break, but anyone who wants only architecture-specific BTFs can do that without paying for all the other architectures.