2021-07-12 18:29:45

by Ben Dooks

[permalink] [raw]
Subject: [PATCH] riscv: add correct as-options for assembly in modules

When trying to load modules built for riscv which include assembly
the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'"
due to R_RISCV_ALIGN relocations being generated by the assembler.

In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading")
the fix for gcc adds -mno-relax to the command line when building
C files. However this was never applied to assembly flags, and gcc
does no pass -mno-relax to gas when presented with a .S file.

The fix (other than making gcc always pass -mno-relax to gas) is
to add -Wa,-mno-relax to gcc to make sure the as is invoked with
the right options.

Signed-off-by: Ben Dooks <[email protected]>
---
arch/riscv/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 1f5c03082976..fca40511a8c6 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -60,6 +60,7 @@ ifeq ($(CONFIG_PERF_EVENTS),y)
endif

KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
+KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)

# GCC versions that support the "-mstrict-align" option default to allowing
# unaligned accesses. While unaligned accesses are explicitly allowed in the
--
2.30.2


2021-07-16 10:27:00

by Ben Dooks

[permalink] [raw]
Subject: Re: [PATCH] riscv: add correct as-options for assembly in modules

On 12/07/2021 18:48, Ben Dooks wrote:
> When trying to load modules built for riscv which include assembly
> the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'"
> due to R_RISCV_ALIGN relocations being generated by the assembler.
>
> In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading")
> the fix for gcc adds -mno-relax to the command line when building
> C files. However this was never applied to assembly flags, and gcc
> does no pass -mno-relax to gas when presented with a .S file.
>
> The fix (other than making gcc always pass -mno-relax to gas) is
> to add -Wa,-mno-relax to gcc to make sure the as is invoked with
> the right options.
>
> Signed-off-by: Ben Dooks <[email protected]>

Just wanted to find out if anyone has had time to review this.
If this is ok, should we also send to -stable ?

> ---
> arch/riscv/Makefile | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
> index 1f5c03082976..fca40511a8c6 100644
> --- a/arch/riscv/Makefile
> +++ b/arch/riscv/Makefile
> @@ -60,6 +60,7 @@ ifeq ($(CONFIG_PERF_EVENTS),y)
> endif
>
> KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
> +KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
>
> # GCC versions that support the "-mstrict-align" option default to allowing
> # unaligned accesses. While unaligned accesses are explicitly allowed in the
>


--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

2021-07-16 10:46:06

by Bin Meng

[permalink] [raw]
Subject: Re: [PATCH] riscv: add correct as-options for assembly in modules

On Tue, Jul 13, 2021 at 2:28 AM Ben Dooks <[email protected]> wrote:
>
> When trying to load modules built for riscv which include assembly

nits: RISC-V

> the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'"
> due to R_RISCV_ALIGN relocations being generated by the assembler.
>
> In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading")
> the fix for gcc adds -mno-relax to the command line when building
> C files. However this was never applied to assembly flags, and gcc
> does no pass -mno-relax to gas when presented with a .S file.

does not pass

FYI

The GCC bug was fixed recently via:
https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

>
> The fix (other than making gcc always pass -mno-relax to gas) is
> to add -Wa,-mno-relax to gcc to make sure the as is invoked with
> the right options.
>
> Signed-off-by: Ben Dooks <[email protected]>
> ---
> arch/riscv/Makefile | 1 +
> 1 file changed, 1 insertion(+)
>

Otherwise,
Reviewed-by: Bin Meng <[email protected]>

2021-07-16 15:35:58

by Ben Dooks

[permalink] [raw]
Subject: Re: [PATCH] riscv: add correct as-options for assembly in modules

On 16/07/2021 11:44, Bin Meng wrote:
> On Tue, Jul 13, 2021 at 2:28 AM Ben Dooks <[email protected]> wrote:
>>
>> When trying to load modules built for riscv which include assembly
>
> nits: RISC-V
>
>> the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'"
>> due to R_RISCV_ALIGN relocations being generated by the assembler.
>>
>> In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading")
>> the fix for gcc adds -mno-relax to the command line when building
>> C files. However this was never applied to assembly flags, and gcc
>> does no pass -mno-relax to gas when presented with a .S file.
>
> does not pass

I'll see if I can make this simpler. Should this get done for a v2?

> FYI
>
> The GCC bug was fixed recently via:
> https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

thanks, I think it still useful to fix this in the kernel.

>>
>> The fix (other than making gcc always pass -mno-relax to gas) is
>> to add -Wa,-mno-relax to gcc to make sure the as is invoked with
>> the right options.
>>
>> Signed-off-by: Ben Dooks <[email protected]>
>> ---
>> arch/riscv/Makefile | 1 +
>> 1 file changed, 1 insertion(+)
>>
>
> Otherwise,
> Reviewed-by: Bin Meng <[email protected]>
>


--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

2021-07-16 22:40:19

by Bin Meng

[permalink] [raw]
Subject: Re: [PATCH] riscv: add correct as-options for assembly in modules

On Fri, Jul 16, 2021 at 11:33 PM Ben Dooks <[email protected]> wrote:
>
> On 16/07/2021 11:44, Bin Meng wrote:
> > On Tue, Jul 13, 2021 at 2:28 AM Ben Dooks <[email protected]> wrote:
> >>
> >> When trying to load modules built for riscv which include assembly
> >
> > nits: RISC-V
> >
> >> the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'"
> >> due to R_RISCV_ALIGN relocations being generated by the assembler.
> >>
> >> In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading")
> >> the fix for gcc adds -mno-relax to the command line when building
> >> C files. However this was never applied to assembly flags, and gcc
> >> does no pass -mno-relax to gas when presented with a .S file.
> >
> > does not pass
>
> I'll see if I can make this simpler. Should this get done for a v2?
>

Yes, please send v2.

> > FYI
> >
> > The GCC bug was fixed recently via:
> > https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857
>
> thanks, I think it still useful to fix this in the kernel.
>
> >>
> >> The fix (other than making gcc always pass -mno-relax to gas) is
> >> to add -Wa,-mno-relax to gcc to make sure the as is invoked with
> >> the right options.
> >>
> >> Signed-off-by: Ben Dooks <[email protected]>
> >> ---
> >> arch/riscv/Makefile | 1 +
> >> 1 file changed, 1 insertion(+)
> >>
> >
> > Otherwise,
> > Reviewed-by: Bin Meng <[email protected]>

Regards,
Bin