linux/tools/bpf
Quentin Monnet cc9b22dfa7 bpftool: Clean up HOST_CFLAGS, HOST_LDFLAGS for bootstrap bpftool
Bpftool's Makefile uses $(HOST_CFLAGS) to build the bootstrap version of
bpftool, in order to pick the flags for the host (where we run the
bootstrap version) and not for the target system (where we plan to run
the full bpftool binary). But we pass too much information through this
variable.

In particular, we set HOST_CFLAGS by copying most of the $(CFLAGS); but
we do this after the feature detection for bpftool, which means that
$(CFLAGS), hence $(HOST_CFLAGS), contain all macro definitions for using
the different optional features. For example, -DHAVE_LLVM_SUPPORT may be
passed to the $(HOST_CFLAGS), even though the LLVM disassembler is not
used in the bootstrap version, and the related library may even be
missing for the host architecture.

A similar thing happens with the $(LDFLAGS), that we use unchanged for
linking the bootstrap version even though they may contains flags to
link against additional libraries.

To address the $(HOST_CFLAGS) issue, we move the definition of
$(HOST_CFLAGS) earlier in the Makefile, before the $(CFLAGS) update
resulting from the feature probing - none of which being relevant to the
bootstrap version. To clean up the $(LDFLAGS) for the bootstrap version,
we introduce a dedicated $(HOST_LDFLAGS) variable that we base on
$(LDFLAGS), before the feature probing as well.

On my setup, the following macro and libraries are removed from the
compiler invocation to build bpftool after this patch:

  -DUSE_LIBCAP
  -DHAVE_LLVM_SUPPORT
  -I/usr/lib/llvm-17/include
  -D_GNU_SOURCE
  -D__STDC_CONSTANT_MACROS
  -D__STDC_FORMAT_MACROS
  -D__STDC_LIMIT_MACROS
  -lLLVM-17
  -L/usr/lib/llvm-17/lib

Another advantage of cleaning up these flags is that displaying
available features with "bpftool version" becomes more accurate for the
bootstrap bpftool, and no longer reflects the features detected (and
available only) for the final binary.

Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Quentin Monnet <qmo@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Message-ID: <20240320014103.45641-1-qmo@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2024-03-20 23:33:49 -07:00
..
bpftool bpftool: Clean up HOST_CFLAGS, HOST_LDFLAGS for bootstrap bpftool 2024-03-20 23:33:49 -07:00
resolve_btfids tools/resolve_btfids: Fix cross-compilation to non-host endianness 2024-02-07 15:56:18 -08:00
runqslower bpf: Replace deprecated -target with --target= for Clang 2023-06-29 15:46:17 +02:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
bpf_asm.c docs: networking: convert filter.txt to ReST 2020-04-28 14:39:46 -07:00
bpf_dbg.c bpf: Simplify the calculation of variables 2021-03-04 19:24:53 -08:00
bpf_exp.l bpf: fix cbpf parser bug for octal numbers 2018-06-03 07:46:55 -07:00
bpf_exp.y tools, bpf_asm: Exit non-zero on errors 2021-02-26 22:53:50 +01:00
bpf_jit_disasm.c tools bpf_jit_disasm: Fix compilation error with new binutils 2022-08-01 15:30:48 -03:00
Makefile tools bpf_jit_disasm: Don't display disassembler-four-args feature test 2022-08-01 15:31:51 -03:00