From: Martin Kaiser <martin@kaiser.cx>
To: Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Chen Pei <cp0613@linux.alibaba.com>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Martin Kaiser <martin@kaiser.cx>
Subject: [PATCH] riscv: ftrace: sorttable: fix mcount sorting
Date: Mon, 8 Jun 2026 22:18:27 +0200 [thread overview]
Message-ID: <20260608201904.715374-1-martin@kaiser.cx> (raw)
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
next reply other threads:[~2026-06-08 20:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 20:18 Martin Kaiser [this message]
2026-06-09 1:30 ` Chen Pei
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=20260608201904.715374-1-martin@kaiser.cx \
--to=martin@kaiser.cx \
--cc=cp0613@linux.alibaba.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mhiramat@kernel.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®