Live-Patching Archive mirror
 help / color / mirror / Atom feed
From: Youling Tang <tangyouling@loongson.cn>
To: Josh Poimboeuf <jpoimboe@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Huacai Chen <chenhuacai@kernel.org>,
	madvenka@linux.microsoft.com
Cc: chenzhongjin@huawei.com, WANG Xuerui <kernel@xen0n.name>,
	Xi Ruoyao <xry111@xry111.site>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
	loongarch@lists.linux.dev, tangyouling00@gmail.com,
	youling.tang@outlook.com
Subject: [RFC PATCH v1 17/23] LoongArch: Support R_LARCH_32_PCREL relocation type in kernel module
Date: Tue, 20 Jun 2023 15:52:04 +0800	[thread overview]
Message-ID: <1687247526-32258-3-git-send-email-tangyouling@loongson.cn> (raw)
In-Reply-To: <1687247526-32258-1-git-send-email-tangyouling@loongson.cn>

Fix "unsupported relocation type" errors caused by adding ORC support,
which generates unsupported relocation types.

The reason is because the generated '.rela.orc_unwind_ip' section will
contain the R_LARCH_32_PCCREL type.

Relocation section '.rela.orc_unwind_ip' at offset 0x1fb58 contains 600 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000000000  000300000063 R_LARCH_32_PCREL  0000000000000000 .text + 0
000000000004  000300000063 R_LARCH_32_PCREL  0000000000000000 .text + 64

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
 arch/loongarch/kernel/module.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/loongarch/kernel/module.c b/arch/loongarch/kernel/module.c
index 44f31b1958b1..3cc31701c76a 100644
--- a/arch/loongarch/kernel/module.c
+++ b/arch/loongarch/kernel/module.c
@@ -368,6 +368,15 @@ static int apply_r_larch_got_pc(struct module *mod,
 	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;
+}
+
 /*
  * reloc_handlers_rela() - Apply a particular relocation to a module
  * @mod: the module to apply the reloc to
@@ -397,6 +406,7 @@ static reloc_rela_handler reloc_rela_handlers[] = {
 	[R_LARCH_SOP_POP_32_S_10_5 ... R_LARCH_SOP_POP_32_U] = apply_r_larch_sop_imm_field,
 	[R_LARCH_ADD32 ... R_LARCH_SUB64]		     = apply_r_larch_add_sub,
 	[R_LARCH_PCALA_HI20...R_LARCH_PCALA64_HI12]	     = apply_r_larch_pcala,
+	[R_LARCH_32_PCREL]				     = apply_r_larch_32_pcrel,
 };
 
 int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
-- 
2.39.2


  parent reply	other threads:[~2023-06-20  7:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20  7:52 [RFC PATCH v1 15/23] objtool: Add ORC support for LoongArch Youling Tang
2023-06-20  7:52 ` [RFC PATCH v1 16/23] LoongArch: Add ORC unwinder support Youling Tang
2023-06-20  7:52 ` Youling Tang [this message]
2023-06-20  7:52 ` [RFC PATCH v1 18/23] LoongArch: Fix fpu.S objtool warning Youling Tang
2023-06-20  7:52 ` [RFC PATCH v1 19/23] LoongArch: Annotate unwind_hint Youling Tang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1687247526-32258-3-git-send-email-tangyouling@loongson.cn \
    --to=tangyouling@loongson.cn \
    --cc=chenhuacai@kernel.org \
    --cc=chenzhongjin@huawei.com \
    --cc=jpoimboe@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=madvenka@linux.microsoft.com \
    --cc=peterz@infradead.org \
    --cc=tangyouling00@gmail.com \
    --cc=xry111@xry111.site \
    --cc=youling.tang@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).