public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
@ 2023-06-15  7:23 Nylon Chen
  2023-06-15  7:36 ` Andreas Schwab
  2023-06-15  7:37 ` Conor Dooley
  0 siblings, 2 replies; 10+ messages in thread
From: Nylon Chen @ 2023-06-15  7:23 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-riscv, jszhang, ajones, conor.dooley, aou, palmer,
	paul.walmsley, greentime.hu, zong.li, nylon7717, Nylon Chen

Fix the 'unsupported relocation type' error caused by
enabling the -fasynchronous-unwind-tables flag,
which generates relocation types that are not supported.

Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
Reviewed-by: Zong Li <zong.li@sifive.com>
---
Changed in v2:
- add commit message.

 arch/riscv/kernel/module.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index 7c651d55fcbd..65be0360a494 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


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-06-15  7:23 [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module Nylon Chen
@ 2023-06-15  7:36 ` Andreas Schwab
  2023-06-15  7:37 ` Conor Dooley
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2023-06-15  7:36 UTC (permalink / raw)
  To: Nylon Chen
  Cc: linux-kernel, linux-riscv, jszhang, ajones, conor.dooley, aou,
	palmer, paul.walmsley, greentime.hu, zong.li, nylon7717

On Jun 15 2023, Nylon Chen wrote:

> Fix the 'unsupported relocation type' error caused by
> enabling the -fasynchronous-unwind-tables flag,
> which generates relocation types that are not supported.

arch/riscv/Makefile has
KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-06-15  7:23 [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module Nylon Chen
  2023-06-15  7:36 ` Andreas Schwab
@ 2023-06-15  7:37 ` Conor Dooley
       [not found]   ` <CAHh=Yk_=oZJ6eY3jJzLavub5rGsvY=MKv4tGXeiqkz+rgJHwDQ@mail.gmail.com>
  1 sibling, 1 reply; 10+ messages in thread
From: Conor Dooley @ 2023-06-15  7:37 UTC (permalink / raw)
  To: Nylon Chen
  Cc: linux-kernel, linux-riscv, jszhang, ajones, aou, palmer,
	paul.walmsley, greentime.hu, zong.li, nylon7717


[-- Attachment #1.1: Type: text/plain, Size: 1748 bytes --]

Hey Nylon, thanks for the update.

On Thu, Jun 15, 2023 at 03:23:02PM +0800, Nylon Chen wrote:
> Fix the 'unsupported relocation type' error caused by
> enabling the -fasynchronous-unwind-tables flag,
> which generates relocation types that are not supported.

What commit adds the -fasynchronous-unwind-tables flag?
Should there be a Fixes: tag for that commit?

Cheers,
Conor.

> 
> Signed-off-by: Nylon Chen <nylon.chen@sifive.com>
> Reviewed-by: Zong Li <zong.li@sifive.com>
> ---
> Changed in v2:
> - add commit message.
> 
>  arch/riscv/kernel/module.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
> index 7c651d55fcbd..65be0360a494 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
> 

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
       [not found]   ` <CAHh=Yk_=oZJ6eY3jJzLavub5rGsvY=MKv4tGXeiqkz+rgJHwDQ@mail.gmail.com>
@ 2023-06-15  8:07     ` Andreas Schwab
  2023-06-15  8:11     ` Conor Dooley
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2023-06-15  8:07 UTC (permalink / raw)
  To: Nylon Chen
  Cc: Conor Dooley, linux-kernel, linux-riscv, jszhang, ajones, aou,
	palmer, paul.walmsley, greentime.hu, zong.li, nylon7717

On Jun 15 2023, Nylon Chen wrote:

> I mean, when we use the flag "-fasynchronous-unwind-tables,"

Why?

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
       [not found]   ` <CAHh=Yk_=oZJ6eY3jJzLavub5rGsvY=MKv4tGXeiqkz+rgJHwDQ@mail.gmail.com>
  2023-06-15  8:07     ` Andreas Schwab
@ 2023-06-15  8:11     ` Conor Dooley
  2023-06-15  8:43       ` Nylon Chen
  1 sibling, 1 reply; 10+ messages in thread
From: Conor Dooley @ 2023-06-15  8:11 UTC (permalink / raw)
  To: Nylon Chen
  Cc: schwab, linux-kernel, linux-riscv, jszhang, ajones, aou, palmer,
	paul.walmsley, greentime.hu, zong.li, nylon7717


[-- Attachment #1.1: Type: text/plain, Size: 969 bytes --]

Hey Nylon,

Firstly, no html emails please :/

On Thu, Jun 15, 2023 at 03:52:27PM +0800, Nylon Chen wrote:
> Conor Dooley <conor.dooley@microchip.com<mailto:conor.dooley@microchip.com>> 於 2023年6月15日 週四 下午3:38寫道:
> > On Thu, Jun 15, 2023 at 03:23:02PM +0800, Nylon Chen wrote:
> > > Fix the 'unsupported relocation type' error caused by
> > > enabling the -fasynchronous-unwind-tables flag,
> > > which generates relocation types that are not supported.
> >
> > What commit adds the -fasynchronous-unwind-tables flag?
> sorry my description is not correct, please allow me to add
> 
> I mean, when we use the flag "-fasynchronous-unwind-tables," it generates
> the relocation type R_RISCV_32_PCCREL. However, this type is currently not
> supported, so an error will occur.

(snip)

> > Should there be a Fixes: tag for that commit?

> yes, I will do it.

What mainline commit actually enables this flag?

Cheers,
Conor.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-06-15  8:11     ` Conor Dooley
@ 2023-06-15  8:43       ` Nylon Chen
  2023-06-15  9:11         ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Nylon Chen @ 2023-06-15  8:43 UTC (permalink / raw)
  To: Conor Dooley
  Cc: schwab, linux-kernel, linux-riscv, jszhang, ajones, aou, palmer,
	paul.walmsley, greentime.hu, zong.li, nylon7717

On Thu, Jun 15, 2023 at 09:11:33AM +0100, Conor Dooley wrote:
Hi Conor,
> Hey Nylon,
> 
> Firstly, no html emails please :/
Sorry, my Gmail settings got messed up. I will be more careful in the future.
> 
> On Thu, Jun 15, 2023 at 03:52:27PM +0800, Nylon Chen wrote:
> > Conor Dooley <conor.dooley@microchip.com<mailto:conor.dooley@microchip.com>> 於 2023年6月15日 週四 下午3:38寫道:
> > > On Thu, Jun 15, 2023 at 03:23:02PM +0800, Nylon Chen wrote:
> > > > Fix the 'unsupported relocation type' error caused by
> > > > enabling the -fasynchronous-unwind-tables flag,
> > > > which generates relocation types that are not supported.
> > >
> > > What commit adds the -fasynchronous-unwind-tables flag?
> > sorry my description is not correct, please allow me to add
> > 
> > I mean, when we use the flag "-fasynchronous-unwind-tables," it generates
> > the relocation type R_RISCV_32_PCCREL. However, this type is currently not
> > supported, so an error will occur.
> 
> (snip)
> 
> > > Should there be a Fixes: tag for that commit?
> 
> > yes, I will do it.
> 
> What mainline commit actually enables this flag?
Because LLVM currently has it enabled by default(https://reviews.llvm.org/D145164), it will generate this
relocation type.

From what I know, GCC will also enable it in the future.

> 
> Cheers,
> Conor.



_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-06-15  8:43       ` Nylon Chen
@ 2023-06-15  9:11         ` Andreas Schwab
  2023-06-15  9:47           ` Nylon Chen
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Schwab @ 2023-06-15  9:11 UTC (permalink / raw)
  To: Nylon Chen
  Cc: Conor Dooley, linux-kernel, linux-riscv, jszhang, ajones, aou,
	palmer, paul.walmsley, greentime.hu, zong.li, nylon7717

On Jun 15 2023, Nylon Chen wrote:

> Because LLVM currently has it enabled by default(https://reviews.llvm.org/D145164), it will generate this
> relocation type.
>
>>From what I know, GCC will also enable it in the future.

That's why the kernel explicitly disables it.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-06-15  9:11         ` Andreas Schwab
@ 2023-06-15  9:47           ` Nylon Chen
  2023-08-21  7:51             ` Nylon Chen
  0 siblings, 1 reply; 10+ messages in thread
From: Nylon Chen @ 2023-06-15  9:47 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Conor Dooley, linux-kernel, linux-riscv, jszhang, ajones, aou,
	palmer, paul.walmsley, greentime.hu, zong.li, nylon7717

On Thu, Jun 15, 2023 at 11:11:49AM +0200, Andreas Schwab wrote:
> On Jun 15 2023, Nylon Chen wrote:
>
Hi Andreas,
> > Because LLVM currently has it enabled by default(https://reviews.llvm.org/D145164), it will generate this
> > relocation type.
> >
> >>From what I know, GCC will also enable it in the future.
> 
> That's why the kernel explicitly disables it.
Ok, thanks for your feedback, after I cross-tested, there is indeed no relevant relocation type generated.

If this error no longer occurs.

I am open to the idea of adding this patch to the upstream and would like to hear your thoughts on whether it is still necessary. 
> 
> -- 
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-06-15  9:47           ` Nylon Chen
@ 2023-08-21  7:51             ` Nylon Chen
  2023-08-21  8:01               ` Andreas Schwab
  0 siblings, 1 reply; 10+ messages in thread
From: Nylon Chen @ 2023-08-21  7:51 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Conor Dooley, linux-kernel, linux-riscv, jszhang, ajones, aou,
	palmer, paul.walmsley, greentime.hu, zong.li, nylon7717

Hi Andreas,

Currently, due to the lack of support for the unwind table in RISC-V,
we have disabled it.

If RISC-V were to support the unwind table in the future, would we
need to re-enable it? Would this require implementing related
changes(module relocation type handler) at that time?

Nylon Chen <nylon.chen@sifive.com> 於 2023年6月15日 週四 下午5:47寫道:


Nylon Chen <nylon.chen@sifive.com> 於 2023年6月15日 週四 下午5:47寫道:
>
> On Thu, Jun 15, 2023 at 11:11:49AM +0200, Andreas Schwab wrote:
> > On Jun 15 2023, Nylon Chen wrote:
> >
> Hi Andreas,
> > > Because LLVM currently has it enabled by default(https://reviews.llvm.org/D145164), it will generate this
> > > relocation type.
> > >
> > >>From what I know, GCC will also enable it in the future.
> >
> > That's why the kernel explicitly disables it.
> Ok, thanks for your feedback, after I cross-tested, there is indeed no relevant relocation type generated.
>
> If this error no longer occurs.
>
> I am open to the idea of adding this patch to the upstream and would like to hear your thoughts on whether it is still necessary.
> >
> > --
> > Andreas Schwab, SUSE Labs, schwab@suse.de
> > GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> > "And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module
  2023-08-21  7:51             ` Nylon Chen
@ 2023-08-21  8:01               ` Andreas Schwab
  0 siblings, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2023-08-21  8:01 UTC (permalink / raw)
  To: Nylon Chen
  Cc: Conor Dooley, linux-kernel, linux-riscv, jszhang, ajones, aou,
	palmer, paul.walmsley, greentime.hu, zong.li, nylon7717

On Aug 21 2023, Nylon Chen wrote:

> If RISC-V were to support the unwind table in the future, would we
> need to re-enable it? Would this require implementing related
> changes(module relocation type handler) at that time?

I'm not quite sure I understand your question.  Nothing in the kernel
makes use of unwind tables on RISC-V, so there is no point in generating
them.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-08-21  8:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-15  7:23 [PATCH v2] RISC-V: Support 32_PCREL relocation type in kernel module Nylon Chen
2023-06-15  7:36 ` Andreas Schwab
2023-06-15  7:37 ` Conor Dooley
     [not found]   ` <CAHh=Yk_=oZJ6eY3jJzLavub5rGsvY=MKv4tGXeiqkz+rgJHwDQ@mail.gmail.com>
2023-06-15  8:07     ` Andreas Schwab
2023-06-15  8:11     ` Conor Dooley
2023-06-15  8:43       ` Nylon Chen
2023-06-15  9:11         ` Andreas Schwab
2023-06-15  9:47           ` Nylon Chen
2023-08-21  7:51             ` Nylon Chen
2023-08-21  8:01               ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox