Re: [PATCH v2] libbpf: add pr_warn() for EINVAL cases in linker_sanity_check_elf

From: Eduard Zingerman
Date: Fri Dec 08 2023 - 17:00:41 EST


On Fri, 2023-12-08 at 21:51 +0000, Sergei Trofimovich wrote:
> 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.
>
> CC: Alexei Starovoitov <ast@xxxxxxxxxx>
> CC: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
> CC: Andrii Nakryiko <andrii@xxxxxxxxxx>
> CC: Martin KaFai Lau <martin.lau@xxxxxxxxx>
> CC: Song Liu <song@xxxxxxxxxx>
> CC: Yonghong Song <yonghong.song@xxxxxxxxx>
> CC: John Fastabend <john.fastabend@xxxxxxxxx>
> CC: KP Singh <kpsingh@xxxxxxxxxx>
> CC: Stanislav Fomichev <sdf@xxxxxxxxxx>
> CC: Hao Luo <haoluo@xxxxxxxxxx>
> CC: Jiri Olsa <jolsa@xxxxxxxxxx>
> CC: Eduard Zingerman <eddyz87@xxxxxxxxx>
> CC: bpf@xxxxxxxxxxxxxxx
> Signed-off-by: Sergei Trofimovich <slyich@xxxxxxxxx>
> ---
> tools/lib/bpf/linker.c | 24 ++++++++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
> Change since v1:
> Following Eduard's suggestion added one extra pr_warn() call around
> section alignment and added compared values into warning messages.

Thank you for doing adjustments.
(Note: when I apply this patch locally full CC block is a part of the
commit message, this is usually omitted from commit messages).

Acked-by: Eduard Zingerman <eddyz87@xxxxxxxxx>