[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1531b195c4cb7af96304341e7cbcaf7aba78e4b3.1764334686.git.mikhail.v.gavrilov@gmail.com>
Date: Fri, 28 Nov 2025 18:26:19 +0500
From: Mikhail Gavrilov <mikhail.v.gavrilov@...il.com>
To: bpf@...r.kernel.org
Cc: andrii@...nel.org,
ast@...nel.org,
daniel@...earbox.net,
netdev@...r.kernel.org,
fweimer@...hat.com,
Mikhail Gavrilov <mikhail.v.gavrilov@...il.com>
Subject: [PATCH v2 bpf-next] tools/lib/bpf: fix -Wdiscarded-qualifiers under C23
glibc ≥ 2.42 (GCC 15) defaults to -std=gnu23, which promotes
-Wdiscarded-qualifiers to an error in the default hardening flags
of Fedora Rawhide, Arch Linux, openSUSE Tumbleweed, Gentoo, etc.
In C23, strstr() and strchr() return "const char *" in most cases,
making previous implicit casts invalid.
This breaks the build of tools/bpf/resolve_btfids on pristine
upstream kernel when using GCC 15 + glibc 2.42+.
Fix the three remaining instances with explicit casts.
No functional changes.
Link: https://bugzilla.redhat.com/show_bug.cgi?id=2417601
Suggested-by: Florian Weimer <fweimer@...hat.com>
Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@...il.com>
---
v2:
- Use explicit casts instead of changing variable types to const char *,
because the variables are already declared as char * earlier in the
functions and used in contexts requiring mutability.
This is common practice in the kernel when full const-correctness
cannot be preserved without major refactoring.
---
tools/lib/bpf/libbpf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index dd3b2f57082d..dd11feef3adf 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -8247,7 +8247,7 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type,
struct extern_desc *ext;
char *res;
- res = strstr(sym_name, ".llvm.");
+ res = (char *)strstr(sym_name, ".llvm.");
if (sym_type == 'd' && res)
ext = find_extern_by_name_with_len(obj, sym_name, res - sym_name);
else
@@ -11576,7 +11576,7 @@ static int avail_kallsyms_cb(unsigned long long sym_addr, char sym_type,
*/
char sym_trim[256], *psym_trim = sym_trim, *sym_sfx;
- if (!(sym_sfx = strstr(sym_name, ".llvm.")))
+ if (!(sym_sfx = (char *)strstr(sym_name, ".llvm.")))
return 0;
/* psym_trim vs sym_trim dance is done to avoid pointer vs array
@@ -12164,7 +12164,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
if (s[0] == ':')
s++;
- next_path = strchr(s, ':');
+ next_path = (char *)strchr(s, ':');
seg_len = next_path ? next_path - s : strlen(s);
if (!seg_len)
continue;
--
2.52.0
Powered by blists - more mailing lists