Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

objtool/powerpc: Enable objtool to be built on ppc

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

authored by

Sathvika Vasireddy and committed by
Michael Ellerman
e52ec98c 4ca993d4

+154
+1
arch/powerpc/Kconfig
··· 238 238 select HAVE_MOD_ARCH_SPECIFIC 239 239 select HAVE_NMI if PERF_EVENTS || (PPC64 && PPC_BOOK3S) 240 240 select HAVE_OPTPROBES 241 + select HAVE_OBJTOOL if PPC32 || MPROFILE_KERNEL 241 242 select HAVE_PERF_EVENTS 242 243 select HAVE_PERF_EVENTS_NMI if PPC64 243 244 select HAVE_PERF_REGS
+7
arch/powerpc/include/asm/asm.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _ASM_POWERPC_ASM_H 3 + #define _ASM_POWERPC_ASM_H 4 + 5 + #define _ASM_PTR " .long " 6 + 7 + #endif /* _ASM_POWERPC_ASM_H */
+2
tools/objtool/arch/powerpc/Build
··· 1 + objtool-y += decode.o 2 + objtool-y += special.o
+85
tools/objtool/arch/powerpc/decode.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <stdio.h> 4 + #include <stdlib.h> 5 + #include <objtool/check.h> 6 + #include <objtool/elf.h> 7 + #include <objtool/arch.h> 8 + #include <objtool/warn.h> 9 + #include <objtool/builtin.h> 10 + #include <objtool/endianness.h> 11 + 12 + unsigned long arch_dest_reloc_offset(int addend) 13 + { 14 + return addend; 15 + } 16 + 17 + bool arch_callee_saved_reg(unsigned char reg) 18 + { 19 + return false; 20 + } 21 + 22 + int arch_decode_hint_reg(u8 sp_reg, int *base) 23 + { 24 + exit(-1); 25 + } 26 + 27 + const char *arch_nop_insn(int len) 28 + { 29 + exit(-1); 30 + } 31 + 32 + const char *arch_ret_insn(int len) 33 + { 34 + exit(-1); 35 + } 36 + 37 + int arch_decode_instruction(struct objtool_file *file, const struct section *sec, 38 + unsigned long offset, unsigned int maxlen, 39 + unsigned int *len, enum insn_type *type, 40 + unsigned long *immediate, 41 + struct list_head *ops_list) 42 + { 43 + unsigned int opcode; 44 + enum insn_type typ; 45 + unsigned long imm; 46 + u32 insn; 47 + 48 + insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset)); 49 + opcode = insn >> 26; 50 + typ = INSN_OTHER; 51 + imm = 0; 52 + 53 + if (opcode == 1) 54 + *len = 8; 55 + else 56 + *len = 4; 57 + 58 + *type = typ; 59 + *immediate = imm; 60 + 61 + return 0; 62 + } 63 + 64 + unsigned long arch_jump_destination(struct instruction *insn) 65 + { 66 + return insn->offset + insn->immediate; 67 + } 68 + 69 + void arch_initial_func_cfi_state(struct cfi_init_state *state) 70 + { 71 + int i; 72 + 73 + for (i = 0; i < CFI_NUM_REGS; i++) { 74 + state->regs[i].base = CFI_UNDEFINED; 75 + state->regs[i].offset = 0; 76 + } 77 + 78 + /* initial CFA (call frame address) */ 79 + state->cfa.base = CFI_SP; 80 + state->cfa.offset = 0; 81 + 82 + /* initial LR (return address) */ 83 + state->regs[CFI_RA].base = CFI_CFA; 84 + state->regs[CFI_RA].offset = 0; 85 + }
+11
tools/objtool/arch/powerpc/include/arch/cfi_regs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + 3 + #ifndef _OBJTOOL_CFI_REGS_H 4 + #define _OBJTOOL_CFI_REGS_H 5 + 6 + #define CFI_BP 1 7 + #define CFI_SP CFI_BP 8 + #define CFI_RA 32 9 + #define CFI_NUM_REGS 33 10 + 11 + #endif
+8
tools/objtool/arch/powerpc/include/arch/elf.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + 3 + #ifndef _OBJTOOL_ARCH_ELF 4 + #define _OBJTOOL_ARCH_ELF 5 + 6 + #define R_NONE R_PPC_NONE 7 + 8 + #endif /* _OBJTOOL_ARCH_ELF */
+21
tools/objtool/arch/powerpc/include/arch/special.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + #ifndef _PPC_ARCH_SPECIAL_H 3 + #define _PPC_ARCH_SPECIAL_H 4 + 5 + #define EX_ENTRY_SIZE 8 6 + #define EX_ORIG_OFFSET 0 7 + #define EX_NEW_OFFSET 4 8 + 9 + #define JUMP_ENTRY_SIZE 16 10 + #define JUMP_ORIG_OFFSET 0 11 + #define JUMP_NEW_OFFSET 4 12 + #define JUMP_KEY_OFFSET 8 13 + 14 + #define ALT_ENTRY_SIZE 12 15 + #define ALT_ORIG_OFFSET 0 16 + #define ALT_NEW_OFFSET 4 17 + #define ALT_FEATURE_OFFSET 8 18 + #define ALT_ORIG_LEN_OFFSET 10 19 + #define ALT_NEW_LEN_OFFSET 11 20 + 21 + #endif /* _PPC_ARCH_SPECIAL_H */
+19
tools/objtool/arch/powerpc/special.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + #include <string.h> 3 + #include <stdlib.h> 4 + #include <objtool/special.h> 5 + #include <objtool/builtin.h> 6 + 7 + 8 + bool arch_support_alt_relocation(struct special_alt *special_alt, 9 + struct instruction *insn, 10 + struct reloc *reloc) 11 + { 12 + exit(-1); 13 + } 14 + 15 + struct reloc *arch_find_switch_table(struct objtool_file *file, 16 + struct instruction *insn) 17 + { 18 + exit(-1); 19 + }