Skip to contentSkip to conversation

selftests/lib.mk: LLVM=1, CC=clang, and warnings

PATCH Superseded John Hubbard 3 participants 7 messages May 29, 2024 – May 31, 2024 Kselftest

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover selftests/lib.mk: LLVM=1, CC=clang, and warnings

The kselftests may be built in a couple different ways:
make LLVM=1
make CC=clang

In order to handle both cases, set LLVM=1 if CC=clang. That way,the rest of lib.mk, and any Makefiles that include lib.mk, can base decisions solely on whether or not LLVM is set.

Then, build upon that to disable a pair of clang warnings that are already silenced on gcc.

Doing it this way is much better than the piecemeal approach that I started with in [1] and [2]. Thanks to Nathan Chancellor for the patch reviews that led to this approach.

[1] https://lore.kernel.org/[email protected]
[2] https://lore.kernel.org/[email protected]

John Hubbard (2):
selftests/lib.mk: handle both LLVM=1 and CC=clang builds selftests/lib.mk: silence some clang warnings that gcc already ignores

 tools/testing/selftests/lib.mk | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

base-commit: e0cce98fe279b64f4a7d81b7f5c3a23d80b92fbc

Signature · 1 line
2.45.1
#1 lore raw

PATCH 1/2 selftests/lib.mk: handle both LLVM=1 and CC=clang builds

The kselftests may be built in a couple different ways:
make LLVM=1
make CC=clang

In order to handle both cases, set LLVM=1 if CC=clang. That way,the rest of lib.mk, and any Makefiles that include lib.mk, can base decisions solely on whether or not LLVM is set.

Cc Nathan Chancellor <[email protected]>
Cc Ryan Roberts <[email protected]>
---
 tools/testing/selftests/lib.mk | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/testing/selftests/lib.mk +12 -0
index 429535816dbd..2902787b89b2 100644
@@ -1,5 +1,17 @@
 # This mimics the top-level Makefile. We do it explicitly here so that this
 # Makefile can operate with or without the kbuild infrastructure.
+
+# The kselftests may be built in a couple different ways:
+#     make LLVM=1
+#     make CC=clang
+#
+# In order to handle both cases, set LLVM=1 if CC=clang. That way,the rest of
+# lib.mk, and any Makefiles that include lib.mk, can base decisions solely on
+# whether or not LLVM is set.
+ifeq ($(CC),clang)
+    LLVM := 1
+endif
+
 ifneq ($(LLVM),)
 ifneq ($(filter %/,$(LLVM)),)
 LLVM_PREFIX := $(LLVM)
Signature · 1 line
2.45.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] selftests/lib.mk: handle both LLVM=1 and CC=clang builds

Quoted 4 lines · John Hubbard

The kselftests may be built in a couple different ways:
make LLVM=1
make CC=clang

Quoted 8 lines

In order to handle both cases, set LLVM=1 if CC=clang. That way,the rest of lib.mk, and any Makefiles that include lib.mk, can base decisions solely on whether or not LLVM is set.

Cc Nathan Chancellor <[email protected]>
Cc Ryan Roberts <[email protected]>

LGTM

Quoted 26 lines
---
 tools/testing/selftests/lib.mk | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/testing/selftests/lib.mk +12 -0
index 429535816dbd..2902787b89b2 100644
@@ -1,5 +1,17 @@
 # This mimics the top-level Makefile. We do it explicitly here so that this
 # Makefile can operate with or without the kbuild infrastructure.
+
+# The kselftests may be built in a couple different ways:
+#     make LLVM=1
+#     make CC=clang
+#
+# In order to handle both cases, set LLVM=1 if CC=clang. That way,the rest of
+# lib.mk, and any Makefiles that include lib.mk, can base decisions solely on
+# whether or not LLVM is set.
+ifeq ($(CC),clang)
+    LLVM := 1
+endif
+
 ifneq ($(LLVM),)
 ifneq ($(filter %/,$(LLVM)),)
 LLVM_PREFIX := $(LLVM)
