Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS

From: Ian Rogers

Date: Thu Mar 12 2026 - 13:19:27 EST


On Wed, Mar 11, 2026 at 1:30 AM Leo Yan <leo.yan@xxxxxxx> wrote:
>
> Prepare for future changes where EXTRA_CFLAGS may include flags not
> applicable to the host compiler.
>
> Move the HOST_CFLAGS assignment before appending EXTRA_CFLAGS to
> CFLAGS so that HOST_CFLAGS does not inherit flags from EXTRA_CFLAGS.
>
> Acked-by: Quentin Monnet <qmo@xxxxxxxxxx>
> Signed-off-by: Leo Yan <leo.yan@xxxxxxx>
> ---
> tools/bpf/bpftool/Makefile | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index 519ea5cb8ab1c0ee31acc67fc5f96b40e21005c2..3e7d8359e1b2a81a29a47544be8539e3b191a0e8 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -81,6 +81,12 @@ CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ \
> ifneq ($(BPFTOOL_VERSION),)
> CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
> endif
> +
> +# This must be done before appending EXTRA_CFLAGS to CFLAGS to avoid
> +# including flags that are not applicable to the host compiler.
> +HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\
> + $(subst $(CLANG_CROSS_FLAGS),,$(CFLAGS)))
> +
> ifneq ($(EXTRA_CFLAGS),)
> CFLAGS += $(EXTRA_CFLAGS)
> endif
> @@ -88,8 +94,6 @@ ifneq ($(EXTRA_LDFLAGS),)
> LDFLAGS += $(EXTRA_LDFLAGS)
> endif
>
> -HOST_CFLAGS := $(subst -I$(LIBBPF_INCLUDE),-I$(LIBBPF_BOOTSTRAP_INCLUDE),\
> - $(subst $(CLANG_CROSS_FLAGS),,$(CFLAGS)))
> HOST_LDFLAGS := $(LDFLAGS)

Should HOST_LDFLAGS be similarly moved? Otherwise, it seems target
flags in EXTRA_LDFLAGS will be added for the host.

Thanks,
Ian

> INSTALL ?= install
>
> --
> 2.34.1
>