linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Sathvika Vasireddy <sv@linux.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: peterz@infradead.org, linux-kernel@vger.kernel.org,
	rostedt@goodmis.org, aik@ozlabs.ru, sv@linux.ibm.com,
	jpoimboe@redhat.com, naveen.n.rao@linux.vnet.ibm.com
Subject: [RFC PATCH 3/3] objtool/mcount: Add powerpc specific functions
Date: Fri, 18 Mar 2022 16:21:40 +0530	[thread overview]
Message-ID: <20220318105140.43914-4-sv@linux.ibm.com> (raw)
In-Reply-To: <20220318105140.43914-1-sv@linux.ibm.com>

This patch adds powerpc specific functions required for
'objtool mcount' to work, and enables mcount for ppc.

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
---
 arch/powerpc/Kconfig                          |  1 +
 tools/objtool/Makefile                        |  4 ++
 tools/objtool/arch/powerpc/Build              |  1 +
 tools/objtool/arch/powerpc/decode.c           | 51 +++++++++++++++++++
 .../arch/powerpc/include/arch/cfi_regs.h      | 37 ++++++++++++++
 tools/objtool/arch/powerpc/include/arch/elf.h |  8 +++
 tools/objtool/utils.c                         | 28 ++++++++--
 7 files changed, 125 insertions(+), 5 deletions(-)
 create mode 100644 tools/objtool/arch/powerpc/Build
 create mode 100644 tools/objtool/arch/powerpc/decode.c
 create mode 100644 tools/objtool/arch/powerpc/include/arch/cfi_regs.h
 create mode 100644 tools/objtool/arch/powerpc/include/arch/elf.h

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index b779603978e1..5ddafd3ce210 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -225,6 +225,7 @@ config PPC
 	select HAVE_MOD_ARCH_SPECIFIC
 	select HAVE_NMI				if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
 	select HAVE_OPTPROBES
+	select HAVE_OBJTOOL_MCOUNT
 	select HAVE_PERF_EVENTS
 	select HAVE_PERF_EVENTS_NMI		if PPC64
 	select HAVE_PERF_REGS
diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile
index 8404cf696954..06a9fcb4a0a3 100644
--- a/tools/objtool/Makefile
+++ b/tools/objtool/Makefile
@@ -49,6 +49,10 @@ ifeq ($(SRCARCH),x86)
 	SUBCMD_MCOUNT := y
 endif
 
+ifeq ($(SRCARCH),powerpc)
+        SUBCMD_MCOUNT := y
+endif
+
 export SUBCMD_CHECK SUBCMD_ORC SUBCMD_MCOUNT
 export srctree OUTPUT CFLAGS SRCARCH AWK
 include $(srctree)/tools/build/Makefile.include
diff --git a/tools/objtool/arch/powerpc/Build b/tools/objtool/arch/powerpc/Build
new file mode 100644
index 000000000000..3ff1f00c6a47
--- /dev/null
+++ b/tools/objtool/arch/powerpc/Build
@@ -0,0 +1 @@
+objtool-y += decode.o
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
new file mode 100644
index 000000000000..58988f88b315
--- /dev/null
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <objtool/check.h>
+#include <objtool/elf.h>
+#include <objtool/arch.h>
+#include <objtool/warn.h>
+#include <objtool/builtin.h>
+
+int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
+			    unsigned long offset, unsigned int maxlen,
+			    unsigned int *len, enum insn_type *type,
+			    unsigned long *immediate,
+			    struct list_head *ops_list)
+{
+	u32 insn;
+	unsigned int opcode;
+	u64 imm;
+
+	*immediate = imm = 0;
+	memcpy(&insn, sec->data->d_buf+offset, 4);
+	*len = 4;
+	*type = INSN_OTHER;
+
+	opcode = (insn >> 26);
+
+	switch (opcode) {
+	case 18: /* bl */
+		*type = INSN_CALL;
+		break;
+	}
+	*immediate = imm;
+	return 0;
+}
+
+unsigned long arch_dest_reloc_offset(int addend)
+{
+	return addend;
+}
+
+unsigned long arch_jump_destination(struct instruction *insn)
+{
+	return insn->offset +  insn->immediate;
+}
+
+const char *arch_nop_insn(int len)
+{
+	return NULL;
+}
diff --git a/tools/objtool/arch/powerpc/include/arch/cfi_regs.h b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
new file mode 100644
index 000000000000..1369176c8a94
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/cfi_regs.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_SP                  1
+#define CFI_TOC                 2
+#define CFI_R3                  3
+#define CFI_R4                  4
+#define CFI_R5                  5
+#define CFI_R6                  6
+#define CFI_R7                  7
+#define CFI_R8                  8
+#define CFI_R9                  9
+#define CFI_R10                 10
+#define CFI_R14                 14
+#define CFI_R15                 15
+#define CFI_R16                 16
+#define CFI_R17                 17
+#define CFI_R18                 18
+#define CFI_R19                 19
+#define CFI_R20                 20
+#define CFI_R21                 21
+#define CFI_R22                 22
+#define CFI_R23                 23
+#define CFI_R24                 24
+#define CFI_R25                 25
+#define CFI_R26                 26
+#define CFI_R27                 27
+#define CFI_R28                 28
+#define CFI_R29                 29
+#define CFI_R30                 30
+#define CFI_R31                 31
+#define CFI_LR                  32
+#define CFI_NUM_REGS            33
+
+#endif
diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
new file mode 100644
index 000000000000..3c8ebb7d2a6b
--- /dev/null
+++ b/tools/objtool/arch/powerpc/include/arch/elf.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_ARCH_ELF
+#define _OBJTOOL_ARCH_ELF
+
+#define R_NONE R_PPC_NONE
+
+#endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/utils.c b/tools/objtool/utils.c
index d1fc6a123a6e..c9c14fa0dfd7 100644
--- a/tools/objtool/utils.c
+++ b/tools/objtool/utils.c
@@ -179,11 +179,29 @@ int create_mcount_loc_sections(struct objtool_file *file)
 		loc = (unsigned long *)sec->data->d_buf + idx;
 		memset(loc, 0, sizeof(unsigned long));
 
