Skip to content

Commit ab21cf8

Browse files
NTMangregkh
authored andcommitted
libbpf: Fix -Wdiscarded-qualifiers under C23
commit d70f79f 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 <fweimer@redhat.com> Suggested-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com> Link: https://lore.kernel.org/r/20251206092825.1471385-1-mikhail.v.gavrilov@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> [ shung-hsi.yu: needed to fix kernel build failure due to libbpf since glibc 2.43+ (which adds 'const' qualifier to strstr) ] Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f749b36 commit ab21cf8

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tools/lib/bpf/libbpf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8245,7 +8245,7 @@ static int kallsyms_cb(unsigned long long sym_addr, char sym_type,
82458245
struct bpf_object *obj = ctx;
82468246
const struct btf_type *t;
82478247
struct extern_desc *ext;
8248-
char *res;
8248+
const char *res;
82498249

82508250
res = strstr(sym_name, ".llvm.");
82518251
if (sym_type == 'd' && res)
@@ -11574,7 +11574,8 @@ static int avail_kallsyms_cb(unsigned long long sym_addr, char sym_type,
1157411574
*
1157511575
* [0] fb6a421fb615 ("kallsyms: Match symbols exactly with CONFIG_LTO_CLANG")
1157611576
*/
11577-
char sym_trim[256], *psym_trim = sym_trim, *sym_sfx;
11577+
char sym_trim[256], *psym_trim = sym_trim;
11578+
const char *sym_sfx;
1157811579

1157911580
if (!(sym_sfx = strstr(sym_name, ".llvm.")))
1158011581
return 0;
@@ -12159,7 +12160,7 @@ static int resolve_full_path(const char *file, char *result, size_t result_sz)
1215912160
if (!search_paths[i])
1216012161
continue;
1216112162
for (s = search_paths[i]; s != NULL; s = strchr(s, ':')) {
12162-
char *next_path;
12163+
const char *next_path;
1216312164
int seg_len;
1216412165

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

0 commit comments

Comments
 (0)