]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool/powerpc: Enable objtool to be built on ppc
authorSathvika Vasireddy <sv@linux.ibm.com>
Mon, 14 Nov 2022 17:57:53 +0000 (23:27 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 18 Nov 2022 08:00:16 +0000 (19:00 +1100)
This patch adds [stub] implementations for required functions, inorder
to enable objtool build on powerpc.

[Christophe Leroy: powerpc: Add missing asm/asm.h for objtool,
Use local variables for type and imm in arch_decode_instruction(),
Adapt len for prefixed instructions.]

Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Reviewed-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20221114175754.1131267-16-sv@linux.ibm.com
arch/powerpc/Kconfig
arch/powerpc/include/asm/asm.h [new file with mode: 0644]
tools/objtool/arch/powerpc/Build [new file with mode: 0644]
tools/objtool/arch/powerpc/decode.c [new file with mode: 0644]
tools/objtool/arch/powerpc/include/arch/cfi_regs.h [new file with mode: 0644]
tools/objtool/arch/powerpc/include/arch/elf.h [new file with mode: 0644]
tools/objtool/arch/powerpc/include/arch/special.h [new file with mode: 0644]
tools/objtool/arch/powerpc/special.c [new file with mode: 0644]

index 699df27b0e2fc2f413c481e3e44ac22e2f134ce2..12e6c16be54e8a4f5c451a3315d42a31453107ee 100644 (file)
@@ -238,6 +238,7 @@ config PPC
        select HAVE_MOD_ARCH_SPECIFIC
        select HAVE_NMI                         if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
        select HAVE_OPTPROBES
+       select HAVE_OBJTOOL                     if PPC32 || MPROFILE_KERNEL
        select HAVE_PERF_EVENTS
        select HAVE_PERF_EVENTS_NMI             if PPC64
        select HAVE_PERF_REGS
diff --git a/arch/powerpc/include/asm/asm.h b/arch/powerpc/include/asm/asm.h
new file mode 100644 (file)
index 0000000..86f46b6
--- /dev/null
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_POWERPC_ASM_H
+#define _ASM_POWERPC_ASM_H
+
+#define _ASM_PTR       " .long "
+
+#endif /* _ASM_POWERPC_ASM_H */
diff --git a/tools/objtool/arch/powerpc/Build b/tools/objtool/arch/powerpc/Build
new file mode 100644 (file)
index 0000000..d24d563
--- /dev/null
@@ -0,0 +1,2 @@
+objtool-y += decode.o
+objtool-y += special.o
diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
new file mode 100644 (file)
index 0000000..dcd0975
--- /dev/null
@@ -0,0 +1,85 @@
+// 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>
+#include <objtool/endianness.h>
+
+unsigned long arch_dest_reloc_offset(int addend)
+{
+       return addend;
+}
+
+bool arch_callee_saved_reg(unsigned char reg)
+{
+       return false;
+}
+
+int arch_decode_hint_reg(u8 sp_reg, int *base)
+{
+       exit(-1);
+}
+
+const char *arch_nop_insn(int len)
+{
+       exit(-1);
+}
+
+const char *arch_ret_insn(int len)
+{
+       exit(-1);
+}
+
+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)
+{
+       unsigned int opcode;
+       enum insn_type typ;
+       unsigned long imm;
+       u32 insn;
+
+       insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
+       opcode = insn >> 26;
+       typ = INSN_OTHER;
+       imm = 0;
+
+       if (opcode == 1)
+               *len = 8;
+       else
+               *len = 4;
+
+       *type = typ;
+       *immediate = imm;
+
+       return 0;
+}
+
+unsigned long arch_jump_destination(struct instruction *insn)
+{
+       return insn->offset + insn->immediate;
+}
+
+void arch_initial_func_cfi_state(struct cfi_init_state *state)
+{
+       int i;
+
+       for (i = 0; i < CFI_NUM_REGS; i++) {
+               state->regs[i].base = CFI_UNDEFINED;
+               state->regs[i].offset = 0;
+       }
+
+       /* initial CFA (call frame address) */
+       state->cfa.base = CFI_SP;
+       state->cfa.offset = 0;
+
+       /* initial LR (return address) */
+       state->regs[CFI_RA].base = CFI_CFA;
+       state->regs[CFI_RA].offset = 0;
+}
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 (file)
index 0000000..59638eb
--- /dev/null
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef _OBJTOOL_CFI_REGS_H
+#define _OBJTOOL_CFI_REGS_H
+
+#define CFI_BP 1
+#define CFI_SP CFI_BP
+#define CFI_RA 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 (file)
index 0000000..3c8ebb7
--- /dev/null
@@ -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/arch/powerpc/include/arch/special.h b/tools/objtool/arch/powerpc/include/arch/special.h
new file mode 100644 (file)
index 0000000..ffef9ad
--- /dev/null
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _PPC_ARCH_SPECIAL_H
+#define _PPC_ARCH_SPECIAL_H
+
+#define EX_ENTRY_SIZE 8
+#define EX_ORIG_OFFSET 0
+#define EX_NEW_OFFSET 4
+
+#define JUMP_ENTRY_SIZE 16
+#define JUMP_ORIG_OFFSET 0
+#define JUMP_NEW_OFFSET 4
+#define JUMP_KEY_OFFSET 8
+
+#define ALT_ENTRY_SIZE 12
+#define ALT_ORIG_OFFSET 0
+#define ALT_NEW_OFFSET 4
+#define ALT_FEATURE_OFFSET 8
+#define ALT_ORIG_LEN_OFFSET 10
+#define ALT_NEW_LEN_OFFSET 11
+
+#endif /* _PPC_ARCH_SPECIAL_H */
diff --git a/tools/objtool/arch/powerpc/special.c b/tools/objtool/arch/powerpc/special.c
new file mode 100644 (file)
index 0000000..d338681
--- /dev/null
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <string.h>
+#include <stdlib.h>
+#include <objtool/special.h>
+#include <objtool/builtin.h>
+
+
+bool arch_support_alt_relocation(struct special_alt *special_alt,
+                                struct instruction *insn,
+                                struct reloc *reloc)
+{
+       exit(-1);
+}
+
+struct reloc *arch_find_switch_table(struct objtool_file *file,
+                                   struct instruction *insn)
+{
+       exit(-1);
+}