Signature · 2 lines
BR,
Muhammad Usama Anjum
#3 lore raw

PATCH 2/2 selftests/lib.mk: silence some clang warnings that gcc already ignores

In reply to John Hubbard

gcc defaults to silence (off) for the following warnings, but clang defaults to the opposite. These warnings are not useful for kselftests, so silence them for the clang builds as well:

-Wno-address-of-packed-member
-Wno-gnu-variable-sized-type-not-at-end

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]>
---
 tools/testing/selftests/lib.mk | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/lib.mk +6 -0
index 2902787b89b2..41e879f3f8a2 100644
@@ -50,6 +50,12 @@ 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. These warnings are not useful for kselftests, so silence them
+# for the clang builds as well.
+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
Signature · 1 line
2.45.1
maintainer
#4 lore raw

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

Quoted 3 lines · John Hubbard

gcc defaults to silence (off) for the following warnings, but clang defaults to the opposite. These warnings are not useful for kselftests, so silence them for the clang builds as well:

Please you add more information on why they aren't useful for kselftests.

Quoted 25 lines

-Wno-address-of-packed-member
-Wno-gnu-variable-sized-type-not-at-end

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]>
---
  tools/testing/selftests/lib.mk | 6 ++++++
  1 file changed, 6 insertions(+)
tools/testing/selftests/lib.mk +0 -0
index 2902787b89b2..41e879f3f8a2 100644
@@ -50,6 +50,12 @@ else
  CLANG_FLAGS     += --target=$(notdir $(CROSS_COMPILE:%-=%))
  endif # CROSS_COMPILE

tools/testing/selftests/lib.mk else · line 61

Quoted 10 lines
tools/testing/selftests/lib.mk +6 -0
 
+# gcc defaults to silence (off) for the following warnings, but clang defaults
+# to the opposite. These warnings are not useful for kselftests, so silence them
+# for the clang builds as well.
+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

thanks,
-- Shuah

#5 lore raw

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

Quoted 7 lines · Shuah Khan
Quoted 3 lines · John Hubbard

gcc defaults to silence (off) for the following warnings, but clang defaults to the opposite. These warnings are not useful for kselftests, so silence them for the clang builds as well:

Please you add more information on why they aren't useful for kselftests.

Ah OK. My wording is a little misleading. The warnings are not useful for the *kernel*, as previous decided by the gcc settings when building the kernel. And it is only only due to including kernel data structures in the selftests, that we get the warnings on clang.

So it is not something 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.

I can post a v2 to update both the comment and the commit description.

thanks,

Signature · 2 lines
John Hubbard
NVIDIA
Quoted 41 lines
Quoted 34 lines

     -Wno-address-of-packed-member
     -Wno-gnu-variable-sized-type-not-at-end

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]>

---
  tools/testing/selftests/lib.mk | 6 ++++++

  1 file changed, 6 insertions(+)
tools/testing/selftests/lib.mk +0 -0
index 2902787b89b2..41e879f3f8a2 100644
@@ -50,6 +50,12 @@ 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. These warnings are not useful for kselftests, so silence them

tools/testing/selftests/lib.mk +4 -0
+# for the clang builds as well.
+CFLAGS += -Wno-address-of-packed-member
+CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
+
Quoted 3 lines

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

thanks,
-- Shuah

maintainer
#6 lore raw

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

Quoted 14 lines · John Hubbard
Quoted 7 lines · Shuah Khan
Quoted 3 lines · John Hubbard

gcc defaults to silence (off) for the following warnings, but clang defaults to the opposite. These warnings are not useful for kselftests, so silence them for the clang builds as well:

Please you add more information on why they aren't useful for kselftests.

Ah OK. My wording is a little misleading. The warnings are not useful for the *kernel*, as previous decided by the gcc settings when building the kernel. And it is only only due to including kernel data structures in the selftests, that we get the warnings on clang.

Quoted 6 lines

So it is not something 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.

I can post a v2 to update both the comment and the commit description.

Yes please.

thanks,
-- Shuah