BPF List
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Cc: bpf@vger.kernel.org,  andrii@kernel.org,  ast@kernel.org,
	daniel@iogearbox.net,  netdev@vger.kernel.org
Subject: Re: [PATCH] tools/lib/bpf: fix -Wdiscarded-qualifiers under C23
Date: Fri, 28 Nov 2025 10:26:31 +0100	[thread overview]
Message-ID: <lhuecpi8q48.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20251128002205.1167572-1-mikhail.v.gavrilov@gmail.com> (Mikhail Gavrilov's message of "Fri, 28 Nov 2025 05:22:05 +0500")

* Mikhail Gavrilov:

> 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 implicit casts from const to non-const 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
> Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
> ---
>  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;

I think you should change the type of the relevant variables to const
char *.  The kernel coding style does not disallow using const, does it?

Thanks,
Florian


  reply	other threads:[~2025-11-28  9:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-28  0:22 [PATCH] tools/lib/bpf: fix -Wdiscarded-qualifiers under C23 Mikhail Gavrilov
2025-11-28  9:26 ` Florian Weimer [this message]
2025-11-28 13:26 ` [PATCH v2 bpf-next] " Mikhail Gavrilov
2025-11-28 13:38   ` Florian Weimer
2025-11-28 14:59 ` Mikhail Gavrilov
2025-12-05 23:51   ` Andrii Nakryiko
2025-12-06  8:05     ` [PATCH v3] " Mikhail Gavrilov
2025-12-06  9:28     ` Mikhail Gavrilov
2025-12-10  7:30       ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lhuecpi8q48.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=mikhail.v.gavrilov@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox