Generate NULL definition as part of vmlinux.h. This is a pretty common and
unfortunate annoyance that most users of vmlinux.h have to deal with. Patch #2
drops such custom NULL definition in one of the selftests. Patches #3 and #4
make bpftool and selftests compilations stricter by treating warnings as
errors.
Andrii Nakryiko (4):
bpftool: generate NULL definition in vmlinux.h
selftests/bpf: drop custom NULL #define in skb_pkt_end selftest
selftests/bpf: treat compilation warnings as errors
bpftool: treat compilation warnings as errors
tools/bpf/bpftool/Makefile | 3 ++-
tools/bpf/bpftool/btf.c | 2 ++
tools/bpf/bpftool/jit_disasm.c | 3 +++
tools/testing/selftests/bpf/Makefile | 4 ++--
tools/testing/selftests/bpf/progs/skb_pkt_end.c | 1 -
5 files changed, 9 insertions(+), 4 deletions(-)
--
2.30.2
Given that vmlinux.h is not compatible with headers like stdint.h, NULL poses
an annoying problem: it is defined as #define, so is not captured in BTF, so
is not emitted into vmlinux.h. This leads to users either sticking to explicit
0, or defining their own NULL (as progs/skb_pkt_end.c does).
It's pretty trivial for bpftool to generate NULL definition, though, so let's
just do that. This might cause compilation warning for existing BPF
applications:
progs/skb_pkt_end.c:7:9: warning: 'NULL' macro redefined [-Wmacro-redefined]
progs/skb_pkt_end.c:7:9: error: 'NULL' macro redefined [-Werror,-Wmacro-redefined]
#define NULL 0
^
/tmp/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:4:9: note: previous definition is here
#define NULL ((void *)0)
^
It is trivial to fix, though, so long-term benefits outweight temporary
inconveniences.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/btf.c | 2 ++
1 file changed, 2 insertions(+)
Make selftests/bpf compilation more strict by treating warnings as errors. We
are generally pretty good at keeping compilation clean, but it's easy to miss
minor warnings. So let's not trust people and just employ stricter compiler
enforcement.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/testing/selftests/bpf/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Now that bpftool generates NULL definition as part of vmlinux.h, drop custom
NULL definition in skb_pkt_end.c.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/testing/selftests/bpf/progs/skb_pkt_end.c | 1 -
1 file changed, 1 deletion(-)
Make bpftool compilation stricter and treat all compilation warnigs as errors.
Depending on libbfd version on the system, jit_disasm.c might trigger the
following compilation warning-turned-error:
jit_disasm.c: In function ‘disasm_print_insn’:
jit_disasm.c:121:29: error: assignment discards ‘const’ qualifier from pointer
target type [-Werror=discarded-qualifiers]
info.disassembler_options = disassembler_options;
^
This was fixed in libbfd, but older versions of the library are still widely
used. So disable -Wdiscarded-qualifiers for that particular line of code.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/Makefile | 3 ++-
tools/bpf/bpftool/jit_disasm.c | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
On Tue, Mar 16, 2021 at 8:03 PM Andrii Nakryiko [off-list ref] wrote:
Given that vmlinux.h is not compatible with headers like stdint.h, NULL poses
an annoying problem: it is defined as #define, so is not captured in BTF, so
is not emitted into vmlinux.h. This leads to users either sticking to explicit
0, or defining their own NULL (as progs/skb_pkt_end.c does).
It's pretty trivial for bpftool to generate NULL definition, though, so let's
just do that. This might cause compilation warning for existing BPF
applications:
progs/skb_pkt_end.c:7:9: warning: 'NULL' macro redefined [-Wmacro-redefined]
progs/skb_pkt_end.c:7:9: error: 'NULL' macro redefined [-Werror,-Wmacro-redefined]
oops, this shouldn't have been copy/pasted. This is how the line above
looks like if -Werror is specified in Makefile.
quoted hunk
#define NULL 0
^
/tmp/linux/tools/testing/selftests/bpf/tools/include/vmlinux.h:4:9: note: previous definition is here
#define NULL ((void *)0)
^
It is trivial to fix, though, so long-term benefits outweight temporary
inconveniences.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/bpf/bpftool/btf.c | 2 ++
1 file changed, 2 insertions(+)