-		if (elf_add_reloc_to_insn(file->elf, sec,
-					  idx * sizeof(unsigned long),
-					  R_X86_64_64,
-					  insn->sec, insn->offset))
-			return -1;
+		if (file->elf->ehdr.e_machine == EM_X86_64) {
+			if (elf_add_reloc_to_insn(file->elf, sec,
+						  idx * sizeof(unsigned long),
+						  R_X86_64_64,
+						  insn->sec, insn->offset))
+				return -1;
+		}
+
+		if (file->elf->ehdr.e_machine == EM_PPC64) {
+			if (elf_add_reloc_to_insn(file->elf, sec,
+						  idx * sizeof(unsigned long),
+						  R_PPC64_ADDR64,
+						  insn->sec, insn->offset))
+				return -1;
+		}
+
+		if (file->elf->ehdr.e_machine == EM_PPC) {
+			if (elf_add_reloc_to_insn(file->elf, sec,
+						  idx * sizeof(unsigned long),
+						  R_PPC_ADDR32,
+						  insn->sec, insn->offset))
+				return -1;
+		}
 
 		idx++;
 	}
-- 
2.31.1


  parent reply	other threads:[~2022-03-18 21:48 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18 10:51 [RFC PATCH 0/3] objtool: Add mcount sub-command Sathvika Vasireddy
2022-03-18 10:51 ` [RFC PATCH 1/3] objtool: Move common code to utils.c Sathvika Vasireddy
2022-03-23 18:02   ` Miroslav Benes
2022-03-18 10:51 ` [RFC PATCH 2/3] objtool: Enable and implement 'mcount' subcommand Sathvika Vasireddy
2022-03-21  7:06   ` Christophe Leroy
2022-03-21  8:19     ` Naveen N. Rao
2022-03-21  8:26       ` Christophe Leroy
2022-03-21  9:48         ` Naveen N. Rao
2022-03-18 10:51 ` Sathvika Vasireddy [this message]
2022-03-18 12:26   ` [RFC PATCH 3/3] objtool/mcount: Add powerpc specific functions Peter Zijlstra
2022-03-18 13:59     ` Christophe Leroy
2022-03-21  2:27       ` Michael Ellerman
2022-03-21  6:47         ` Christophe Leroy
2022-03-21  7:46         ` Christophe Leroy
2022-03-21  7:56         ` Christophe Leroy
2022-03-21  8:30           ` Christophe Leroy
2022-03-21  8:59             ` Christophe Leroy
2022-03-26  7:58           ` Christophe Leroy
2022-03-21  6:25     ` Naveen N. Rao
2022-03-27  9:09     ` Christophe Leroy
2022-03-28 19:59       ` Josh Poimboeuf
2022-03-28 20:14         ` Peter Zijlstra
2022-03-28 20:15           ` Peter Zijlstra
2022-03-28 20:21           ` Josh Poimboeuf
2022-03-29 12:01         ` Michael Ellerman
2022-03-29 17:32           ` Christophe Leroy
2022-03-30  4:26             ` Josh Poimboeuf
2022-03-30 18:40             ` Naveen N. Rao
2022-05-12 14:52         ` Christophe Leroy
2022-05-12 15:12           ` Josh Poimboeuf
2022-05-21  9:38             ` Christophe Leroy
2022-05-21 10:57               ` Peter Zijlstra
2022-05-23  5:39                 ` Naveen N. Rao
2022-03-19  1:35 ` [RFC PATCH 0/3] objtool: Add mcount sub-command Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220318105140.43914-4-sv@linux.ibm.com \
    --to=sv@linux.ibm.com \
    --cc=aik@ozlabs.ru \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).