libbpf: Add pr_warn() for EINVAL cases in linker_sanity_check_elf
authorSergei Trofimovich <slyich@gmail.com>
Fri, 8 Dec 2023 21:51:00 +0000 (21:51 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Sat, 9 Dec 2023 01:11:18 +0000 (17:11 -0800)
commit32fa058398624166dd04ff4af49cfef69c94abbc
treef32cdfd1ffa633a2877467d11fa9a87a187c50b7
parent09115c33e6ec4a98a0609ac5fa702b7fe566d8f9
libbpf: Add pr_warn() for EINVAL cases in linker_sanity_check_elf

Before the change on `i686-linux` `systemd` build failed as:

    $ bpftool gen object src/core/bpf/socket_bind/socket-bind.bpf.o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    Error: failed to link 'src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o': Invalid argument (22)

After the change it fails as:

    $ bpftool gen object src/core/bpf/socket_bind/socket-bind.bpf.o src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    libbpf: ELF section #9 has inconsistent alignment addr=8 != d=4 in src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o
    Error: failed to link 'src/core/bpf/socket_bind/socket-bind.bpf.unstripped.o': Invalid argument (22)

Now it's slightly easier to figure out what is wrong with an ELF file.

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20231208215100.435876-1-slyich@gmail.com
tools/lib/bpf/linker.c