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@xxxxxxxxxx> --- tools/bpf/bpftool/Makefile | 3 ++- tools/bpf/bpftool/jit_disasm.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index b3073ae84018..59de954faaf5 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -56,7 +56,8 @@ prefix ?= /usr/local bash_compdir ?= /usr/share/bash-completion/completions CFLAGS += -O2 -CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers +CFLAGS += -W -Wall -Wextra -Werror +CFLAGS += -Wno-unused-parameter -Wno-missing-field-initializers CFLAGS += $(filter-out -Wswitch-enum -Wnested-externs,$(EXTRA_WARNINGS)) CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \ -I$(if $(OUTPUT),$(OUTPUT),.) \ diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c index e7e7eee9f172..48bc7f7a542f 100644 --- a/tools/bpf/bpftool/jit_disasm.c +++ b/tools/bpf/bpftool/jit_disasm.c @@ -118,7 +118,10 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, info.arch = bfd_get_arch(bfdf); info.mach = bfd_get_mach(bfdf); if (disassembler_options) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" info.disassembler_options = disassembler_options; +#pragma GCC diagnostic push info.buffer = image; info.buffer_length = len; -- 2.30.2