Skip to content

Commit 7ce0477

Browse files
nathanchancepalmer-dabbelt
authored andcommitted
riscv: Workaround mcount name prior to clang-13
Prior to clang 13.0.0, the RISC-V name for the mcount symbol was "mcount", which differs from the GCC version of "_mcount", which results in the following errors: riscv64-linux-gnu-ld: init/main.o: in function `__traceiter_initcall_level': main.c:(.text+0xe): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `__traceiter_initcall_start': main.c:(.text+0x4e): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `__traceiter_initcall_finish': main.c:(.text+0x92): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `.LBB32_28': main.c:(.text+0x30c): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `free_initmem': main.c:(.text+0x54c): undefined reference to `mcount' This has been corrected in https://reviews.llvm.org/D98881 but the minimum supported clang version is 10.0.1. To avoid build errors and to gain a working function tracer, adjust the name of the mcount symbol for older versions of clang in mount.S and recordmcount.pl. Link: ClangBuiltLinux#1331 Signed-off-by: Nathan Chancellor <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 2f09550 commit 7ce0477

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

arch/riscv/include/asm/ftrace.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@
1313
#endif
1414
#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
1515

16+
/*
17+
* Clang prior to 13 had "mcount" instead of "_mcount":
18+
* https://reviews.llvm.org/D98881
19+
*/
20+
#if defined(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 130000
21+
#define MCOUNT_NAME _mcount
22+
#else
23+
#define MCOUNT_NAME mcount
24+
#endif
25+
1626
#define ARCH_SUPPORTS_FTRACE_OPS 1
1727
#ifndef __ASSEMBLY__
18-
void _mcount(void);
28+
void MCOUNT_NAME(void);
1929
static inline unsigned long ftrace_call_adjust(unsigned long addr)
2030
{
2131
return addr;
@@ -36,7 +46,7 @@ struct dyn_arch_ftrace {
3646
* both auipc and jalr at the same time.
3747
*/
3848

39-
#define MCOUNT_ADDR ((unsigned long)_mcount)
49+
#define MCOUNT_ADDR ((unsigned long)MCOUNT_NAME)
4050
#define JALR_SIGN_MASK (0x00000800)
4151
#define JALR_OFFSET_MASK (0x00000fff)
4252
#define AUIPC_OFFSET_MASK (0xfffff000)

arch/riscv/kernel/mcount.S

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848
ENTRY(ftrace_stub)
4949
#ifdef CONFIG_DYNAMIC_FTRACE
50-
.global _mcount
51-
.set _mcount, ftrace_stub
50+
.global MCOUNT_NAME
51+
.set MCOUNT_NAME, ftrace_stub
5252
#endif
5353
ret
5454
ENDPROC(ftrace_stub)
@@ -78,7 +78,7 @@ ENDPROC(return_to_handler)
7878
#endif
7979

8080
#ifndef CONFIG_DYNAMIC_FTRACE
81-
ENTRY(_mcount)
81+
ENTRY(MCOUNT_NAME)
8282
la t4, ftrace_stub
8383
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
8484
la t0, ftrace_graph_return
@@ -124,6 +124,6 @@ do_trace:
124124
jalr t5
125125
RESTORE_ABI_STATE
126126
ret
127-
ENDPROC(_mcount)
127+
ENDPROC(MCOUNT_NAME)
128128
#endif
129-
EXPORT_SYMBOL(_mcount)
129+
EXPORT_SYMBOL(MCOUNT_NAME)

scripts/recordmcount.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ sub check_objcopy
392392
$mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$";
393393
} elsif ($arch eq "riscv") {
394394
$function_regex = "^([0-9a-fA-F]+)\\s+<([^.0-9][0-9a-zA-Z_\\.]+)>:";
395-
$mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL(_PLT)?\\s_mcount\$";
395+
$mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL(_PLT)?\\s_?mcount\$";
396396
$type = ".quad";
397397
$alignment = 2;
398398
} elsif ($arch eq "nds32") {

0 commit comments

Comments
 (0)