Skip to content

Commit

Permalink
LoongArch/ftrace: Add recordmcount support
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
zhangqingmy authored and chenhuacai committed Dec 14, 2022
1 parent dbe3ba3 commit a0a458f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions arch/loongarch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ config LOONGARCH
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
select HAVE_ASM_MODVERSIONS
select HAVE_CONTEXT_TRACKING_USER
select HAVE_C_RECORDMCOUNT
select HAVE_DEBUG_STACKOVERFLOW
select HAVE_DMA_CONTIGUOUS
select HAVE_EBPF_JIT
select HAVE_EXIT_THREAD
select HAVE_FAST_GUP
select HAVE_FTRACE_MCOUNT_RECORD
select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_FUNCTION_TRACER
select HAVE_GENERIC_VDSO
Expand Down
39 changes: 39 additions & 0 deletions scripts/recordmcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
#define R_AARCH64_ABS64 257
#endif

#ifndef EM_LOONGARCH
#define EM_LOONGARCH 258
#define R_LARCH_32 1
#define R_LARCH_64 2
#define R_LARCH_MARK_LA 20
#define R_LARCH_SOP_PUSH_PLT_PCREL 29
#endif

#define R_ARM_PC24 1
#define R_ARM_THM_CALL 10
#define R_ARM_CALL 28
Expand Down Expand Up @@ -441,6 +449,28 @@ static int arm64_is_fake_mcount(Elf64_Rel const *rp)
return ELF64_R_TYPE(w8(rp->r_info)) != R_AARCH64_CALL26;
}

static int LARCH32_is_fake_mcount(Elf32_Rel const *rp)
{
switch (ELF64_R_TYPE(w(rp->r_info))) {
case R_LARCH_MARK_LA:
case R_LARCH_SOP_PUSH_PLT_PCREL:
return 0;
}

return 1;
}

static int LARCH64_is_fake_mcount(Elf64_Rel const *rp)
{
switch (ELF64_R_TYPE(w(rp->r_info))) {
case R_LARCH_MARK_LA:
case R_LARCH_SOP_PUSH_PLT_PCREL:
return 0;
}

return 1;
}

/* 64-bit EM_MIPS has weird ELF64_Rela.r_info.
* http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf
* We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40]
Expand Down Expand Up @@ -558,6 +588,7 @@ static int do_file(char const *const fname)
break;
case EM_IA_64: reltype = R_IA64_IMM64; break;
case EM_MIPS: /* reltype: e_class */ break;
case EM_LOONGARCH: /* reltype: e_class */ break;
case EM_PPC: reltype = R_PPC_ADDR32; break;
case EM_PPC64: reltype = R_PPC64_ADDR64; break;
case EM_S390: /* reltype: e_class */ break;
Expand Down Expand Up @@ -589,6 +620,10 @@ static int do_file(char const *const fname)
reltype = R_MIPS_32;
is_fake_mcount32 = MIPS32_is_fake_mcount;
}
if (w2(ehdr->e_machine) == EM_LOONGARCH) {
reltype = R_LARCH_32;
is_fake_mcount32 = LARCH32_is_fake_mcount;
}
if (do32(ehdr, fname, reltype) < 0)
goto out;
break;
Expand All @@ -610,6 +645,10 @@ static int do_file(char const *const fname)
Elf64_r_info = MIPS64_r_info;
is_fake_mcount64 = MIPS64_is_fake_mcount;
}
if (w2(ghdr->e_machine) == EM_LOONGARCH) {
reltype = R_LARCH_64;
is_fake_mcount64 = LARCH64_is_fake_mcount;
}
if (do64(ghdr, fname, reltype) < 0)
goto out;
break;
Expand Down

0 comments on commit a0a458f

Please sign in to comment.