linux/tools/bpf/bpftool
Quentin Monnet 6ae32b29c0 tools: bpftool: Restore message on failure to guess program type
In commit 4a3d6c6a6e ("libbpf: Reduce log level for custom section
names"), log level for messages for libbpf_attach_type_by_name() and
libbpf_prog_type_by_name() was downgraded from "info" to "debug". The
latter function, in particular, is used by bpftool when attempting to
load programs, and this change caused bpftool to exit with no hint or
error message when it fails to detect the type of the program to load
(unless "-d" option was provided).

To help users understand why bpftool fails to load the program, let's do
a second run of the function with log level in "debug" mode in case of
failure.

Before:

    # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
    # echo $?
    255

Or really verbose with -d flag:

    # bpftool -d prog load sample_ret0.o /sys/fs/bpf/sample_ret0
    libbpf: loading sample_ret0.o
    libbpf: section(1) .strtab, size 134, link 0, flags 0, type=3
    libbpf: skip section(1) .strtab
    libbpf: section(2) .text, size 16, link 0, flags 6, type=1
    libbpf: found program .text
    libbpf: section(3) .debug_abbrev, size 55, link 0, flags 0, type=1
    libbpf: skip section(3) .debug_abbrev
    libbpf: section(4) .debug_info, size 75, link 0, flags 0, type=1
    libbpf: skip section(4) .debug_info
    libbpf: section(5) .rel.debug_info, size 32, link 14, flags 0, type=9
    libbpf: skip relo .rel.debug_info(5) for section(4)
    libbpf: section(6) .debug_str, size 150, link 0, flags 30, type=1
    libbpf: skip section(6) .debug_str
    libbpf: section(7) .BTF, size 155, link 0, flags 0, type=1
    libbpf: section(8) .BTF.ext, size 80, link 0, flags 0, type=1
    libbpf: section(9) .rel.BTF.ext, size 32, link 14, flags 0, type=9
    libbpf: skip relo .rel.BTF.ext(9) for section(8)
    libbpf: section(10) .debug_frame, size 40, link 0, flags 0, type=1
    libbpf: skip section(10) .debug_frame
    libbpf: section(11) .rel.debug_frame, size 16, link 14, flags 0, type=9
    libbpf: skip relo .rel.debug_frame(11) for section(10)
    libbpf: section(12) .debug_line, size 74, link 0, flags 0, type=1
    libbpf: skip section(12) .debug_line
    libbpf: section(13) .rel.debug_line, size 16, link 14, flags 0, type=9
    libbpf: skip relo .rel.debug_line(13) for section(12)
    libbpf: section(14) .symtab, size 96, link 1, flags 0, type=2
    libbpf: looking for externs among 4 symbols...
    libbpf: collected 0 externs total
    libbpf: failed to guess program type from ELF section '.text'
    libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]

After:

    # bpftool prog load sample_ret0.o /sys/fs/bpf/sample_ret0
    libbpf: failed to guess program type from ELF section '.text'
    libbpf: supported section(type) names are: socket sk_reuseport kprobe/ [...]

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200311021205.9755-1-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2020-03-13 12:49:51 -07:00
..
bash-completion tools: bpftool: Fix minor bash completion mistakes 2020-03-13 00:24:08 +01:00
Documentation bpftool: Documentation for bpftool prog profile 2020-03-10 00:04:07 +01:00
skeleton bpftool: Use linux/types.h from source tree for profiler build 2020-03-12 16:22:41 +01:00
.gitignore bpftool: Add _bpftool and profiler.skel.h to .gitignore 2020-03-13 00:08:33 +01:00
btf_dumper.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2020-01-23 08:10:16 +01:00
btf.c bpftool: Add header guards to generated vmlinux.h 2020-03-02 16:25:14 -08:00
cfg.c tools: bpftool: teach cfg code about JMP32 2019-01-26 13:33:01 -08:00
cfg.h tools: bpftool: replace Netronome boilerplate with SPDX license headers 2018-12-13 12:08:44 +01:00
cgroup.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
common.c tools: bpftool: Restore message on failure to guess program type 2020-03-13 12:49:51 -07:00
feature.c bpftool: Make probes which emit dmesg warnings optional 2020-02-26 18:34:34 +01:00
gen.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
jit_disasm.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
json_writer.c tools: bpftool: move "__printf()" attributes to header file 2019-08-15 22:06:46 -07:00
json_writer.h tools: bpftool: move "__printf()" attributes to header file 2019-08-15 22:06:46 -07:00
main.c tools: bpftool: Restore message on failure to guess program type 2020-03-13 12:49:51 -07:00
main.h tools: bpftool: Restore message on failure to guess program type 2020-03-13 12:49:51 -07:00
Makefile bpftool: Skeleton should depend on libbpf 2020-03-13 00:08:33 +01:00
map_perf_ring.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
map.c tools: bpftool: Allow all prog/map handles for pinning objects 2020-03-13 00:24:08 +01:00
net.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
netlink_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
netlink_dumper.h tools: bpftool: dual license all files 2018-12-13 12:08:44 +01:00
perf.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
prog.c tools: bpftool: Restore message on failure to guess program type 2020-03-13 12:49:51 -07:00
tracelog.c tools: bpftool: add an option to prevent auto-mount of bpffs, tracefs 2018-12-18 14:47:17 +01:00
xlated_dumper.c bpftool: Use consistent include paths for libbpf 2020-01-20 16:37:45 -08:00
xlated_dumper.h tools: bpftool: replace Netronome boilerplate with SPDX license headers 2018-12-13 12:08:44 +01:00