2021-12-08 19:54:35

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
CFLAGS have -mno-relax added. This however does not get applied to
KBUILD_AFLAGS_MODULE so when a module builds a .S file, the -mno-relax
is not passed and the above error is seen. Fix it by adding the flags
'-Wa,-mno-relax' to KBUILD_AFLAGS_MODULE.

This may have been fixed in gcc, in:
https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

Signed-off-by: Ben Dooks <[email protected]>
--
Changes since v1:
- added Bin Meng's review of the original patch
---
arch/riscv/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 0289a97325d1..cf2ea9a1ac20 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -58,6 +58,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.33.0



2022-01-10 16:11:56

by Ben Dooks

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

On 08/12/2021 19:26, 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
> CFLAGS have -mno-relax added. This however does not get applied to
> KBUILD_AFLAGS_MODULE so when a module builds a .S file, the -mno-relax
> is not passed and the above error is seen. Fix it by adding the flags
> '-Wa,-mno-relax' to KBUILD_AFLAGS_MODULE.
>
> This may have been fixed in gcc, in:
> https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

Can I just check this can be included in the next release?

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

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

2022-01-11 07:41:52

by Bin Meng

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

On Thu, Dec 9, 2021 at 3:26 AM Ben Dooks <[email protected]> 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
> CFLAGS have -mno-relax added. This however does not get applied to
> KBUILD_AFLAGS_MODULE so when a module builds a .S file, the -mno-relax
> is not passed and the above error is seen. Fix it by adding the flags
> '-Wa,-mno-relax' to KBUILD_AFLAGS_MODULE.
>
> This may have been fixed in gcc, in:
> https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857
>
> Signed-off-by: Ben Dooks <[email protected]>
> --
> Changes since v1:
> - added Bin Meng's review of the original patch

Looks like you forgot to include the RB tag? :)

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

> ---
> arch/riscv/Makefile | 1 +
> 1 file changed, 1 insertion(+)
>

Regards,
Bin

2022-05-30 00:42:45

by Ben Dooks

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

On 29/05/2022 16:19, 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
> CFLAGS have -mno-relax added. This however does not get applied to
> KBUILD_AFLAGS_MODULE so when a module builds a .S file, the -mno-relax
> is not passed and the above error is seen. Fix it by adding the flags
> '-Wa,-mno-relax' to KBUILD_AFLAGS_MODULE.
>
> This may have been fixed in gcc, in:
> https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857
>
> Signed-off-by: Ben Dooks <[email protected]>
> Reviewed-by: Bin Meng <[email protected]>
Apologies, this was the wrong branch. Will resen

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

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