[PATCH v2] perf riscv: Fix discarded const qualifier in _get_field()

Li Guan guanli.oerv at isrc.iscas.ac.cn
Wed May 13 11:07:21 PDT 2026


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>
---
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