Commit e8aff71c authored by Tiezhu Yang's avatar Tiezhu Yang Committed by Huacai Chen
Browse files

objtool/LoongArch: Enable objtool to be built



Add the minimal changes to enable objtool build on LoongArch,
most of the functions are stubs to only fix the build errors
when make -C tools/objtool.

This is similar with commit e52ec98c ("objtool/powerpc:
Enable objtool to be built on ppc").

Co-developed-by: default avatarJinyang He <hejinyang@loongson.cn>
Signed-off-by: default avatarJinyang He <hejinyang@loongson.cn>
Co-developed-by: default avatarYouling Tang <tangyouling@loongson.cn>
Signed-off-by: default avatarYouling Tang <tangyouling@loongson.cn>
Signed-off-by: default avatarTiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
parent e8f897f4
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
objtool-y += decode.o
objtool-y += special.o
+71 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string.h>
#include <objtool/check.h>

int arch_ftrace_match(char *name)
{
	return !strcmp(name, "_mcount");
}

unsigned long arch_jump_destination(struct instruction *insn)
{
	return insn->offset + (insn->immediate << 2);
}

unsigned long arch_dest_reloc_offset(int addend)
{
	return addend;
}

bool arch_pc_relative_reloc(struct reloc *reloc)
{
	return false;
}

bool arch_callee_saved_reg(unsigned char reg)
{
	switch (reg) {
	case CFI_RA:
	case CFI_FP:
	case CFI_S0 ... CFI_S8:
		return true;
	default:
		return false;
	}
}

int arch_decode_hint_reg(u8 sp_reg, int *base)
{
	return 0;
}

int arch_decode_instruction(struct objtool_file *file, const struct section *sec,
			    unsigned long offset, unsigned int maxlen,
			    struct instruction *insn)
{
	return 0;
}

const char *arch_nop_insn(int len)
{
	return NULL;
}

const char *arch_ret_insn(int len)
{
	return NULL;
}

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;
}
+22 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef _OBJTOOL_ARCH_CFI_REGS_H
#define _OBJTOOL_ARCH_CFI_REGS_H

#define CFI_RA		1
#define CFI_SP		3
#define CFI_A0		4
#define CFI_FP		22
#define CFI_S0		23
#define CFI_S1		24
#define CFI_S2		25
#define CFI_S3		26
#define CFI_S4		27
#define CFI_S5		28
#define CFI_S6		29
#define CFI_S7		30
#define CFI_S8		31
#define CFI_NUM_REGS	32

#define CFI_BP		CFI_FP

#endif /* _OBJTOOL_ARCH_CFI_REGS_H */
+30 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef _OBJTOOL_ARCH_ELF_H
#define _OBJTOOL_ARCH_ELF_H

/*
 * See the following link for more info about ELF Relocation types:
 * https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_relocations
 */
#ifndef R_LARCH_NONE
#define R_LARCH_NONE		0
#endif
#ifndef R_LARCH_32
#define R_LARCH_32		1
#endif
#ifndef R_LARCH_64
#define R_LARCH_64		2
#endif
#ifndef R_LARCH_32_PCREL
#define R_LARCH_32_PCREL	99
#endif

#define R_NONE			R_LARCH_NONE
#define R_ABS32			R_LARCH_32
#define R_ABS64			R_LARCH_64
#define R_DATA32		R_LARCH_32_PCREL
#define R_DATA64		R_LARCH_32_PCREL
#define R_TEXT32		R_LARCH_32_PCREL
#define R_TEXT64		R_LARCH_32_PCREL

#endif /* _OBJTOOL_ARCH_ELF_H */
+33 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-or-later */
#ifndef _OBJTOOL_ARCH_SPECIAL_H
#define _OBJTOOL_ARCH_SPECIAL_H

/*
 * See more info about struct exception_table_entry
 * in arch/loongarch/include/asm/extable.h
 */
#define EX_ENTRY_SIZE		12
#define EX_ORIG_OFFSET		0
#define EX_NEW_OFFSET		4

/*
 * See more info about struct jump_entry
 * in include/linux/jump_label.h
 */
#define JUMP_ENTRY_SIZE		16
#define JUMP_ORIG_OFFSET	0
#define JUMP_NEW_OFFSET		4
#define JUMP_KEY_OFFSET		8

/*
 * See more info about struct alt_instr
 * in arch/loongarch/include/asm/alternative.h
 */
#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 /* _OBJTOOL_ARCH_SPECIAL_H */
Loading