libbpf: Fix -Wdiscarded-qualifiers under C23
PATCH 1/1 libbpf: Fix -Wdiscarded-qualifiers under C23
From: Mikhail Gavrilov <[email protected]>
commit d70f79fef65810faf64dbae1f3a1b5623cdb2345 upstream.
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 <[email protected]>
Suggested-by Andrii Nakryiko <[email protected]>
Signed-off-by Mikhail Gavrilov <[email protected]>
Signed-off-by Alexei Starovoitov <[email protected]>
[shung-hsi.yu: needed to fix kernel build failure due to libbpf since glibc 2.43+ (which adds 'const' qualifier to strstr). 'sym_sfx' hunk dropped because commit f8a05692de06 ("libbpf: Work around kernel inconsistently stripping '.llvm.' suffix") is not present.]
Signed-off-by Shung-Hsi Yu <[email protected]>
--- tools/lib/bpf/libbpf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/lib/bpf/libbpf.c +2 -2
@@ -8174,7 +8174,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)
@@ -11959,7 +11959,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 ] ==':' )
Signature · 1 line
2.52.0