Skip to contentSkip to conversation

bpftool: improve error handing for missing .BTF section

PATCH Superseded Changbin Du 2 participants 8 messages Nov 29, 2022 – Dec 17, 2022

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover bpftool: improve error handing for missing .BTF section

v2:
- remove vmlinux specific error info.
- use builtin target .DELETE_ON_ERROR: to delete empty vmlinux.h

Changbin Du (2):
libbpf: show error info about missing ".BTF" section
bpf: makefiles: do not generate empty vmlinux.h

 tools/bpf/bpftool/Makefile           | 3 +++
 tools/lib/bpf/btf.c                  | 1 +
 tools/perf/Makefile.perf             | 2 ++
 tools/testing/selftests/bpf/Makefile | 3 +++
 4 files changed, 9 insertions(+)
Signature · 1 line
2.37.2
#1 lore raw

PATCH v2 1/2 libbpf: show error info about missing ".BTF" section

Show the real problem instead of just saying "No such file or directory".

Now will print below info:
libbpf: can not find '.BTF' section
Error: failed to load BTF from /home/changbin/work/linux/vmlinux: No such file or directory

---
 tools/lib/bpf/btf.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/btf.c +1 -0
index d88647da2c7f..1adc0f6019a0 100644
@@ -990,6 +990,7 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
 	err = 0;
 
 	if (!btf_data) {
+		pr_warn("can not find '%s' section\n", BTF_ELF_SEC);
 		err = -ENOENT;
 		goto done;
 	}
Signature · 1 line
2.37.2
#2 lore raw

Re: [PATCH v2 1/2] libbpf: show error info about missing ".BTF" section

Quoted 17 lines · Changbin Du

Show the real problem instead of just saying "No such file or directory".

Now will print below info:
libbpf: can not find '.BTF' section
Error: failed to load BTF from /home/changbin/work/linux/vmlinux: No such file or directory

---
 tools/lib/bpf/btf.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/btf.c +0 -0
index d88647da2c7f..1adc0f6019a0 100644

tools/lib/bpf/btf.c static struct btf *btf_parse_elf(const char *path, struct btf *base_btf, · line 993

Quoted 4 lines
tools/lib/bpf/btf.c +1 -0
@@ -990,6 +990,7 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
        err = 0;
 
        if (!btf_data) {
+               pr_warn("can not find '%s' section\n", BTF_ELF_SEC);

let's use consistent form of error messages:

pr_warn("failed to find '%s' ELF section in %s\n", BTF_ELF_SEC, path);

Quoted 6 lines
tools/lib/bpf/btf.c +0 -1
                err = -ENOENT;
                goto done;
        }
--

2.37.2

#3 lore raw

Re: [PATCH v2 1/2] libbpf: show error info about missing ".BTF" section

Quoted 20 lines · Andrii Nakryiko
Quoted 19 lines · Changbin Du

Show the real problem instead of just saying "No such file or directory".

Now will print below info:
libbpf: can not find '.BTF' section
Error: failed to load BTF from /home/changbin/work/linux/vmlinux: No such file or directory

---
 tools/lib/bpf/btf.c | 1 +
 1 file changed, 1 insertion(+)
tools/lib/bpf/btf.c +0 -0
index d88647da2c7f..1adc0f6019a0 100644
@@ -990,6 +990,7 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
        err = 0;
 
Quoted 7 lines

tools/lib/bpf/btf.c static struct btf *btf_parse_elf(const char *path, struct btf *base_btf, · line 993

Quoted 2 lines
tools/lib/bpf/btf.c +1 -0
        if (!btf_data) {
+               pr_warn("can not find '%s' section\n", BTF_ELF_SEC);

let's use consistent form of error messages:

pr_warn("failed to find '%s' ELF section in %s\n", BTF_ELF_SEC, path);

okay.

Quoted 6 lines
Quoted 6 lines
tools/lib/bpf/btf.c +0 -1
                err = -ENOENT;
                goto done;
        }
--

2.37.2

Signature · 2 lines
Cheers,
Changbin Du
#4 lore raw

PATCH v2 2/2 bpf: makefiles: do not generate empty vmlinux.h

In reply to Changbin Du

Remove the empty vmlinux.h if bpftool failed to dump btf info. The emptry vmlinux.h can hide real error when reading output of make.

This is done by adding .DELETE_ON_ERROR special target in related makefiles.

---
 tools/bpf/bpftool/Makefile           | 3 +++
 tools/perf/Makefile.perf             | 2 ++
 tools/testing/selftests/bpf/Makefile | 3 +++
 3 files changed, 8 insertions(+)
tools/bpf/bpftool/Makefile +3 -0
index 4a95c017ad4c..f6b1e65085db 100644
@@ -265,3 +265,6 @@ FORCE:
 .PHONY: all FORCE bootstrap clean install-bin install uninstall
 .PHONY: doc doc-clean doc-install doc-uninstall
 .DEFAULT_GOAL := all
+
+# Delete partially updated (corrupted) files on error
+.DELETE_ON_ERROR:
tools/perf/Makefile.perf +2 -0
index a432e59afc42..265254fc641a 100644
@@ -1149,3 +1149,5 @@ FORCE:
 .PHONY: libtraceevent_plugins archheaders
 
 endif # force_fixdep
+
+.DELETE_ON_ERROR:
tools/testing/selftests/bpf/Makefile +3 -0
index e6cf21fad69f..f41c4b011221 100644
@@ -617,3 +617,6 @@ EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)	\
 			       liburandom_read.so)
 
 .PHONY: docs docs-clean
