Skip to content

Commit a0a458f

Browse files
zhangqingmychenhuacai
authored andcommitted
LoongArch/ftrace: Add recordmcount support
Recordmcount utility under scripts is run, after compiling each object, to find out all the locations of calling _mcount() and put them into specific seciton named __mcount_loc. Then the linker collects all such information into a table in the kernel image (between __start_mcount_loc and __stop_mcount_loc) for later use by ftrace. This patch adds LoongArch specific definitions to identify such locations. And on LoongArch, only the C version is used to build the kernel now that CONFIG_HAVE_C_RECORDMCOUNT is on. Acked-by: Steven Rostedt (Google) <[email protected]> Signed-off-by: Qing Zhang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent dbe3ba3 commit a0a458f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

arch/loongarch/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ config LOONGARCH
8585
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
8686
select HAVE_ASM_MODVERSIONS
8787
select HAVE_CONTEXT_TRACKING_USER
88+
select HAVE_C_RECORDMCOUNT
8889
select HAVE_DEBUG_STACKOVERFLOW
8990
select HAVE_DMA_CONTIGUOUS
9091
select HAVE_EBPF_JIT
9192
select HAVE_EXIT_THREAD
9293
select HAVE_FAST_GUP
94+
select HAVE_FTRACE_MCOUNT_RECORD
9395
select HAVE_FUNCTION_GRAPH_TRACER
9496
select HAVE_FUNCTION_TRACER
9597
select HAVE_GENERIC_VDSO

scripts/recordmcount.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
#define R_AARCH64_ABS64 257
3939
#endif
4040

41+
#ifndef EM_LOONGARCH
42+
#define EM_LOONGARCH 258
43+
#define R_LARCH_32 1
44+
#define R_LARCH_64 2
45+
#define R_LARCH_MARK_LA 20
46+
#define R_LARCH_SOP_PUSH_PLT_PCREL 29
47+
#endif
48+
4149
#define R_ARM_PC24 1
4250
#define R_ARM_THM_CALL 10
4351
#define R_ARM_CALL 28
@@ -441,6 +449,28 @@ static int arm64_is_fake_mcount(Elf64_Rel const *rp)
441449
return ELF64_R_TYPE(w8(rp->r_info)) != R_AARCH64_CALL26;
442450
}
443451

452+
static int LARCH32_is_fake_mcount(Elf32_Rel const *rp)
453+
{
454+
switch (ELF64_R_TYPE(w(rp->r_info))) {
455+
case R_LARCH_MARK_LA:
456+
case R_LARCH_SOP_PUSH_PLT_PCREL:
457+
return 0;
458+
}
459+
460+
return 1;
461+
}
462+
463+
static int LARCH64_is_fake_mcount(Elf64_Rel const *rp)
464+
{
465+
switch (ELF64_R_TYPE(w(rp->r_info))) {
466+
case R_LARCH_MARK_LA:
467+
case R_LARCH_SOP_PUSH_PLT_PCREL:
468+
return 0;
469+
}
470+
471+
return 1;
472+
}
473+
444474
/* 64-bit EM_MIPS has weird ELF64_Rela.r_info.
445475
* http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf
446476
* We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40]
@@ -558,6 +588,7 @@ static int do_file(char const *const fname)
558588
break;
559589
case EM_IA_64: reltype = R_IA64_IMM64; break;
560590
case EM_MIPS: /* reltype: e_class */ break;
591+
case EM_LOONGARCH: /* reltype: e_class */ break;
561592
case EM_PPC: reltype = R_PPC_ADDR32; break;
562593
case EM_PPC64: reltype = R_PPC64_ADDR64; break;
563594
case EM_S390: /* reltype: e_class */ break;
@@ -589,6 +620,10 @@ static int do_file(char const *const fname)
589620
reltype = R_MIPS_32;
590621
is_fake_mcount32 = MIPS32_is_fake_mcount;
591622
}
623+
if (w2(ehdr->e_machine) == EM_LOONGARCH) {
624+
reltype = R_LARCH_32;
625+
is_fake_mcount32 = LARCH32_is_fake_mcount;
626+
}
592627
if (do32(ehdr, fname, reltype) < 0)
593628
goto out;
594629
break;
@@ -610,6 +645,10 @@ static int do_file(char const *const fname)
610645
Elf64_r_info = MIPS64_r_info;
611646
is_fake_mcount64 = MIPS64_is_fake_mcount;
612647
}
648+
if (w2(ghdr->e_machine) == EM_LOONGARCH) {
649+
reltype = R_LARCH_64;
650+
is_fake_mcount64 = LARCH64_is_fake_mcount;
651+
}
613652
if (do64(ghdr, fname, reltype) < 0)
614653
goto out;
615654
break;

0 commit comments

Comments
 (0)