[PATCH v2] perf riscv: Fix discarded const qualifier in _get_field()
Ian Rogers
irogers at google.com
Wed May 13 16:11:37 PDT 2026
On Wed, May 13, 2026 at 11:12 AM Li Guan <guanli.oerv at 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 at isrc.iscas.ac.cn>
Reviewed-by: Ian Rogers <irogers at 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
>
>
More information about the linux-riscv
mailing list