Skip to content

Commit e52ec98

Browse files
sathvika-vmpe
authored andcommitted
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 <[email protected]> Reviewed-by: Naveen N. Rao <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Signed-off-by: Sathvika Vasireddy <[email protected]> Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4ca993d commit e52ec98

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ config PPC
238238
select HAVE_MOD_ARCH_SPECIFIC
239239
select HAVE_NMI if PERF_EVENTS || (PPC64 && PPC_BOOK3S)
240240
select HAVE_OPTPROBES
241+
select HAVE_OBJTOOL if PPC32 || MPROFILE_KERNEL
241242
select HAVE_PERF_EVENTS
242243
select HAVE_PERF_EVENTS_NMI if PPC64
243244
select HAVE_PERF_REGS

arch/powerpc/include/asm/asm.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 */

tools/objtool/arch/powerpc/Build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
objtool-y += decode.o
2+
objtool-y += special.o

tools/objtool/arch/powerpc/decode.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 */

tools/objtool/arch/powerpc/special.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)