2024-05-31 18:38:42

by John Hubbard

[permalink] [raw]
Subject: [PATCH v2 2/2] selftests/lib.mk: silence some clang warnings that gcc already ignores

gcc defaults to silence (off) for the following warnings, but clang
defaults to the opposite. The warnings are not useful for the kernel
itself, which is why they have remained disabled in gcc for the main
kernel build. And it is only due to including kernel data structures in
the selftests, that we get the warnings from clang.

-Waddress-of-packed-member
-Wgnu-variable-sized-type-not-at-end

In other words, the warnings are not unique to the selftests: there is
nothing that the selftests' code does that triggers these warnings,
other than the act of including the kernel's data structures. Therefore,
silence them for the clang builds as well.

This eliminates warnings for the net/ and user_events/ kselftest
subsystems, in these files:

./net/af_unix/scm_rights.c
./net/timestamping.c
./net/ipsec.c
./user_events/perf_test.c

Cc: Nathan Chancellor <[email protected]>
Signed-off-by: John Hubbard <[email protected]>
---
tools/testing/selftests/lib.mk | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 2902787b89b2..c179c02281e9 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -50,6 +50,14 @@ else
CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
endif # CROSS_COMPILE

+# gcc defaults to silence (off) for the following warnings, but clang defaults
+# to the opposite. The warnings are not useful for the kernel itself, which is
+# why they have remained disabled in gcc for the main kernel build. And it is
+# only due to including kernel data structures in the selftests, that we get the
+# warnings from clang. Therefore, disable the warnings for clang builds.
+CFLAGS += -Wno-address-of-packed-member
+CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
+
CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
else
CC := $(CROSS_COMPILE)gcc
--
2.45.1



2024-06-03 21:06:57

by John Hubbard

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] selftests/lib.mk: silence some clang warnings that gcc already ignores

On 5/31/24 11:37 AM, John Hubbard wrote:
> gcc defaults to silence (off) for the following warnings, but clang
> defaults to the opposite. The warnings are not useful for the kernel
> itself, which is why they have remained disabled in gcc for the main
> kernel build. And it is only due to including kernel data structures in
> the selftests, that we get the warnings from clang.
>
> -Waddress-of-packed-member
> -Wgnu-variable-sized-type-not-at-end

Even if patch 1/1 here is not merged, I would still like to get this
one reviewed and merged. It still solves the problem for LLVM=1 builds.

thanks,
--
John Hubbard
NVIDIA

>
> In other words, the warnings are not unique to the selftests: there is
> nothing that the selftests' code does that triggers these warnings,
> other than the act of including the kernel's data structures. Therefore,
> silence them for the clang builds as well.
>
> This eliminates warnings for the net/ and user_events/ kselftest
> subsystems, in these files:
>
> ./net/af_unix/scm_rights.c
> ./net/timestamping.c
> ./net/ipsec.c
> ./user_events/perf_test.c
>
> Cc: Nathan Chancellor <[email protected]>
> Signed-off-by: John Hubbard <[email protected]>
> ---
> tools/testing/selftests/lib.mk | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
> index 2902787b89b2..c179c02281e9 100644
> --- a/tools/testing/selftests/lib.mk
> +++ b/tools/testing/selftests/lib.mk
> @@ -50,6 +50,14 @@ else
> CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
> endif # CROSS_COMPILE
>
> +# gcc defaults to silence (off) for the following warnings, but clang defaults
> +# to the opposite. The warnings are not useful for the kernel itself, which is
> +# why they have remained disabled in gcc for the main kernel build. And it is
> +# only due to including kernel data structures in the selftests, that we get the
> +# warnings from clang. Therefore, disable the warnings for clang builds.
> +CFLAGS += -Wno-address-of-packed-member
> +CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
> +
> CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
> else
> CC := $(CROSS_COMPILE)gcc



2024-06-03 22:36:21

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] selftests/lib.mk: silence some clang warnings that gcc already ignores