+
+# Delete partially updated (corrupted) files on error
+.DELETE_ON_ERROR:
Signature · 1 line
2.37.2
#5 lore raw

Re: [PATCH v2 2/2] bpf: makefiles: do not generate empty vmlinux.h

Quoted 3 lines · Changbin Du

Remove the empty vmlinux.h if bpftool failed to dump btf info. The emptry vmlinux.h can hide real error when reading output

typo: empty

Quoted 28 lines

of make.

This is done by adding .DELETE_ON_ERROR special target in related makefiles.

---
 tools/bpf/bpftool/Makefile           | 3 +++
 tools/perf/Makefile.perf             | 2 ++
 tools/testing/selftests/bpf/Makefile | 3 +++
 3 files changed, 8 insertions(+)
tools/bpf/bpftool/Makefile +3 -0
index 4a95c017ad4c..f6b1e65085db 100644
@@ -265,3 +265,6 @@ FORCE:
 .PHONY: all FORCE bootstrap clean install-bin install uninstall
 .PHONY: doc doc-clean doc-install doc-uninstall
 .DEFAULT_GOAL := all
+
+# Delete partially updated (corrupted) files on error
+.DELETE_ON_ERROR:
tools/perf/Makefile.perf +0 -0
index a432e59afc42..265254fc641a 100644

tools/perf/Makefile.perf FORCE: · line 1153

Quoted 5 lines
tools/perf/Makefile.perf +2 -0
@@ -1149,3 +1149,5 @@ FORCE:
 .PHONY: libtraceevent_plugins archheaders
 
 endif # force_fixdep
+
+.DELETE_ON_ERROR:

please split out perf changes, they should go through perf tree

Quoted 14 lines
tools/testing/selftests/bpf/Makefile +3 -1
index e6cf21fad69f..f41c4b011221 100644
@@ -617,3 +617,6 @@ EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)      \
                               liburandom_read.so)
 
 .PHONY: docs docs-clean
+
+# Delete partially updated (corrupted) files on error
+.DELETE_ON_ERROR:
--

2.37.2

#6 lore raw

Re: [PATCH v2 2/2] bpf: makefiles: do not generate empty vmlinux.h

Quoted 7 lines · Andrii Nakryiko
Quoted 3 lines · Changbin Du

Remove the empty vmlinux.h if bpftool failed to dump btf info. The emptry vmlinux.h can hide real error when reading output

typo: empty

Will be fixed, thanks.

Quoted 30 lines
Quoted 30 lines

of make.

This is done by adding .DELETE_ON_ERROR special target in related makefiles.

---
 tools/bpf/bpftool/Makefile           | 3 +++
 tools/perf/Makefile.perf             | 2 ++
 tools/testing/selftests/bpf/Makefile | 3 +++
 3 files changed, 8 insertions(+)
tools/bpf/bpftool/Makefile +3 -0
index 4a95c017ad4c..f6b1e65085db 100644
@@ -265,3 +265,6 @@ FORCE:
 .PHONY: all FORCE bootstrap clean install-bin install uninstall
 .PHONY: doc doc-clean doc-install doc-uninstall
 .DEFAULT_GOAL := all
+
+# Delete partially updated (corrupted) files on error
+.DELETE_ON_ERROR:
tools/perf/Makefile.perf +0 -0
index a432e59afc42..265254fc641a 100644
@@ -1149,3 +1149,5 @@ FORCE:
 .PHONY: libtraceevent_plugins archheaders
 
Quoted 6 lines

tools/perf/Makefile.perf FORCE: · line 1153

Quoted 3 lines
tools/perf/Makefile.perf +2 -0
 endif # force_fixdep
+
+.DELETE_ON_ERROR:

please split out perf changes, they should go through perf tree

sure, I'll send a standalone patch to perf tree.

Quoted 14 lines
Quoted 14 lines
tools/testing/selftests/bpf/Makefile +3 -1
index e6cf21fad69f..f41c4b011221 100644
@@ -617,3 +617,6 @@ EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR)      \
                               liburandom_read.so)
 
 .PHONY: docs docs-clean
+
+# Delete partially updated (corrupted) files on error
+.DELETE_ON_ERROR:
--

2.37.2

Signature · 2 lines
Cheers,
Changbin Du
#7 lore raw
In reply to Changbin Du
Quoted 1 line · Changbin Du

please fill out cover letter

Quoted 17 lines

v2:
- remove vmlinux specific error info.
- use builtin target .DELETE_ON_ERROR: to delete empty vmlinux.h

Changbin Du (2):
libbpf: show error info about missing ".BTF" section
bpf: makefiles: do not generate empty vmlinux.h

 tools/bpf/bpftool/Makefile           | 3 +++
 tools/lib/bpf/btf.c                  | 1 +
 tools/perf/Makefile.perf             | 2 ++
 tools/testing/selftests/bpf/Makefile | 3 +++
 4 files changed, 9 insertions(+)

--
2.37.2