linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/libbpf: add WERROR option
@ 2025-07-05 10:43 Sam James
  2025-07-07 13:18 ` Daniel Borkmann
  0 siblings, 1 reply; 8+ messages in thread
From: Sam James @ 2025-07-05 10:43 UTC (permalink / raw)
  To: bpf, Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa
  Cc: linux-kernel, Sam James

Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.

This mirrors what tools/perf and other directories in tools do to handle
-Werror rather than adding it unconditionally.

Signed-off-by: Sam James <sam@gentoo.org>
---
 tools/lib/bpf/Makefile | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 168140f8e646..9563d37265da 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -77,10 +77,15 @@ else
   CFLAGS := -g -O2
 endif
 
+# Treat warnings as errors unless directed not to
+ifneq ($(WERROR),0)
+  CFLAGS += -Werror
+endif
+
 # Append required CFLAGS
 override CFLAGS += -std=gnu89
 override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
-override CFLAGS += -Werror -Wall
+override CFLAGS += -Wall
 override CFLAGS += $(INCLUDES)
 override CFLAGS += -fvisibility=hidden
 override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-05 10:43 [PATCH] tools/libbpf: add WERROR option Sam James
@ 2025-07-07 13:18 ` Daniel Borkmann
  2025-07-07 13:33   ` Quentin Monnet
  2025-07-13  6:23   ` Sam James
  0 siblings, 2 replies; 8+ messages in thread
From: Daniel Borkmann @ 2025-07-07 13:18 UTC (permalink / raw)
  To: Sam James, bpf, Andrii Nakryiko, Eduard Zingerman,
	Alexei Starovoitov, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Quentin Monnet
  Cc: linux-kernel

On 7/5/25 12:43 PM, Sam James wrote:
> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
> 
> This mirrors what tools/perf and other directories in tools do to handle
> -Werror rather than adding it unconditionally.

Could you also add to the commit desc why you need it? Are there particular
warnings you specifically need to suppress when building under gentoo?

> Signed-off-by: Sam James <sam@gentoo.org>
> ---
>   tools/lib/bpf/Makefile | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index 168140f8e646..9563d37265da 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -77,10 +77,15 @@ else
>     CFLAGS := -g -O2
>   endif
>   
> +# Treat warnings as errors unless directed not to
> +ifneq ($(WERROR),0)
> +  CFLAGS += -Werror
> +endif

Should we also add sth similar to tools/bpf/bpftool/Makefile and by default
enforce with -Werror with the option to disable?

>   # Append required CFLAGS
>   override CFLAGS += -std=gnu89
>   override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
> -override CFLAGS += -Werror -Wall
> +override CFLAGS += -Wall
>   override CFLAGS += $(INCLUDES)
>   override CFLAGS += -fvisibility=hidden
>   override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-07 13:18 ` Daniel Borkmann
@ 2025-07-07 13:33   ` Quentin Monnet
  2025-07-13  6:21     ` Sam James
  2025-07-13  6:23   ` Sam James
  1 sibling, 1 reply; 8+ messages in thread
From: Quentin Monnet @ 2025-07-07 13:33 UTC (permalink / raw)
  To: Daniel Borkmann, Sam James, bpf, Andrii Nakryiko,
	Eduard Zingerman, Alexei Starovoitov, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
	Hao Luo, Jiri Olsa
  Cc: linux-kernel

2025-07-07 15:18 UTC+0200 ~ Daniel Borkmann <daniel@iogearbox.net>
> On 7/5/25 12:43 PM, Sam James wrote:
>> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
>>
>> This mirrors what tools/perf and other directories in tools do to handle
>> -Werror rather than adding it unconditionally.
> 
> Could you also add to the commit desc why you need it? Are there particular
> warnings you specifically need to suppress when building under gentoo?


And if you need to disable the flag on a particular target, have you
considered using the existing variables and pass EXTRA_CFLAGS=-Wno-error
rather than adding another flag?

Quentin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-07 13:33   ` Quentin Monnet
@ 2025-07-13  6:21     ` Sam James
  0 siblings, 0 replies; 8+ messages in thread
