mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] riscv: ftrace: sorttable: fix mcount sorting
@ 2026-06-08 20:18 Martin Kaiser
  2026-06-09  1:30 ` Chen Pei
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Kaiser @ 2026-06-08 20:18 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Paul Walmsley, Palmer Dabbelt,
	Chen Pei
  Cc: linux-riscv, linux-kernel, Martin Kaiser

Commit de04fca5d2f8 ("riscv: ftrace: select HAVE_BUILDTIME_MCOUNT_SORT")
enabled mcount sorting for risc-v. On my system, the sorting changes all
entries to address 0. The startup test reports that the mcount section is
properly sorted, but no traceable functions are registered at boot time.

[    0.000000] ftrace section at ffffffff8101bba0 sorted properly
[    0.000000] ftrace: allocating 0 entries in 128 pages
[    0.000000] ftrace: allocated 128 pages with 1 groups

The sorttable helper program does not take into account that the
-fpatchable-function-entry compiler flag reserves an additional 8 bytes
before each traceable function. (The size in bytes is the same for
RV32/64 or compressed/uncompressed instructions).

Define before_func = 8 to fix the mcount sorting for risc-v, share this
setting with arm64.

Fixes: de04fca5d2f8 ("riscv: ftrace: select HAVE_BUILDTIME_MCOUNT_SORT")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
---
 scripts/sorttable.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/scripts/sorttable.c b/scripts/sorttable.c
index e8ed11c680c6..da70f0938d04 100644
--- a/scripts/sorttable.c
+++ b/scripts/sorttable.c
@@ -895,13 +895,19 @@ static int do_file(char const *const fname, void *addr)
 #ifdef MCOUNT_SORT_ENABLED
 		sort_reloc = true;
 		rela_type = 0x403;
-		/* arm64 uses patchable function entry placing before function */
+#endif
+		/* fallthrough */
+	case EM_RISCV:
+#ifdef MCOUNT_SORT_ENABLED
+		/*
+		 * risc-v and arm64 use patchable function entry that stores
+		 * 8 bytes of nops before the function
+		 */
 		before_func = 8;
 #endif
 		/* fallthrough */
 	case EM_386:
 	case EM_LOONGARCH:
-	case EM_RISCV:
 	case EM_S390:
 	case EM_X86_64:
 		custom_sort = sort_relative_table_with_data;
-- 
2.43.7


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-09  1:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-08 20:18 [PATCH] riscv: ftrace: sorttable: fix mcount sorting Martin Kaiser
2026-06-09  1:30 ` Chen Pei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®