[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230613072644.10487-1-nylon.chen@sifive.com>
Date: Tue, 13 Jun 2023 15:26:44 +0800
From: Nylon Chen <nylon.chen@...ive.com>
To: linux-kernel@...r.kernel.org
Cc: linux-riscv@...ts.infradead.org, jszhang@...nel.org,
conor.dooley@...rochip.com, ajones@...tanamicro.com,
aou@...s.berkeley.edu, palmer@...belt.com,
paul.walmsley@...ive.com, greentime.hu@...ive.com,
zong.li@...ive.com, nylon7717@...il.com,
Nylon Chen <nylon.chen@...ive.com>
Subject: [PATCH] RISC-V: Support 32_PCREL relocation type in kernel module
Signed-off-by: Nylon Chen <nylon.chen@...ive.com>
---
arch/riscv/kernel/module.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 7c651d55fcbd..f52d8e3d4b63 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -310,6 +310,15 @@ static int apply_r_riscv_sub64_rela(struct module *me, u32 *location,
return 0;
}
+static int apply_r_riscv_pcrel_32_rela(struct module *me, u32 *location,
+ Elf_Addr v)
+{
+ ptrdiff_t offset = (void *)v - (void *)location;
+
+ *location = (*location & 0xffff0000) | (offset & 0xffff);
+ return 0;
+}
+
static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
Elf_Addr v) = {
[R_RISCV_32] = apply_r_riscv_32_rela,
@@ -335,6 +344,7 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
[R_RISCV_SUB16] = apply_r_riscv_sub16_rela,
[R_RISCV_SUB32] = apply_r_riscv_sub32_rela,
[R_RISCV_SUB64] = apply_r_riscv_sub64_rela,
+ [R_RISCV_32_PCREL] = apply_r_riscv_pcrel_32_rela,
};
int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
--
2.40.1
Powered by blists - more mailing lists