On Fri, May 31, 2024 at 11:37:51AM -0700, John Hubbard wrote:
> gcc defaults to silence (off) for the following warnings, but clang
> defaults to the opposite. The warnings are not useful for the kernel
> itself, which is why they have remained disabled in gcc for the main
> kernel build. And it is only due to including kernel data structures in
> the selftests, that we get the warnings from clang.
>
> -Waddress-of-packed-member
> -Wgnu-variable-sized-type-not-at-end
>
> In other words, the warnings are not unique to the selftests: there is
> nothing that the selftests' code does that triggers these warnings,
> other than the act of including the kernel's data structures. Therefore,
> silence them for the clang builds as well.
>
> This eliminates warnings for the net/ and user_events/ kselftest
> subsystems, in these files:
>
> ./net/af_unix/scm_rights.c
> ./net/timestamping.c
> ./net/ipsec.c
> ./user_events/perf_test.c
>
> Cc: Nathan Chancellor <[email protected]>
> Signed-off-by: John Hubbard <[email protected]>

This seems reasonable to me.

Acked-by: Nathan Chancellor <[email protected]>

> ---
> tools/testing/selftests/lib.mk | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
> index 2902787b89b2..c179c02281e9 100644
> --- a/tools/testing/selftests/lib.mk
> +++ b/tools/testing/selftests/lib.mk
> @@ -50,6 +50,14 @@ else
> CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
> endif # CROSS_COMPILE
>
> +# gcc defaults to silence (off) for the following warnings, but clang defaults
> +# to the opposite. The warnings are not useful for the kernel itself, which is
> +# why they have remained disabled in gcc for the main kernel build. And it is
> +# only due to including kernel data structures in the selftests, that we get the
> +# warnings from clang. Therefore, disable the warnings for clang builds.
> +CFLAGS += -Wno-address-of-packed-member
> +CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
> +
> CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
> else
> CC := $(CROSS_COMPILE)gcc
> --
> 2.45.1
>
>

2024-06-07 17:23:48

by Shuah Khan

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] selftests/lib.mk: silence some clang warnings that gcc already ignores

On 6/3/24 16:36, Nathan Chancellor wrote:
> On Fri, May 31, 2024 at 11:37:51AM -0700, John Hubbard wrote:
>> gcc defaults to silence (off) for the following warnings, but clang
>> defaults to the opposite. The warnings are not useful for the kernel
>> itself, which is why they have remained disabled in gcc for the main
>> kernel build. And it is only due to including kernel data structures in
>> the selftests, that we get the warnings from clang.
>>
>> -Waddress-of-packed-member
>> -Wgnu-variable-sized-type-not-at-end
>>
>> In other words, the warnings are not unique to the selftests: there is
>> nothing that the selftests' code does that triggers these warnings,
>> other than the act of including the kernel's data structures. Therefore,
>> silence them for the clang builds as well.
>>
>> This eliminates warnings for the net/ and user_events/ kselftest
>> subsystems, in these files:
>>
>> ./net/af_unix/scm_rights.c
>> ./net/timestamping.c
>> ./net/ipsec.c
>> ./user_events/perf_test.c
>>
>> Cc: Nathan Chancellor <[email protected]>
>> Signed-off-by: John Hubbard <[email protected]>
>
> This seems reasonable to me.
>
> Acked-by: Nathan Chancellor <[email protected]>
>
>> ---
>> tools/testing/selftests/lib.mk | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
>> index 2902787b89b2..c179c02281e9 100644
>> --- a/tools/testing/selftests/lib.mk
>> +++ b/tools/testing/selftests/lib.mk
>> @@ -50,6 +50,14 @@ else
>> CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
>> endif # CROSS_COMPILE
>>
>> +# gcc defaults to silence (off) for the following warnings, but clang defaults
>> +# to the opposite. The warnings are not useful for the kernel itself, which is
>> +# why they have remained disabled in gcc for the main kernel build. And it is
>> +# only due to including kernel data structures in the selftests, that we get the
>> +# warnings from clang. Therefore, disable the warnings for clang builds.
>> +CFLAGS += -Wno-address-of-packed-member
>> +CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
>> +

Thank you for adding this comment block.

>> CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
>> else
>> CC := $(CROSS_COMPILE)gcc
>> --
>> 2.45.1
>>
>>
>

Thank you both. I will apply this for the next release. I want this
change soaking in next for a bit.

thanks,
-- Shuah