Merge pull request #39 from chenhengqi/update-btf-example

Update btf example
This commit is contained in:
Toke Høiland-Jørgensen
2022-03-09 12:00:39 +01:00
committed by GitHub
3 changed files with 24 additions and 16 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ compile_commands.json
*.ll
*.o
*.skel.h
lib/libbpf-install/

View File

@@ -35,9 +35,9 @@ int print_all_levels(enum libbpf_print_level level,
int main(int argc, char **argv)
{
struct btf *vmlinux_btf, *module_btf;
struct btf *vmlinux_btf, *module_btf = NULL;
int opt, longindex = 0;
__s32 type_id;
__s32 type_id;
int err = 0;
/* Parse commands line args */
@@ -46,7 +46,6 @@ int main(int argc, char **argv)
switch (opt) {
case 'd':
libbpf_set_print(print_all_levels);
// verifier_logs = true;
break;
default:
pr_err("Unrecognized option '%s'\n", argv[optind - 1]);
@@ -66,17 +65,25 @@ int main(int argc, char **argv)
module_btf = btf__load_module_btf(module_name, vmlinux_btf);
err = libbpf_get_error(module_btf);
if (err) {
pr_err("ERROR(%d): btf__load_module_btf() module_name:%s\n",
pr_err("ERROR(%d): btf__load_module_btf() module_name: %s\n",
err, module_name);
goto out;
}
type_id = btf__find_by_name(module_btf, symbol_name);
type_id = btf__find_by_name(module_btf, symbol_name);
if (type_id < 0) {
err = type_id;
pr_err("ERROR(%d): btf__find_by_name() symbol_name: %s\n",
err, symbol_name);
goto out;
}
printf("Module:%s Symbol:%s have BTF id:%d\n",
module_name, symbol_name, type_id);
out:
btf__free(module_btf);
btf__free(vmlinux_btf);
if (err)
return EXIT_FAILURE;
return EXIT_SUCCESS;

22
configure vendored
View File

@@ -159,17 +159,17 @@ EOF
compile_err=$($CLANG -target bpf -c $TMPDIR/bpf_use_errno_test.c 2>&1)
if [ "$?" -ne "0" ]; then
echo "*** ERROR - Clang BPF-prog cannot include <errno.h>"
echo " - Install missing userspace header file"
echo ""
echo "Compile error: $compile_err"
echo ""
echo " On Fedora install:"
echo " dnf install glibc-devel.i686"
echo " On Debian install:"
echo " apt install libc6-dev-i386"
echo ""
exit 1
echo "*** ERROR - Clang BPF-prog cannot include <errno.h>"
echo " - Install missing userspace header file"
echo ""
echo "Compile error: $compile_err"
echo ""
echo " On Fedora install:"
echo " dnf install glibc-devel.i686"
echo " On Debian install:"
echo " apt install libc6-dev-i386"
echo ""
exit 1
fi
}