diff mbox series

[v4,16/16] objtool/powerpc: Add --mcount specific implementation

Message ID 20221002104240.1316480-17-sv@linux.ibm.com (mailing list archive)
State Changes Requested
Headers show
Series objtool: Enable and implement --mcount option on powerpc | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 10 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 10 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 23 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.

Commit Message

Sathvika Vasireddy Oct. 2, 2022, 10:42 a.m. UTC
This patch enables objtool --mcount on powerpc, and adds implementation
specific to powerpc.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
---
 arch/powerpc/Kconfig                          |  1 +
 tools/objtool/arch/powerpc/decode.c           | 16 ++++++++++++++++
 tools/objtool/arch/powerpc/include/arch/elf.h |  2 ++
 3 files changed, 19 insertions(+)

Comments

Christophe Leroy Oct. 2, 2022, 5:42 p.m. UTC | #1
Le 02/10/2022 à 12:42, Sathvika Vasireddy a écrit :
> This patch enables objtool --mcount on powerpc, and adds implementation
> specific to powerpc.
> 
> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>

> ---
>   arch/powerpc/Kconfig                          |  1 +
>   tools/objtool/arch/powerpc/decode.c           | 16 ++++++++++++++++
>   tools/objtool/arch/powerpc/include/arch/elf.h |  2 ++
>   3 files changed, 19 insertions(+)
> 
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index dc05cd23c233..6be2e68fa9eb 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -238,6 +238,7 @@ config PPC
>   	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
>   	select HAVE_OPTPROBES
>   	select HAVE_OBJTOOL			if PPC32 || MPROFILE_KERNEL
> +	select HAVE_OBJTOOL_MCOUNT		if HAVE_OBJTOOL
>   	select HAVE_PERF_EVENTS
>   	select HAVE_PERF_EVENTS_NMI		if PPC64
>   	select HAVE_PERF_REGS
> diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
> index dcd0975cad6b..01cade98b49e 100644
> --- a/tools/objtool/arch/powerpc/decode.c
> +++ b/tools/objtool/arch/powerpc/decode.c
> @@ -9,6 +9,11 @@
>   #include <objtool/builtin.h>
>   #include <objtool/endianness.h>
>   
> +int arch_ftrace_match(char *name)
> +{
> +	return !strcmp(name, "_mcount");
> +}
> +
>   unsigned long arch_dest_reloc_offset(int addend)
>   {
>   	return addend;
> @@ -50,6 +55,17 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
>   	typ = INSN_OTHER;
>   	imm = 0;
>   
> +	switch (opcode) {
> +	case 18: /* b[l][a] */
> +		if ((insn & 3) == 1) /* bl */
> +			typ = INSN_CALL;
> +
> +		imm = insn & 0x3fffffc;
> +		if (imm & 0x2000000)
> +			imm -= 0x4000000;
> +		break;
> +	}
> +
>   	if (opcode == 1)
>   		*len = 8;
>   	else
> diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
> index 3c8ebb7d2a6b..73f9ae172fe5 100644
> --- a/tools/objtool/arch/powerpc/include/arch/elf.h
> +++ b/tools/objtool/arch/powerpc/include/arch/elf.h
> @@ -4,5 +4,7 @@
>   #define _OBJTOOL_ARCH_ELF
>   
>   #define R_NONE R_PPC_NONE
> +#define R_ABS64 R_PPC64_ADDR64
> +#define R_ABS32 R_PPC_ADDR32
>   
>   #endif /* _OBJTOOL_ARCH_ELF */
diff mbox series

Patch

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index dc05cd23c233..6be2e68fa9eb 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -238,6 +238,7 @@  config PPC
 	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
 	select HAVE_OPTPROBES
 	select HAVE_OBJTOOL			if PPC32 || MPROFILE_KERNEL
+	select HAVE_OBJTOOL_MCOUNT		if HAVE_OBJTOOL
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI		if PPC64
 	select HAVE_PERF_REGS
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index dcd0975cad6b..01cade98b49e 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -9,6 +9,11 @@ 
 #include <objtool/builtin.h>
 #include <objtool/endianness.h>
 
+int arch_ftrace_match(char *name)
+{
+	return !strcmp(name, "_mcount");
+}
+
 unsigned long arch_dest_reloc_offset(int addend)
 {
 	return addend;
@@ -50,6 +55,17 @@  int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 	typ = INSN_OTHER;
 	imm = 0;
 
+	switch (opcode) {
+	case 18: /* b[l][a] */
+		if ((insn & 3) == 1) /* bl */
+			typ = INSN_CALL;
+
+		imm = insn & 0x3fffffc;
+		if (imm & 0x2000000)
+			imm -= 0x4000000;
+		break;
+	}
+
 	if (opcode == 1)
 		*len = 8;
 	else
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
index 3c8ebb7d2a6b..73f9ae172fe5 100644
--- a/tools/objtool/arch/powerpc/include/arch/elf.h
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -4,5 +4,7 @@ 
 #define _OBJTOOL_ARCH_ELF
 
 #define R_NONE R_PPC_NONE
+#define R_ABS64 R_PPC64_ADDR64
+#define R_ABS32 R_PPC_ADDR32
 
 #endif /* _OBJTOOL_ARCH_ELF */