Skip to content

Commit 7d85ef3

Browse files
NTManKernel Patches Daemon
authored andcommitted
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 C23, strstr() and strchr() return "const char *". Declare `res` and `next_path` as const char * — they are never modified. Keep `sym_sfx` as char * because it is advanced in a loop. Suggested-by: Florian Weimer <[email protected]> Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Mikhail Gavrilov <[email protected]>
1 parent 6ba2fc1 commit 7d85ef3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8484,7 +8484,7 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type,
84848484
struct bpf_object *obj = ctx;
84858485
const struct btf_type *t;
84868486
struct extern_desc *ext;
8487-
char *res;
8487+
const char *res;
84888488

84898489
res = strstr(sym_name, ".llvm.");
84908490
if (sym_type == 'd' && res)
@@ -11820,7 +11820,7 @@ static int avail_kallsyms_cb(unsigned long long sym_addr, char sym_type,
1182011820
*/
1182111821
char sym_trim[256], *psym_trim = sym_trim, *sym_sfx;
1182211822

11823-
if (!(sym_sfx = strstr(sym_name, ".llvm.")))
11823+
if (!(sym_sfx = (char *)strstr(sym_name, ".llvm."))) /* needs mutation */
1182411824
return 0;
1182511825

1182611826
/* psym_trim vs sym_trim dance is done to avoid pointer vs array
@@ -12401,7 +12401,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
1240112401
if (!search_paths[i])
1240212402
continue;
1240312403
for (s = search_paths[i]; s != NULL; s = strchr(s, ':')) {
12404-
char *next_path;
12404+
const char *next_path;
1240512405
int seg_len;
1240612406

1240712407
if (s[0] == ':')

0 commit comments

Comments
 (0)