From: Sam James @ 2025-07-13  6:21 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Daniel Borkmann, bpf, Andrii Nakryiko, Eduard Zingerman,
	Alexei Starovoitov, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	linux-kernel

Quentin Monnet <qmo@kernel.org> writes:

> 2025-07-07 15:18 UTC+0200 ~ Daniel Borkmann <daniel@iogearbox.net>
>> On 7/5/25 12:43 PM, Sam James wrote:
>>> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
>>>
>>> This mirrors what tools/perf and other directories in tools do to handle
>>> -Werror rather than adding it unconditionally.
>> 
>> Could you also add to the commit desc why you need it? Are there particular
>> warnings you specifically need to suppress when building under gentoo?
>
>
> And if you need to disable the flag on a particular target, have you
> considered using the existing variables and pass EXTRA_CFLAGS=-Wno-error
> rather than adding another flag?

I think inconsistency with other tools/ is unfortunate, but yes, I guess
we could.

>
> Quentin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-07 13:18 ` Daniel Borkmann
  2025-07-07 13:33   ` Quentin Monnet
@ 2025-07-13  6:23   ` Sam James
  2025-07-13 22:45     ` Alexei Starovoitov
  1 sibling, 1 reply; 8+ messages in thread
From: Sam James @ 2025-07-13  6:23 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: bpf, Andrii Nakryiko, Eduard Zingerman, Alexei Starovoitov,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, Quentin Monnet,
	linux-kernel

Daniel Borkmann <daniel@iogearbox.net> writes:

> On 7/5/25 12:43 PM, Sam James wrote:
>> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
>> This mirrors what tools/perf and other directories in tools do to
>> handle
>> -Werror rather than adding it unconditionally.
>
> Could you also add to the commit desc why you need it? Are there particular
> warnings you specifically need to suppress when building under gentoo?

Sure. In this case, it was https://bugs.gentoo.org/959293 where I think
it's fixed by
https://github.com/libbpf/libbpf/commit/715808d3e2d8c54f3001ce3d7fcda0844f765969
(and the corresponding commit in the kernel tree proper). Backporting
that was a bit too big for our tastes.

The real issue is just that -Werror when we have users who might be
testing with in-development compilers or with alternative options
results in a build failure when you didn't expect one.

>
>> Signed-off-by: Sam James <sam@gentoo.org>
>> ---
>>   tools/lib/bpf/Makefile | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
>> index 168140f8e646..9563d37265da 100644
>> --- a/tools/lib/bpf/Makefile
>> +++ b/tools/lib/bpf/Makefile
>> @@ -77,10 +77,15 @@ else
>>     CFLAGS := -g -O2
>>   endif
>>   +# Treat warnings as errors unless directed not to
>> +ifneq ($(WERROR),0)
>> +  CFLAGS += -Werror
>> +endif
>
> Should we also add sth similar to tools/bpf/bpftool/Makefile and by default
> enforce with -Werror with the option to disable?

Yes, that sounds good to me, though I was nervous of stumbling onto a
philosophical debate about -Werror and wasn't sure what y'all preferred
:)

I can send v2 with an updated commit message and this change. I'll wait
a bit for further comments based on my two replies here.

>
>>   # Append required CFLAGS
>>   override CFLAGS += -std=gnu89
>>   override CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
>> -override CFLAGS += -Werror -Wall
>> +override CFLAGS += -Wall
>>   override CFLAGS += $(INCLUDES)
>>   override CFLAGS += -fvisibility=hidden
>>   override CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64

