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

Konstantin Khorenko khorenko at virtuozzo.com
Tue May 12 14:59:17 MSK 2026


On 4/27/26 18:20, Eva Kurchatova wrote:
> 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>

1. let's not mess mainstream commit and our appends, so i would ask you to send something like

     ms/libbpf: Fix -Wdiscarded-qualifiers under C23

     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).

     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>

     Backport changes: the hunk in avail_kallsyms_cb() has been dropped -
     no appropriate code to be changed yet there.

     https://virtuozzo.atlassian.net/browse/VSTOR-129993
     Feature: fix ms/C23

     (cherry picked from commit d70f79fef65810faf64dbae1f3a1b5623cdb2345)
     Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>

2. Let's use "Feature: fix ms/C23", i expect more patches related to C23 and they normally are totally 
not about changes in logic.

3. You are backporting a commit.
If it applies clean - ok, no extra comments required.
If you had to perform any changes in order to get it applied - please, always write a note on what has 
been changed and why.
He you have dropped a hunk from a ms commit.

4. when you send a patch to the list with a jira bug id, please, also put a line into that bug with 
the patch subject - that way anyone will be able to understand which patches were sent to fix that or 
another jira bug.

> ---
>   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] == ':')



More information about the Devel mailing list