[Devel] [PATCH vz10 1/2] libbpf: Fix -Wdiscarded-qualifiers under C23

Eva Kurchatova eva.kurchatova at virtuozzo.com
Mon Apr 27 19:20:40 MSK 2026


From: Mikhail Gavrilov <mikhail.v.gavrilov at gmail.com>

glibc ≥ 2.42 (GCC 15) defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error.

In C23, strstr() and strchr() return "const char *".

Change variable types to const char * where the pointers are never
modified (res, sym_sfx, next_path).

Feature: fix ms/selftest

https://virtuozzo.atlassian.net/browse/VSTOR-129993

Suggested-by: Florian Weimer <fweimer at redhat.com>
Suggested-by: Andrii Nakryiko <andrii at kernel.org>
Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov at gmail.com>
Link: https://lore.kernel.org/r/20251206092825.1471385-1-mikhail.v.gavrilov@gmail.com
Signed-off-by: Alexei Starovoitov <ast at kernel.org>
(cherry picked from commit d70f79fef65810faf64dbae1f3a1b5623cdb2345)
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
---
 tools/lib/bpf/libbpf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 219facd0e66e..bf8a29ce63e2 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8115,7 +8115,7 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type,
 	struct bpf_object *obj = ctx;
 	const struct btf_type *t;
 	struct extern_desc *ext;
-	char *res;
+	const char *res;
 
 	res = strstr(sym_name, ".llvm.");
 	if (sym_type == 'd' && res)
@@ -11912,7 +11912,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
 		if (!search_paths[i])
 			continue;
 		for (s = search_paths[i]; s != NULL; s = strchr(s, ':')) {
-			char *next_path;
+			const char *next_path;
 			int seg_len;
 
 			if (s[0] == ':')
-- 
2.54.0



More information about the Devel mailing list