tools/perf/arch/riscv/util/header.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
The assignment of strrchr() return values to non-const char * variables
triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
This happens because in newer glibc versions, strrchr() returns a
const char * if the input string is const.
Properly declare 'line2' and 'nl' as const char * to match the glibc
function signature and ensure type safety. This avoids the need for
explicit type casting and aligns with the design pattern of not
modifying read-only memory in the perf tool.
Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
---
v2:
- Drop the auxtrace decoupling and weak stub approach as they interfered
with the cross-platform analysis intent, per Ian's feedback.
- Focus on a clean fix for the const qualifier issue in RISC-V header.c
by properly declaring local variables as const.
- Use Li Guan as the preferred name format for consistency.
- Verified that this fix is not yet present in acme/perf-tools-next.
tools/perf/arch/riscv/util/header.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
index 4b839203d4..891984e909 100644
--- a/tools/perf/arch/riscv/util/header.c
+++ b/tools/perf/arch/riscv/util/header.c
@@ -19,7 +19,7 @@
static char *_get_field(const char *line)
{
- char *line2, *nl;
+ const char *line2, *nl;
line2 = strrchr(line, ' ');
if (!line2)
--
2.54.0
Hi Arnaldo, Namhyung,
Just a gentle ping on this patch. It has received a Reviewed-by from Ian.
Could you please consider picking it up for perf-tools-next?
Thanks,
Li Guan
On 5/14/2026 2:07 AM, Li Guan wrote:
> The assignment of strrchr() return values to non-const char * variables
> triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
> This happens because in newer glibc versions, strrchr() returns a
> const char * if the input string is const.
>
> Properly declare 'line2' and 'nl' as const char * to match the glibc
> function signature and ensure type safety. This avoids the need for
> explicit type casting and aligns with the design pattern of not
> modifying read-only memory in the perf tool.
>
> Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> ---
> v2:
> - Drop the auxtrace decoupling and weak stub approach as they interfered
> with the cross-platform analysis intent, per Ian's feedback.
> - Focus on a clean fix for the const qualifier issue in RISC-V header.c
> by properly declaring local variables as const.
> - Use Li Guan as the preferred name format for consistency.
> - Verified that this fix is not yet present in acme/perf-tools-next.
>
> tools/perf/arch/riscv/util/header.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> index 4b839203d4..891984e909 100644
> --- a/tools/perf/arch/riscv/util/header.c
> +++ b/tools/perf/arch/riscv/util/header.c
> @@ -19,7 +19,7 @@
>
> static char *_get_field(const char *line)
> {
> - char *line2, *nl;
> + const char *line2, *nl;
>
> line2 = strrchr(line, ' ');
> if (!line2)
On Sun, May 24, 2026 at 02:41:26AM +0800, Li Guan wrote:
> Hi Arnaldo, Namhyung,
>
> Just a gentle ping on this patch. It has received a Reviewed-by from Ian.
> Could you please consider picking it up for perf-tools-next?
Thanks, applying.
- Arnaldo
> Thanks,
> Li Guan
>
> On 5/14/2026 2:07 AM, Li Guan wrote:
> > The assignment of strrchr() return values to non-const char * variables
> > triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
> > This happens because in newer glibc versions, strrchr() returns a
> > const char * if the input string is const.
> >
> > Properly declare 'line2' and 'nl' as const char * to match the glibc
> > function signature and ensure type safety. This avoids the need for
> > explicit type casting and aligns with the design pattern of not
> > modifying read-only memory in the perf tool.
> >
> > Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
> > ---
> > v2:
> > - Drop the auxtrace decoupling and weak stub approach as they interfered
> > with the cross-platform analysis intent, per Ian's feedback.
> > - Focus on a clean fix for the const qualifier issue in RISC-V header.c
> > by properly declaring local variables as const.
> > - Use Li Guan as the preferred name format for consistency.
> > - Verified that this fix is not yet present in acme/perf-tools-next.
> >
> > tools/perf/arch/riscv/util/header.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> > index 4b839203d4..891984e909 100644
> > --- a/tools/perf/arch/riscv/util/header.c
> > +++ b/tools/perf/arch/riscv/util/header.c
> > @@ -19,7 +19,7 @@
> > static char *_get_field(const char *line)
> > {
> > - char *line2, *nl;
> > + const char *line2, *nl;
> > line2 = strrchr(line, ' ');
> > if (!line2)
On Wed, May 13, 2026 at 11:12 AM Li Guan <guanli.oerv@isrc.iscas.ac.cn> wrote:
>
> The assignment of strrchr() return values to non-const char * variables
> triggers a -Werror=discarded-qualifiers warning when building with GCC 14.
> This happens because in newer glibc versions, strrchr() returns a
> const char * if the input string is const.
>
> Properly declare 'line2' and 'nl' as const char * to match the glibc
> function signature and ensure type safety. This avoids the need for
> explicit type casting and aligns with the design pattern of not
> modifying read-only memory in the perf tool.
>
> Signed-off-by: Li Guan <guanli.oerv@isrc.iscas.ac.cn>
Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> ---
> v2:
> - Drop the auxtrace decoupling and weak stub approach as they interfered
> with the cross-platform analysis intent, per Ian's feedback.
> - Focus on a clean fix for the const qualifier issue in RISC-V header.c
> by properly declaring local variables as const.
> - Use Li Guan as the preferred name format for consistency.
> - Verified that this fix is not yet present in acme/perf-tools-next.
>
> tools/perf/arch/riscv/util/header.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/arch/riscv/util/header.c b/tools/perf/arch/riscv/util/header.c
> index 4b839203d4..891984e909 100644
> --- a/tools/perf/arch/riscv/util/header.c
> +++ b/tools/perf/arch/riscv/util/header.c
> @@ -19,7 +19,7 @@
>
> static char *_get_field(const char *line)
> {
> - char *line2, *nl;
> + const char *line2, *nl;
>
> line2 = strrchr(line, ' ');
> if (!line2)
> --
> 2.54.0
>
>
© 2016 - 2026 Red Hat, Inc.