sam

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-13  6:23   ` Sam James
@ 2025-07-13 22:45     ` Alexei Starovoitov
  2025-07-13 22:58       ` Sam James
  0 siblings, 1 reply; 8+ messages in thread
From: Alexei Starovoitov @ 2025-07-13 22:45 UTC (permalink / raw)
  To: Sam James
  Cc: Daniel Borkmann, bpf, Andrii Nakryiko, Eduard Zingerman,
	Alexei Starovoitov, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Quentin Monnet, LKML

On Sat, Jul 12, 2025 at 11:24 PM Sam James <sam@gentoo.org> wrote:
>
> Daniel Borkmann <daniel@iogearbox.net> writes:
>
> > On 7/5/25 12:43 PM, Sam James wrote:
> >> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
> >> This mirrors what tools/perf and other directories in tools do to
> >> handle
> >> -Werror rather than adding it unconditionally.
> >
> > Could you also add to the commit desc why you need it? Are there particular
> > warnings you specifically need to suppress when building under gentoo?
>
> Sure. In this case, it was https://bugs.gentoo.org/959293 where I think

I don't recall it was reported on bpf mailing list.

> it's fixed by
> https://github.com/libbpf/libbpf/commit/715808d3e2d8c54f3001ce3d7fcda0844f765969

and looks like it was fixed by accident, so..

> (and the corresponding commit in the kernel tree proper). Backporting
> that was a bit too big for our tastes.
>
> The real issue is just that -Werror when we have users who might be
> testing with in-development compilers or with alternative options
> results in a build failure when you didn't expect one.
>
> >
> >> Signed-off-by: Sam James <sam@gentoo.org>
> >> ---
> >>   tools/lib/bpf/Makefile | 7 ++++++-
> >>   1 file changed, 6 insertions(+), 1 deletion(-)
> >> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> >> index 168140f8e646..9563d37265da 100644
> >> --- a/tools/lib/bpf/Makefile
> >> +++ b/tools/lib/bpf/Makefile
> >> @@ -77,10 +77,15 @@ else
> >>     CFLAGS := -g -O2
> >>   endif
> >>   +# Treat warnings as errors unless directed not to
> >> +ifneq ($(WERROR),0)
> >> +  CFLAGS += -Werror
> >> +endif
> >
> > Should we also add sth similar to tools/bpf/bpftool/Makefile and by default
> > enforce with -Werror with the option to disable?
>
> Yes, that sounds good to me, though I was nervous of stumbling onto a
> philosophical debate about -Werror and wasn't sure what y'all preferred
> :)
>
> I can send v2 with an updated commit message and this change. I'll wait
> a bit for further comments based on my two replies here.

No.
We want Werror to be there by default and it shouldn't be trivial to turn off,
so that people report and fix issues with new compilers.
Like in this case, looks like it was a legitimate error of
in-development gcc-16.
If it was reported to us and turned out to be not a libbpf issue than
gentoo should have reported it back to gcc devs to make sure they don't
add bogus warnings to the compiler. Win-win.

You're right, in many ways it is a philosophical debate.
We cleaned up libbpf and selftests/bpf from warnings and
we don't want them to reappear. So we don't want an easy way
to silence them. Report issues instead.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-13 22:45     ` Alexei Starovoitov
@ 2025-07-13 22:58       ` Sam James
  2025-07-13 23:03         ` Alexei Starovoitov
  0 siblings, 1 reply; 8+ messages in thread
From: Sam James @ 2025-07-13 22:58 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Daniel Borkmann, bpf, Andrii Nakryiko, Eduard Zingerman,
	Alexei Starovoitov, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Quentin Monnet, LKML

Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:

> On Sat, Jul 12, 2025 at 11:24 PM Sam James <sam@gentoo.org> wrote:
>>
>> Daniel Borkmann <daniel@iogearbox.net> writes:
>>
>> > On 7/5/25 12:43 PM, Sam James wrote:
>> >> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
>> >> This mirrors what tools/perf and other directories in tools do to
>> >> handle
>> >> -Werror rather than adding it unconditionally.
>> >
>> > Could you also add to the commit desc why you need it? Are there particular
>> > warnings you specifically need to suppress when building under gentoo?
>>
>> Sure. In this case, it was https://bugs.gentoo.org/959293 where I think
>
> I don't recall it was reported on bpf mailing list.
>
>> it's fixed by
>> https://github.com/libbpf/libbpf/commit/715808d3e2d8c54f3001ce3d7fcda0844f765969
>
> and looks like it was fixed by accident, so..

I'll note that I've sent patches that have been merged for these
before. It's just that they're sensitive to optimisation level and prone
to false positives. Especially with e.g. -Og.

>
>> (and the corresponding commit in the kernel tree proper). Backporting
>> that was a bit too big for our tastes.
>>
>> The real issue is just that -Werror when we have users who might be
>> testing with in-development compilers or with alternative options
>> results in a build failure when you didn't expect one.
>>
>> >
>> >> Signed-off-by: Sam James <sam@gentoo.org>
>> >> ---
>> >>   tools/lib/bpf/Makefile | 7 ++++++-
>> >>   1 file changed, 6 insertions(+), 1 deletion(-)
>> >> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
>> >> index 168140f8e646..9563d37265da 100644
>> >> --- a/tools/lib/bpf/Makefile
>> >> +++ b/tools/lib/bpf/Makefile
>> >> @@ -77,10 +77,15 @@ else
>> >>     CFLAGS := -g -O2
>> >>   endif
>> >>   +# Treat warnings as errors unless directed not to
>> >> +ifneq ($(WERROR),0)
>> >> +  CFLAGS += -Werror
>> >> +endif
>> >
>> > Should we also add sth similar to tools/bpf/bpftool/Makefile and by default
>> > enforce with -Werror with the option to disable?
>>
>> Yes, that sounds good to me, though I was nervous of stumbling onto a
>> philosophical debate about -Werror and wasn't sure what y'all preferred
>> :)
>>
>> I can send v2 with an updated commit message and this change. I'll wait
>> a bit for further comments based on my two replies here.
>
> No.
> We want Werror to be there by default and it shouldn't be trivial to turn off,
> so that people report and fix issues with new compilers.
> Like in this case, looks like it was a legitimate error of
> in-development gcc-16.
> If it was reported to us and turned out to be not a libbpf issue than
> gentoo should have reported it back to gcc devs to make sure they don't
> add bogus warnings to the compiler. Win-win.
>
> You're right, in many ways it is a philosophical debate.
> We cleaned up libbpf and selftests/bpf from warnings and
> we don't want them to reappear. So we don't want an easy way
> to silence them. Report issues instead.

OK then.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] tools/libbpf: add WERROR option
  2025-07-13 22:58       ` Sam James
@ 2025-07-13 23:03         ` Alexei Starovoitov
  0 siblings, 0 replies; 8+ messages in thread
From: Alexei Starovoitov @ 2025-07-13 23:03 UTC (permalink / raw)
  To: Sam James
  Cc: Daniel Borkmann, bpf, Andrii Nakryiko, Eduard Zingerman,
	Alexei Starovoitov, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Quentin Monnet, LKML

On Sun, Jul 13, 2025 at 3:58 PM Sam James <sam@gentoo.org> wrote:
>
> Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
>
> > On Sat, Jul 12, 2025 at 11:24 PM Sam James <sam@gentoo.org> wrote:
> >>
> >> Daniel Borkmann <daniel@iogearbox.net> writes:
> >>
> >> > On 7/5/25 12:43 PM, Sam James wrote:
> >> >> Check the 'WERROR' variable and suppress adding '-Werror' if WERROR=0.
> >> >> This mirrors what tools/perf and other directories in tools do to
> >> >> handle
> >> >> -Werror rather than adding it unconditionally.
> >> >
> >> > Could you also add to the commit desc why you need it? Are there particular
> >> > warnings you specifically need to suppress when building under gentoo?
> >>
> >> Sure. In this case, it was https://bugs.gentoo.org/959293 where I think
> >
> > I don't recall it was reported on bpf mailing list.
> >
> >> it's fixed by
> >> https://github.com/libbpf/libbpf/commit/715808d3e2d8c54f3001ce3d7fcda0844f765969
> >
> > and looks like it was fixed by accident, so..
>
> I'll note that I've sent patches that have been merged for these
> before. It's just that they're sensitive to optimisation level and prone
> to false positives. Especially with e.g. -Og.

Yeah. Compilers do produce false positives and, like any tool,
any warning is not authoritative, but we prefer people reporting
them instead of silencing and moving on.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-07-13 23:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-05 10:43 [PATCH] tools/libbpf: add WERROR option Sam James
2025-07-07 13:18 ` Daniel Borkmann
2025-07-07 13:33   ` Quentin Monnet
2025-07-13  6:21     ` Sam James
2025-07-13  6:23   ` Sam James
2025-07-13 22:45     ` Alexei Starovoitov
2025-07-13 22:58       ` Sam James
2025-07-13 23:03         ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).