Unverified Commit c4ccaf3b authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!2694 LoongArch: add 32/64 pc relative relocation type support

Merge Pull Request from: @ci-robot 
 
PR sync from: Hongchen Zhang <zhanghongchen@loongson.cn>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/ANT5VOVG52XBNQIILVP7JWYCGQQXZDEZ/ 
Hongchen Zhang (3):
  LoongArch: Define relocation types for ABI v2.10
  LoongArch: Add support for 32_PCREL relocation type
  LoongArch: Add support for 64_PCREL relocation type


-- 
2.33.0
 
https://gitee.com/openeuler/kernel/issues/I8C3BV 
 
Link:https://gitee.com/openeuler/kernel/pulls/2694

 

Reviewed-by: default avatarLi Xuefeng <lixuefeng@loongson.cn>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents b45a4c0d 5de9501c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -111,6 +111,15 @@
#define R_LARCH_TLS_GD_HI20			98
#define R_LARCH_32_PCREL			99
#define R_LARCH_RELAX				100
#define R_LARCH_DELETE				101
#define R_LARCH_ALIGN				102
#define R_LARCH_PCREL20_S2			103
#define R_LARCH_CFA				104
#define R_LARCH_ADD6				105
#define R_LARCH_SUB6				106
#define R_LARCH_ADD_ULEB128			107
#define R_LARCH_SUB_ULEB128			108
#define R_LARCH_64_PCREL			109

#ifndef ELF_ARCH

+21 −1
Original line number Diff line number Diff line
@@ -372,6 +372,24 @@ static int apply_r_larch_got_pc(struct module *mod, u32 *location, Elf_Addr v,
	return apply_r_larch_pcala(mod, location, got, rela_stack, rela_stack_top, type);
}

static int apply_r_larch_32_pcrel(struct module *mod, u32 *location, Elf_Addr v,
				  s64 *rela_stack, size_t *rela_stack_top, unsigned int type)
{
	ptrdiff_t offset = (void *)v - (void *)location;

	*(u32 *)location = offset;
	return 0;
}

static int apply_r_larch_64_pcrel(struct module *mod, u32 *location, Elf_Addr v,
				  s64 *rela_stack, size_t *rela_stack_top, unsigned int type)
{
	ptrdiff_t offset = (void *)v - (void *)location;

	*(u64 *)location = offset;
	return 0;
}

/*
 * reloc_handlers_rela() - Apply a particular relocation to a module
 * @mod: the module to apply the reloc to
@@ -387,7 +405,7 @@ typedef int (*reloc_rela_handler)(struct module *mod, u32 *location, Elf_Addr v,

/* The handlers for known reloc types */
static reloc_rela_handler reloc_rela_handlers[] = {
	[R_LARCH_NONE ... R_LARCH_RELAX]		     = apply_r_larch_error,
	[R_LARCH_NONE ... R_LARCH_64_PCREL]		     = apply_r_larch_error,

	[R_LARCH_NONE]					     = apply_r_larch_none,
	[R_LARCH_32]					     = apply_r_larch_32,
@@ -404,6 +422,8 @@ static reloc_rela_handler reloc_rela_handlers[] = {
	[R_LARCH_B26]					     = apply_r_larch_b26,
	[R_LARCH_PCALA_HI20...R_LARCH_PCALA64_HI12]	     = apply_r_larch_pcala,
	[R_LARCH_GOT_PC_HI20...R_LARCH_GOT_PC_LO12]	     = apply_r_larch_got_pc,
	[R_LARCH_32_PCREL]				     = apply_r_larch_32_pcrel,
	[R_LARCH_64_PCREL]				     = apply_r_larch_64_pcrel,
};

int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,