Skip to contentSkip to conversation

selftests: proc: mark vsyscall strings maybe-unused

PATCH Applied Bala-Vignesh-Reddy 2 participants 3 messages Aug 20, 2025 – Aug 21, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: proc: mark vsyscall strings maybe-unused

The str_vsyscall_* constants in proc-pid-vm.c triggers -Wunused-const-variable warnings with gcc-13.32 and clang 18.1.

Define and apply __maybe_unused locally to suppress the warnings. No functional change

Fixes compiler warning:
warning: ‘str_vsyscall_*’ defined but not used[-Wunused-const-variable]

---
 tools/testing/selftests/proc/proc-pid-vm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/proc/proc-pid-vm.c +8 -4
index d04685771952..978cbcb3eb11 100644
@@ -47,6 +47,10 @@
 #include <sys/resource.h>
 #include <linux/fs.h>
 
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
+#endif
+
 #include "../kselftest.h"
 
 static inline long sys_execveat(int dirfd, const char *pathname, char **argv, char **envp, int flags)
@@ -218,12 +222,12 @@ static int make_exe(const uint8_t *payload, size_t len)
  * 2: vsyscall VMA is r-xp		vsyscall=emulate
  */
 static volatile int g_vsyscall;
-static const char *str_vsyscall;
+static const char *str_vsyscall __maybe_unused;
 
-static const char str_vsyscall_0[] = "";
-static const char str_vsyscall_1[] =
+static const char str_vsyscall_0[] __maybe_unused = "";
+static const char str_vsyscall_1[] __maybe_unused =
 "ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0                  [vsyscall]\n";
-static const char str_vsyscall_2[] =
+static const char str_vsyscall_2[] __maybe_unused =
 "ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]\n";
 
 #ifdef __x86_64__
Signature · 1 line
2.43.0
#1 lore raw
Quoted 2 lines · On Wed, 20 Aug 2025 23:26:10 +0530 Bala-Vignesh-Reddy…

The str_vsyscall_* constants in proc-pid-vm.c triggers -Wunused-const-variable warnings with gcc-13.32 and clang 18.1.

OT but lol. My head is spinning at the term "const-variable". I understand what they mean, but it's oxymoronic.

Quoted 11 lines

Define and apply __maybe_unused locally to suppress the warnings. No functional change

Fixes compiler warning:
warning: ‘str_vsyscall_*’ defined but not used[-Wunused-const-variable]

...

tools/testing/selftests/proc/proc-pid-vm.c line 52

Quoted 6 lines
tools/testing/selftests/proc/proc-pid-vm.c +3 -0
@@ -47,6 +47,10 @@
 #include <sys/resource.h>
 #include <linux/fs.h>
 
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
+#endif

This would be approximately the seventh definition of __maybe_unused under tools/testing/selftests. And there's another in tools/testing/memblock, which, as if admitting that its directory is in the wrong place, had to go and include ../selftests/kselftest.h.

So it would be pleasing if some kind soul were to define __maybe_unused in a common place, which looks to be tools/testing/selftests/kselftest.h. Then go zap all those private definitions.

This could be done either before or after your patch.

tools/testing/selftests/proc/proc-pid-vm.c line 54

Quoted 1 line
tools/testing/selftests/proc/proc-pid-vm.c +0 -0
 #include "../kselftest.h"

And we have 350 occurrences of "../kselftest.h". Shouldn't the build system be providing -Itools/testing/selftests?

Anyway, patch looks OK - I'll add it to mm.git, thanks.

#2 lore raw

Hi Andrew,

Thanks for your feedback, I didn't notice that __maybe_unused is defined repeatedly in selftests directory.

Following your suggestions, I've submitted a cleanup patch that centralise the __maybe_unused definition in tools/testing/selftests/kselftest.h and removed the redundant copies across the selftests subdirectories. I've tested it with gcc and clang, and it builds cleanly.

Patch Link:
https://lore.kernel.org/lkml/[email protected]/

Will also look into build system, to tackle including kselftest.h everywhere

Thanks,
Bala Vignesh