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

Leo Yan posted 30 patches 4 weeks ago
There is a newer version of this series
[PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Posted by Leo Yan 4 weeks ago
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@kernel.org>
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 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)
 
 INSTALL ?= install

-- 
2.34.1
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Posted by Ian Rogers 3 weeks, 6 days ago
On Wed, Mar 11, 2026 at 1:30 AM Leo Yan <leo.yan@arm.com> 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@kernel.org>
> Signed-off-by: Leo Yan <leo.yan@arm.com>
> ---
>  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
>
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Posted by Leo Yan 3 weeks, 5 days ago
On Thu, Mar 12, 2026 at 10:19:01AM -0700, Ian Rogers wrote:
> On Wed, Mar 11, 2026 at 1:30 AM Leo Yan <leo.yan@arm.com> 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@kernel.org>
> > Signed-off-by: Leo Yan <leo.yan@arm.com>
> > ---
> >  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.

Though this series is irrelevant to LDFLAGS, I am fine to move
HOST_LDFLAGS together.

Quentin, how about you think?
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Posted by Quentin Monnet 3 weeks, 5 days ago
2026-03-13 15:56 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> On Thu, Mar 12, 2026 at 10:19:01AM -0700, Ian Rogers wrote:
>> On Wed, Mar 11, 2026 at 1:30 AM Leo Yan <leo.yan@arm.com> 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@kernel.org>
>>> Signed-off-by: Leo Yan <leo.yan@arm.com>
>>> ---
>>>  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.
> 
> Though this series is irrelevant to LDFLAGS, I am fine to move
> HOST_LDFLAGS together.


If we move the HOST_LDFLAGS earlier so that they no longer receive the
EXTRA_LDFLAGS, then we lose the possibility to use any EXTRA variable to
pass additional flags to HOST_LDFLAGS. So OK to move, but maybe add a
"HOST_LDFLAGS += $(HOST_EXTRALDFLAGS)" to it for consistency with the
processing of HOST_CFLAGS?

Quentin
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Posted by Leo Yan 3 weeks, 5 days ago
On Fri, Mar 13, 2026 at 04:07:27PM +0000, Quentin Monnet wrote:

[...]

> >>> +
> >>> +# 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.
> > 
> > Though this series is irrelevant to LDFLAGS, I am fine to move
> > HOST_LDFLAGS together.
> 
> 
> If we move the HOST_LDFLAGS earlier so that they no longer receive the
> EXTRA_LDFLAGS, then we lose the possibility to use any EXTRA variable to
> pass additional flags to HOST_LDFLAGS. So OK to move, but maybe add a
> "HOST_LDFLAGS += $(HOST_EXTRALDFLAGS)" to it for consistency with the
> processing of HOST_CFLAGS?

Adding HOST_EXTRALDFLAGS seems a bit over designed to me, as there is
no use case for it currently.  To avoid complexity, let's keep this
patch as it is, we can add HOST_EXTRALDFLAGS if later have requirement.

P.s. I saw that you already replied the same comment in the previous
version.  I should have confirmed at that time, sorry for the duplicate
discussion.
Re: [PATCH v4 05/30] bpftool: Avoid adding EXTRA_CFLAGS to HOST_CFLAGS
Posted by Quentin Monnet 3 weeks, 5 days ago
2026-03-13 16:24 UTC+0000 ~ Leo Yan <leo.yan@arm.com>
> On Fri, Mar 13, 2026 at 04:07:27PM +0000, Quentin Monnet wrote:
> 
> [...]
> 
>>>>> +
>>>>> +# 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.
>>>
>>> Though this series is irrelevant to LDFLAGS, I am fine to move
>>> HOST_LDFLAGS together.
>>
>>
>> If we move the HOST_LDFLAGS earlier so that they no longer receive the
>> EXTRA_LDFLAGS, then we lose the possibility to use any EXTRA variable to
>> pass additional flags to HOST_LDFLAGS. So OK to move, but maybe add a
>> "HOST_LDFLAGS += $(HOST_EXTRALDFLAGS)" to it for consistency with the
>> processing of HOST_CFLAGS?
> 
> Adding HOST_EXTRALDFLAGS seems a bit over designed to me, as there is
> no use case for it currently.  To avoid complexity, let's keep this
> patch as it is, we can add HOST_EXTRALDFLAGS if later have requirement.
> 
> P.s. I saw that you already replied the same comment in the previous
> version.  I should have confirmed at that time, sorry for the duplicate
> discussion.


That's fine :) - And agreed, it's probably best to leave it as-is for
now. Thanks!

Quentin