riscv: ftrace: sorttable: fix mcount sorting
PATCH 1/1 riscv: ftrace: sorttable: fix mcount sorting
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.
--- scripts/sorttable.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
scripts/sorttable.c +8 -2
@@ -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;
Signature · 1 line
2.43.7
Quoted 9 lines · On Mon, 8 Jun 2026 22:18:27 +0200, [email protected] wrote:
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")
Hi Martin,
Thanks for the patch.
This has already been addressed by Wang Han here:
https://lore.kernel.org/linux-riscv/[email protected]/
Thanks,
Pei